Skip to content
Open
Changes from 2 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
9 changes: 7 additions & 2 deletions src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
allow_query_components: true,
validate_length: true,
max_allowed_length: 2084,
allow_unsafe_protocol: true,
};

const wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
Expand All @@ -58,8 +59,12 @@
if (!url || /[\s<>]/.test(url)) {
return false;
}
if (url.indexOf('mailto:') === 0) {
return false;
if (!options.allow_unsafe_protocol) {
const lowerUrl = url.trim().toLowerCase();
const dangerousSchemes = ['javascript:', 'data:', 'vbscript:', 'file:', 'blob:', 'mailto:'];

Check failure on line 64 in src/lib/isURL.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 18

Script URL is a form of eval

Check failure on line 64 in src/lib/isURL.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 16

Script URL is a form of eval

Check failure on line 64 in src/lib/isURL.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 22

Script URL is a form of eval

Check failure on line 64 in src/lib/isURL.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 20

Script URL is a form of eval

Check failure on line 64 in src/lib/isURL.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Script URL is a form of eval

Check failure on line 64 in src/lib/isURL.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Script URL is a form of eval

Check failure on line 64 in src/lib/isURL.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Script URL is a form of eval
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition to harden the URL validation

Two suggestions:

  • The inclusion of 'javascript:' and similar literals seems to trigger CI’s static analysis ("Script URL is a form of eval"). You might avoid this by dynamically constructing the strings (e.g. 'java' + 'script:') or pulling them from a constants file.
  • Consider moving dangerousSchemes outside the function scope or converting this logic into a single regex to improve clarity and performance.

if (dangerousSchemes.some(scheme => lowerUrl.startsWith(scheme))) {
return false;
}
}
options = merge(options, default_url_options);

Expand Down
Loading