|
10 | 10 | */
|
11 | 11 |
|
12 | 12 | import python
|
| 13 | +import semmle.python.dataflow.new.DataFlow |
| 14 | +import semmle.python.ApiGraphs |
13 | 15 |
|
14 |
| -private ModuleValue theParamikoClientModule() { result = Value::named("paramiko.client") } |
15 |
| - |
16 |
| -private ClassValue theParamikoSSHClientClass() { |
17 |
| - result = theParamikoClientModule().attr("SSHClient") |
| 16 | +private API::Node unsafe_paramiko_policy(string name) { |
| 17 | + name in ["AutoAddPolicy", "WarningPolicy"] and |
| 18 | + result = API::moduleImport("paramiko").getMember("client").getMember(name) |
18 | 19 | }
|
19 | 20 |
|
20 |
| -private ClassValue unsafe_paramiko_policy(string name) { |
21 |
| - (name = "AutoAddPolicy" or name = "WarningPolicy") and |
22 |
| - result = theParamikoClientModule().attr(name) |
| 21 | +private API::Node paramikoSSHClientInstance() { |
| 22 | + result = API::moduleImport("paramiko").getMember("client").getMember("SSHClient").getReturn() |
23 | 23 | }
|
24 | 24 |
|
25 |
| -from CallNode call, ControlFlowNode arg, string name |
| 25 | +from DataFlow::CallCfgNode call, DataFlow::Node arg, string name |
26 | 26 | where
|
27 |
| - call = |
28 |
| - theParamikoSSHClientClass().lookup("set_missing_host_key_policy").(FunctionValue).getACall() and |
| 27 | + call = paramikoSSHClientInstance().getMember("set_missing_host_key_policy").getACall() and |
29 | 28 | arg = call.getAnArg() and
|
30 | 29 | (
|
31 |
| - arg.pointsTo(unsafe_paramiko_policy(name)) or |
32 |
| - arg.pointsTo().getClass() = unsafe_paramiko_policy(name) |
| 30 | + arg = unsafe_paramiko_policy(name).getAUse() or |
| 31 | + arg = unsafe_paramiko_policy(name).getReturn().getAUse() |
33 | 32 | )
|
34 | 33 | select call, "Setting missing host key policy to " + name + " may be unsafe."
|
0 commit comments