Skip to content

fix(sdk-api): guard v1 auth path against undefined accessToken in testnet - #9405

Draft
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
wci-1213-fix-undefined-access-token-testnet
Draft

fix(sdk-api): guard v1 auth path against undefined accessToken in testnet#9405
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
wci-1213-fix-undefined-access-token-testnet

Conversation

@bitgo-ai-agent-dev

Copy link
Copy Markdown
Contributor

What

  • In `_sendRequestWithHmac` (modules/sdk-api/src/bitgoAPI.ts), moved the `this._token &&` guard outside the v1-auth condition so `req.forceV1Auth = true` can no longer bypass the token check.
  • Old condition: `(this._token && A && B) || req.forceV1Auth` — when token is undefined and `forceV1Auth` is set, the expression is truthy, causing `Authorization: 'Bearer undefined'` to be sent.
  • New condition: `this._token && (A && B || req.forceV1Auth)` — the v1 path is only entered when a token is actually present.
  • Added two unit tests asserting the header is never `'Bearer undefined'` when `accessToken` is not provided.

Why

  • When `BitGoAPI` is constructed with `accessToken: process.env.TESTNET_ACCESS_TOKEN` and the environment variable is not set, `accessToken` is `undefined`. In the v1 auth path, JavaScript string concatenation converts this to `'Bearer undefined'`, which the server rejects with an "undefined access token" error in testnet.

Test plan

  • New unit tests in `modules/sdk-api/test/unit/bitgoAPI.ts` cover both normal authenticate and `forceV1Auth` paths with an undefined accessToken
  • Existing SDK-API unit tests continue to pass

Ticket: WCI-1213

…tnet

When BitGoAPI is constructed with accessToken: undefined (e.g.
TESTNET_ACCESS_TOKEN env var not set) and a request sets
forceV1Auth = true, the v1 auth condition previously evaluated as:

  (undefined && ...) || true  →  true

causing the request to set Authorization: 'Bearer undefined',
which the server rejects with an 'undefined access token' error.

Fix: require this._token to be truthy before entering the v1 path,
so forceV1Auth cannot bypass the token guard. Unauthenticated
requests now proceed without an Authorization header (the existing
behaviour for requests with no token) rather than sending a
literally-undefined bearer value.

Ticket: WCI-1213
Session-Id: 90ff7750-f83b-4600-a00a-fb07afa1cb4a
Task-Id: a55a5860-e651-49e1-9ea1-0867be6b19d3
@ralph-bitgo
ralph-bitgo Bot force-pushed the wci-1213-fix-undefined-access-token-testnet branch from dedbd32 to d73cfab Compare August 3, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants