Repository navigation
fix(child-process): stop passing encoding buffer to spawnSync - #19298
shahidbeig-a11y wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
Fixed issue severity: Medium Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Synchronous child processes can run without Node rejecting the unsupported buffer encoding, allowing Windows browser cookie key extraction to proceed while preserving string stdout and stderr behavior. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 critical issues — the fix is correct; one minor finding about the regression test is inline.
Reviewed changes
runProcessSyncdropsencoding: 'buffer'—spawnSyncnow returnsstdout/stderras Buffers (its configured default), which the existing.toString('utf8')already converts to the strings theProcessResultcontract promises.- New regression test — asserts
runProcessSyncreturns stringstdout/stderrwith a zero exit code.
The fix itself is verified: spawnSync(file, args, { input: <string>, encoding: 'buffer' }) throws ERR_UNKNOWN_ENCODING on Node 24 (CI's 24.19.0 and Electron 43.6's embedded 24.20.0), because Node encodes the string input via Buffer.from(input, 'buffer'). Dropping the option makes the input encode as UTF-8 and stdout/stderr return as Buffers — the DPAPI input is ASCII base64, so the bytes are identical and getWindowsEncryptionKey is unblocked.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Regression test now passes
input: 'dpapi-data'— the new commit adds a stringinput, mirroring the Windows DPAPI path so the test genuinely guards theERR_UNKNOWN_ENCODINGregression (verifiedspawnSync(..., { input: <string>, encoding: 'buffer' })throws, and the full 17-test suite passes).
The prior finding about the test not exercising the failing encode path is now fully addressed.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
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. |

Problem
On Windows, browser cookie import fails before DPAPI key extraction with:
User-facing message: Could not access Brave/Chrome encryption key.
Root cause
runProcessSyncinsrc/shared/child-process/run-process.tspassesencoding: 'buffer'intonode:child_process.spawnSync. Node rejects'buffer'as an encoding, so the sync PowerShell DPAPI helper insrc/main/browser/browser-cookie-key.ts(getWindowsEncryptionKey) throws before decryption completes.Callers already convert stdout/stderr with
.toString('utf8'), so the option is unnecessary.Fix
Remove
encoding: 'buffer'from thespawnSyncoptions so stdout/stderr return as Buffers (Node default) and existing.toString('utf8')conversion keeps working.Test plan
pnpm test src/shared/child-process/run-process.test.ts— all 17 tests passrunProcessSyncreturns string stdout/stderr and would fail withERR_UNKNOWN_ENCODINGifencoding: 'buffer'were reintroducedFixes #18670