Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42ded89

Browse files
committed
Reformulate security check using getsockname().
1 parent eca991d commit 42ded89

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Demo/pysvr/pysvr.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ def main_thread(port):
4848
print "Listening on port", port, "..."
4949
while 1:
5050
(conn, addr) = sock.accept()
51+
if addr[0] != conn.getsockname()[0]:
52+
conn.close()
53+
print "Refusing connection from non-local host", addr[0], "."
54+
continue
5155
thread.start_new_thread(service_thread, (conn, addr))
5256
del conn, addr
5357

5458
def service_thread(conn, addr):
5559
(caddr, cport) = addr
56-
if caddr != socket.gethostbyname(socket.gethostname()):
57-
print "Connection from", caddr, "not accepted."
58-
return
5960
print "Thread %s has connection from %s.\n" % (str(thread.get_ident()),
6061
caddr),
6162
stdin = conn.makefile("r")

0 commit comments

Comments
 (0)