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: Regular Expression Denial of Service (ReDoS) #6132

Merged
merged 11 commits into from
Dec 26, 2023
Prev Previous commit
Next Next commit
perf: optimize regex and remove unnecessary regex
  • Loading branch information
WillianAgostini committed Dec 26, 2023
commit ae9f3039ca485e2705a83410f98afb2ee6d123aa
4 changes: 2 additions & 2 deletions lib/helpers/combineURLs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
export default function combineURLs(baseURL, relativeURL) {
if (!relativeURL) return baseURL;

const baseURLRegex = new RegExp(/\/+$/);
const baseURLRegex = new RegExp(/\/?\/$/);
const relativeURLRegex = new RegExp(/^\/+/);
const multipleSlashes = new RegExp(/\/{3,}/g);
return baseURL.replace(multipleSlashes, '/').replace(baseURLRegex, '')
+ '/'
+ relativeURL.replace(multipleSlashes, '/').replace(relativeURLRegex, '');
+ relativeURL.replace(relativeURLRegex, '');
}