Skip to content

Commit 98680f1

Browse files
committed
allow unsafe protocol option
1 parent c5d29b2 commit 98680f1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/lib/isURL.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const default_url_options = {
4949
allow_query_components: true,
5050
validate_length: true,
5151
max_allowed_length: 2084,
52+
allow_unsafe_protocol: true,
5253
};
5354

5455
const wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
@@ -58,10 +59,12 @@ export default function isURL(url, options) {
5859
if (!url || /[\s<>]/.test(url)) {
5960
return false;
6061
}
61-
const lowerUrl = url.trim().toLowerCase();
62-
const dangerousSchemes = ['javascript:', 'data:', 'vbscript:', 'file:', 'blob:', 'mailto:'];
63-
if (dangerousSchemes.some(scheme => lowerUrl.startsWith(scheme))) {
64-
return false;
62+
if (!options.allow_unsafe_protocol) {
63+
const lowerUrl = url.trim().toLowerCase();
64+
const dangerousSchemes = ['javascript:', 'data:', 'vbscript:', 'file:', 'blob:', 'mailto:'];
65+
if (dangerousSchemes.some(scheme => lowerUrl.startsWith(scheme))) {
66+
return false;
67+
}
6568
}
6669
options = merge(options, default_url_options);
6770

0 commit comments

Comments
 (0)