Add configurable timeouts to regex execution (default 60 seconds)#1904
Add configurable timeouts to regex execution (default 60 seconds)#1904SharonHart merged 8 commits intomainfrom
Conversation
Co-authored-by: SharonHart <15013757+SharonHart@users.noreply.github.com>
presidio-analyzer/presidio_analyzer/predefined_recognizers/generic/iban_recognizer.py
Show resolved
Hide resolved
Co-authored-by: SharonHart <15013757+SharonHart@users.noreply.github.com>
…ith timeout only Co-authored-by: SharonHart <15013757+SharonHart@users.noreply.github.com>
…c_info=True to warnings Co-authored-by: SharonHart <15013757+SharonHart@users.noreply.github.com>
|
@copilot tests are failing on the CI |
…failure Co-authored-by: SharonHart <15013757+SharonHart@users.noreply.github.com>
Fixed in 3324351. The CI failure was a diff-coverage check —
|
Coverage report (presidio-analyzer)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||
|
@copilot add an option to override REGEX_TIMEOUT_SECONDS with a env var with the same name, make the REGEX_TIMEOUT_SECONDS 60 second by default if empty |
Co-authored-by: SharonHart <15013757+SharonHart@users.noreply.github.com>
Done in 6d3f34f. All three files ( REGEX_TIMEOUT_SECONDS = int(os.environ.get("REGEX_TIMEOUT_SECONDS", 60))A test for the override ( |
Adds timeout protection to regex execution across the analyzer to prevent catastrophic backtracking. The timeout value defaults to 60 seconds and can be overridden via the
REGEX_TIMEOUT_SECONDSenvironment variable.Changes Made
pattern_recognizer.py: Addedtimeout=REGEX_TIMEOUT_SECONDStore.finditer().TimeoutErroris caught and logged withexc_info=True; the pattern is skipped on timeout.analyzer_engine.py: Addedtimeout=REGEX_TIMEOUT_SECONDStore.search().TimeoutErroris caught and logged withexc_info=True.iban_recognizer.py: Addedtimeout=REGEX_TIMEOUT_SECONDStore.finditer()andre.match().TimeoutErroris caught and logged withexc_info=Truein both locations.REGEX_TIMEOUT_SECONDSfrom the environment variable of the same name, falling back to60if unset or empty:Testing
test_pattern_recognizer.pyandtest_analyzer_engine.pytest_iban_recognizer.pytest_regex_timeout_seconds_env_var_overrideto verify the environment variable override works correctly💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.