Skip to content

fix: polynomial regex on uncontrolled input#3196

Merged
stefannibrasil merged 2 commits intomainfrom
ta/polynomial-regex-uncontrolled
Jan 29, 2026
Merged

fix: polynomial regex on uncontrolled input#3196
stefannibrasil merged 2 commits intomainfrom
ta/polynomial-regex-uncontrolled

Conversation

@thdaraujo
Copy link
Contributor

(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

@thdaraujo thdaraujo self-assigned this Jan 29, 2026
(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
@thdaraujo thdaraujo force-pushed the ta/polynomial-regex-uncontrolled branch from 20d5b8e to 32600f5 Compare January 29, 2026 05:21
@thdaraujo thdaraujo force-pushed the ta/polynomial-regex-uncontrolled branch from 32600f5 to 066f63a Compare January 29, 2026 05:24
Copy link
Contributor

@stefannibrasil stefannibrasil left a comment

Choose a reason for hiding this comment

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

Thanks!

@stefannibrasil stefannibrasil merged commit 4c57e48 into main Jan 29, 2026
9 checks passed
@stefannibrasil stefannibrasil deleted the ta/polynomial-regex-uncontrolled branch January 29, 2026 21:02
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
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 this pull request may close these issues.

Fix 'Polynomial regular expression used on uncontrolled data code' scanning alert

2 participants