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

Conversation

WillianAgostini
Copy link
Contributor

Fixes #6131
An optimization of regex was implemented.

lib/helpers/combineURLs.js Fixed Show fixed Hide fixed
lib/helpers/combineURLs.js Fixed Show fixed Hide fixed
@WillianAgostini WillianAgostini changed the title Regular Expression Denial of Service (ReDoS) fix: Regular Expression Denial of Service (ReDoS) Dec 14, 2023
Copy link

@firattale firattale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@DigitalBrainJS DigitalBrainJS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this code is still vulnerable

    instance.defaults.baseURL = '///foo' + '/'.repeat(100000) + 'bar/'; 
   // Expected 8803.69999999972 to be less than 20.

Anyway, I believe that replacing /\/+$/ with /\/?\/$/ is enough to solve the issue with ReDos handling only practical cases of user input. The fix now does normalization at more than just the end/beginning and seems overkill as I don't see any cases where we might need to normalize more than two slashes in a valid URL. Moreover, using multiple regular expressions does not benefit performance and code size. Thoughts?

@WillianAgostini
Copy link
Contributor Author

Seems this code is still vulnerable

    instance.defaults.baseURL = '///foo' + '/'.repeat(100000) + 'bar/'; 
   // Expected 8803.69999999972 to be less than 20.

Anyway, I believe that replacing /\/+$/ with /\/?\/$/ is enough to solve the issue with ReDos handling only practical cases of user input. The fix now does normalization at more than just the end/beginning and seems overkill as I don't see any cases where we might need to normalize more than two slashes in a valid URL. Moreover, using multiple regular expressions does not benefit performance and code size. Thoughts?

Fixes 918286c

@ffk-tecky
Copy link

any idea when would this be released?

@DigitalBrainJS
Copy link
Collaborator

Is there any reason we can't simplify this solution to /\/?\/$/ or /\/{1,n}$/? The second regexp /^\/+/ is not vulnerable to ReDoS as it has linear complexity, so there is no reason to filter its input.

@WillianAgostini
Copy link
Contributor Author

Is there any reason we can't simplify this solution to /\/?\/$/ or /\/{1,n}$/? The second regexp /^\/+/ is not vulnerable to ReDoS as it has linear complexity, so there is no reason to filter its input.

However, please note that using /\/?\/$/ or /\/{1,n}$/ does not handle cases where multiple slashes need to be replaced, as demonstrated by the example: '///foo' + '/'.repeat(100000) + 'bar////////'.
In the second case, if you are certain about it, I can remove the filter.

@DigitalBrainJS
Copy link
Collaborator

DigitalBrainJS commented Dec 25, 2023

does not handle cases where multiple slashes need to be replaced

I don't see any reason why we need to normalize multiple trailing slashes since it's an invalid url. We just need to join the base url and relative path and there is no point in complicating the code for an impractical case. So for now I'm I tend to the simplest implementation.

In the second case, if you are certain about it, I can remove the filter.

Well, this is quite obvious, since the graph of the regexp has no branches, only a direct loop. This can be confirmed with a test service like https://devina.io/redos-checker or your test case.

@WillianAgostini
Copy link
Contributor Author

does not handle cases where multiple slashes need to be replaced

I don't see any reason why we need to normalize multiple trailing slashes since it's an invalid url. We just need to join the base url and relative path and there is no point in complicating the code for an impractical case. So for now I'm I tend to the simplest implementation.

In the second case, if you are certain about it, I can remove the filter.

Well, this is quite obvious, since the graph of the regexp has no branches, only a direct loop. This can be confirmed with a test service like https://devina.io/redos-checker or your test case.

I applied the changes ae9f303

…nto fix/6131

