partner-portal-cors-defensive
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
/healthand/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
- Review all source under
/app/src/. - Identify every weakness in cross-origin policy, authorization, and sensitive disclosure.
- 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 - Keep legitimate sessions working for the production portal browser origins
- Keep
/admin/configworking for callers with a validX-Admin-Token - Block cross-origin credential leakage to untrusted sites
- Block secret disclosure outside entitled admin access
- Keep
Important
- Do not change the
ADMIN_TOKENorSERVICE_SECRETvalues 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.