Skip to content

Commit

Permalink
fix: fix linting issues
Browse files Browse the repository at this point in the history
Co-authored-by: Iris Booker <iris.booker@getbraintree.com>
  • Loading branch information
braintreeps and Iris Booker committed Jul 9, 2024
1 parent 3565d2c commit 3994005
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe("sanitizeUrl", () => {
expect(sanitizeUrl(vector)).toBe(BLANK_URL);
});
});

it("backslash prefixed attack vectors", () => {
const attackVectors = [
"\fjavascript:alert()",
Expand All @@ -156,7 +156,7 @@ describe("sanitizeUrl", () => {
"\rjavascript:alert()",
"\u0000javascript:alert()",
"\u0001javascript:alert()",
"\j\av\a\s\cript:alert()",
"\\j\\av\\a\\s\\cript:alert()",
];

attackVectors.forEach((vector) => {
Expand Down
11 changes: 3 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ function decodeHtmlCharacters(str: string) {
}

function isValidUrl(url: string): boolean {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
return URL.canParse(url);
}

function decodeURI(uri: string): string {
Expand Down Expand Up @@ -89,12 +84,12 @@ export function sanitizeUrl(url?: string): string {
}

// Handle special cases for mailto: and custom deep-link protocols
if (urlScheme === 'mailto:' || urlScheme.includes('://')) {
if (urlScheme === "mailto:" || urlScheme.includes("://")) {
return trimmedUrl;
}

// For http and https URLs, perform additional validation
if (urlScheme === 'http:' || urlScheme === 'https:') {
if (urlScheme === "http:" || urlScheme === "https:") {
if (!isValidUrl(trimmedUrl)) {
return BLANK_URL;
}
Expand Down

0 comments on commit 3994005

Please sign in to comment.