signed-cookie-session-defensive
Task Instructions
You are performing a defensive security audit on a Python FastAPI internal signed-cookie session service used by browser-based admin tools.
Background
The service exposes:
- public
/healthand/status /session/login,/session/me,/session/patch, and/session/admin-check/admin/configfor privileged operators
Authorization contract: privileged admin operations require either a valid
X-Admin-Token or a session that truly entitles the caller to an admin role.
Client-supplied identity / mesh / forwarding headers alone do not establish
entitlement. Cookie integrity and claim interpretation must be trustworthy.
Operators report unexpected privilege, integrity failures in session handling, unsafe session mutation, and public responses containing material that should stay internal.
Your Objective
- Review all source under
/app/src/. - Identify every weakness that violates session integrity, authorization, safe mutation, or confidentiality.
- 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 login/me flows working - Keep
/admin/configworking for callers with a validX-Admin-Token - Keep a legitimate admin session usable: an admin-role session minted
with a valid
X-Admin-Tokenmust reach/session/admin-check - Keep
/session/patchusable for non-privileged claim updates that do not escalate role - Reject sessions that are outside their declared validity window, even when their signature and other claims are otherwise well formed
- Block forged or altered sessions and unauthorized privilege escalation
- Keep
/statuspublic without leaking internal secrets or cookie samples
- Keep
Important
- Do not change the
ADMIN_TOKEN,SERVICE_SECRET, orCOOKIE_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.