fix: mitigate ReDoS in /nodes/conf_search (CWE-1333)#442
Open
mattimustang wants to merge 1 commit into
Open
Conversation
Regexp.new was called directly on unsanitised user input with no error handling or timeout, allowing an authenticated attacker to supply a pathological pattern that hangs a Puma worker thread indefinitely, or an invalid pattern that raises an unhandled exception. - Wrap Regexp.new in rescue RegexpError → HTTP 400 for invalid patterns - Wrap each per-node config match in Timeout.timeout(2) → skip node on timeout, preventing a crafted regex from exhausting the thread pool - Add tests covering invalid pattern, no match, match, and timeout cases
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.
Summary
Regexp.newwas called directly on unsanitised user input with no error handling or timeout, allowing an authenticated attacker to supply a pathological regex that hangs a Puma worker thread indefinitely, or an invalid pattern that raises an unhandled 500 exceptionRegexp.newinrescue RegexpError→ returns HTTP 400 for syntactically invalid patterns (all Ruby versions)Timeout.timeout(2)→ skips that node and continues if a pattern runs long, preventing thread pool exhaustion (Ruby 3.0+)Test plan
bundle exec rakepasses (RuboCop + full test suite) — 43 tests, 0 failures/nodes/conf_searchwith invalid pattern (e.g.[invalid() returns 400/nodes/conf_searchwith valid pattern returns matching nodes as before/nodes/conf_searchwith a slow/malicious pattern no longer hangs the server indefinitely