mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 12:56:01 +01:00
7199d9c567
An externally hosted phishing warning page is now used rather than the built-in phishing warning page.The phishing page warning URL is set via configuration file or environment variable. The default URL is either the expected production URL or `http://localhost:9999/` for e2e testing environments. The new external phishing page includes a design change when it is loaded within an iframe. In that case it now shows a condensed message, and prompts the user to open the full warning page in a new tab to see more details or bypass the warning. This is to prevent a clickjacking attack from safelisting a site without user consent. The new external phishing page also includes a simple caching service worker to ensure it continues to work offline (or if our hosting goes offline), as long as the user has successfully loaded the page at least once. We also load the page temporarily during the extension startup process to trigger the service worker installation. The old phishing page and all related lines have been removed. The property `web_accessible_resources` has also been removed from the manifest. The only entry apart from the phishing page was `inpage.js`, and we don't need that to be web accessible anymore because we inject the script inline into each page rather than loading the file directly. New e2e tests have been added to cover more phishing warning page functionality, including the "safelist" action and the "iframe" case.
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
const path = require('path');
|
|
const createStaticServer = require('../../development/create-static-server');
|
|
|
|
const phishingWarningDirectory = path.resolve(
|
|
__dirname,
|
|
'..',
|
|
'..',
|
|
'node_modules',
|
|
'@metamask',
|
|
'phishing-warning',
|
|
'dist',
|
|
);
|
|
|
|
class PhishingWarningPageServer {
|
|
constructor() {
|
|
this._server = createStaticServer(phishingWarningDirectory);
|
|
}
|
|
|
|
async start({ port = 9999 } = {}) {
|
|
this._server.listen(port);
|
|
|
|
let resolveStart;
|
|
let rejectStart;
|
|
const result = new Promise((resolve, reject) => {
|
|
resolveStart = resolve;
|
|
rejectStart = reject;
|
|
});
|
|
this._server.once('listening', resolveStart);
|
|
this._server.once('error', rejectStart);
|
|
|
|
try {
|
|
await result;
|
|
// clean up listener to ensure later errors properly bubble up
|
|
this._server.removeListener('error', rejectStart);
|
|
} catch (error) {
|
|
this._server.removeListener('listening', resolveStart);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
isRunning() {
|
|
return this._server.listening;
|
|
}
|
|
|
|
async quit() {
|
|
await new Promise((resolve, reject) =>
|
|
this._server.close((error) => {
|
|
if (error) {
|
|
reject(error);
|
|
} else {
|
|
resolve();
|
|
}
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
module.exports = PhishingWarningPageServer;
|