Skip to content

fix: validate header name and value in webRequest.onBeforeSendHeaders#51340

Merged
jkleinsc merged 4 commits into
electron:mainfrom
loufultoncz-coder:fix/electron/webrequestheaders
Apr 28, 2026
Merged

fix: validate header name and value in webRequest.onBeforeSendHeaders#51340
jkleinsc merged 4 commits into
electron:mainfrom
loufultoncz-coder:fix/electron/webrequestheaders

Conversation

@loufultoncz-coder
Copy link
Copy Markdown
Contributor

@loufultoncz-coder loufultoncz-coder commented Apr 27, 2026

Description of Change

Chromium's net::HttpRequestHeaders::SetHeader() uses CHECK() to enforce valid header names and values, which causes a fatal crash if the caller passes invalid strings. When users modify requestHeaders in the onBeforeSendHeaders callback with invalid header names (e.g. containing spaces) or invalid header values (e.g. containing CRLF), the gin::Converternet::HttpRequestHeaders::FromV8() calls SetHeader() directly, triggering the CHECK and crashing the process.

This change adds pre-validation using net::HttpUtil::IsValidHeaderName() and net::HttpUtil::IsValidHeaderValue() before calling SetHeader(), silently skipping invalid headers instead of crashing.

Checklist

Release Notes

Notes: Fixed a crash when providing invalid HTTP header names or values in the webRequest.onBeforeSendHeaders() callback

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Apr 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ This PR contains unsigned commits. This repository enforces commit signatures
for all incoming PRs. To get your PR merged, please sign those commits
(git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch
(git push --force-with-lease)

For more information on signing commits, see GitHub's documentation on Telling Git about your signing key.

@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Apr 27, 2026
@loufultoncz-coder loufultoncz-coder force-pushed the fix/electron/webrequestheaders branch from 789819d to 284a77b Compare April 27, 2026 12:12
@github-actions github-actions Bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Apr 27, 2026
Chromium's net::HttpRequestHeaders::SetHeader() uses CHECK() to enforce
valid header names and values, which causes a fatal crash if the caller
passes invalid strings. When users modify requestHeaders in the
onBeforeSendHeaders callback with invalid header names (e.g. containing
spaces) or invalid header values (e.g. containing CRLF), the
gin::Converter<net::HttpRequestHeaders>::FromV8() calls SetHeader()
directly, triggering the CHECK and crashing the process.

This change adds pre-validation using net::HttpUtil::IsValidHeaderName()
and net::HttpUtil::IsValidHeaderValue() before calling SetHeader(),
silently skipping invalid headers instead of crashing.
@loufultoncz-coder loufultoncz-coder force-pushed the fix/electron/webrequestheaders branch from 284a77b to d0fb3d5 Compare April 27, 2026 12:16
@xakep8
Copy link
Copy Markdown
Contributor

xakep8 commented Apr 27, 2026

@loufultoncz-coder please add release note in the PR description.

@loufultoncz-coder
Copy link
Copy Markdown
Contributor Author

@loufultoncz-coder please add release note in the PR description.

Done! I've added the release note to the PR description.

@xakep8
Copy link
Copy Markdown
Contributor

xakep8 commented Apr 27, 2026

I checked this path locally and the change looks correct to me. @loufultoncz-coder could you also complete the checklist? Thanks.

Copy link
Copy Markdown
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

This PR is a good idea & should be backported to the maintenance branches.

I had a style nit for the C++ code and made a suggestion to fix a potential timing issue in the new test, but overall this is good. Thanks for the PR!

Comment thread spec/api-web-request-spec.ts Outdated
Comment thread shell/common/gin_converters/net_converter.cc Outdated
loufultoncz-coder and others added 2 commits April 28, 2026 11:55
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
@loufultoncz-coder
Copy link
Copy Markdown
Contributor Author

This PR is a good idea & should be backported to the maintenance branches.

I had a style nit for the C++ code and made a suggestion to fix a potential timing issue in the new test, but overall this is good. Thanks for the PR!

Agreed. I'll make the requested changes. Thank you for the review!

@loufultoncz-coder
Copy link
Copy Markdown
Contributor Author

I checked this path locally and the change looks correct to me. @loufultoncz-coder could you also complete the checklist? Thanks.

Thanks for verifying it locally! I have just completed the PR checklist. Let me know if there's anything else needed.

Copy link
Copy Markdown
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

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

Thanks! @loufultoncz-coder please note that @xakep8 is in no way officially associated with the project so you can consider his feedback if you so choose but it is not relevant to whether the PR is ultimately approved.

@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Apr 28, 2026
@loufultoncz-coder loufultoncz-coder force-pushed the fix/electron/webrequestheaders branch from 55eb4a2 to 1d642c2 Compare April 28, 2026 08:30
@github-actions github-actions Bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Apr 28, 2026
@loufultoncz-coder loufultoncz-coder requested a review from ckerr April 28, 2026 08:34
@loufultoncz-coder
Copy link
Copy Markdown
Contributor Author

loufultoncz-coder commented Apr 28, 2026

Thanks! @loufultoncz-coder please note that @xakep8 is in no way officially associated with the project so you can consider his feedback if you so choose but it is not relevant to whether the PR is ultimately approved.

Thanks for the clarification and the approval! Really appreciate your time reviewing this.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/40-x-y PR should also be added to the "40-x-y" branch. target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 28, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Apr 28, 2026
@jkleinsc jkleinsc merged commit 3f0c48f into electron:main Apr 28, 2026
85 checks passed
@release-clerk
Copy link
Copy Markdown

release-clerk Bot commented Apr 28, 2026

Release Notes Persisted

Fixed a crash when providing invalid HTTP header names or values in the webRequest.onBeforeSendHeaders() callback

@welcome
Copy link
Copy Markdown

welcome Bot commented Apr 28, 2026

Congrats on merging your first pull request! 🎉🎉🎉

@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Apr 28, 2026

I have automatically backported this PR to "40-x-y", please check out #51364

@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Apr 28, 2026

I have automatically backported this PR to "41-x-y", please check out #51365

@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Apr 28, 2026

I have automatically backported this PR to "42-x-y", please check out #51366

@trop trop Bot added in-flight/41-x-y in-flight/42-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/40-x-y PR was merged to the "40-x-y" branch. and removed target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/42-x-y in-flight/41-x-y in-flight/40-x-y labels Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/40-x-y PR was merged to the "40-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants