Visitar URL original
Fix B106 reporting wrong line number on multiline function calls by worksbyfriday · Pull Request #1360 · PyCQA/bandit · GitHub
Skip to content

Fix B106 reporting wrong line number on multiline function calls - #1360

Merged
ericwb merged 1 commit into
PyCQA:mainfrom
worksbyfriday:fix-b106-multiline-lineno
Feb 23, 2026
Merged

ericwb merged 1 commit into
PyCQA:mainfrom
worksbyfriday:fix-b106-multiline-lineno

Conversation

@worksbyfriday

Copy link
Copy Markdown
Contributor

Summary

Fixes #1328.

B106 (hardcoded_password_funcarg) reported the line number of the ast.Call node rather than the line of the specific keyword argument containing the hardcoded password. For multiline function calls, this meant:

  • The reported location pointed to the function call start, not the actual password
  • # nosec B106 placed on the correct line (with the password) was ineffective
  • # nosec B106 on the reported line (function call) silenced the warning but was misleading

Fix

Pass kw.value.lineno to the Issue constructor so the reported location points to the actual hardcoded string, not the call.

Before

>> Issue: [B106:hardcoded_password_funcarg] Possible hardcoded password: 'on_behalf_of'
   Location: ./auth.py:8:15    <-- line of dict( call

After

>> Issue: [B106:hardcoded_password_funcarg] Possible hardcoded password: 'on_behalf_of'
   Location: ./auth.py:12:15   <-- line of requested_token_use="on_behalf_of"

Test plan

  • Existing test_hardcoded_passwords functional test passes (issue counts unchanged)
  • Verified manually: before fix reports line 8, after fix reports line 12
  • Verified # nosec B106 on the keyword line now works correctly

🤖 Generated with Claude Code

B106 (hardcoded_password_funcarg) reported the line of the function
call node rather than the line of the keyword argument containing the
hardcoded password. This made it difficult to locate the actual issue
in multiline calls, and caused `# nosec` placed on the correct line
to be ineffective.

Pass the keyword value's lineno to the Issue so the reported location
points to the actual hardcoded string, not the call.

Fixes PyCQA#1328

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ericwb
ericwb merged commit 92ae8b8 into PyCQA:main Feb 23, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Line Reporting for B106 on Multiline Function Calls

2 participants