Skip to content

Commit f241dba

Browse files
committed
Python: Clean up query a bit
1 parent 002d0fe commit f241dba

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

python/ql/src/Security/CWE-295/MissingHostKeyValidation.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import python
13+
import semmle.python.dataflow.new.DataFlow
1314
import semmle.python.ApiGraphs
1415

1516
private API::Node unsafe_paramiko_policy(string name) {
@@ -21,12 +22,12 @@ private API::Node paramikoSSHClientInstance() {
2122
result = API::moduleImport("paramiko").getMember("client").getMember("SSHClient").getReturn()
2223
}
2324

24-
from CallNode call, ControlFlowNode arg, string name
25+
from DataFlow::CallCfgNode call, DataFlow::Node arg, string name
2526
where
26-
call = paramikoSSHClientInstance().getMember("set_missing_host_key_policy").getACall().asCfgNode() and
27+
call = paramikoSSHClientInstance().getMember("set_missing_host_key_policy").getACall() and
2728
arg = call.getAnArg() and
2829
(
29-
arg = unsafe_paramiko_policy(name).getAUse().asCfgNode() or
30-
arg = unsafe_paramiko_policy(name).getReturn().getAUse().asCfgNode()
30+
arg = unsafe_paramiko_policy(name).getAUse() or
31+
arg = unsafe_paramiko_policy(name).getReturn().getAUse()
3132
)
3233
select call, "Setting missing host key policy to " + name + " may be unsafe."

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ class CallCfgNode extends CfgNode {
193193

194194
/** Gets the data-flow node corresponding to the named argument of the call corresponding to this data-flow node */
195195
Node getArgByName(string name) { result.asCfgNode() = node.getArgByName(name) }
196+
197+
/** Gets the data-flow node corresponding to an argument of the call corresponding to this data-flow node */
198+
Node getAnArg() {
199+
exists(int n | result = this.getArg(n))
200+
or
201+
exists(string name | result = this.getArgByName(name))
202+
}
196203
}
197204

198205
/**

0 commit comments

Comments
 (0)