Fix sanitizer base64 scan ReDoS#13
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
Co-authored-by: Andre Schu <Art.Int.Interface@gmail.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.
Bug and impact
A recent sanitizer change introduced a variable-length lookahead in
ENCODING_BASE64. Benign long alphabetic inputs such as a 50k-characterZ...Zstring causedscan_encoding_blocks()to spend ~8.6s rescanning the same run, which can stallclassify()/inspect()on user-supplied content and create a practical denial-of-service path.Root cause
(?=[A-Za-z0-9+/]*[+/=])was evaluated at each candidate position in long base64-like runs that ultimately contained no marker character, producing quadratic behavior before the scanner could reject the input.Fix
Replaced the variable-length lookahead with a linear candidate regex and an explicit marker check (
+,/, or padding) before recording base64 findings. Added regression coverage for long benign alphabetic runs and preserved padded base64 detection.Validation
PYTHONPATH=src python3 -m pytest tests/test_security_regressions.py::test_scan_encoding_blocks_long_alpha_run_completes_quickly tests/test_security_regressions.py::test_scan_encoding_blocks_still_flags_padded_base64 -q-> 2 passedPYTHONPATH=src python3 -m pytest tests/test_security_regressions.py tests/test_sanitize_encoding_evasion.py tests/test_sanitize_fragmentation.py -q-> 87 passedscan_encoding_blocks('Z' * 50000)~0.0005s;classify('Z' * 50000)~0.52stests/test_contract_document_hash.py