From 433bc2387354c38a1cab4ebaf4cdcc3b5c6058f4 Mon Sep 17 00:00:00 2001 From: witmicko Date: Tue, 21 Nov 2023 13:14:55 +0000 Subject: [PATCH] added dev build, moved to using href --- .vscode/launch.json | 2 +- .vscode/settings.json | 2 +- package.json | 6 +++--- src/index.ts | 17 +++++++++-------- tests/failed-lookup.spec.ts | 2 +- tests/metamask-block.spec.ts | 10 ++++++---- tests/phishfort-block.spec.ts | 2 +- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a50dc60..593dcc8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,4 +11,4 @@ "type": "node-terminal" } ] -} \ No newline at end of file +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 9e26dfe..0967ef4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/package.json b/package.json index 9b39f5c..a66956c 100644 --- a/package.json +++ b/package.json @@ -12,17 +12,17 @@ ], "scripts": { "build": "node ./build/index.js", - "build:prod": "NODE='production' yarn build", "build:dev": "node ./build/dev.js", + "build:prod": "NODE='production' yarn build", + "dev": "yarn build:dev", "lint": "yarn lint:eslint && yarn lint:misc --check", "lint:eslint": "eslint . --cache --ext js,ts", "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write", "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern", "prepack": "./scripts/prepack.sh", + "serve": "yarn http-server ./dist", "setup": "yarn install && yarn allow-scripts", "start": "yarn build && yarn http-server ./dist", - "dev": "yarn build:dev", - "serve": "yarn http-server ./dist", "test": "yarn playwright test" }, "dependencies": { diff --git a/src/index.ts b/src/index.ts index 9929845..4574fe5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -141,20 +141,21 @@ async function isBlockedByMetamask(href: string) { /** * Extract hostname and href from the query string. * - * @returns the suspect hostname and href from the query string. + * @returns The suspect hostname and href from the query string. * @param href - The href value to check. */ -function getSuspect( - href: string | null, -): { +function getSuspect(href: string | null): { suspectHostname: string; suspectHref: string; + suspectHrefPlain: string; } { try { - const url = new URL(href || ''); + const hrefStr = href || ''; + const url = new URL(hrefStr); return { suspectHostname: url.hostname, suspectHref: url.href, + suspectHrefPlain: hrefStr, }; } catch (error) { throw new Error(`Invalid 'href' query parameter`); @@ -181,7 +182,7 @@ function start() { const hashContents = hash.slice(1); // drop leading '#' from hash const hashQueryString = new URLSearchParams(hashContents); - const { suspectHostname, suspectHref } = getSuspect( + const { suspectHostname, suspectHref, suspectHrefPlain } = getSuspect( hashQueryString.get('href'), ); @@ -197,8 +198,8 @@ function start() { } const newIssueParams = `?title=[Legitimate%20Site%20Blocked]%20${encodeURIComponent( - suspectHostname, - )}&body=${encodeURIComponent(suspectHref)}`; + suspectHrefPlain, + )}&body=${encodeURIComponent(suspectHrefPlain)}`; newIssueLink.addEventListener('click', async () => { const listName = (await isBlockedByMetamask(suspectHref)) diff --git a/tests/failed-lookup.spec.ts b/tests/failed-lookup.spec.ts index 465064f..a01947e 100644 --- a/tests/failed-lookup.spec.ts +++ b/tests/failed-lookup.spec.ts @@ -17,6 +17,6 @@ test('directs users to eth-phishing-detect to dispute a block, including issue t await page.waitForLoadState('networkidle'); await expect(page).toHaveURL( - 'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20test.com&body=https%3A%2F%2Ftest.com%2F', + 'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20https%3A%2F%2Ftest.com&body=https%3A%2F%2Ftest.com', ); }); diff --git a/tests/metamask-block.spec.ts b/tests/metamask-block.spec.ts index 3f27138..9db8560 100644 --- a/tests/metamask-block.spec.ts +++ b/tests/metamask-block.spec.ts @@ -22,7 +22,7 @@ test('directs users to eth-phishing-detect to dispute a block, including issue t await page.waitForLoadState('networkidle'); await expect(page).toHaveURL( - 'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20test.com&body=https%3A%2F%2Ftest.com%2F', + 'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20https%3A%2F%2Ftest.com&body=https%3A%2F%2Ftest.com', ); }); @@ -33,10 +33,12 @@ test('correctly matches unicode domains', async ({ context, page }) => { blacklist: ['xn--metamsk-en4c.io'], }, }); + const url = 'https://metamạsk.io'; const querystring = new URLSearchParams({ - hostname: 'test.com', - href: 'https://metamạsk.io', + hostname: url, + href: url, }); + const encoded = encodeURIComponent(url); await page.goto(`/#${querystring}`); await page.getByRole('link', { name: 'report a detection problem' }).click(); @@ -44,6 +46,6 @@ test('correctly matches unicode domains', async ({ context, page }) => { await page.waitForLoadState('networkidle'); await expect(page).toHaveURL( - 'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20test.com&body=https%3A%2F%2Fmetamạsk.io', + `https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20${encoded}&body=${encoded}`, ); }); diff --git a/tests/phishfort-block.spec.ts b/tests/phishfort-block.spec.ts index aff3ba3..9b9028d 100644 --- a/tests/phishfort-block.spec.ts +++ b/tests/phishfort-block.spec.ts @@ -19,6 +19,6 @@ test('directs users to PhishFort to dispute a block, including issue template pa await page.waitForLoadState('networkidle'); await expect(page).toHaveURL( - 'https://github.com/phishfort/phishfort-lists/issues/new?title=[Legitimate%20Site%20Blocked]%20test.com&body=https%3A%2F%2Ftest.com%2F', + 'https://github.com/phishfort/phishfort-lists/issues/new?title=[Legitimate%20Site%20Blocked]%20https%3A%2F%2Ftest.com&body=https%3A%2F%2Ftest.com', ); });