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 AttributeError on detect of tuple assign condition #931

Merged
merged 1 commit into from
Jul 14, 2022
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
4 changes: 3 additions & 1 deletion bandit/plugins/django_xss.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def is_assigned(self, node):
if isinstance(target, ast.Name):
if target.id == self.var_name.id:
assigned = node.value
elif isinstance(target, ast.Tuple):
elif isinstance(target, ast.Tuple) and isinstance(
node.value, ast.Tuple
):
pos = 0
for name in target.elts:
if name.id == self.var_name.id:
Expand Down
8 changes: 8 additions & 0 deletions examples/mark_safe_insecure.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@ def test_insecure_with_assign(str_arg=None):
if not str_arg:
str_arg = 'could be insecure'
safestring.mark_safe(str_arg)

def test_insecure_tuple_assign():
HTML_CHOICES = (
(_('Donate'), 'https://example.org/donate/'),
(_('More info'), 'https://example.org/'),
)
text, url = choice(HTML_CHOICES)
safestring.mark_safe('<a href="{0}">{1}</a>'.format(url, text))
4 changes: 2 additions & 2 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ def test_django_xss_secure(self):
def test_django_xss_insecure(self):
"""Test for Django XSS via django.utils.safestring"""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 28, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 28},
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 29, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 29},
}
self.b_mgr.b_ts = b_test_set.BanditTestSet(
config=self.b_mgr.b_conf, profile={"exclude": ["B308"]}
Expand Down