mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-28 01:49:00 +09:00
## Summary Two fixes: 1. **Real client IPs** — All stored IPs were `169.254.169.126` (Cloud Run LB). Now uses `X-Forwarded-For` header via shared `get_client_ip()` helper. Fixed in magic link, verify, and job creation endpoints. Backfill endpoint updated to clear bad IPs and re-fetch. 2. **User detail identity info** — Admin user detail page now shows: - Identity & Security card: signup IP, device fingerprint, welcome credits status - Active sessions: IP, user agent, fingerprint, last activity - Total spent and feedback status After deploy, re-run backfill to fix the bad IPs: ```bash curl -X POST .../api/admin/abuse/backfill-ips -H "Authorization: Bearer $TOKEN" ``` @coderabbitai ignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
24 lines
677 B
Python
24 lines
677 B
Python
"""
|
|
Request utility helpers for extracting client information.
|
|
"""
|
|
from typing import Optional
|
|
from fastapi import Request
|
|
|
|
|
|
def get_client_ip(request: Request) -> Optional[str]:
|
|
"""
|
|
Extract real client IP address from a request.
|
|
|
|
Cloud Run and load balancers set X-Forwarded-For header with the
|
|
original client IP as the first entry. Falls back to request.client.host
|
|
for direct connections (local dev).
|
|
|
|
Returns None if no IP can be determined.
|
|
"""
|
|
forwarded = request.headers.get("x-forwarded-for", "")
|
|
if forwarded:
|
|
return forwarded.split(",")[0].strip()
|
|
if request.client:
|
|
return request.client.host
|
|
return None
|