fix: polynomial regex on uncontrolled input#3196
Merged
stefannibrasil merged 2 commits intomainfrom Jan 29, 2026
Merged
Conversation
(Fixes https://github.com/faker-ruby/faker/security/code-scanning/14) Adds a possessive quantifier (an extra `+`) to the regex to prevent backtracking. This is to prevent the issue 'Polynomial regular expression used on uncontrolled data code'. It seems a bit overkill, given how these formatted strings are used, but I don't think it hurts either. See reference: https://ruby-doc.org/3.4.1/Regexp.html#class-Regexp-label-Greedy-2C+Lazy-2C+or+Possessive+Matching
20d5b8e to
32600f5
Compare
(Fixes https://github.com/faker-ruby/faker/security/code-scanning/13) Similar to commit fa6d5df. Adds a possessive quantifier (an extra `+`) to the regex to prevent backtracking. See reference: https://ruby-doc.org/3.4.1/Regexp.html#class-Regexp-label-Greedy-2C+Lazy-2C+or+Possessive+Matching
32600f5 to
066f63a
Compare
stefannibrasil
pushed a commit
that referenced
this pull request
Jan 30, 2026
* fix: add possessive quantifier to regex match for formatted strings (Fixes https://github.com/faker-ruby/faker/security/code-scanning/14) Adds a possessive quantifier (an extra `+`) to the regex to prevent backtracking. This is to prevent the issue 'Polynomial regular expression used on uncontrolled data code'. It seems a bit overkill, given how these formatted strings are used, but I don't think it hurts either. See reference: https://ruby-doc.org/3.4.1/Regexp.html#class-Regexp-label-Greedy-2C+Lazy-2C+or+Possessive+Matching * fix: add possessive quantifier to regex match for regexify (Fixes https://github.com/faker-ruby/faker/security/code-scanning/13) Similar to commit fa6d5df. Adds a possessive quantifier (an extra `+`) to the regex to prevent backtracking. See reference: https://ruby-doc.org/3.4.1/Regexp.html#class-Regexp-label-Greedy-2C+Lazy-2C+or+Possessive+Matching
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
(Fixes #3183)
Adds a possessive quantifier (an extra
+) to some regexes to prevent backtracking.This is to prevent the issue 'Polynomial regular expression used on
uncontrolled data code' issue.
It seems a bit overkill to me, given how these
formatted strings are used. But I don't think it hurts either.
See reference for regex possessive quantifiers:
https://ruby-doc.org/3.4.1/Regexp.html#class-Regexp-label-Greedy-2C+Lazy-2C+or+Possessive+Matching