Python

Python

Made by DeepSource

Audit: Binding to all interfaces detected with hardcoded values BAN-B104

Security
Major
a05 owasp top 10

Binding to all network interfaces can potentially open up a service to traffic on unintended interfaces, that may not be properly documented or secured. This can be prevented by changing the code so it explicitly only allows access from localhost.

When binding to 0.0.0.0, you accept incoming connections from anywhere. During development, an application may have security vulnerabilities making it susceptible to SQL injections and other attacks. Therefore when the application is not ready for production, accepting connections from anywhere can be dangerous.

It is recommended to use 127.0.0.1 or local host during development phase. This prevents others from targeting your application and executing SQL injections against your project.

Bad practice

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0, 31137)) # Binding to all interfaces

Recommended

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 31137)) # Binding to local host

```

References: