Skip to content

Fix B104 false negative for empty-string wildcard bind#1396

Open
9iang22 wants to merge 1 commit intoPyCQA:mainfrom
9iang22:fix/b104-empty-string-bind
Open

Fix B104 false negative for empty-string wildcard bind#1396
9iang22 wants to merge 1 commit intoPyCQA:mainfrom
9iang22:fix/b104-empty-string-bind

Conversation

@9iang22
Copy link
Copy Markdown

@9iang22 9iang22 commented Apr 19, 2026

Summary

  • Extend B104 detection to treat "" as a wildcard bind host in addition to "0.0.0.0".
  • Add a functional regression example and test for socket.bind(("", port)).

Validation

  • python -m pytest tests/functional/test_functional.py -k binding.

Resolved: #1395

Copy link
Copy Markdown
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This results in too many false positives.

@test.test_id("B104")
def hardcoded_bind_all_interfaces(context):
if context.string_val == "0.0.0.0": # nosec: B104
if context.string_val in ("0.0.0.0", ""): # nosec: B104
Copy link
Copy Markdown
Member

@ericwb ericwb Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This results in an excessive number of false positives. This effectively matches a str literal of the empty string (""). So it would match tons of lines in a code base.

For example, even the most basic snippet of code:

test_str = ""

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 negative: B104 misses bind(("", port)) wildcard host

2 participants