mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
This takes care of most of the false negatives from the preceding commit. Additionally, we add models for some known wrappers of `socket.socket` from the `gevent` and `eventlet` packages.
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
import socket
|
|
|
|
# binds to all interfaces, insecure
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.bind(('0.0.0.0', 31137)) # $ Alert[py/bind-socket-all-network-interfaces]
|
|
|
|
# binds to all interfaces, insecure
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.bind(('', 4040)) # $ Alert[py/bind-socket-all-network-interfaces]
|
|
|
|
# binds only to a dedicated interface, secure
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.bind(('84.68.10.12', 8080))
|
|
|
|
# binds to all interfaces, insecure
|
|
ALL_LOCALS = "0.0.0.0"
|
|
s.bind((ALL_LOCALS, 9090)) # $ Alert[py/bind-socket-all-network-interfaces]
|
|
|
|
# binds to all interfaces, insecure
|
|
tup = (ALL_LOCALS, 8080)
|
|
s.bind(tup) # $ Alert[py/bind-socket-all-network-interfaces]
|
|
|
|
|
|
# IPv6
|
|
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
|
s.bind(("::", 8080)) # $ Alert[py/bind-socket-all-network-interfaces]
|
|
|
|
|
|
# FN cases from https://github.com/github/codeql/issues/21582
|
|
|
|
# Address stored in a class attribute
|
|
class Server:
|
|
def __init__(self):
|
|
self.bind_addr = '0.0.0.0'
|
|
self.port = 31137
|
|
|
|
def start(self):
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.bind((self.bind_addr, self.port)) # $ Alert[py/bind-socket-all-network-interfaces]
|
|
|
|
server = Server()
|
|
server.start()
|
|
|
|
# os.environ.get with insecure default
|
|
import os
|
|
host = os.environ.get('APP_HOST', '0.0.0.0')
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.bind((host, 8080)) # $ Alert[py/bind-socket-all-network-interfaces]
|
|
|
|
# gevent.socket (alternative socket module)
|
|
from gevent import socket as gsocket
|
|
gs = gsocket.socket(gsocket.AF_INET, gsocket.SOCK_STREAM)
|
|
gs.bind(('0.0.0.0', 31137)) # $ Alert[py/bind-socket-all-network-interfaces]
|
|
|
|
# eventlet.green.socket (another alternative socket module)
|
|
from eventlet.green import socket as esocket
|
|
es = esocket.socket(esocket.AF_INET, esocket.SOCK_STREAM)
|
|
es.bind(('0.0.0.0', 31137)) # $ Alert[py/bind-socket-all-network-interfaces]
|