partner-portal-cors-defensive

defensivepythonfastapisecuritycorsdefensive

Task Instructions

You are performing a defensive security audit on a Python FastAPI partner portal that serves browser sessions and admin configuration.

Background

The service exposes:

  • public /health and /status
  • session routes under /session/* for cookie-less session tokens
  • admin configuration for privileged operators

Authorization contract: privileged admin operations require a valid X-Admin-Token. Client-controlled request metadata alone does not establish admin entitlement.

Operators report that third-party sites can read authenticated browser session responses, that admin configuration is reachable without a real admin token, and that internal service material shows up on surfaces that third parties or ordinary session clients should not see.

Credentialed CORS must be limited to production end-user portal browser origins https://app.example.com and https://portal.example.com. Session flows need that access; non-session operational surfaces should not advertise credentialed cross-origin access.

Credentialed responses must be safe for shared caches by varying on Origin. Preflight responses for trusted session origins must enumerate the supported methods and headers rather than using wildcard grants. Untrusted origins and non-session operational or admin surfaces must not advertise wildcard method/header grants or credentialed cross-origin access.

Your Objective

  1. Review all source under /app/src/.
  2. Identify every weakness in cross-origin policy, authorization, and sensitive disclosure.
  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
    • Keep legitimate sessions working for the production portal browser origins
    • Keep /admin/config working for callers with a valid X-Admin-Token
    • Block cross-origin credential leakage to untrusted sites
    • Block secret disclosure outside entitled admin access

Important

  • Do not change the ADMIN_TOKEN or SERVICE_SECRET values in /app/src/config.py.
  • Prefer tightening CORS and 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.