fix(giskard-checks): catch TimeoutError in RegexMatching.run() - #2711
Open
kevinmessiaen wants to merge 1 commit into
Open
fix(giskard-checks): catch TimeoutError in RegexMatching.run()#2711kevinmessiaen wants to merge 1 commit into
kevinmessiaen wants to merge 1 commit into
Conversation
RegexMatching only caught regex.error, so a regex timeout raised a bare TimeoutError that escaped uncaught and aborted scenario execution when return_exception=False (the default). Catch TimeoutError alongside regex.error and return a CheckResult.error instead, matching the handling already used for invalid patterns. Reported in GHSA-7rwv-f9p2-g8rm. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Description
RegexMatching.run()calledregex.search(pattern, text, timeout=self.match_timeout_seconds)but only caughtregex.error. When the search hits its timeout, theregexlibrary raises a bareTimeoutError, which was left uncaught. That exception then propagates up throughTestCaseRunner._run_check()and, sinceScenario.run()defaults toreturn_exception=False, aborts scenario execution entirely instead of surfacing as a normal check result.This behavior was introduced intentionally in #2381 (which added the timeout to mitigate ReDoS) — the commit explicitly chose to let
TimeoutErrorpropagate, and the regression test was written to assert that (pytest.raises(TimeoutError)). This PR changes that: a timeout now returnsCheckResult.errorwith a clear message, consistent with how invalid regex patterns are already handled in the same function.Fix
RegexMatching.run()now catchesTimeoutErrorin addition toregex.errorand returnsCheckResult.error.Tests
test_regex_redos_bounded_by_timeoutto assert the gracefulCheckResult.erroroutcome instead of asserting the propagating exception. Verified red (fails against pre-fix code with rawTimeoutError) → green.giskard-checkssuite: 805 passed, 4 skipped.basedpyright --level erroron touched files: 0 errors.Related Issue
Reported in GHSA-7rwv-f9p2-g8rm. Reclassified from security advisory to bug fix:
giskard-checksis a testing framework where the regex pattern is authored by the person writing the test, not supplied by an untrusted third party at runtime, so there's no trust boundary being crossed. The underlying inconsistency (one exception type fromregex.searchcaught, its sibling not) is still worth fixing on its own merits.Type of Change
Checklist
CODE_OF_CONDUCT.mddocument.CONTRIBUTING.mdguide.uv.lockrunninguv lock. (n/a — nopyproject.tomlchanges)