session-broker-jwt-defensive
Task Instructions
You are performing a defensive security audit on a Python FastAPI internal session broker that issues and verifies bearer tokens for partner services.
Background
The service exposes:
- public
/healthand/status /meand/tokens/inspectfor bearer-authenticated callers/tokens/issueand/admin/configfor privileged operators- ops helpers under
/ops/*for session restore and sandbox notes
Authorization contract: privileged admin operations require either a valid
X-Admin-Token or a bearer token that truly entitles the caller to an admin
role. Client-supplied identity / mesh / forwarding headers alone do not
establish entitlement. Token integrity and key selection must be trustworthy.
Operators report unexpected privilege, cross-principal confusion, unsafe behavior in operational helpers, and public responses containing material that should stay internal.
Your Objective
- Review all source under
/app/src/(and related key material layout under/app/keys/as needed to understand verification). - Identify every weakness that violates the authorization, session integrity, data-boundary, or confidentiality contracts above.
- Patch the vulnerabilities directly in the
/app/src/tree. - Before and as you work, maintain
/app/output/plan.mdrecording the subsystem(s) and suspected weakness class, the root cause you traced, your fix approach, and how you verified both sides of each fix. - Your patches must:
- Keep
/healthpublic and keep legitimate HS256 tokens with kiddefaultworking for/me - Keep
/tokens/issueworking for callers with a validX-Admin-Token - Reject otherwise valid tokens that were issued for a different audience or service, while preserving tokens issued for this broker
- Keep JSON session restore working for entitled admins
- Block forged privilege and unauthenticated secret disclosure
- Keep
/statuspublic without leaking token samples or key identifiers from recent audits
- Keep
Important
- Do not change the
ADMIN_TOKEN,SERVICE_SECRET, orJWT_HMAC_SECRETvalues in/app/src/config.py. - Prefer fixing verification / authorization logic over deleting features.
- There is more than one independent weakness.
Scoring
Scoring uses deterministic HTTP behavior (55%), output quality (25%), and
process quality (20%). Validity and task quality are advisory. Binary reward
requires every deterministic check to pass and the required non-empty
/app/output/plan.md to be present; judge output cannot override either gate.