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.
e441aef to
ad5ba73
Compare
ad5ba73 to
c1e0bfb
Compare
| // receiver has no Sentry to strip a trailing metadata argument. | ||
| enableRpcTracePropagation: ['SUB_WORKER', 'SUB_WORKER_NO_PROPAGATION'], | ||
| }), |
There was a problem hiding this comment.
Bug: The integration test for RPC trace propagation incorrectly includes 'SUB_WORKER_NO_PROPAGATION' in the enableRpcTracePropagation allowlist, contradicting the test's goal of verifying behavior for a disabled binding.
Severity: LOW
Suggested Fix
To align the test's behavior with its stated purpose, remove 'SUB_WORKER_NO_PROPAGATION' from the enableRpcTracePropagation allowlist within the test's configuration. This will ensure the test correctly validates that trace metadata is not injected when propagation is disabled.
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:
dev-packages/cloudflare-integration-tests/suites/tracing/propagation/worker-workerentrypoint-rpc/index.ts#L36-L38
Potential issue: An integration test for RPC trace propagation has a configuration
error. The test, named "does not inject RPC trace metadata into receiver calls when
enableRpcTracePropagation is disabled", is meant to verify that trace metadata is not
injected for a disabled binding. However, the test configuration explicitly includes the
binding `'SUB_WORKER_NO_PROPAGATION'` in the `enableRpcTracePropagation` allowlist. The
test currently passes because the receiver worker is also instrumented and strips the
metadata, but this means the test is not validating its stated purpose. It's testing
that metadata is stripped, not that it isn't injected in the first place.
|
Currently rethinking. It might make more sense to get rid of |
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)