Skip to content

fix(B104): detect empty string '' as wildcard bind address#1434

Open
nilavra17ghosh wants to merge 2 commits into
PyCQA:mainfrom
nilavra17ghosh:fix/b104-empty-string-wildcard-bind
Open

fix(B104): detect empty string '' as wildcard bind address#1434
nilavra17ghosh wants to merge 2 commits into
PyCQA:mainfrom
nilavra17ghosh:fix/b104-empty-string-wildcard-bind

Conversation

@nilavra17ghosh

Copy link
Copy Markdown

Summary

Empty string "" is equivalent to "0.0.0.0" when used as a socket bind address in Python — it binds to all interfaces. B104 was missing this case entirely.

Changes

  • Plugin: check for "" in addition to "0.0.0.0"
  • Example: added s.bind(('', 8080)) test case
  • Test: updated expected issue count from 1 → 2

Related

Fixes #1395

Copilot AI review requested due to automatic review settings June 9, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates Bandit’s B104 detection to treat bind(("", port)) as a wildcard bind and adjusts functional expectations/examples accordingly.

Changes:

  • Expand B104 plugin logic to flag empty-string binds as “bind all interfaces”.
  • Add an empty-string bind case to the binding.py example.
  • Update multiple functional test expected severity/confidence distributions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/functional/test_functional.py Updates expected finding-count distributions across several functional tests.
examples/binding.py Adds an example of wildcard bind using an empty string host.
bandit/plugins/general_bind_all_interfaces.py Expands B104 detection to include "" as a wildcard bind host.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bandit/plugins/general_bind_all_interfaces.py Outdated
Comment thread tests/functional/test_functional.py
Comment thread examples/binding.py Outdated
Empty string '' is equivalent to '0.0.0.0' when used as a bind
address in Python sockets, binding to all interfaces. Previously
B104 only checked for '0.0.0.0' and missed this case.

Fixes PyCQA#1395
@nilavra17ghosh nilavra17ghosh force-pushed the fix/b104-empty-string-wildcard-bind branch from 695ec02 to f2424e5 Compare June 9, 2026 18:15
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