fix: suppress insecure resource warning for more local hostnames (#30885)

* fix: suppress insecure resource warning for more local hostnames

* fix tests
This commit is contained in:
Jeremy Rose 2021-09-20 23:47:54 -07:00 committed by GitHub
parent 82da4b0090
commit e38a0a67c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View file

@ -103,10 +103,14 @@ const warnAboutInsecureResources = function () {
return; 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 const resources = window.performance
.getEntriesByType('resource') .getEntriesByType('resource')
.filter(({ name }) => /^(http|ftp):/gi.test(name || '')) .filter(({ name }) => isInsecure(new URL(name)))
.filter(({ name }) => new URL(name).hostname !== 'localhost')
.map(({ name }) => `- ${name}`) .map(({ name }) => `- ${name}`)
.join('\n'); .join('\n');

View file

@ -30,6 +30,7 @@ app.on('window-all-closed', () => null);
// Use fake device for Media Stream to replace actual camera and microphone. // Use fake device for Media Stream to replace actual camera and microphone.
app.commandLine.appendSwitch('use-fake-device-for-media-stream'); app.commandLine.appendSwitch('use-fake-device-for-media-stream');
app.commandLine.appendSwitch('host-rules', 'MAP localhost2 127.0.0.1');
global.standardScheme = 'app'; global.standardScheme = 'app';
global.zoomScheme = 'zoom'; global.zoomScheme = 'zoom';

View file

@ -59,7 +59,7 @@ describe('security warnings', () => {
}); });
}); });
}).listen(0, '127.0.0.1', () => { }).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(); done();
}); });
}); });