Repository navigation
fix(windows): stop string stdin throwing in the sync child-process chokepoint - #19304
brennanb2025 wants to merge 1 commit into
Conversation
…okepoint `runProcessSync` passed `encoding: 'buffer'` to `spawnSync`. That is valid for the output shape the reads below depend on, but `encoding` also decodes a string `input`, and `Buffer.from(str, 'buffer')` throws ERR_UNKNOWN_ENCODING before the child starts. Encode the input to bytes instead. The only caller in the tree that passes `input` is the Windows DPAPI master-key decrypt, so every Chromium cookie import on Windows aborted and rendered the caught throw as "The OS may have denied access" -- an error the OS never raised. The sync path had three tests and none passed `input`, which is how #15746 shipped a regression through the very chokepoint it was consolidating.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthrough
Merge Risk: ⚪ Minimal · up to String stdin is now reliably passed as UTF-8 bytes to synchronous child processes, preventing the Windows cookie-import failure while preserving buffer-based output handling. The covered change is ready to merge. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the single-commit fix for the sync child-process chokepoint, plus its two new tests.
- Encode string
inputto a Buffer at the chokepoint —runProcessSyncnow passesBuffer.from(spec.input, 'utf8')instead of the raw string, soencoding: 'buffer'only governs the stdout/stderrBuffershape the.toString('utf8')reads rely on, and no longer tripsERR_UNKNOWN_ENCODINGon string stdin. - Two discriminating tests — one round-trips
piped-payloadthrough stdin viaprocess.execPath(cross-OS), one pins the utf8 choice by assertinghélloarrives as 6 bytes.
I reproduced the underlying Node semantics directly (spawnSync with { input: 'hello', encoding: 'buffer' } throws Unknown encoding: buffer), so the mechanism is confirmed and the fix is correct and minimal. The change only alters behavior when input is a string — previously an unconditional throw, now correct utf8 delivery — so the ~19 callers that omit input (undefined) see no change. The async runProcess path already writes string input via child.stdin.end(spec.input) under utf8, so the two paths now agree on utf8.
ℹ️ Nitpicks
- The comments in
run-process.tsandrun-process.test.tssayencoding"decodes" string stdin (and "decodes a stringinput"). That option actually encodes the input string and decodes the output; a one-word swap if you touch either comment again is all that's needed.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Status: reviewed CLEAN · manual validation platform-gatedIndependent review — CLEANA wholly fresh reviewer (same model, no involvement in authoring) re-ran the load-bearing claims rather than accepting them. It reproduced the four-row
It also read node's Two review findings, both acted onThe reviewer caught an error in this PR's own description: it claimed the Buffer-returning stdout default was "undocumented". It is documented, in One nit was assessed and deliberately not acted on: Manual validation: mechanism proven here, end-to-end is Windows-gatedStated plainly rather than implied:
The causal chain to the user-visible message was confirmed by reading: the throw is caught at GatesTypecheck clean across all three projects (node, web, cli). |
Windows validation: PASS on the real machine, with an honest caveat on browser coverageRun on a real Windows host with What could not be tested, and whyOn that machine the only Chromium browser Orca detects is Microsoft Edge. Chrome is not installed (only "Chrome for Testing", under a root Orca does not scan) and Brave is not installed at all. Edge is installed, but it was running, and the import aborts before it ever reaches the DPAPI path:
That is a snapshot/copy failure at Two independent proofs on the real Windows host1. Direct probe of the chokepoint, using the app's own PowerShell DPAPI script and the same Note it throws synchronously out of 2. Full UI before/after through Settings → Browser → Session & Cookies → Import Cookies, against synthetic Chromium profiles built for this test: a real CurrentUser DPAPI-wrapped master key, with cookies generated for the run on
Both after-states are exactly what the fix predicts: the misleading permissions error is gone, The build state was verified in the running bundle rather than assumed. Before: Evidence handlingFour screenshots were captured and transferred back as numbered base64 with sha256 verification end to end. All four were opened and inspected before being reported: they show an empty isolated dev profile with no projects or workspaces, the Browser settings pane, and the resulting toast. No cookie values, host keys, decryption keys, tokens, private repository names, or unrelated workspace content appear in any of them. What remains unprovenA real Chrome, Edge or Brave profile on a real user's machine was not imported. The synthetic profiles exercise the genuine DPAPI unwrap path and the genuine |
|
Closing as superseded by merged #28225 ( I compared this PR’s complete diff with the current runner: #18670 is closed with that fix linked. App-bound cookie encryption remains a separate concern in #13192. |

