Skip to content

Commit 5333bb5

Browse files
authored
Extract client_ip from x-forwarded-for header (#5547)
1 parent 19a4059 commit 5333bb5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

reflex/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,9 +2087,20 @@ async def on_event(self, sid: str, data: Any):
20872087
# Get the client IP
20882088
try:
20892089
client_ip = environ["asgi.scope"]["client"][0]
2090+
headers["asgi-scope-client"] = client_ip
20902091
except (KeyError, IndexError):
20912092
client_ip = environ.get("REMOTE_ADDR", "0.0.0.0")
20922093

2094+
# Unroll reverse proxy forwarded headers.
2095+
client_ip = (
2096+
headers.get(
2097+
"x-forwarded-for",
2098+
client_ip,
2099+
)
2100+
.partition(",")[0]
2101+
.strip()
2102+
)
2103+
20932104
async with contextlib.aclosing(
20942105
process(self.app, event, sid, headers, client_ip)
20952106
) as updates_gen:

0 commit comments

Comments
 (0)