This commit is contained in:
Mateusz Gruszczyński
2025-07-26 22:48:28 +02:00
parent 6b2469778f
commit e5ef1309e7

14
app.py
View File

@@ -551,6 +551,15 @@ def attempts_remaining(ip):
####################################################
def get_client_ip():
# Obsługuje: X-Forwarded-For, X-Real-IP, fallback na remote_addr
for header in ["X-Forwarded-For", "X-Real-IP"]:
if header in request.headers:
# Pierwszy IP w X-Forwarded-For jest najczęściej klientem
ip = request.headers[header].split(",")[0].strip()
if ip:
return ip
return request.remote_addr
@login_manager.user_loader
def load_user(user_id):
@@ -626,8 +635,9 @@ def start_timer():
@app.after_request
def log_request(response):
forwarded_for = request.headers.get("X-Forwarded-For", request.remote_addr)
client_ip = forwarded_for.split(",")[0].strip()
if request.path == "/healthcheck":
return response
client_ip = get_client_ip()
method = request.method
path = request.path
status = response.status_code