Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Redos vuln in string().url() regex #2245

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let rEmail =

let rUrl =
// eslint-disable-next-line
/^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|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|::)|(::(?:\d{1,3}\.){1,3}\d{1,3}))\])|localhost|([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(-[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*\.)+[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))(?:\:\d{2,5})?(?:\/[a-z\d\-._~%!$&'()*+,;=:@\/]*)?(?:\?[a-z\d\-._~%!$&'()*+,;=:@\/?]*)?(?:#[a-z\d\-._~%!$&'()*+,;=:@\/?]*)?$/i;

// eslint-disable-next-line
let rUUID =
Expand Down
14 changes: 12 additions & 2 deletions test/string.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as TestHelpers from './helpers';

import {
string,
AnySchema,
number,
object,
ref,
string,
ValidationError,
AnySchema,
} from '../src';

describe('String types', () => {
Expand Down Expand Up @@ -209,7 +209,17 @@

return Promise.all([
expect(v.isValid('//www.github.com/')).resolves.toBe(true),
expect(v.isValid('https://username:[email protected]:8080/path#fragment')).resolves.toBe(true),
expect(v.isValid('https://username:[email protected]/path#fragment')).resolves.toBe(true),
expect(v.isValid('http://127.0.0.1:8080/')).resolves.toBe(true),
expect(v.isValid('http://127.0.0.1/')).resolves.toBe(true),
expect(v.isValid('https://www.github.com/')).resolves.toBe(true),
expect(v.isValid('http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]')).resolves.toBe(true),
expect(v.isValid('ftp://localhost')).resolves.toBe(true),
expect(v.isValid('http://[::255.255.255.255]')).resolves.toBe(true),
expect(v.isValid('http://localhost/')).resolves.toBe(true),
expect(v.isValid('http://localhost:8000/')).resolves.toBe(true),
expect(v.isValid('//T.' + '0.'.repeat(3000) + '\x00')).resolves.toBe(false),
expect(v.isValid('this is not a url')).resolves.toBe(false),
]);
});
Expand Down Expand Up @@ -336,7 +346,7 @@
});
});

xit('should check allowed values at the end', () => {

Check warning on line 349 in test/string.ts

View workflow job for this annotation

GitHub Actions / build

Disabled test
return Promise.all([
expect(
string()
Expand Down
Loading