Skip to content
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
13 changes: 13 additions & 0 deletions packages/snaps-utils/src/ui.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,19 @@ describe('validateLink', () => {
expect(fn).toHaveBeenCalledWith('https://test.metamask-phishing.io');
});

it('throws an error for an email containing more than one "@" symbol', () => {
const fn = jest.fn().mockReturnValue(false);
const getSnap = jest.fn();

expect(() =>
validateLink('mailto:foo@bar.com@baz.com', fn, getSnap),
).toThrow(
'Invalid URL: Unable to parse email address "foo@bar.com@baz.com".',
);

expect(fn).not.toHaveBeenCalled();
});

it('throws an error for a phishing email when using parameters', () => {
const fn = jest.fn().mockImplementation((email) => {
if (email === 'https://test.metamask-phishing.io') {
Expand Down
5 changes: 4 additions & 1 deletion packages/snaps-utils/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ export function validateLink(
} else if (url.protocol === 'mailto:') {
const emails = url.pathname.split(',');
for (const email of emails) {
const hostname = email.split('@')[1];
const parts = email.split('@');
assert(parts.length === 2, `Unable to parse email address "${email}".`);

const hostname = parts[1];
assert(!hostname.includes(':'));
const href = `https://${hostname}`;
assert(!isOnPhishingList(href), 'The specified URL is not allowed.');
Expand Down
Loading