diff --git a/lib/renderer/security-warnings.ts b/lib/renderer/security-warnings.ts index 314d4d42c972..97fbe6234521 100644 --- a/lib/renderer/security-warnings.ts +++ b/lib/renderer/security-warnings.ts @@ -103,10 +103,14 @@ const warnAboutInsecureResources = function () { return; } + const isLocal = (url: URL): boolean => + ['localhost', '127.0.0.1', '[::1]', ''].includes(url.hostname); + const isInsecure = (url: URL): boolean => + ['http:', 'ftp:'].includes(url.protocol) && !isLocal(url); + const resources = window.performance .getEntriesByType('resource') - .filter(({ name }) => /^(http|ftp):/gi.test(name || '')) - .filter(({ name }) => new URL(name).hostname !== 'localhost') + .filter(({ name }) => isInsecure(new URL(name))) .map(({ name }) => `- ${name}`) .join('\n'); diff --git a/spec-main/index.js b/spec-main/index.js index cc605acf3cec..40c783093027 100644 --- a/spec-main/index.js +++ b/spec-main/index.js @@ -30,6 +30,7 @@ app.on('window-all-closed', () => null); // Use fake device for Media Stream to replace actual camera and microphone. app.commandLine.appendSwitch('use-fake-device-for-media-stream'); +app.commandLine.appendSwitch('host-rules', 'MAP localhost2 127.0.0.1'); global.standardScheme = 'app'; global.zoomScheme = 'zoom'; diff --git a/spec-main/security-warnings-spec.ts b/spec-main/security-warnings-spec.ts index cf25d8530dc8..474e9246d875 100644 --- a/spec-main/security-warnings-spec.ts +++ b/spec-main/security-warnings-spec.ts @@ -59,7 +59,7 @@ describe('security warnings', () => { }); }); }).listen(0, '127.0.0.1', () => { - serverUrl = `http://127.0.0.1:${(server.address() as AddressInfo).port}`; + serverUrl = `http://localhost2:${(server.address() as AddressInfo).port}`; done(); }); });