Skip to content

Commit b35637e

Browse files
authored
Merge pull request github#12858 from RasmusWL/paramiko-modeling
Python: Expand modeling of `paramiko`
2 parents 89ee2b9 + a168af3 commit b35637e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ import semmle.python.ApiGraphs
1616

1717
private API::Node unsafe_paramiko_policy(string name) {
1818
name in ["AutoAddPolicy", "WarningPolicy"] and
19-
result = API::moduleImport("paramiko").getMember("client").getMember(name)
19+
(
20+
result = API::moduleImport("paramiko").getMember("client").getMember(name)
21+
or
22+
result = API::moduleImport("paramiko").getMember(name)
23+
)
2024
}
2125

2226
private API::Node paramikoSshClientInstance() {
2327
result = API::moduleImport("paramiko").getMember("client").getMember("SSHClient").getReturn()
28+
or
29+
result = API::moduleImport("paramiko").getMember("SSHClient").getReturn()
2430
}
2531

2632
from DataFlow::CallCfgNode call, DataFlow::Node arg, string name

python/ql/test/query-tests/Security/CWE-295-MissingHostKeyValidation/MissingHostKeyValidation.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| paramiko_host_key.py:7:1:7:49 | ControlFlowNode for Attribute() | Setting missing host key policy to WarningPolicy may be unsafe. |
33
| paramiko_host_key.py:11:1:11:51 | ControlFlowNode for Attribute() | Setting missing host key policy to AutoAddPolicy may be unsafe. |
44
| paramiko_host_key.py:13:1:13:51 | ControlFlowNode for Attribute() | Setting missing host key policy to WarningPolicy may be unsafe. |
5+
| paramiko_host_key.py:20:1:20:58 | ControlFlowNode for Attribute() | Setting missing host key policy to AutoAddPolicy may be unsafe. |

python/ql/test/query-tests/Security/CWE-295-MissingHostKeyValidation/paramiko_host_key.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@
1111
client.set_missing_host_key_policy(AutoAddPolicy()) # bad
1212
client.set_missing_host_key_policy(RejectPolicy()) # good
1313
client.set_missing_host_key_policy(WarningPolicy()) # bad
14+
15+
# different import
16+
17+
import paramiko
18+
19+
client = paramiko.SSHClient()
20+
client.set_missing_host_key_policy(paramiko.AutoAddPolicy) # bad

0 commit comments

Comments
 (0)