/algo-trading-skills:sandbox-credential-leakage-preventionfrom algo-trading-skills
Prevents credential leakage in dual-mode trading apps by validating outbound broker requests against an allow-list of environment-specific endpoints. Refuses unrecognized destinations and sanitizes secrets from logs.
Ships in algo-trading-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Use this skill when a trading application runs in dual modes — paper/sandbox and live production — and a single misrouted request would either burn real capital or silently reject a paper order. CredentialEnvironmentGuard.validate_request_boundary() is a veto gate called immediately before each outbound broker HTTP call: it parses the destination URL and requires the hostname (plus a path prefix, where the venue separates environments by path) to positively match an endpoint declared for the environment the process says it is running in.
The design decision that matters is allow-list, not deny-list. A guard built as "reject the URL if it contains a known live hostname" approves every destination its author did not think to enumerate — including look-alike domains, hosts the venue added after the rules were written, and any URL where the word paper happens to appear in a query parameter. This engine inverts that: the request is refused unless it is recognised. An unknown broker is a violation, not a pass.
Its second job is not becoming a leak itself. Broker URLs routinely carry secrets in the query string (Binance appends &signature=<hmac> to signed REST calls). Every URL reaching an exception message or a log line is stripped of userinfo, query, and fragment first.
api-key-least-privilege-audit-tool).alpaca-paper-live-key-separation adds a live GET /v2/account probe of the is_paper flag and an ALLOW_LIVE_TRADING gate. This guard validates the request boundary; it never contacts the broker and so cannot detect that correct-looking credentials belong to the wrong account.centralized-secrets-management-vault-integration and secrets-rotation-without-bot-downtime.TradingEnvironment (SANDBOX or PRODUCTION) sourced from deployment configuration, not inferred from a URL or a key.BrokerEnvironmentRules per broker in use: broker_name, sandbox_endpoints, production_endpoints, and optionally sandbox_key_prefixes / production_key_prefixes. Endpoints are "host" or "host/path/prefix" shorthand, or EndpointRule objects.Declare the environment once, at process start.
CredentialEnvironmentGuard(TradingEnvironment.SANDBOX | PRODUCTION). Passing anything other than the enum raises TypeError rather than being coerced.allow_unknown_brokers at its default False. Setting it True disables the boundary check for unregistered brokers and logs a warning each time — treat it as an explicit, reviewed risk acceptance, never a convenience default.Validate the destination URL structurally, before comparing it to anything.
https schemes: an http:// broker call sends the API key in cleartext headers.https://[email protected]/v2/orders reads as the Alpaca host and resolves to evil.example; credentials in a URL are the leak this skill exists to stop.Match the destination against the environment's allow-list, on parsed components.
"api.alpaca.markets" in url also matches https://api.alpaca.markets.attacker.example/v2/orders.gateway.saxobank.com/sim/openapi and live is gateway.saxobank.com/openapi on the same hostname, so a host-only check treats live and sim as interchangeable./sim/openapi/../../openapi/port/v1/orders is judged as the live path it actually resolves to.Treat the key prefix as corroboration, never as the decision.
AK… in sandbox mode) is a hard violation — that is a high-confidence positive signal.PK/AK convention is not a contract; Binance keys and Saxo OAuth tokens have no prefix whatsoever. Absence of a prefix proves nothing, and blocking on it would break every venue without a prefix scheme.ak_live_… is still a production-shaped key.Redact before reporting. Strip userinfo, query, and fragment from every URL that reaches a SecurityViolationError message or a log record. Never log the API key; report only which prefix matched.
Review the shipped allow-list on a schedule. iter_declared_endpoints() dumps every (broker, environment, endpoint) triple for diffing against current vendor documentation. Venues add and retire hosts without changing their API version — Binance alone serves production spot from six hostnames.
Full procedure: see
references/workflows.md. Endpoint facts and citations: seereferences/standards.md. Printable pre-flight checklist: seeassets/checklist.md.
"paper" in url approves https://api.alpaca.markets/v2/orders?client_tag=paper — a live order, in sandbox mode, blessed by the guard because an unrelated query parameter contained the word. Any allow or deny decision driven by attacker- or operator-controlled URL text is not a control.https://attacker.example/v2/orders approved, and with it the live credential in the request headers. Both directions need a positive match.True there converts the guard into decoration. Fail closed and make the operator register the broker or opt out in writing.data-api.binance.vision and the spot testnet from testnet.binance.vision — same domain, opposite environments.PK/AK is an observed Alpaca convention, not a documented one, and most venues have no prefix at all. Gate on the endpoint; corroborate with the prefix.&signature=<hmac>; an OAuth callback carries the token. A leak-prevention guard that writes those into logs and tracebacks has become the leak.validate_request_boundary() — a health check, a retry helper, a vendored SDK — is the path the bad request will take.CredentialEnvironmentGuard(SANDBOX) with PK… to https://paper-api.alpaca.markets/v2/orders $\implies$ returns True.https://api.alpaca.markets/v2/orders?client_tag=paper $\implies$ raises SecurityViolationError("ENDPOINT LEAK DETECTED…"). This is the regression case: the previous substring implementation approved it.CredentialEnvironmentGuard(PRODUCTION) with AK… to https://api.alpaca.markets.attacker.example/v2/orders $\implies$ raises SecurityViolationError, message containing not a recognised.CredentialEnvironmentGuard(PRODUCTION) with a PK… key $\implies$ raises SecurityViolationError("CREDENTIAL LEAK DETECTED…").SecurityViolationError unless allow_unknown_brokers=True was passed explicitly.&signature=<secret> $\implies$ the secret does not appear in the raised message.python -m unittest discover -s skills/sandbox-credential-leakage-prevention/scripts (46 tests).alpaca-paper-live-key-separationbinance-futures-testnet-to-mainnet-promotionsandbox-vs-production-endpoint-driftcentralized-secrets-management-vault-integrationpaper-to-live-promotion-checklistWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub himanshuj16/algo-trading-skills --plugin algo-trading-broker-integration36 skills in this plugin
/alpaca-paper-live-key-separationUse when a bot connects to the Alpaca Trading API and must never cross paper keys with the live endpoint; pins the base URL per environment, checks the key prefix, probes /v2/account and requires an explicit ALLOW_LIVE_TRADING flag./api-key-least-privilege-audit-toolUse before deploying a live bot, to audit existing broker API keys for scopes they do not need. Flags withdrawal, transfer and admin rights that turn a leaked execution key into theft./broker-account-margin-call-handlingUse when a bot trades a Reg T, portfolio or futures margin account and must act before the broker liquidates: tiered maintenance-margin warnings cross-checked against broker excess liquidity, initial-margin order gating and liquidity-aware de-leveraging.Other plugins' skills for the same job