Visitar URL original
B107: Skip None values in hardcoded password detection by lukehinds · Pull Request #1232 · PyCQA/bandit · GitHub
Skip to content

B107: Skip None values in hardcoded password detection - #1232

Merged
ericwb merged 2 commits into
PyCQA:mainfrom
lukehinds:B107-fix
Feb 10, 2025
Merged

ericwb merged 2 commits into
PyCQA:mainfrom
lukehinds:B107-fix

Conversation

@lukehinds

Copy link
Copy Markdown
Member

The B107 check was incorrectly flagging None default values as hardcoded passwords in function definitions. This is a false positive since None is a legitimate and commonly used within init initialization

This change modifies the hardcoded_password_default function to:

  • Skip None values in parameter defaults
  • Handle both ast.Constant (Python 3.8+) and ast.NameConstant (Python 3.7-) representations of None
  • Update documentation to clarify None handling behavior

Example of code that no longer triggers B107:
def init(self, auth_scheme, auth_password=None):
pass

Fixes: #1227

The B107 check was incorrectly flagging None default values as hardcoded
passwords in function definitions. This is a false positive since None is a
legitimate and commonly used within __init__ initialization

This change modifies the hardcoded_password_default function to:
- Skip None values in parameter defaults
- Handle both ast.Constant (Python 3.8+) and ast.NameConstant (Python 3.7-)
  representations of None
- Update documentation to clarify None handling behavior

Example of code that no longer triggers B107:
def __init__(self, auth_scheme, auth_password=None):
    pass

Fixes #PyCQA#1227
@ericwb
ericwb merged commit def123a into PyCQA:main Feb 10, 2025
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.

False-positive B107:hardcoded_password_default with None parameter

3 participants