Skip to content

Fix ReDoS in Bootstrap sample #63264

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Fix ReDoS in Bootstrap sample #63264

wants to merge 9 commits into from

Conversation

wukunyu264
Copy link

@wukunyu264 wukunyu264 commented Aug 15, 2025

{PR title}

  • [ √] You've read the Contributor Guide and Code of Conduct.
  • [√ ] You've included unit or integration tests for your change, where applicable.
  • [√ ] You've included inline docs for your change, where applicable.
  • [ √] There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

{Detail}

Fixes #{63264}
The Bootstrap JS vendored by the sample contains three uses of:
/.*(?=#[^\s]+$)/
src/Security/samples/ClaimsTransformation/wwwroot/lib/bootstrap/dist/js/bootstrap.js(513,707,1267)
to keep the trailing #… part of a URL. This pattern can catastrophically backtrack under crafted inputs and cause high CPU.
Changes (two lines only)

line 514:

- href = href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
+ href = href && href.indexOf('#') !== -1 ? href.slice(href.lastIndexOf('#')) : href // strip for ie7 (safe)

line 708:

- || (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
+ || ((href = $trigger.attr('href')) && (href.indexOf('#') !== -1 ? href.slice(href.lastIndexOf('#')) : href)) // strip for ie7 (safe)

line 1268:

- (href && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
+ (href && href.replace(/^[^#]*(?=#\S+$)/, '')) // strip for ie7 - safe

Why

/.(?=#[^\s]+$)/ mixes a greedy . with an end-anchored look-ahead; inputs like very long runs of characters followed by a short terminator can trigger catastrophic backtracking (ReDoS).

The replacement using href.slice(href.lastIndexOf('#')) preserves exactly the same behavior (keep the trailing #… segment when present) with linear complexity and no new dependencies.

Tests

How to run:

git clone https://github.com/wukunyu264/aspnetcore.git
cd src/Security/samples/ClaimsTransformation/wwwroot/lib/bootstrap
node --test 

before:
image

image

after:
image

gist:https://gist.github.com/wukunyu264/05afd852d727cbc6d4ab533e363fd886
https://gist.github.com/wukunyu264/d6465afd5e9f30356a200e78110920cf
https://gist.github.com/wukunyu264/932fea8d20d9e4c5059fd119e4f463c0

@wukunyu264 wukunyu264 requested a review from halter73 as a code owner August 15, 2025 05:13
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Aug 15, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 15, 2025
Copy link
Contributor

Thanks for your PR, @@wukunyu264. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@wukunyu264
Copy link
Author

@dotnet-policy-service agree

@wukunyu264
Copy link
Author

wukunyu264 commented Aug 15, 2025 via email

Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Aug 22, 2025
@wukunyu264
Copy link
Author

Hi team - I have updated this PR: I have fixed another Redos vulnerability in the same file, resolved the conflict based on the latest main content, and included previous feedback. I also ran CI again to clear outdated status (/azp run).
The test passed locally; If you need anything else, please let me know. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates that the PR has been added by a community member needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant