feat(cloudflare): Add allow list to enableRpcTracePropagation - #23363
feat(cloudflare): Add allow list to enableRpcTracePropagation#23363JPeer264 wants to merge 1 commit into
Conversation
size-limit report 📦
|
1230b45 to
e441aef
Compare
| return instrumented; | ||
| } | ||
|
|
||
| if (!options?.enableRpcTracePropagation) { | ||
| if (!shouldPropagateRpcTrace(String(prop))) { | ||
| return item; | ||
| } | ||
|
|
There was a problem hiding this comment.
Bug: The module-level instrumentedBindings cache is checked before the shouldPropagateRpcTrace predicate, causing cached bindings to bypass RPC propagation rules on subsequent requests with different configurations.
Severity: MEDIUM
Suggested Fix
The order of operations should be changed. The shouldPropagateRpcTrace predicate should be checked before attempting to retrieve a binding from the instrumentedBindings cache. This ensures that the current invocation's configuration is always respected, even if a cached version of the binding exists from a previous invocation with a different configuration.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/cloudflare/src/instrumentations/worker/instrumentEnv.ts#L94-L100
Potential issue: A module-level cache, `instrumentedBindings`, stores instrumented RPC
bindings. This cache is checked before the `shouldPropagateRpcTrace` predicate is
evaluated. If an RPC binding is accessed with a permissive configuration (e.g.,
`enableRpcTracePropagation: true`), it is instrumented and cached. A subsequent
invocation with a more restrictive configuration will hit the cache and return the
already-instrumented binding, bypassing the new configuration's allow-list check. This
results in unintended trace propagation for RPC calls.
Did we get this right? 👍 / 👎 to inform future reviews.
This adds an allow list to
enableRpcTracePropagationthe accepts an array of strings and regular expressions. ThecreateRpcPropagationResolverreturns a function so inside the Proxy we don't have to go over the if's over and over (as the config doesn't change dynamically).This closes #23233, but I'd like to add one more feature into the stack: That our Vite plugin is automatically allow listing bindings within the same deployment, as these are safe to be added (we know for sure that these are instrumented with Sentry and RPC trace propagation is ok to have)