Commit f820401
fix(cloudflare): use correct Proxy receiver in instrumentDurableObjectStorage (#19662)
## 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.
---------
Co-authored-by: Nicolas Hrubec <nico.hrubec@sentry.io>1 parent 0ff0468 commit f820401
File tree
2 files changed
+26
-2
lines changed- packages/cloudflare
- src/instrumentations
- test
2 files changed
+26
-2
lines changedLines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
| |||
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
185 | 204 | | |
186 | 205 | | |
187 | 206 | | |
| |||
0 commit comments