-
Notifications
You must be signed in to change notification settings - Fork 0
fix: prevent ReDoS in URL regex pattern #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -861,8 +861,15 @@ Abide.defaults = { | |
| // From CommonRegexJS (@talyssonoc) | ||
| // https://github.com/talyssonoc/CommonRegexJS/blob/e2901b9f57222bc14069dc8f0598d5f412555411/lib/commonregex.js#L76 | ||
| // For more restrictive URL Regexs, see https://mathiasbynens.be/demo/url-regex. | ||
| url: /^((?:(https?|ftps?|file|ssh|sftp):\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019]))$/, | ||
|
|
||
| url: (function() { | ||
| const protocol = '(?:https?|ftps?|file|ssh|sftp):\\/\\/'; | ||
| const www = 'www\\d{0,3}[.]'; | ||
| const domain = '[a-z0-9.\\-]+[.][a-z]{2,4}\\/'; | ||
| const body = '(?:[^\\s()<>]+|\\((?:[^\\s()<>]+|(?:\\([^\\s()<>]+\\)))*\\))+' + | ||
| '(?:\\((?:[^\\s()<>]+|(?:\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'".,<>?\\xab\\xbb\\u201c\\u201d\\u2018\\u2019])'; | ||
| return new RegExp(`^((?:${protocol}|${www}|${domain})${body})$`, 'i'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question (bug_risk): The added The original regex was case-sensitive; constructing it with |
||
| })(), | ||
|
|
||
| // abc.de | ||
| domain : /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,8}$/, | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): New use of
constand template literals introduces ES2015 features into what appears to be an ES5-oriented file.The new
const, template literals, and IIFE-basedRegExpmean this file now relies on ES2015 syntax. If this bundle must run in ES5-only environments (e.g., IE11 or non-transpiled tooling), this can cause syntax errors. If ES2015+ is required/guaranteed, no change needed; otherwise, please revert to ES5 constructs or ensure this file is transpiled.