Skip to content

Commit 002d0fe

Browse files
committed
Python: Port missing host key query
1 parent f65843a commit 002d0fe

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,23 @@
1010
*/
1111

1212
import python
13+
import semmle.python.ApiGraphs
1314

14-
private ModuleValue theParamikoClientModule() { result = Value::named("paramiko.client") }
15-
16-
private ClassValue theParamikoSSHClientClass() {
17-
result = theParamikoClientModule().attr("SSHClient")
15+
private API::Node unsafe_paramiko_policy(string name) {
16+
name in ["AutoAddPolicy", "WarningPolicy"] and
17+
result = API::moduleImport("paramiko").getMember("client").getMember(name)
1818
}
1919

20-
private ClassValue unsafe_paramiko_policy(string name) {
21-
(name = "AutoAddPolicy" or name = "WarningPolicy") and
22-
result = theParamikoClientModule().attr(name)
20+
private API::Node paramikoSSHClientInstance() {
21+
result = API::moduleImport("paramiko").getMember("client").getMember("SSHClient").getReturn()
2322
}
2423

2524
from CallNode call, ControlFlowNode arg, string name
2625
where
27-
call =
28-
theParamikoSSHClientClass().lookup("set_missing_host_key_policy").(FunctionValue).getACall() and
26+
call = paramikoSSHClientInstance().getMember("set_missing_host_key_policy").getACall().asCfgNode() and
2927
arg = call.getAnArg() and
3028
(
31-
arg.pointsTo(unsafe_paramiko_policy(name)) or
32-
arg.pointsTo().getClass() = unsafe_paramiko_policy(name)
29+
arg = unsafe_paramiko_policy(name).getAUse().asCfgNode() or
30+
arg = unsafe_paramiko_policy(name).getReturn().getAUse().asCfgNode()
3331
)
3432
select call, "Setting missing host key policy to " + name + " may be unsafe."

0 commit comments

Comments
 (0)