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

Fix traceback in hashlib_insecure_functions #834

Merged
merged 1 commit into from Feb 28, 2022
Merged
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
6 changes: 3 additions & 3 deletions bandit/plugins/hashlib_insecure_functions.py
Expand Up @@ -52,9 +52,7 @@ def _hashlib_func(context):

if "hashlib" in qualname_list:
func = qualname_list[-1]
args = context.call_args
keywords = context.call_keywords
name = args[0] if args else keywords["name"]

if func in ("md4", "md5", "sha", "sha1"):
if keywords.get("usedforsecurity", "True") == "True":
Expand All @@ -67,6 +65,8 @@ def _hashlib_func(context):
lineno=context.node.lineno,
)
elif func == "new":
args = context.call_args
name = args[0] if args else keywords.get("name", None)
if isinstance(name, str) and name.lower() in (
"md4",
"md5",
Expand All @@ -92,7 +92,7 @@ def _hashlib_new(context):
if "hashlib" in qualname_list and func == "new":
args = context.call_args
keywords = context.call_keywords
name = args[0] if args else keywords["name"]
name = args[0] if args else keywords.get("name", None)
if isinstance(name, str) and name.lower() in (
"md4",
"md5",
Expand Down