Skip to content

Service worker incorrectly intercepting http redirects (302) #36068

@klemenoslaj

Description

@klemenoslaj

🐞 bug report

Affected Package

The issue is caused by package @angular/service-worker

Is this a regression?

No

Description

In our application we use a http redirect to the login page if for an example session times out.
This works perfectly fine without the service worker enabled, however with the service worker this fails.

To my observation, the mode of the Request is changed from navigate to cors.

Without SW:

Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate

With SW:

Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors

Would it be a good solution simply ignore the requests with redirect mode?

🔥 Exception or Error

Access to fetch at 'https://authentication-url.com/...' (redirected from 'https://my-w
ebsite.com/file-request.json') from origin 'https://my-website.com' has been blocked by
CORS policy: Response to preflight request doesn't pass access control check: No 
'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque
response serves your needs, set the request's mode to 'no-cors' to fetch the resource
with CORS disabled.

🌍 Your Environment

Angular CLI: 9.0.5
Node: 12.15.0
OS: darwin x64

Angular: 9.0.5
... animations, cli, common, compiler, compiler-cli, core
... elements, forms, language-service, localize
... platform-browser, platform-browser-dynamic, router
... service-worker
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.900.5
@angular-devkit/build-angular      0.900.5
@angular-devkit/build-ng-packagr   0.900.5
@angular-devkit/build-optimizer    0.900.5
@angular-devkit/build-webpack      0.900.5
@angular-devkit/core               9.0.5
@angular-devkit/schematics         9.0.5
@angular/cdk                       9.1.1
@angular/flex-layout               9.0.0-beta.29
@angular/material                  9.1.1
@angular/pwa                       0.900.5
@ngtools/webpack                   9.0.5
@schematics/angular                9.0.5
@schematics/update                 0.900.5
ng-packagr                         9.0.3
rxjs                               6.5.4
typescript                         3.7.5
webpack                            4.41.2

Anything else relevant?

I tried adding ngsw-bypass=true query param to the redirect, but that did not help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions