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

Add Check: REDoS from match/match? coercing unsafe strings to regular expressions #1714

Open
bensheldon opened this issue Jun 8, 2022 · 0 comments · May be fixed by #1715
Open

Add Check: REDoS from match/match? coercing unsafe strings to regular expressions #1714

bensheldon opened this issue Jun 8, 2022 · 0 comments · May be fixed by #1715

Comments

@bensheldon
Copy link

Is your feature request related to a problem? Please describe.

Ruby's #match and #match? methods will coerce string inputs to regular expressions (docs):

Computes regexp by converting pattern (if not already a Regexp).

Example:

irb(main):001:0> RUBY_VERSION
=> "3.1.2"
irb(main):002:0> "haystack".match?(".*")
=> true
irb(main):003:0> "haystack".match(".*")
=> #<MatchData "haystack">
irb(main):004:0> "haystack".match? Regexp.escape(".*")
=> false

This is unsafe. Currently Brakeman checks for unescaped regex construction like /#{params[:regex]}/, but does not check for string coercion by match or match?.

Describe the solution you'd like

I'd like Brakeman to add a check for match and match? called with unsafe string input.

Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant