Repository navigation
Conversation
`stripe.webhooks` is a single object shared by every Stripe client (stripe 9, 10, early 11.x and 18+), but the instrumentation wrapped `constructEvent` and `constructEventAsync` again on every `new Stripe()`. Each client added one wrapper layer, so processes that create clients per request eventually threw `RangeError: Maximum call stack size exceeded` on webhook verification, and with AppSec enabled every webhook published once per client created. Track the wrappers we install and skip methods that are already wrapped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 4 Pipeline jobs failed
Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 3fd7d41 | Docs | View more details | Give us feedback! |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
BridgeAR
left a comment
There was a problem hiding this comment.
Change LGTM (the test should be more resilient, while that can land afterwards)
There was a problem hiding this comment.
More details
Isolated checks using the actual instrumentation and Shimmer support retaining one wrapper per shared Stripe method across repeated client creation. The full Stripe suite remains unverified because dependencies are absent.
🤖 Bits Code Review · Commit ebec24d
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db5b8d5eb3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| // `webhooks` is shared by every Stripe instance, so wrapping it on each | ||
| // construction would stack one wrapper per client until the stack overflows | ||
| function wrapOnce (target, name, wrapper) { |
There was a problem hiding this comment.
Type the new wrapOnce parameters
wrapOnce is a newly introduced production helper with three parameters but no TypeScript-compatible JSDoc types. Add concrete parameter types for the target object, property name, and wrapper so the helper's contract remains statically checkable (without adding a primitive @returns tag).
AGENTS.md reference: AGENTS.md:L105-L108
Useful? React with 👍 / 👎.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@BridgeAR thanks for the approval! I added the JSDoc types Codex asked for on |
ratomirjovanovic
left a comment
There was a problem hiding this comment.
Checked this against stripe-node across the hooked range. Sharing of webhooks differs by major: 9 to 11 assign the module singleton (this.webhooks = require('./Webhooks')), 12 to 17 build a fresh object per client (this.webhooks = createWebhooks(platformFunctions), and 17 uses createWebhooksDefault()), and 18+ reuse the static Stripe.webhooks created in initialize(). Keying the guard on the function value rather than on the target is the right call because of that: per-client objects in 12 to 17 still get their own wrapper, and the shared ones only get one. Two small points inline, neither blocking.
|
|
||
| const wrappedMethods = new WeakSet() | ||
|
|
||
| // `webhooks` is shared by every Stripe instance, so wrapping it on each |
There was a problem hiding this comment.
Nit: this is true for stripe 9 to 11 and 18+, but 12 to 17 create a new webhooks object per client, so nothing stacked there. Maybe "webhooks is shared by every Stripe instance in most versions" so nobody later moves this to a one-time wrap on Stripe.webhooks at hook time, which would miss 12 to 17 (there Stripe.webhooks is the createWebhooks factory, not the object).
|
|
||
| it('does not stack wrappers when many clients are created', async () => { | ||
| let stripe | ||
| for (let i = 0; i < 20_000; i++) { |
There was a problem hiding this comment.
The publishes assertions already catch the regression with two clients: two stacked wrappers publish twice. 20k constructions only reproduce the stack overflow, and each one instantiates every resource class, for each version withVersions runs. Something like new Stripe(...) twice plus assert.equal(publishes, 1) keeps the coverage and avoids the timing risk. On the shared-object versions you could also assert a.webhooks.constructEvent === b.webhooks.constructEvent.
|
Closing as superseded |
What does this PR do?
Makes the Stripe instrumentation wrap each method once.
instrumentStripeInstanceruns on everynew Stripe()and used to callshimmer.wraponwebhooks.constructEventandwebhooks.constructEventAsynceach time. In stripe 9, 10, early 11.x and 18+,webhooksis a single object shared by every client:this.webhooks = require('./Webhooks')Stripe.webhooks = createWebhooks(...)once, thenthis.webhooks = Stripe.webhooksper instanceStripe.initialize(), thenthis.webhooks = Stripe.webhooksper instanceSo every client added one more wrapper around the same function. The fix keeps a
WeakSetof the wrappers we install and skips a method that is already one of them. It marks the functions rather than thewebhooksobject, so a method the user replaces later (for example a stub) still gets wrapped exactly once.Motivation
A process that creates a Stripe client per request (per account or per API key) eventually fails webhook signature verification:
Reproduced with the default config (
--require dd-trace/init, AppSec off) on dd-trace 5.105.0, 5.132.0 and 6.21.0 with stripe 9.16.0, 21.0.1 and 23.0.1. It fails at about 8,870 clients on Node 24, for bothconstructEventandconstructEventAsync. At that depthconstructEventAsyncthrows synchronously instead of returning a rejected promise.The bug costs something before the overflow too. With AppSec enabled, each webhook published
datadog:stripe:constructEvent:finishonce per client ever created, so the WAF ran N times for the same payment event. Verification latency also grows linearly with the number of clients.checkout.sessionsandpaymentIntentsare per-instance objects, so they never stacked. They now go through the same helper for consistency. Later 11.x releases and stripe 12–17 create a per-instancewebhooksand were not affected.Additional Notes
🤖 Generated with Claude Code