security: restrict /api/ingest to internal IPs only
Checks X-Forwarded-For/X-Real-IP from NPM proxy to get real client IP. Only allows localhost, LAN (10.5.0.x), and NetBird (100.79.x) prefixes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1dff4630fe
commit
50c3b116f7
1 changed files with 10 additions and 0 deletions
|
|
@ -102,8 +102,18 @@ def queue_status() -> str:
|
||||||
|
|
||||||
|
|
||||||
# Custom non-MCP routes (no auth required - local access only)
|
# Custom non-MCP routes (no auth required - local access only)
|
||||||
|
INTERNAL_PREFIXES = ("127.", "10.5.0.", "::1", "100.79.") # localhost, LAN, NetBird
|
||||||
|
|
||||||
|
|
||||||
async def ingest_message(request: Request) -> JSONResponse:
|
async def ingest_message(request: Request) -> JSONResponse:
|
||||||
"""HTTP endpoint for local services to log messages into the bridge."""
|
"""HTTP endpoint for local services to log messages into the bridge."""
|
||||||
|
# Check real client IP (X-Forwarded-For from NPM, or direct connection)
|
||||||
|
forwarded = request.headers.get("x-forwarded-for", "")
|
||||||
|
real_ip = request.headers.get("x-real-ip", "")
|
||||||
|
client_ip = forwarded.split(",")[0].strip() or real_ip or (request.client.host if request.client else "")
|
||||||
|
if not any(client_ip.startswith(p) for p in INTERNAL_PREFIXES):
|
||||||
|
return JSONResponse({"error": "forbidden"}, status_code=403)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue