Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(service-worker): Strips sensitive headers on cross-origin redirects - #69029

Merged
atscott merged 1 commit into
angular:mainfrom
SkyZeroZx:fix/more-service-worker-again
Jun 8, 2026
Merged

fix(service-worker): Strips sensitive headers on cross-origin redirects#69029
atscott merged 1 commit into
angular:mainfrom
SkyZeroZx:fix/more-service-worker-again

Conversation

@SkyZeroZx

@SkyZeroZx SkyZeroZx commented May 31, 2026

Copy link
Copy Markdown
Contributor

Removes Authorization, Cookie, and Proxy-Authorization headers when a request is redirected to a different origin. This prevent sensitive information from being sent to third-party origins.

See https://fetch.spec.whatwg.org/#http-redirect-fetch

More context : https://issuetracker.google.com/issues/516064418

@angular-robot angular-robot Bot added the area: service-worker Issues related to the @angular/service-worker package label May 31, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 31, 2026
let headers = options.headers;
const scopeUrl = this.scope.registration.scope;
if (
this.adapter.parseUrl(url, scopeUrl).origin !==

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a workaround to avoid the associated problems mentioned in this comment previously.
#41931 (comment)

@SkyZeroZx
SkyZeroZx marked this pull request as ready for review May 31, 2026 17:19
@pullapprove
pullapprove Bot requested a review from JeanMeche May 31, 2026 17:19

@JeanMeche JeanMeche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AGENT: The PR correctly and successfully addresses the security concern by stripping Authorization, Proxy-Authorization, and Cookie headers when an intercepted request is redirected to a different origin. The logic perfectly aligns with the WHATWG Fetch Spec's HTTP-redirect fetch algorithm.

Changing the options parameter type from RequestInit to Request is safe because newRequestWithMetadata is only ever called internally with Request instances. The manual header cloning with forEach is necessary given that Adapter.newHeaders requires a record instead of a Headers instance. The tests are well-written and correctly cover the new behavior.

I've left one minor performance optimization inline for consideration.

Comment thread packages/service-worker/worker/src/assets.ts Outdated
Comment thread packages/service-worker/worker/src/assets.ts
@JeanMeche
JeanMeche requested a review from alan-agius4 June 1, 2026 15:46
Comment thread packages/service-worker/worker/src/assets.ts Outdated
Comment thread packages/service-worker/worker/src/assets.ts
Removes `Authorization`, `Cookie`, and `Proxy-Authorization` headers when a request is redirected to a different origin. This aligns with the Fetch API's redirect algorithm to prevent sensitive information from being sent to third-party origins.
@SkyZeroZx
SkyZeroZx force-pushed the fix/more-service-worker-again branch from 173f62b to 423a109 Compare June 2, 2026 17:42
@SkyZeroZx
SkyZeroZx requested a review from alan-agius4 June 3, 2026 12:12
@SkyZeroZx

Copy link
Copy Markdown
Contributor Author

@alan-agius4 @JeanMeche I don't know if anything else is missing besides this. This is ready, so I can perform the respective backport.

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release and removed action: merge The PR is ready for merge by the caretaker labels Jun 8, 2026
@alan-agius4
alan-agius4 requested a review from JeanMeche June 8, 2026 13:42
@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 8, 2026
@atscott
atscott merged commit 47d68dc into angular:main Jun 8, 2026
30 checks passed
@atscott

atscott commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@angular-automatic-lock-bot

Copy link
Copy Markdown

This pull request has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: service-worker Issues related to the @angular/service-worker package target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants