ghost-keychain/packages/extension/src/page.ts
Thibaut Sardan ae9227ef6d
Add phishing site detection, redirection and information (#488)
* missing type declarations for @polkadot/phishing

* phishing landing page

* Update packages/extension-base/src/background/types.ts

* wording make it short

* fix build

* add test for xml pdf utils

* fix export

* Update packages/extension-base/src/utils/isXmlOrPdf.ts

* use Trans from i18n

* alpha ordering

* i18nKey

* lint

* move pdf and xml detection to enable to prevent unwanted redirection

* styled component refactoring

* import odering

* remove a css hack :)

Co-authored-by: Github Actions <action@github.com>
2020-10-13 14:14:55 +02:00

45 lines
1.3 KiB
TypeScript

// Copyright 2019-2020 @polkadot/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Message } from '@polkadot/extension-base/types';
import { enable, handleResponse, redirectPhishing } from '@polkadot/extension-base/page';
import { injectExtension } from '@polkadot/extension-inject';
import retrieveCheckDeny from '@polkadot/phishing';
// setup a response listener (events created by the loader for extension responses)
window.addEventListener('message', ({ data, source }: Message): void => {
// only allow messages from our window, by the loader
if (source !== window || data.origin !== 'content') {
return;
}
if (data.id) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handleResponse(data as any);
} else {
console.error('Missing id for response.');
}
});
const currentUrl = window.location.host;
retrieveCheckDeny(currentUrl)
.then((isOnDeny) => {
if (isOnDeny) {
console.log('Phishing detected, redirecting to phishing info landing page');
redirectPhishing().catch(console.error);
} else {
inject();
}
}).catch((e) => {
console.error(e);
});
function inject () {
injectExtension(enable, {
name: 'polkadot-js',
version: process.env.PKG_VERSION as string
});
}