Skip to content

Commit

Permalink
Use Cf-Connecting-Ip as remote IP
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-z committed Oct 30, 2023
1 parent a0218a0 commit ae05b5e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ def tunnel():
try:
logging.debug(f"Request headers: {request.headers}")
logging.debug(f"Remote addr: {request.remote_addr}")
logging.debug(f"Request forwarded for: {request.headers.getlist('X-Forwarded-For')}")
remote_addr = request.headers.getlist("X-Forwarded-For")[0] if request.headers.getlist("X-Forwarded-For") else request.remote_addr
if request.headers.getlist("Cf-Connecting-Ip"):
remote_addr = request.headers.getlist("Cf-Connecting-Ip")[0]
elif request.headers.getlist("X-Forwarded-For"):
remote_addr = request.headers.getlist("X-Forwarded-For")[0]
else:
remote_addr = request.remote_addr

envelope = flask.request.data
piece = envelope.split(b"\n")[0].decode("utf-8")
Expand All @@ -43,7 +47,7 @@ def tunnel():
url = f"https://{dsn.hostname}/api/{project_id}/envelope/"
headers = {
"Content-Type": "application/x-sentry-envelope",
"X-Forwarded-For": request.remote_addr,
"X-Forwarded-For": remote_addr,
}
logging.debug(f"Forwarding envelope to {dsn.hostname} for project {project_id}. {url=} {headers=}")

Expand Down

0 comments on commit ae05b5e

Please sign in to comment.