Repository navigation
fix(wire-codec): stop encode silently dropping a literal __proto__ field - #342
Conversation
…field
`decodeWire` has always preserved a `__proto__` key faithfully, installing it
with `Object.defineProperty` so it lands as an own data property rather than
firing the prototype setter. `encodeWire` did not: its plain-object branch used
a bare `result[key] = …`, which for that one key invokes the setter and creates
no own property — so the field simply vanished from the output.
The two halves therefore disagreed, and the loss was silent. A stored document
carrying a literal `__proto__` field (`JSON.parse` makes it an OWN key, so this
is reachable for anything written before the codec shipped) lost it on every
re-encode. Studio's row editor is one such path: it seeds from
`encodeWire(doc)`, so the field was absent from the editor text and an
untouched save deleted it from the row.
Encode now mirrors decode. No pollution is introduced — `defineProperty` is
precisely what avoids invoking the setter, and the round-trip test asserts a
bare `{}` gains nothing.
Found by the thermos review of plan 300; filed as plan 303(b).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019WfuWNN3cWJE6beZjng347
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (2)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
|
Thank you for following the naming conventions! 🙏 |
The round-trip deliberately goes through `JSON.parse(JSON.stringify(...))` to model the actual transport. `structuredClone` preserves values JSON drops, so swapping it in would make the assertion vacuous. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019WfuWNN3cWJE6beZjng347
Merging this PR will regress 1 benchmark
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Plan 303(b). Found by the thermos review of #339.
The asymmetry
decodeWirehas always preserved a__proto__key faithfully, installing it withObject.definePropertyso it lands as an own data property rather than firing the prototype setter.encodeWiredid not. Its plain-object branch used a bareresult[key] = …, which for that one key invokes the setter and creates no own property — so the field silently vanished:Why it's reachable
JSON.parsemakes__proto__an own key, so any document written before the codec shipped can carry one. Studio's row editor is one such path: it seeds fromencodeWire(doc), so the field was absent from the editor text and an untouched save deleted it from the row.Not a pollution change
definePropertyis precisely what avoids invoking the setter. The test asserts the key survives all three hops (parse → encode → JSON → decode) and that a bare{}gains nothing along the way.Demonstrated to fail against
alpha:expected [ 'amount' ] to strictly equal [ '__proto__', 'amount' ].Suites: client 641, do 519, shard-engine 981, studio 1012.
🤖 Generated with Claude Code
https://claude.ai/code/session_019WfuWNN3cWJE6beZjng347