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
8 changes: 7 additions & 1 deletion src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ export default function isURL(url, options) {
const valid_auth_regex = /^[a-zA-Z0-9\-_.%:]*$/;
const is_valid_auth = valid_auth_regex.test(before_at);

if (is_valid_auth) {
// Check if this contains URL-encoded content that could be malicious
// For example: javascript:%61%6c%65%72%74%28%31%29@example.com
// The encoded part decodes to: alert(1)
const has_encoded_content = /%[0-9a-fA-F]{2}/.test(before_at);

if (is_valid_auth && !has_encoded_content) {
// This looks like authentication (e.g., user:password@host), not a protocol
if (options.require_protocol) {
return false;
Expand All @@ -135,6 +140,7 @@ export default function isURL(url, options) {
// Don't consume the colon; let the auth parsing handle it later
} else {
// This looks like a malicious protocol (e.g., javascript:alert();@host)
// or URL-encoded protocol handler (e.g., javascript:%61%6c%65%72%74%28%31%29@host)
url = cleanUpProtocol(potential_protocol);

if (url === false) {
Expand Down
3 changes: 2 additions & 1 deletion test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ describe('Validators', () => {
'http://1337.com',
// TODO: those probably should not be marked as valid URLs; CVE-2025-56200
/* eslint-disable no-script-url */
'javascript:%61%6c%65%72%74%28%31%29@example.com',
'http://evil-site.com@example.com/',
'javascript:alert(1)@example.com',
/* eslint-enable no-script-url */
Expand Down Expand Up @@ -480,6 +479,8 @@ describe('Validators', () => {
'javascript:var a=1; alert(a);@example.com',
'javascript:alert(1)@user@example.com',
'javascript:alert(1)@example.com?q=safe',
'javascript:%61%6c%65%72%74%28%31%29@example.com',
'javascript:%22@a.com#";alert(origin)//',
'data:text/html,<script>alert(1)</script>@example.com',
'vbscript:msgbox("XSS")@example.com',
'//evil-site.com/path@example.com',
Expand Down
Loading