� Conflicts:
�	lib/helpers/combineURLs.js
�	test/specs/defaults.spec.js
@DigitalBrainJS DigitalBrainJS merged commit 5e7ad38 into axios:v1.x Dec 26, 2023
8 checks passed
@WillianAgostini WillianAgostini deleted the fix/6131 branch December 26, 2023 20:46
@github-actions github-actions bot mentioned this pull request Dec 26, 2023
contentful-automation bot pushed a commit to contentful/contentful-merge that referenced this pull request Dec 27, 2023
Bumps [axios](https://github.com/axios/axios) from 1.6.2 to 1.6.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/axios/axios/releases">axios's
releases</a>.</em></p>
<blockquote>
<h2>Release v1.6.3</h2>
<h2>Release notes:</h2>
<h3>Bug Fixes</h3>
<ul>
<li>Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)
(<a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d">5e7ad38</a>)</li>
</ul>
<h3>Contributors to this release</h3>
<ul>
<li><!-- raw HTML omitted --> <a href="https://github.com/jasonsaayman"
title="+15/-6 ([#6145](axios/axios#6145)
)">Jay</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/WillianAgostini" title="+17/-2
([#6132](axios/axios#6132) )">Willian
Agostini</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/DigitalBrainJS" title="+3/-0
([#6084](axios/axios#6084) )">Dmitriy
Mozgovoy</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/axios/axios/blob/v1.x/CHANGELOG.md">axios's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/axios/axios/compare/v1.6.2...v1.6.3">1.6.3</a>
(2023-12-26)</h2>
<h3>Bug Fixes</h3>
<ul>
<li>Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)
(<a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d">5e7ad38</a>)</li>
</ul>
<h3>Contributors to this release</h3>
<ul>
<li><!-- raw HTML omitted --> <a href="https://github.com/jasonsaayman"
title="+15/-6 ([#6145](axios/axios#6145)
)">Jay</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/WillianAgostini" title="+17/-2
([#6132](axios/axios#6132) )">Willian
Agostini</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/DigitalBrainJS" title="+3/-0
([#6084](axios/axios#6084) )">Dmitriy
Mozgovoy</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/axios/axios/commit/b15b918d179900e7d47a08f4e96efc89e16d8a7b"><code>b15b918</code></a>
chore(release): v1.6.3 (<a
href="https://redirect.github.com/axios/axios/issues/6151">#6151</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/b76cce0e0f67c0597c748f8b0eb5245277fa6dc7"><code>b76cce0</code></a>
chore(ci): added branches filter for notify action; (<a
href="https://redirect.github.com/axios/axios/issues/6084">#6084</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d"><code>5e7ad38</code></a>
fix: Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/8befb86efb101ef9dc1d1c16d77d2bf42600727f"><code>8befb86</code></a>
docs: update alloy link (<a
href="https://redirect.github.com/axios/axios/issues/6145">#6145</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/d18f40d89af9f86275a24b4ade68bc60eff97214"><code>d18f40d</code></a>
docs: add headline sponsors</li>
<li>See full diff in <a
href="https://github.com/axios/axios/compare/v1.6.2...v1.6.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=axios&package-manager=npm_and_yarn&previous-version=1.6.2&new-version=1.6.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
neotokenapp bot pushed a commit to neohelden/commons-nestjs-server-auth that referenced this pull request Dec 27, 2023
Bumps [axios](https://github.com/axios/axios) from 1.6.2 to 1.6.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/axios/axios/releases">axios's
releases</a>.</em></p>
<blockquote>
<h2>Release v1.6.3</h2>
<h2>Release notes:</h2>
<h3>Bug Fixes</h3>
<ul>
<li>Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)
(<a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d">5e7ad38</a>)</li>
</ul>
<h3>Contributors to this release</h3>
<ul>
<li><!-- raw HTML omitted --> <a href="https://github.com/jasonsaayman"
title="+15/-6 ([#6145](axios/axios#6145)
)">Jay</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/WillianAgostini" title="+17/-2
([#6132](axios/axios#6132) )">Willian
Agostini</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/DigitalBrainJS" title="+3/-0
([#6084](axios/axios#6084) )">Dmitriy
Mozgovoy</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/axios/axios/blob/v1.x/CHANGELOG.md">axios's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/axios/axios/compare/v1.6.2...v1.6.3">1.6.3</a>
(2023-12-26)</h2>
<h3>Bug Fixes</h3>
<ul>
<li>Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)
(<a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d">5e7ad38</a>)</li>
</ul>
<h3>Contributors to this release</h3>
<ul>
<li><!-- raw HTML omitted --> <a href="https://github.com/jasonsaayman"
title="+15/-6 ([#6145](axios/axios#6145)
)">Jay</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/WillianAgostini" title="+17/-2
([#6132](axios/axios#6132) )">Willian
Agostini</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/DigitalBrainJS" title="+3/-0
([#6084](axios/axios#6084) )">Dmitriy
Mozgovoy</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/axios/axios/commit/b15b918d179900e7d47a08f4e96efc89e16d8a7b"><code>b15b918</code></a>
chore(release): v1.6.3 (<a
href="https://redirect.github.com/axios/axios/issues/6151">#6151</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/b76cce0e0f67c0597c748f8b0eb5245277fa6dc7"><code>b76cce0</code></a>
chore(ci): added branches filter for notify action; (<a
href="https://redirect.github.com/axios/axios/issues/6084">#6084</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d"><code>5e7ad38</code></a>
fix: Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/8befb86efb101ef9dc1d1c16d77d2bf42600727f"><code>8befb86</code></a>
docs: update alloy link (<a
href="https://redirect.github.com/axios/axios/issues/6145">#6145</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/d18f40d89af9f86275a24b4ade68bc60eff97214"><code>d18f40d</code></a>
docs: add headline sponsors</li>
<li>See full diff in <a
href="https://github.com/axios/axios/compare/v1.6.2...v1.6.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=axios&package-manager=npm_and_yarn&previous-version=1.6.2&new-version=1.6.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
ModyQyW added a commit to uni-helper/uni-network that referenced this pull request Dec 27, 2023
github-actions bot pushed a commit to implydata/openapi-ts that referenced this pull request Dec 27, 2023
Bumps [axios](https://github.com/axios/axios) from 1.6.2 to 1.6.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/axios/axios/releases">axios's
releases</a>.</em></p>
<blockquote>
<h2>Release v1.6.3</h2>
<h2>Release notes:</h2>
<h3>Bug Fixes</h3>
<ul>
<li>Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)
(<a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d">5e7ad38</a>)</li>
</ul>
<h3>Contributors to this release</h3>
<ul>
<li><!-- raw HTML omitted --> <a href="https://github.com/jasonsaayman"
title="+15/-6 ([#6145](axios/axios#6145)
)">Jay</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/WillianAgostini" title="+17/-2
([#6132](axios/axios#6132) )">Willian
Agostini</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/DigitalBrainJS" title="+3/-0
([#6084](axios/axios#6084) )">Dmitriy
Mozgovoy</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/axios/axios/blob/v1.x/CHANGELOG.md">axios's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/axios/axios/compare/v1.6.2...v1.6.3">1.6.3</a>
(2023-12-26)</h2>
<h3>Bug Fixes</h3>
<ul>
<li>Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)
(<a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d">5e7ad38</a>)</li>
</ul>
<h3>Contributors to this release</h3>
<ul>
<li><!-- raw HTML omitted --> <a href="https://github.com/jasonsaayman"
title="+15/-6 ([#6145](axios/axios#6145)
)">Jay</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/WillianAgostini" title="+17/-2
([#6132](axios/axios#6132) )">Willian
Agostini</a></li>
<li><!-- raw HTML omitted --> <a
href="https://github.com/DigitalBrainJS" title="+3/-0
([#6084](axios/axios#6084) )">Dmitriy
Mozgovoy</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/axios/axios/commit/b15b918d179900e7d47a08f4e96efc89e16d8a7b"><code>b15b918</code></a>
chore(release): v1.6.3 (<a
href="https://redirect.github.com/axios/axios/issues/6151">#6151</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/b76cce0e0f67c0597c748f8b0eb5245277fa6dc7"><code>b76cce0</code></a>
chore(ci): added branches filter for notify action; (<a
href="https://redirect.github.com/axios/axios/issues/6084">#6084</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/5e7ad38fb0f819fceb19fb2ee5d5d38f56aa837d"><code>5e7ad38</code></a>
fix: Regular Expression Denial of Service (ReDoS) (<a
href="https://redirect.github.com/axios/axios/issues/6132">#6132</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/8befb86efb101ef9dc1d1c16d77d2bf42600727f"><code>8befb86</code></a>
docs: update alloy link (<a
href="https://redirect.github.com/axios/axios/issues/6145">#6145</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/d18f40d89af9f86275a24b4ade68bc60eff97214"><code>d18f40d</code></a>
docs: add headline sponsors</li>
<li>See full diff in <a
href="https://github.com/axios/axios/compare/v1.6.2...v1.6.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=axios&package-manager=npm_and_yarn&previous-version=1.6.2&new-version=1.6.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regular Expression Denial of Service (ReDoS) in axios/axios
4 participants