1- import { toASCII , toUnicode } from 'punycode/' ;
1+ import { toUnicode } from 'punycode/' ;
22import { pipeline } from 'readable-stream' ;
3- import PhishingDetector from 'eth-phishing-detect/src/detector' ;
43import { WindowPostMessageStream } from '@metamask/post-message-stream' ;
54import ObjectMultiplex from '@metamask/object-multiplex' ;
65
@@ -93,50 +92,8 @@ function isValidSuspectHref(href: string) {
9392 return disallowedProtocols . indexOf ( parsedSuspectHref . protocol ) < 0 ;
9493}
9594
96- const newIssueUrls = {
97- metamask : 'https://github.com/MetaMask/eth-phishing-detect/issues/new' ,
98- phishfort : 'https://github.com/phishfort/phishfort-lists/issues/new' ,
99- } ;
100-
101- const metamaskConfigUrl =
102- 'https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/config.json' ;
103-
104- /**
105- * Determines whether the given URL was blocked by our phishing configuration or not.
106- *
107- * @param href - The blocked URL.
108- * @returns `true` if this URL is blocked by our phishing configuration, `false` otherwise.
109- */
110- async function isBlockedByMetamask ( href : string ) {
111- try {
112- const response = await fetch ( metamaskConfigUrl , { cache : 'no-cache' } ) ;
113- if ( ! response . ok ) {
114- throw new Error ( `Received non-200 response: ${ response . status } ` ) ;
115- }
116- const config = await response . json ( ) ;
117- const detector = new PhishingDetector ( [
118- {
119- allowlist : config . whitelist ,
120- blocklist : config . blacklist ,
121- fuzzylist : config . fuzzylist ,
122- tolerance : config . tolerance ,
123- name : 'MetaMask' ,
124- version : config . version ,
125- } ,
126- ] ) ;
127- const { hostname } = new URL ( href ) ;
128-
129- const punycodeHostname = toASCII ( hostname ) ;
130- const phishingTestResponse = detector . check ( punycodeHostname ) ;
131- console . debug ( 'Phishing config test results:' , phishingTestResponse ) ;
132-
133- return phishingTestResponse . result ;
134- } catch ( error ) {
135- console . error ( error ) ;
136- // default to assuming that it is blocked by our configuration
137- return true ;
138- }
139- }
95+ const newIssueUrl =
96+ 'https://github.com/MetaMask/eth-phishing-detect/issues/new' ;
14097
14198/**
14299 * Extract hostname and href from the query string.
@@ -181,20 +138,6 @@ function start() {
181138 ] ) ;
182139 const phishingSafelistStream = mux . createStream ( 'metamask-phishing-safelist' ) ;
183140
184- const backToSafetyLink = document . getElementById ( 'back-to-safety' ) ;
185- if ( ! backToSafetyLink ) {
186- throw new Error ( 'Unable to locate back to safety link' ) ;
187- }
188-
189- backToSafetyLink . addEventListener ( 'click' , async ( ) => {
190- phishingSafelistStream . write ( {
191- jsonrpc : '2.0' ,
192- method : 'backToSafetyPhishingWarning' ,
193- params : [ ] ,
194- id : createRandomId ( ) ,
195- } ) ;
196- } ) ;
197-
198141 const { hash } = new URL ( window . location . href ) ;
199142 const hashContents = hash . slice ( 1 ) ; // drop leading '#' from hash
200143 const hashQueryString = new URLSearchParams ( hashContents ) ;
@@ -222,10 +165,7 @@ function start() {
222165 ) } &body=${ encodeURIComponent ( toUnicode ( suspectHrefUnicode ) ) } `;
223166
224167 newIssueLink . addEventListener ( 'click' , async ( ) => {
225- const listName = ( await isBlockedByMetamask ( suspectHref ) )
226- ? 'metamask'
227- : 'phishfort' ;
228- window . location . href = `${ newIssueUrls [ listName ] } ${ newIssueParams } ` ;
168+ window . location . href = `${ newIssueUrl } ${ newIssueParams } ` ;
229169 } ) ;
230170
231171 const continueLink = document . getElementById ( 'unsafe-continue' ) ;
@@ -251,4 +191,18 @@ function start() {
251191
252192 // To know when the event listener has been added, to mitigate an e2e race condition
253193 continueLink . setAttribute ( 'data-testid' , 'unsafe-continue-loaded' ) ;
194+
195+ const portfolioLink = document . getElementById ( 'portfolio-link' ) ;
196+ if ( ! portfolioLink ) {
197+ throw new Error ( 'Unable to locate portfolio link' ) ;
198+ }
199+
200+ portfolioLink . addEventListener ( 'click' , async ( ) => {
201+ phishingSafelistStream . write ( {
202+ jsonrpc : '2.0' ,
203+ method : 'backToSafetyPhishingWarning' ,
204+ params : [ ] ,
205+ id : createRandomId ( ) ,
206+ } ) ;
207+ } ) ;
254208}
0 commit comments