diff --git a/bandit/plugins/general_bind_all_interfaces.py b/bandit/plugins/general_bind_all_interfaces.py index 58b840e86..6b9f6438a 100644 --- a/bandit/plugins/general_bind_all_interfaces.py +++ b/bandit/plugins/general_bind_all_interfaces.py @@ -43,7 +43,7 @@ @test.checks("Str") @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 return bandit.Issue( severity=bandit.MEDIUM, confidence=bandit.MEDIUM, diff --git a/examples/binding.py b/examples/binding.py index fee248702..6b574b5ec 100644 --- a/examples/binding.py +++ b/examples/binding.py @@ -1,5 +1,6 @@ import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.bind(('0.0.0.0', 31137)) -s.bind(('192.168.0.1', 8080)) +s.bind(('', 31137)) \ No newline at end of file diff --git a/tests/functional/test_functional.py b/tests/functional/test_functional.py index 08b1c5c5b..d0db444a4 100644 --- a/tests/functional/test_functional.py +++ b/tests/functional/test_functional.py @@ -112,8 +112,8 @@ def check_metrics(self, example_script, expect): def test_binding(self): """Test the bind-to-0.0.0.0 example.""" expect = { - "SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 1, "HIGH": 0}, - "CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 1, "HIGH": 0}, + "SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 2, "HIGH": 0}, + "CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 2, "HIGH": 0}, } self.check_example("binding.py", expect)