mirror of
https://github.com/evennia/evennia.git
synced 2026-03-19 22:36:31 +01:00
Merge pull request #2014 from GulliblePsychologist/websocket
Allow X-Forwarded-For to be accepted for the WebSocket connections.
This commit is contained in:
commit
3496ffb602
1 changed files with 11 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ _RE_SCREENREADER_REGEX = re.compile(
|
|||
r"%s" % settings.SCREENREADER_REGEX_STRIP, re.DOTALL + re.MULTILINE
|
||||
)
|
||||
_CLIENT_SESSIONS = mod_import(settings.SESSION_ENGINE).SessionStore
|
||||
_UPSTREAM_IPS = settings.UPSTREAM_IPS
|
||||
|
||||
|
||||
CLOSE_NORMAL = WebSocketServerProtocol.CLOSE_STATUS_CODE_NORMAL
|
||||
|
|
@ -75,6 +76,16 @@ class WebSocketClient(WebSocketServerProtocol, Session):
|
|||
"""
|
||||
client_address = self.transport.client
|
||||
client_address = client_address[0] if client_address else None
|
||||
|
||||
if client_address in _UPSTREAM_IPS and 'x-forwarded-for' in self.http_headers:
|
||||
addresses = [x.strip() for x in self.http_headers['x-forwarded-for'].split(',')]
|
||||
addresses.reverse()
|
||||
|
||||
for addr in addresses:
|
||||
if addr not in _UPSTREAM_IPS:
|
||||
client_address = addr
|
||||
break
|
||||
|
||||
self.init_session("websocket", client_address, self.factory.sessionhandler)
|
||||
|
||||
csession = self.get_client_session() # this sets self.csessid
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue