session-broker-jwt-defensive

defensivepythonfastapisecurityjwtauthenticationdeserializationdefensive

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 /health and /status
  • /me and /tokens/inspect for bearer-authenticated callers
  • /tokens/issue and /admin/config for 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

  1. Review all source under /app/src/ (and related key material layout under /app/keys/ as needed to understand verification).
  2. Identify every weakness that violates the authorization, session integrity, data-boundary, or confidentiality contracts above.
  3. Patch the vulnerabilities directly in the /app/src/ tree.
  4. Before and as you work, maintain /app/output/plan.md recording the subsystem(s) and suspected weakness class, the root cause you traced, your fix approach, and how you verified both sides of each fix.
  5. Your patches must:
    • Keep /health public and keep legitimate HS256 tokens with kid default working for /me
    • Keep /tokens/issue working for callers with a valid X-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 /status public without leaking token samples or key identifiers from recent audits

Important

  • Do not change the ADMIN_TOKEN, SERVICE_SECRET, or JWT_HMAC_SECRET values 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.