fix(service-worker): ignore passive mixed content requests (#25994)

Although [passive mixed content][1] requests (like images) only produce
a warning without a ServiceWorker, fetching it via a ServiceWorker
results in an error. See
https://github.com/angular/angular/issues/23012#issuecomment-376430187
for more details.

This commit makes the ServiceWorker ignore such requests and let them be
handled by the browser directly to avoid breaking apps that would work
without the ServiceWorker.

[1]: https://developers.google.com/web/fundamentals/security/prevent-mixed-content/what-is-mixed-content#passive_mixed_content

Fixes #23012

PR Close #25994
This commit is contained in:
George Kalpakas
2018-09-18 10:52:02 +03:00
committed by Andrew Kushnir
parent 95989a12dd
commit 48214e2a05
3 changed files with 48 additions and 7 deletions

View File

@ -204,8 +204,6 @@ const brokenServer =
const server404 = new MockServerStateBuilder().withStaticFiles(dist).build();
const scope = new SwTestHarnessBuilder().withServerState(server).build();
const manifestHash = sha1(JSON.stringify(manifest));
const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
@ -1008,6 +1006,38 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
expect(await requestFoo('only-if-cached', 'no-cors')).toBeNull();
});
async_it('ignores passive mixed content requests ', async() => {
const scopeFetchSpy = spyOn(scope, 'fetch').and.callThrough();
const getRequestUrls = () => scopeFetchSpy.calls.allArgs().map(args => args[0].url);
const httpScopeUrl = 'http://mock.origin.dev';
const httpsScopeUrl = 'https://mock.origin.dev';
const httpRequestUrl = 'http://other.origin.sh/unknown.png';
const httpsRequestUrl = 'https://other.origin.sh/unknown.pnp';
// Registration scope: `http:`
(scope.registration.scope as string) = httpScopeUrl;
await makeRequest(scope, httpRequestUrl);
await makeRequest(scope, httpsRequestUrl);
const requestUrls1 = getRequestUrls();
expect(requestUrls1).toContain(httpRequestUrl);
expect(requestUrls1).toContain(httpsRequestUrl);
scopeFetchSpy.calls.reset();
// Registration scope: `https:`
(scope.registration.scope as string) = httpsScopeUrl;
await makeRequest(scope, httpRequestUrl);
await makeRequest(scope, httpsRequestUrl);
const requestUrls2 = getRequestUrls();
expect(requestUrls2).not.toContain(httpRequestUrl);
expect(requestUrls2).toContain(httpsRequestUrl);
});
describe('Backwards compatibility with v5', () => {
beforeEach(() => {
const serverV5 = new MockServerStateBuilder()