Fixes STA-6700. Also unblocks STA-3706 — see below, because it is not the same cause.
The defect
src/shared/child-process/run-process.tspassesencoding: 'buffer'tospawnSync. That is documented and valid for spawnSync's output — but wheninputis a string, node doespipe.input = Buffer.from(input, options.encoding), andBuffer.from(str, 'buffer')throwsERR_UNKNOWN_ENCODING.Reproduced directly (node v26.5.0, macOS — this is Node semantics, not Windows behaviour):
'hello''buffer'ERR_UNKNOWN_ENCODING: Unknown encoding: bufferBuffer'buffer''hello''buffer'So
runProcessSyncthrows for any caller passing a stringinput— andProcessSpec.inputis typedinput?: string, so the API actively invites the broken usage.Blast radius is one call site today. Across
src/,config/,tests/andscripts/— including the untyped.mjscallers —src/main/browser/browser-cookie-key.ts:150is the only caller that passesinput— the PowerShell DPAPI master-key decrypt. The throw is caught, logged, and returned asnull, which the Chromium prepare step renders as "Could not access Brave encryption key. The OS may have denied access."That message is wrong, and that is the real user cost. The OS denied nothing. Windows users see a permissions error for what is a string-encoding bug, and every Chromium cookie import aborts before it starts.
Introduced by
b7e79b7ca6(#15746, "one chokepoint for every child process").run-process.test.tshad threerunProcessSynctests and none passedinput, so the consolidation shipped a regression through the exact path it was consolidating.The fix — at the chokepoint, not the call site
encoding: 'buffer'stays, and the reason is symmetry rather than necessity:runProcess(the async path) already writes stdin viachild.stdin?.end(spec.input), which defaults to utf8. Converting here makes the sync path match the async one instead of quietly diverging from it — that, not the stdout shape, is the argument for'utf8'.Dropping
encoding: 'buffer'would also have worked; the Buffer-returning default is documented in the overload set (SpawnSyncOptionsWithBufferEncoding). Keeping it simply leaves'buffer'meaning one thing. The code comment names the surprise that caused this — thatencodinggoverns stdin decoding and stdout shape.browser-cookie-key.tsis untouched.The missing test is the headline
writes string input to the child stdin— writes string stdin to a child and asserts it arrived. Usesprocess.execPath, so it runs on every OS: this would have caught fix(windows): one chokepoint for every child process #15746 in CI on Linux, with no Windows host needed.encodes non-ASCII stdin as utf8— asserts the child receives 6 bytes forhéllo, pinning the encoding choice (latin1 would report 5).One edge checked by measurement rather than reasoning: converting to a Buffer flips the truthiness of an empty-string input, since node gates on
if (options.input)and a zero-length Buffer is truthy. All three cases — empty string, empty Buffer,undefined— produceeof:0and status 0, so they are observationally identical and no special case was added. No caller passes''today regardless.Evidence
a87a19c996TypeError: Unknown encoding: bufferinput: spec.inputrestored on the committed fix)The ablation threw at runtime rather than at import, so it exercised the code rather than failing to compile. Both new tests are discriminating — only they flip, and only on this line.
Wider sweep across
src/shared/child-processandsrc/main/browser: 189 files, 1,785 passed, 0 failed, 48 skipped. Typecheck clean on all three projects (node, web, cli).Why this closes STA-3706 too — and why that is not a grouping
These are two sequential stages, not one cause. The timeline settles it: STA-3706 was filed 2026-08-08 at v1.4.176-rc.1, before this regression; STA-6700 is v1.4.197, after. They were never observed together because 6700 now aborts the import one stage earlier than 3706 ever ran.
STA-3706's fix is already on
main—isAppBoundEncryptedCookie, thev20classification before decrypt, and the "app-bound encryption / import from a file instead" toast, with 28 green tests. None of it is touched here.So fixing 6700 unmasks 3706's landed fix: Chrome/Edge 140+ Windows users go from a false "key access denied" error to the correct actionable app-bound toast, and Brave (still v10) gets a real import.
Boundary, stated not buried
The mechanism is Node semantics and is reproduced above on macOS. The end-to-end Windows cookie import is unproven — that needs a Windows host with a real Chrome profile. No real browser profile was read at any point; the fixtures are
piped-payloadandhéllo, and the change contains no cookie values, host keys or decryption keys.