Skip to content

Commit 6646e98

Browse files
committed
Python: Fix results outside DB for StackTraceExposure
1 parent 972cfa5 commit 6646e98

File tree

2 files changed

+25
-111
lines changed

2 files changed

+25
-111
lines changed

python/ql/lib/semmle/python/security/dataflow/StackTraceExposureCustomizations.qll

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,31 @@ module StackTraceExposure {
4242
* A source of exception info, considered as a flow source.
4343
*/
4444
class ExceptionInfoAsSource extends Source {
45-
ExceptionInfoAsSource() { this instanceof ExceptionInfo }
45+
ExceptionInfoAsSource() {
46+
this instanceof ExceptionInfo and
47+
// since `traceback.format_exc()` in Python 2 is internally implemented as
48+
// ```py
49+
// def format_exc(limit=None):
50+
// """Like print_exc() but return a string."""
51+
// try:
52+
// etype, value, tb = sys.exc_info()
53+
// return ''.join(format_exception(etype, value, tb, limit))
54+
// finally:
55+
// etype = value = tb = None
56+
// ```
57+
// any time we would report flow to such from a call to format_exc, we can ALSO report
58+
// the flow from the `sys.exc_info()` source -- obviously we don't want that.
59+
//
60+
//
61+
// To avoid this, we use the same approach as for sinks in the command injection
62+
// query (and others).
63+
not exists(Module traceback |
64+
traceback.getName() = "traceback" and
65+
this.getScope().getEnclosingModule() = traceback and
66+
// do allow this call if we're analyzing traceback.py as part of CPython though
67+
not exists(traceback.getFile().getRelativePath())
68+
)
69+
}
4670
}
4771

4872
/**

0 commit comments

Comments
 (0)