Skip to content

fix(cloudflare): use correct Proxy receiver in instrumentDurableObjectStorage#19662

Merged
nicohrubec merged 2 commits intogetsentry:developfrom
dmmulroy:fix/cloudflare-do-storage-sql-illegal-invocation
Mar 6, 2026
Merged

fix(cloudflare): use correct Proxy receiver in instrumentDurableObjectStorage#19662
nicohrubec merged 2 commits intogetsentry:developfrom
dmmulroy:fix/cloudflare-do-storage-sql-illegal-invocation

Conversation

@dmmulroy
Copy link
Contributor

@dmmulroy dmmulroy commented Mar 5, 2026

Summary

Fixes #19661

instrumentDurableObjectStorage's Proxy get trap passes receiver (the proxy) to Reflect.get, breaking native workerd getters like storage.sql that validate this via internal slots.

  • Change Reflect.get(target, prop, receiver)Reflect.get(target, prop, target) so native getters execute with the real storage object as this
  • Add regression tests using a class with private fields to simulate workerd's native brand-checked getters

Details

The sql property on DurableObjectStorage is a native getter that requires the real native object as this. When the Proxy's get trap calls Reflect.get(target, prop, receiver), the getter runs with this = proxy → "Illegal invocation". Using target as receiver ensures native getters always run against the real storage object.

Instrumented KV methods (get, put, delete, list) were unaffected because they're functions that get explicitly .bind(target)ed or called via .apply(target, args). The bug only manifests for non-function getters (like sql).

Regression tests use a BrandCheckedStorage class with private fields — accessing #sqlInstance on the wrong this throws TypeError, faithfully simulating workerd's native internal-slot validation.

…tStorage

The storage Proxy's get trap passed `receiver` (the proxy itself) to
`Reflect.get`, causing native workerd getters like `storage.sql` to
throw 'Illegal invocation' due to failed internal slot / brand checks.

Use `target` as the receiver so native getters execute with the correct
`this` binding.
@dmmulroy dmmulroy force-pushed the fix/cloudflare-do-storage-sql-illegal-invocation branch from 5e71dc4 to 1cef324 Compare March 5, 2026 22:07
Copy link
Member

@nicohrubec nicohrubec left a comment

Choose a reason for hiding this comment

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

Thanks for contributing! I have updated the tests a bit since I think most are redundant with the existing test suite but else lgtm.

@nicohrubec nicohrubec merged commit f820401 into getsentry:develop Mar 6, 2026
334 of 337 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.

instrumentDurableObjectStorage Proxy breaks native storage.sql getter (Illegal invocation)

2 participants