DEV_JWKS_PATH loopback guard is bypassed when app.py runs under an external ASGI server
Summary
In claude-for-msft-365-install/examples/python-bootstrap, the guard that is
supposed to confine DEV_JWKS_PATH to loopback only inspects the HOST
environment variable. It never observes the address the server actually binds
to. When the app is started through the uvicorn / gunicorn CLI, which is the
normal way to run a FastAPI app, --host controls the bind address and HOST
is never read. The guard sees its own default of 127.0.0.1, passes, and the
server accepts self-signed tokens on a public interface.
config.py:
HOST = os.getenv("HOST", "127.0.0.1")
DEV_JWKS_PATH = os.getenv("DEV_JWKS_PATH")
if DEV_JWKS_PATH and HOST != "127.0.0.1":
raise SystemExit("DEV_JWKS_PATH may only be used when HOST=127.0.0.1")HOST only reaches a socket via the __main__ block in app.py
(uvicorn.run(app, host=HOST, ...)). Any other launch path leaves the guard
comparing a value that has no effect on binding.
Reproduction
cd claude-for-msft-365-install/examples/python-bootstrap
pip install -r requirements.txt
export TENANT_ID=dev-tenant
python mint_dev_token.py --oid attacker --group risk > forged.jwt
# HOST is deliberately unset, so the guard's check passes
DEV_JWKS_PATH=dev_jwks.json uvicorn app:app --host 0.0.0.0 --port 8099
curl -H "Authorization: Bearer $(cat forged.jwt)" \
-H "X-Claude-User-Agent: claude-word/1.0.0" \
http://127.0.0.1:8099/bootstrapObserved: the server starts with no warning, ss -ltn confirms it is listening
on 0.0.0.0:8099, and the forged token is accepted. The response returns the
risk group's grants, including the risk-api MCP server entry and its
Authorization: Bearer {{gateway_token}} header.
The asymmetry is easy to see in isolation:
| Invocation | Guard fires? | Actual bind |
|---|---|---|
HOST=0.0.0.0 python app.py |
yes, SystemExit |
n/a |
uvicorn app:app --host 0.0.0.0 (HOST unset) |
no | 0.0.0.0 |
Impact
Whoever reaches the port fully controls oid and groups, because
mint_dev_token.py signs with the same key the server has been told to trust.
resolve() in app.py derives all authorization from those two claims, so
every rule in RULES can be matched at will. This is the RBAC table this
example exists to demonstrate, so the failure mode is a complete bypass of it
rather than a partial one.
This is sample code rather than a deployed service, so there is no live system
at risk. The concern is that it is written to be copied, and the guard plus the
README's "It refuses to start unless bound to 127.0.0.1" both read as stronger
assurances than they are.
Suggested fix
Enforce the invariant per request, where the peer address is actually known, instead of at import time against an env var that may not govern binding:
from fastapi import Request
@app.get("/bootstrap")
def bootstrap(request: Request, ...):
if DEV_JWKS_PATH and request.client.host not in ("127.0.0.1", "::1"):
raise HTTPException(403, "DEV_JWKS_PATH is loopback-only")This holds regardless of how the process was launched. Keeping the existing
import-time check as a fast failure for the python app.py path is still
worthwhile. It would also be worth softening the README's wording, since the
current phrasing invites readers to trust the guard more than its
implementation supports.
Environment
Reproduced at commit 574ed3624aebd0418c7e96cd101262f30210ab26 on Python
3.14.7, Fedora, with the pinned requirements.txt.
Source: anthropics/financial-services