-
Notifications
You must be signed in to change notification settings - Fork 83
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 Vulnerability in PermitScrubber and Add Performance Test #186
Closed
+2
−1
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
26a34b1
Fix ReDoS vulnerability in PermitScrubber by optimizing regex
ch4n3-yoon f461d2a
Add linear performance test to verify ReDoS mitigation in PermitScrubber
ch4n3-yoon e1c1537
Fix: Add missing require 'benchmark' to scrubbers_test.rb
ch4n3-yoon 713241f
Revert "Add linear performance test to verify ReDoS mitigation in Per…
ch4n3-yoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
require "benchmark" | ||
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. Please remove this line, it's no longer necessary. |
||
require "minitest/autorun" | ||
require "rails-html-sanitizer" | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think the meaning of the regexp is changed. It began to match to any character that starts with
/\s/
.I'm not sure what the original regexp want to match to. maybe:
/^[^\S\n]*[^#\s]/
: nearly or identical to the original regexp/\A\s*[^#\s]/
: matches to"\n\n a..."
but doesn't match to" #\n #\n a"
or perhaps using
attr_node.value !~ allow_pattern
would be more simple?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.
This regular expression originally came from the
html5lib
library:https://github.com/html5lib/html5lib-ruby/blob/master/lib/html5/sanitizer.rb#L141-L143
The goal of this line is to accept "local links" (like
#some-id
) but not full URLs, with initial whitespace being ignored. There are test cases for this behavior in Loofah, which rails-html-sanitizer originally copied this code from.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.
So @tompng is correct, this patch changes the behavior in unwanted ways. One example test case is:
Specifically, in this case the
xlink:href
attribute should not be removed but is being removed because: