Skip to content

Commit

Permalink
feat(snaps-utils): Allow overriding allowed protocols in validateLink
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed May 15, 2024
1 parent 8df9a32 commit fb6eb15
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/snaps-utils/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { lexer, walkTokens } from 'marked';
import type { Token, Tokens } from 'marked';

const MAX_TEXT_LENGTH = 50_000; // 50 kb
const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];
const DEFAULT_ALLOWED_PROTOCOLS = ['https:', 'mailto:'];

/**
* Get the button variant from a legacy button component variant.
Expand Down Expand Up @@ -320,16 +320,18 @@ function getMarkdownLinks(text: string) {
* @param link - The link to validate.
* @param isOnPhishingList - The function that checks the link against the
* phishing list.
* @param allowedProtocols - Allowed protocols (example: ['https:'])

Check failure on line 323 in packages/snaps-utils/src/ui.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (@metamask/snaps-utils)

JSDoc description does not satisfy the regex pattern
*/
function validateLink(
link: string,
isOnPhishingList: (url: string) => boolean,
allowedProtocols: string[] = DEFAULT_ALLOWED_PROTOCOLS,
) {
try {
const url = new URL(link);
assert(
ALLOWED_PROTOCOLS.includes(url.protocol),
`Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,
allowedProtocols.includes(url.protocol),
`Protocol must be one of: ${allowedProtocols.join(', ')}.`,
);

const hostname =
Expand Down

0 comments on commit fb6eb15

Please sign in to comment.