fix: webRequest.onBeforeSendHeaders not being able to modify reserved headers#49226
Merged
MarshallOfSound merged 2 commits intomainfrom Dec 19, 2025
Merged
fix: webRequest.onBeforeSendHeaders not being able to modify reserved headers#49226MarshallOfSound merged 2 commits intomainfrom
webRequest.onBeforeSendHeaders not being able to modify reserved headers#49226MarshallOfSound merged 2 commits intomainfrom
Conversation
codebytere
approved these changes
Dec 19, 2025
|
Release Notes Persisted
|
This was referenced Dec 19, 2025
Contributor
|
I have automatically backported this PR to "40-x-y", please check out #49241 |
Contributor
|
I have automatically backported this PR to "39-x-y", please check out #49242 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
webRequest.onBeforeSendHeadersnot being able to modify headers likeProxy-Authorizationfor requests made via thenetmodule.When using
webRequest.onBeforeSendHeadersto inject headers likeProxy-Authorizationinto requests made vianet.requestornet.fetch, the request fails withnet::ERR_INVALID_ARGUMENT. However, the same webRequest listener works correctly for renderer-initiated requests (e.g.,fetch()from a BrowserWindow). The network service validates headers and headers starting withProxy-are rejected byAreRequestHeadersSafe()inCorsURLLoaderFactory::IsValidRequest().For renderer requests, this isn't a problem because:
Proxy-Authorizationheader yet)TrustedHeaderClientcallback, which occurs after validationFor
netmodule requests, theTrustedHeaderClientpath was not being used becausenetwork_service_request_idwas always0. This caused header modifications to go through theFollowRedirect()path instead, which re-validates headers withAreRequestHeadersSafe()and rejectsProxy-*headers.The condition that gates
TrustedHeaderClientusage (inproxying_url_loader_factory.cc):current_request_uses_header_client_ = factory_->url_loader_header_client_receiver_.is_bound() && (for_cors_preflight_ || network_service_request_id_ != 0) && has_any_extra_headers_listeners_;Solution
Set a non-zero request ID for
netmodule requests using Chromium'sGlobalRequestID::MakeBrowserInitiated(). This generates unique negative request IDs (-2, -3, -4, ...) that are distinct from renderer request IDs (positive numbers). This is the same mechanism Chromium uses internally for other browser-initiated requests.Setting
Proxy-Authorizationdirectly in thenet.fetchoptions will still fail, as the header would be present in the initial request before validation. The header must be injected viawebRequest.onBeforeSendHeadersto use theTrustedHeaderClientpath.Notes: Requests sent via
netare now capable of having their headers modified to use reserved headers viawebRequest