fix(lockdown): tame TextDecoder fast-path symbols#3245
Draft
kumavis wants to merge 1 commit into
Draft
Conversation
Recent Node.js releases (20.18.3+, 22.15.1+, 24.x) store private "fast path" flags on each TextDecoder instance as own data properties keyed by `Symbol(kUTF8FastPath)` and `Symbol(kWindows1252FastPath)`. The decode() method mutates these flags via `&&=`, so once a TextDecoder instance was hardened the next decode() call threw `TypeError: Cannot assign to read only property` for any encoding whose initial flag is `true` (utf-8, ascii, latin1, iso-8859-1, windows-1252). Following Mathieu's suggestion in the bug report, replace the per-instance own data properties with prototype accessors backed by a WeakMap. The setter only honors writes that lower the flag, which matches Node's one-way `&&=` semantics and avoids introducing a new covert channel beyond what is already observable on an unhardened instance. Closes: #2813
🦋 Changeset detectedLatest commit: ca84cc8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR mitigates a Node.js compatibility issue where hardened TextDecoder instances throw during decode() due to Node’s per-instance “fast path” symbol flags being mutated via &&=.
Changes:
- Adds a lockdown-time patch that replaces per-instance fast-path symbol data properties with prototype accessors backed by a
WeakMap. - Hooks the patch into
@endo/lockdown’s post-lockdown setup beforeTextDecoderis hardened. - Adds regression tests in
@endo/initcovering multiple encodings and streaming, plus a changeset entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/lockdown/text-decoder-fast-path-patch.js | Implements the TextDecoder fast-path symbol migration and constructor wrapper. |
| packages/lockdown/post.js | Invokes the patch before hardening globalThis.TextDecoder. |
| packages/init/test/text-decoder.test.js | Adds regression coverage for hardened TextDecoder across encodings and stream behavior. |
| .changeset/lockdown-text-decoder-fast-path.md | Documents the patch-level release note for the fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+86
to
+96
| get() { | ||
| const state = states.get(this); | ||
| return state === undefined ? undefined : state[sym]; | ||
| }, | ||
| set(value) { | ||
| // Node toggles the flag from `true` to `false` via `&&=`; it never | ||
| // raises a falsy flag back to `true`. Honor only the lowering write | ||
| // so the accessor is not usable as a multi-bit covert channel. | ||
| if (value === false) { | ||
| ensureState(this)[sym] = false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recent Node.js releases (20.18.3+, 22.15.1+, 24.x) store private
"fast path" flags on each TextDecoder instance as own data properties
keyed by
Symbol(kUTF8FastPath)andSymbol(kWindows1252FastPath).The decode() method mutates these flags via
&&=, so once aTextDecoder instance was hardened the next decode() call threw
TypeError: Cannot assign to read only propertyfor any encodingwhose initial flag is
true(utf-8, ascii, latin1, iso-8859-1,windows-1252).
Following Mathieu's suggestion in the bug report, replace the
per-instance own data properties with prototype accessors backed by
a WeakMap. The setter only honors writes that lower the flag, which
matches Node's one-way
&&=semantics and avoids introducing a newcovert channel beyond what is already observable on an unhardened
instance.
Closes: #2813