Skip to content

Commit

Permalink
Use X-Forwarded-For to forward IP
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-z committed Oct 30, 2023
1 parent 47c1782 commit 41870b9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

@app.route("/tunnel", methods=["POST"])
def tunnel():
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')}")
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

envelope = flask.request.data
piece = envelope.split(b"\n")[0].decode("utf-8")
header = json.loads(piece)
Expand All @@ -41,7 +43,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 41870b9

Please sign in to comment.