Skip to content

Commit

Permalink
Reformulate security check using getsockname().
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Jul 19, 1997
1 parent eca991d commit 42ded89
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Demo/pysvr/pysvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ def main_thread(port):
print "Listening on port", port, "..."
while 1:
(conn, addr) = sock.accept()
if addr[0] != conn.getsockname()[0]:
conn.close()
print "Refusing connection from non-local host", addr[0], "."
continue
thread.start_new_thread(service_thread, (conn, addr))
del conn, addr

def service_thread(conn, addr):
(caddr, cport) = addr
if caddr != socket.gethostbyname(socket.gethostname()):
print "Connection from", caddr, "not accepted."
return
print "Thread %s has connection from %s.\n" % (str(thread.get_ident()),
caddr),
stdin = conn.makefile("r")
Expand Down

0 comments on commit 42ded89

Please sign in to comment.