fix(service-worker): bypass CSP violation reports#67918
Open
pierluigilenoci wants to merge 1 commit intoangular:mainfrom
Open
fix(service-worker): bypass CSP violation reports#67918pierluigilenoci wants to merge 1 commit intoangular:mainfrom
pierluigilenoci wants to merge 1 commit intoangular:mainfrom
Conversation
The Angular service worker intercepts all fetch requests, including CSP violation reports (Content-Type: application/csp-report) and Reporting API reports (Content-Type: application/reports+json). These are POST requests sent autonomously by the browser, and handling them in the SW causes errors due to CORS restrictions or redirect mode mismatches, preventing the reports from reaching the server. This change detects these report requests by checking for POST method combined with the specific content-type headers, and lets them pass through to the network without SW intervention. Fixes angular#31477 Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
@googlebot I signed it. |
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.
Summary
The Angular service worker intercepts all fetch events, including CSP violation reports (
Content-Type: application/csp-report) and Reporting API reports (Content-Type: application/reports+json). These are POST requests sent autonomously by the browser, and intercepting them causes errors due to CORS restrictions or redirect mode mismatches.This PR adds an early check in the SW
onFetchhandler: if the request is a POST with a CSP/Reporting API content-type, the SW returns immediately without callingevent.respondWith(), letting the browser handle the request natively.Changes
packages/service-worker/worker/src/driver.ts: Added content-type check after existingngsw-bypasscheckpackages/service-worker/worker/test/happy_spec.ts: Added 5 tests (positive + negative cases)Fixes #31477