fix: Replace broad exception handling with specific exception types#2
Merged
Desperado merged 1 commit intoQuality-Max:mainfrom Mar 26, 2026
Merged
Conversation
Replace all bare `except Exception: pass` blocks with the specific exceptions each decoding operation can actually raise. This prevents masking unexpected errors that could indicate scanner evasion.
Contributor
|
Another good hardening — scanner evasion via unexpected exceptions is a real vector. Thanks! |
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
Replace all bare
except Exception: passblocks with specific, narrowly-scoped exception types that each decoding operation can actually raise.Problem
The scanner uses
except Exception: passin 6 locations across the codebase — every place it attempts to decode a potentially malicious payload:Why this matters
except Exceptioncatches everything — not just the expectedbinascii.ErrororValueError, but also:MemoryError— a crafted payload with an enormous decoded size would be silently ignored instead of surfacingRecursionError— pathological inputs could blow the stack silentlySystemError/RuntimeError— interpreter-level issues would be swallowedThis creates a scanner evasion vector: a sufficiently creative attacker could craft a payload that triggers an unexpected exception during analysis, causing the scanner to silently skip it and report "all clear."
OWASP Reference
Fix
Each
try/exceptblock now catches only the specific exceptions that the contained operations can raise:base64.b64decode()binascii.Error,ValueErrorbytes.fromhex()ValueError.decode("utf-8")UnicodeDecodeErrorzlib.decompress()zlib.errorcodecs.decode(_, "rot_13")ValueError,LookupErrorThis also adds the missing
import binasciiat the top of the file.Impact