Skip to content

fix(diff): strip control chars from generated diff headers#9741

Open
ubeddulla wants to merge 1 commit into
npm:latestfrom
ubeddulla:diff-header-control-chars
Open

fix(diff): strip control chars from generated diff headers#9741
ubeddulla wants to merge 1 commit into
npm:latestfrom
ubeddulla:diff-header-control-chars

Conversation

@ubeddulla

Copy link
Copy Markdown
Contributor

formatDiff and lib/utils/patch-diff.js build git diff headers by interpolating file paths and manifest versions straight into the diff --git, ---, +++ and index lines. Tarball entry names (read verbatim by untar.js) and non-registry manifest versions are attacker controlled and can hold a newline, so a crafted name or version forges extra header and hunk lines in the output; the global C0/C1 filter lets \n and \r through, so the forgery survives to the terminal and to anything that parses the diff (git apply, or Arborist parsePatch for npm patch). Strip control characters from the name and version before they land in a header line, keeping the original name for refs lookups and disk reads so valid inputs are unchanged.

@ubeddulla ubeddulla requested review from a team as code owners July 10, 2026 07:46
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.

1 participant