Skip to content

fix(child-process): stop passing encoding buffer to spawnSync - #19298

Closed
shahidbeig-a11y wants to merge 2 commits into
stablyai:mainfrom
shahidbeig-a11y:cursor/fix-runprocesssync-encoding-buffer-da99
Closed

shahidbeig-a11y wants to merge 2 commits into
stablyai:mainfrom
shahidbeig-a11y:cursor/fix-runprocesssync-encoding-buffer-da99

Conversation

@shahidbeig-a11y

Copy link
Copy Markdown
Contributor

Problem

On Windows, browser cookie import fails before DPAPI key extraction with:

TypeError [ERR_UNKNOWN_ENCODING]: Unknown encoding: buffer

User-facing message: Could not access Brave/Chrome encryption key.

Root cause

runProcessSync in src/shared/child-process/run-process.ts passes encoding: 'buffer' into node:child_process.spawnSync. Node rejects 'buffer' as an encoding, so the sync PowerShell DPAPI helper in src/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 the spawnSync options 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 pass
  • New test asserts runProcessSync returns string stdout/stderr and would fail with ERR_UNKNOWN_ENCODING if encoding: 'buffer' were reintroduced

Fixes #18670

@shahidbeig-a11y
shahidbeig-a11y marked this pull request as ready for review September 8, 2026 15:54
@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0dc4197c-ecca-4999-9d83-798379c6a33e

📥 Commits

Reviewing files that changed from the base of the PR and between fc49e79 and 3d2f468.

📒 Files selected for processing (1)
  • src/shared/child-process/run-process.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

runProcessSync no longer passes encoding: 'buffer' to nodeSpawnSync. It retains the configured or default maxBuffer value. A regression test verifies that stdout and stderr are returned as strings without an encoding option. This covers the Windows DPAPI subprocess path that previously raised ERR_UNKNOWN_ENCODING.

Fixed issue severity: Medium

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3d2f4

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)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: removing the invalid encoding: 'buffer' option from spawnSync.
Description check ✅ Passed The description explains the Windows failure, root cause, fix, linked issue, and test coverage. It omits several template sections, but the core required information is complete.
Linked Issues check ✅ Passed The change directly addresses issue #18670 by removing the invalid encoding option that prevents Windows Brave and Chrome cookie imports from reaching DPAPI key extraction. The regression test covers …
Out of Scope Changes check ✅ Passed The code change and regression test are limited to the child-process encoding failure described in issue #18670. No unrelated changes are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot 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.

ℹ️ No critical issues — the fix is correct; one minor finding about the regression test is inline.

Reviewed changes

  • runProcessSync drops encoding: 'buffer' — spawnSync now returns stdout/stderr as Buffers (its configured default), which the existing .toString('utf8') already converts to the strings the ProcessResult contract promises.
  • New regression test — asserts runProcessSync returns string stdout/stderr with 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

  • Regression test now passes input: 'dpapi-data' — the new commit adds a string input, mirroring the Windows DPAPI path so the test genuinely guards the ERR_UNKNOWN_ENCODING regression (verified spawnSync(..., { 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor

Closing as superseded by merged #28225 (3308eb3d00aaf9219ab88609ee24d4150765a94a). Thank you for identifying and testing the synchronous string-stdin encoding failure.

I compared this PR’s complete diff with the current runner: encoding: null now fixes the same failure at its shared source. The merged regression cases exercise string input, Unicode bytes, stdout/stderr decoding and binary capture, covering the regression this PR tests. The current runner and byte-capture suites also pass in this audit. The implementation now lives in src/packages/process-host; no independent production or regression scope remains here.

#18670 is closed with that fix linked. App-bound cookie encryption remains a separate concern in #13192.

@nwparker nwparker closed this Oct 18, 2026
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.

[Bug]: Windows cookie import fails with ERR_UNKNOWN_ENCODING: Unknown encoding: buffer

3 participants