Skip to content

Commit b36e0d0

Browse files
committed
Python: target SSA variable rather than Cfg node
also add "INTERNAL: Do not use." also give test functions different names
1 parent 2962979 commit b36e0d0

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

python/ql/src/semmle/python/security/dataflow/ExceptionInfo.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import semmle.python.dataflow.new.DataFlow
55
private import semmle.python.ApiGraphs
66

77
/**
8+
* INTERNAL: Do not use.
9+
*
810
* A data-flow node that carries information about a raised exception.
911
* Such information should rarely be exposed directly to the user.
1012
*/
@@ -25,7 +27,10 @@ private class TracebackFunctionCall extends ExceptionInfo, DataFlow::CallCfgNode
2527

2628
/** A caught exception. */
2729
private class CaughtException extends ExceptionInfo {
28-
CaughtException() { this.asExpr() = any(ExceptStmt s).getName() }
30+
CaughtException() {
31+
this.asVar().getDefinition().(EssaNodeDefinition).getDefiningNode().getNode() =
32+
any(ExceptStmt s).getName()
33+
}
2934
}
3035

3136
/** A call to `sys.exc_info`. */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
edges
2+
| test.py:23:25:23:25 | SSA variable e | test.py:24:16:24:16 | ControlFlowNode for e |
23
| test.py:49:15:49:36 | ControlFlowNode for Attribute() | test.py:50:29:50:31 | ControlFlowNode for err |
34
| test.py:50:29:50:31 | ControlFlowNode for err | test.py:50:16:50:32 | ControlFlowNode for format_error() |
45
nodes
56
| test.py:16:16:16:37 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
7+
| test.py:23:25:23:25 | SSA variable e | semmle.label | SSA variable e |
8+
| test.py:24:16:24:16 | ControlFlowNode for e | semmle.label | ControlFlowNode for e |
69
| test.py:49:15:49:36 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
710
| test.py:50:16:50:32 | ControlFlowNode for format_error() | semmle.label | ControlFlowNode for format_error() |
811
| test.py:50:29:50:31 | ControlFlowNode for err | semmle.label | ControlFlowNode for err |
912
#select
1013
| test.py:16:16:16:37 | ControlFlowNode for Attribute() | test.py:16:16:16:37 | ControlFlowNode for Attribute() | test.py:16:16:16:37 | ControlFlowNode for Attribute() | $@ may be exposed to an external user | test.py:16:16:16:37 | ControlFlowNode for Attribute() | Error information |
14+
| test.py:24:16:24:16 | ControlFlowNode for e | test.py:23:25:23:25 | SSA variable e | test.py:24:16:24:16 | ControlFlowNode for e | $@ may be exposed to an external user | test.py:23:25:23:25 | SSA variable e | Error information |
1115
| test.py:50:16:50:32 | ControlFlowNode for format_error() | test.py:49:15:49:36 | ControlFlowNode for Attribute() | test.py:50:16:50:32 | ControlFlowNode for format_error() | $@ may be exposed to an external user | test.py:49:15:49:36 | ControlFlowNode for Attribute() | Error information |

python/ql/test/query-tests/Security/CWE-209/test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ def server_bad():
1616
return traceback.format_exc() #$ exceptionInfo
1717

1818
# BAD
19-
@app.route('/bad/clearly')
20-
def server_bad():
19+
@app.route('/bad/direct')
20+
def server_bad_direct():
2121
try:
2222
do_computation()
2323
except Exception as e: #$ exceptionInfo
2424
return e
2525

2626
# BAD
27-
@app.route('/bad/also')
28-
def server_bad():
27+
@app.route('/bad/traceback')
28+
def server_bad_traceback():
2929
try:
3030
do_computation()
3131
except Exception as e: #$ exceptionInfo

0 commit comments

Comments
 (0)