Skip to content

Commit 9c9e9d6

Browse files
committed
update
1 parent b57287d commit 9c9e9d6

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎constructs/exceptions.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,28 @@ for item in data:
153153
continue # Just as dangerous as pass
154154
```
155155

156+
### Can `pass` and `continue` be reliably identified as security weaknesses?
156157

158+
The presence of `pass` or `continue` in an `except` block is an indicator that an exception is being suppressed.
157159

160+
A good SAST Python scanner does this. However many SAST scanners try to suppress so called 'false positives' with complex logic or use a scoring approach. This has a very high risk, no method is solid and when findings within exception clauses have a low score, you might think that your code is secure. But the risk of a false sense of security is enormous.
158161

162+
Use of `pass` or `continue` in an `except` block does not, by itself, imply a directly security weakness.
163+
There are many cases, suppressing an expected exception is intentional and forms part of the function's documented behavior (for example, converting a `ValueError` into `False` during input validation).
164+
165+
Determining whether suppressing an exception is appropriate requires understanding the program's intent, the expected behavior of the API, and the effect on the remainder of the program. These properties cannot be inferred from the syntax of the exception handler alone.
166+
167+
Static analysis can identify suspicious patterns, such as `except: pass` or `except Exception: continue`, but it **cannot** determine with certainty whether the suppression is correct or harmful. As a result, these patterns should be treated as potential findings that require further review rather than definitive security weakness finding.
168+
169+
Even sophisticated analyses, such as taint analysis, cannot achieve 100% accuracy. Taint analysis tracks the flow of data through a program but does not capture the developer's intent or the full semantics of Python's runtime behavior.
170+
171+
Python's dynamic features—including dynamic typing, reflection, monkey patching, runtime code generation (`exec` and `eval`), dynamic imports, and polymorphic dispatch—prevent any static analysis from precisely modeling every possible execution path. Furthermore, determining all possible behaviors of an arbitrary program is fundamentally undecidable in the general case.
172+
173+
Consequently, no analysis tool can determine with complete certainty whether the use of `pass` or `continue` in an exception handler constitutes a genuine security weakness.
174+
175+
:::{hint}
176+
The best approach is to identify suspicious constructs and rely on human review to determine whether the exception suppression is appropriate in its specific context. Using heuristics to identify suspicious constructs can be dangerous and error prone.
177+
:::
159178

160179

161180
## More Information

0 commit comments

Comments
 (0)