Skip to content

fix(lockdown): tame TextDecoder fast-path symbols#3245

Draft
kumavis wants to merge 1 commit into
masterfrom
claude/fix-nodejs-compatibility-KEKc0
Draft

fix(lockdown): tame TextDecoder fast-path symbols#3245
kumavis wants to merge 1 commit into
masterfrom
claude/fix-nodejs-compatibility-KEKc0

Conversation

@kumavis

@kumavis kumavis commented May 6, 2026

Copy link
Copy Markdown
Member

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

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-bot

changeset-bot Bot commented May 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ca84cc8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@endo/lockdown Patch
@endo/bundle-source Patch
@endo/goblin-chat Patch
@endo/init Patch
@endo/ocapn Patch
@endo/cli Patch
@endo/daemon Patch
@endo/netstring Patch
@endo/ses-ava Patch

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

@kumavis kumavis marked this pull request as draft May 6, 2026 07:38
@kumavis kumavis requested a review from Copilot May 6, 2026 07:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 before TextDecoder is hardened.
  • Adds regression tests in @endo/init covering 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;
}
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.

Lockdown Compat: Hardened TextDecoder instance with nodejs fast path (eg ascii encoding)

3 participants