Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update phishingSafelistStream to send origin as a parameter for safelistPhishingDomain #165

Merged
merged 6 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- **BREAKING**: Update `phishingSafelistStream` to send `origin` instead of `hostname` as a parameter for `safelistPhishingDomain` method ([#165](https://github.com/MetaMask/phishing-warning/pull/165))

## [3.0.4]
### Changed
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ async function isBlockedByMetamask(href: string) {
* @param href - The href value to check.
*/
function getSuspect(href = ''): {
suspectHostname: string;
suspectHostnameUnicode: string;
suspectHref: string;
suspectHrefUnicode: string;
suspectOrigin: string;
} {
try {
const url = new URL(href);
const unicodeHostname = toUnicode(url.hostname);
const unicodeHref = `${url.protocol}//${unicodeHostname}${url.pathname}${url.search}${url.hash}`;
return {
suspectHostname: url.hostname,
suspectHostnameUnicode: unicodeHostname,
suspectHref: url.href,
suspectHrefUnicode: unicodeHref,
suspectOrigin: url.origin,
};
} catch (error) {
throw new Error(`Invalid 'href' query parameter`);
Expand Down Expand Up @@ -200,10 +200,10 @@ function start() {
const hashQueryString = new URLSearchParams(hashContents);

const {
suspectHostname,
suspectHref,
suspectHostnameUnicode,
suspectHrefUnicode,
suspectOrigin,
} = getSuspect(hashQueryString.get('href'));

const suspectLink = document.getElementById('suspect-link');
Expand Down Expand Up @@ -242,7 +242,7 @@ function start() {
phishingSafelistStream.write({
jsonrpc: '2.0',
method: 'safelistPhishingDomain',
params: [suspectHostname],
params: [suspectOrigin],
id: createRandomId(),
});

Expand Down
4 changes: 2 additions & 2 deletions tests/bypass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test.beforeEach(async ({ context }) => {
await setupDefaultMocks(context);
});

test('allows the user to bypass the warning and add the site to the allowlist', async ({
test('allows the user to bypass the warning and add the site origin to the allowlist', async ({
page,
}) => {
const postMessageLogs = await setupStreamInitialization(page);
Expand All @@ -24,7 +24,7 @@ test('allows the user to bypass the warning and add the site to the allowlist',
id: expect.any(Number),
jsonrpc: '2.0',
method: 'safelistPhishingDomain',
params: ['test.com'],
params: ['https://test.com'],
},
name: 'metamask-phishing-safelist',
});
Expand Down
Loading