Skip to content

Strip Sec-Fetch-* headers on redirect#4190

Open
AtomicNibble wants to merge 1 commit into
chromiumembedded:masterfrom
AtomicNibble:strip-sec-fetch-on-redirect
Open

Strip Sec-Fetch-* headers on redirect#4190
AtomicNibble wants to merge 1 commit into
chromiumembedded:masterfrom
AtomicNibble:strip-sec-fetch-on-redirect

Conversation

@AtomicNibble

Copy link
Copy Markdown
Contributor

Fixes a network-service / renderer process kill on HTTP redirects of renderer-initiated subresource requests.

On redirect, CEF restarts the request through the URLLoaderFactory (InterceptedRequest::FollowRedirect -> Restart -> ContinueToBeforeRedirect) instead of following it on the existing loader. The restart re-submits the network-service-managed Sec-Fetch-* headers that were populated on the prior hop. With kRestrictForbiddenSecurityHeaders now enabled by default in Chromium, CorsURLLoaderFactory::IsValidRequest ->
ContainsForbiddenSecurityHeader rejects those renderer-forbidden headers via mojo::ReportBadMessage, tearing down the network service.

Only renderer-initiated subresources (fetch/XHR/img/script) trigger this; browser-initiated top-level navigations skip the check, which is why a top-level redirect doesn't reproduce it.

The fix strips the Sec-Fetch- header family by prefix (mirroring Chromium's own network::MaybeRemoveSecHeaders) from remove_headers before the restart, so new members like Sec-Fetch-Frame-Top / Sec-Fetch-Frame-Ancestors are covered without maintaining an explicit list. URLLoader re-derives them downstream (SetFetchMetadataHeaders), so this is lossless and mirrors CorsURLLoader's normal redirect path.

Adds CorsTest.XhrRedirectSubresource and CorsTest.FetchRedirectSubresource regression tests.

Fixes a network-service / renderer process kill on HTTP redirects of
renderer-initiated subresource requests.

On redirect, CEF restarts the request through the URLLoaderFactory
(InterceptedRequest::FollowRedirect -> Restart -> ContinueToBeforeRedirect)
instead of following it on the existing loader. The restart re-submits the
network-service-managed Sec-Fetch-* headers that were populated on the prior
hop. With kRestrictForbiddenSecurityHeaders now enabled by default in
Chromium, CorsURLLoaderFactory::IsValidRequest ->
ContainsForbiddenSecurityHeader rejects those renderer-forbidden headers via
mojo::ReportBadMessage, tearing down the network service.

Only renderer-initiated subresources (fetch/XHR/img/script) trigger this;
browser-initiated top-level navigations skip the check, which is why a
top-level redirect doesn't reproduce it.

The fix strips the Sec-Fetch- header family by prefix (mirroring Chromium's
own network::MaybeRemoveSecHeaders) from remove_headers before the restart,
so new members like Sec-Fetch-Frame-Top / Sec-Fetch-Frame-Ancestors are
covered without maintaining an explicit list. URLLoader re-derives them
downstream (SetFetchMetadataHeaders), so this is lossless and mirrors
CorsURLLoader's normal redirect path.

Adds CorsTest.XhrRedirectSubresource and CorsTest.FetchRedirectSubresource
regression tests.
@AtomicNibble

Copy link
Copy Markdown
Contributor Author

Fix for #4189

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