File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 15
15
import hmac
16
16
import importlib
17
17
import io
18
+ import ipaddress
18
19
import json
19
20
import logging
20
21
import mimetypes
@@ -833,7 +834,7 @@ def _token_changed(self, change):
833
834
"""
834
835
)
835
836
836
- allow_remote_access = Bool (False , config = True ,
837
+ allow_remote_access = Bool (config = True ,
837
838
help = """Allow requests where the Host header doesn't point to a local server
838
839
839
840
By default, requests get a 403 forbidden response if the 'Host' header
@@ -848,6 +849,21 @@ def _token_changed(self, change):
848
849
along with hostnames configured in local_hostnames.
849
850
""" )
850
851
852
+ @default ('allow_remote_access' )
853
+ def _default_allow_remote (self ):
854
+ """Disallow remote access if we're listening only on loopback addresses"""
855
+ try :
856
+ addr = ipaddress .ip_address (self .ip )
857
+ except ValueError :
858
+ # Address is a hostname
859
+ for info in socket .getaddrinfo (self .ip , self .port , type = socket .SOCK_STREAM ):
860
+ addr = ipaddress .ip_address (info [4 ][0 ])
861
+ if not addr .is_loopback :
862
+ return True
863
+ return False
864
+ else :
865
+ return not addr .is_loopback
866
+
851
867
local_hostnames = List (Unicode (), ['localhost' ], config = True ,
852
868
help = """Hostnames to allow as local when allow_remote_access is False.
853
869
You can’t perform that action at this time.
0 commit comments