Fix sanitizer stalls on long benign base64-like input#11
Draft
cursor[bot] wants to merge 7 commits into
Draft
Conversation
Co-authored-by: Andre Schu <Art.Int.Interface@gmail.com>
Co-authored-by: Andre Schu <Art.Int.Interface@gmail.com>
Co-authored-by: Andre Schu <Art.Int.Interface@gmail.com>
Co-authored-by: Andre Schu <Art.Int.Interface@gmail.com>
Co-authored-by: Andre Schu <Art.Int.Interface@gmail.com>
Co-authored-by: Andre Schu <Art.Int.Interface@gmail.com>
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
Recent encoding-evasion hardening made
scan_encoding_blocks()spend ~1.36s on a 20k-character benign non-hex alphabetic run and causedclassify()to take ~9s on a 50k-character benign input. Becauseinspect()callsclassify()in the core SCP path and the package allows inputs up to 2M characters by default, this could create practical CPU denial-of-service / user-facing hangs from non-malicious content.Root cause
The base64 detector used a greedy lookahead regex (
(?=[A-Za-z0-9+/]*[+/=])...) that backtracked heavily on long base64-character runs without+,/, or=. During the fix pass, padded alphanumeric base64 also needed explicit preservation because PowerShell-style-EncodedCommand ...=payloads do not necessarily contain+or/.Fix
=is still detected.Validation
PYTHONPATH=src python3 -m pytest tests/test_sanitize_encoding_evasion.py tests/test_security_regressions.py tests/test_appsec_host_allowlists.py -q-> 92 passedPYTHONPATH=src python3 -m pytest -q --ignore=tests/test_contract_document_hash.py-> 283 passed, 3 skippedPYTHONPATH=src python3 -m pytest -qstill has the known baseline contract-hash failures intests/test_contract_document_hash.pyonly (3 failed, 283 passed, 3 skipped).classify('g' * 50_000)now completes in ~0.17s; before the fix, a comparable 50k-character input took ~9s.