fix(B104): detect empty string '' as wildcard bind address#1434
Open
nilavra17ghosh wants to merge 2 commits into
Open
fix(B104): detect empty string '' as wildcard bind address#1434nilavra17ghosh wants to merge 2 commits into
nilavra17ghosh wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.pyexample. - 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.
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
695ec02 to
f2424e5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
""in addition to"0.0.0.0"s.bind(('', 8080))test caseRelated
Fixes #1395