Skip to content

fix(express): handle circular request bodies in error redaction - #10032

Merged
MohammedRyaan786 merged 1 commit into
masterfrom
COINS-1940-fix-express-redaction-recursion
Oct 23, 2026
Merged

MohammedRyaan786 merged 1 commit into
masterfrom
COINS-1940-fix-express-redaction-recursion

Conversation

@MohammedRyaan786

@MohammedRyaan786 MohammedRyaan786 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a send route fails partway through, BitGo Express hangs and never responds. The client eventually gets a 503 Response timeout.

Root cause

  • createSendParams / createTSSSendParams passed req.body itself to the SDK.
  • During prebuild, sdk-core runs Object.assign(params, { wallet: this }), so req.body ended up holding a self-referencing Wallet.
  • If the send then failed, handleRequestHandlerError walked req.body to collect secrets for redaction. collectSensitiveRequestValues had no cycle check, so it threw RangeError: Maximum call stack size exceeded.
  • That rejection was never handled, so no response was ever sent.

This reproduces on Express 17.x with a TZEC multi-recipient sendmany. Single-recipient sends succeed, so they never reach the error handler.

Changes (modules/express/src/clientRoutes.ts)

  • createSendParams and createTSSSendParams now pass the SDK a shallow copy of req.body (cloneRequestBody), so the SDK's changes to its params don't end up on req.body. The externalSignerUrl branches already spread the body. Every handler finishes writing to req.body (reqId, eip1559, …) before the copy is made, and none reads it after the SDK call.
  • collectSensitiveRequestValues tracks objects it has already visited in a WeakSet, so circular values can't recurse forever.
  • redactSensitiveValues tracks the objects on the current path. A real cycle comes out as '[Circular]'; an object referenced from two places is still redacted in both. This covers circular err.result payloads.

This fixes the Express hang. Failed sends now return their real error, properly redacted. It does not fix the underlying ZEC multi-recipient sendmany error, which is still tracked under COINS-1940 and can be diagnosed once Express returns it.

Issue Number

COINS-1940

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Reproduced locally: a two-recipient TZEC sendmany through Express hung with RangeError: Maximum call stack size exceeded in collectSensitiveRequestValues, then 503 Response timeout.
  • test/unit/clientRoutes/index.ts, "should handle circular request bodies while redacting errors": runs promiseWrapper with a circular request body and a circular err.result. It checks for a 500 response, the message failed with [REDACTED], result.secret redacted, and result.self set to '[Circular]'.
  • test/unit/typedRoutes/sendmany.ts, "should redact secrets when sendMany mutates the cloned params and then fails": goes through the real /sendmany route. A mocked wallet.sendMany attaches a self-referencing wallet to its params, deletes walletPassphrase, and throws an error that contains the passphrase. The test checks for a 400 with failed to sign with [REDACTED], no passphrase in the response or the logs, and that the SDK received a copy rather than the request body. It fails when createSendParams returns req.body directly.
  • Ran npx mocha test/unit/typedRoutes/sendmany.ts (sendmany cases) locally. CI is green on Node 22/24/26 and in the browser test.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My commits follow Conventional Commits and I have properly described any BREAKING CHANGES
  • The ticket or github issue was included in the commit message as a reference
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

🤖 Generated with Claude Code

https://claude.ai/code/session_017jhLrU9uZW7fCwMPnqSQ6b

@linear-code

linear-code Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

COINS-1940

@MohammedRyaan786
MohammedRyaan786 force-pushed the COINS-1940-fix-express-redaction-recursion branch from 445f797 to 4817b69 Compare October 22, 2026 17:18
@MohammedRyaan786

Copy link
Copy Markdown
Contributor Author

@claude please review the PR for correctness and provide a verdict

@MohammedRyaan786
MohammedRyaan786 marked this pull request as ready for review October 22, 2026 17:32
@MohammedRyaan786
MohammedRyaan786 requested review from a team as code owners October 22, 2026 17:32

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

@kisslove-dewangan

Copy link
Copy Markdown
Contributor

@claude review thoroughly and give approval rating

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

Comment thread modules/express/src/clientRoutes.ts Resolved
@MohammedRyaan786
MohammedRyaan786 force-pushed the COINS-1940-fix-express-redaction-recursion branch from 4817b69 to ddb9fad Compare October 23, 2026 10:39
Ticket: COINS-1940

Co-authored-by: Ralph CLI <ralph-cli@bitgo.com>
Ralph: 18.12.3-bitgo.3 openrouter/z-ai/glm-5.3-flash@smol openrouter/google/gemini-3.8-flash@commit openrouter/z-ai/glm-5.3@task+plan openrouter/openai/gpt-5.6-luna@advisor+slow openrouter/openai/gpt-5.6-luna-pro@default
@MohammedRyaan786
MohammedRyaan786 force-pushed the COINS-1940-fix-express-redaction-recursion branch from ddb9fad to 9621bbd Compare October 23, 2026 10:42
@pranishnepal

Copy link
Copy Markdown
Contributor

@claude review

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

@MohammedRyaan786
MohammedRyaan786 merged commit 02a718e into master Oct 23, 2026
40 of 42 checks passed
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.

3 participants