Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle variant in how policy is passed in paramiko #1078

Merged
merged 1 commit into from Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion bandit/plugins/ssh_no_host_key_verification.py
Expand Up @@ -55,8 +55,13 @@ def ssh_no_host_key_verification(context):
policy_argument_value = None
if isinstance(policy_argument, ast.Attribute):
policy_argument_value = policy_argument.attr
elif isinstance(policy_argument, ast.Name):
policy_argument_value = policy_argument.id
elif isinstance(policy_argument, ast.Call):
policy_argument_value = policy_argument.func.attr
if isinstance(policy_argument.func, ast.Attribute):
policy_argument_value = policy_argument.func.attr
elif isinstance(policy_argument.func, ast.Name):
policy_argument_value = policy_argument.func.id

if policy_argument_value in ["AutoAddPolicy", "WarningPolicy"]:
return bandit.Issue(
Expand Down
7 changes: 7 additions & 0 deletions examples/no_host_key_verification.py
@@ -1,7 +1,14 @@
from paramiko import client
from paramiko import AutoAddPolicy
from paramiko import WarningPolicy

ssh_client = client.SSHClient()
ssh_client.set_missing_host_key_policy(client.AutoAddPolicy)
ssh_client.set_missing_host_key_policy(client.WarningPolicy)
ssh_client.set_missing_host_key_policy(client.AutoAddPolicy())
ssh_client.set_missing_host_key_policy(client.WarningPolicy())

ssh_client.set_missing_host_key_policy(AutoAddPolicy)
ssh_client.set_missing_host_key_policy(WarningPolicy)
ssh_client.set_missing_host_key_policy(AutoAddPolicy())
ssh_client.set_missing_host_key_policy(WarningPolicy())
4 changes: 2 additions & 2 deletions tests/functional/test_functional.py
Expand Up @@ -543,8 +543,8 @@ def test_yaml(self):
def test_host_key_verification(self):
"""Test for ignoring host key verification."""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 4},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 4, "HIGH": 0},
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 8},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 8, "HIGH": 0},
}
self.check_example("no_host_key_verification.py", expect)

Expand Down