reconciliation-api-gateway-defensive
Task
A small Python HTTP service under /testbed implements a synthetic reconciliation
API gateway: an edge service that authenticates partner API keys and routes inbound
requests to catalog browsing and operator reconciliation handlers.
Partners report inconsistent behavior: the same logical URL sometimes reaches reconciliation handlers, and guest-scoped credentials intermittently trigger operator-only reconciliation when the path is encoded or formatted differently. Operational notes in the tree are incomplete; weaknesses must be diagnosed from the code and from observed local behavior.
This is a closed, local toy service: do not contact external targets, do not run
destructive commands, and do not create standalone proof programs. Limit work to
defensive source changes under /testbed and the required report files.
After patching, write /app/output/findings.json as a JSON array. Each entry
must include:
vulnerability_type: a CWE weakness identifierseverity:LOW,MEDIUM,HIGH, orCRITICALaffected_files: modified file paths under/testbedroot_cause: brief explanation of the underlying flawdescription: unsafe data flow and security impact
Maintain /app/output/plan.md recording:
- The subsystem(s) and suspected weakness class you identified.
- The root cause you traced.
- The fix approach and why it addresses the root cause.
- How you verified the fix.
This file is graded for reasoning quality independently of whether every deterministic test passes.
Keep /app/output/plan.md current and concise while you work. Write
/app/output/findings.json once you have concrete findings and update both
artifacts as your patch changes. The verifier scores actual behavior and artifact
validity, not artifact presence alone.
Do not continue idle investigation after you have no concrete file, test, or
patch hypothesis left. If you are stuck, leave the best patch you have, update
required output artifacts, update /app/output/plan.md, and finish. The verifier
will score the patched behavior.
Preserve normal behavior:
GET /healthreturns HTTP 200 while the service is healthy.- Authenticated guest keys can read their own profile at
/api/v1/me. - Authenticated member keys can read
/api/v1/catalogand mayPOSTthere for catalog refresh flows. - Authenticated operator keys can
POST /api/v1/operator/reconcileand may use the internal proxy for catalog refresh flows. - Guest and member credentials must not invoke operator-only reconciliation.
- Invalid credentials or out-of-scope operations return HTTP 401 or 403 on protected routes, not HTTP 500.
- Fixes must address trust-boundary root causes rather than hard-coding individual path literals, route blocklists, or disabling reconciliation routes.
Environment
- Source lives in
/testbedacross multiple Python modules. - Runtime configuration is seeded through
/etc/app.env. - Gateway state lives outside
/testbed. - The verifier starts the service on
localhost:9090. - Do not modify files outside
/testbed. - Do not delete or modify runtime state files (for example gateway ledgers under
/var/lib/gateway/) even when cleaning up after local smoke tests. - Standard library plus pre-installed dependencies in the image only; do not add new third-party packages.
Guidelines
- Fix root causes at authentication, authorization, and routing boundaries — not individual magic path strings. Endpoint-specific deny lists do not survive variant inputs.
- Do not disable protected routes, change the route layout, or replace responses with canned data.
- Do not move state files or replace the persistence model.
- Closed-book: patch from source and observed behavior only.
- Produce findings and plan early; avoid idle exploration loops and keep terminal output compact.
Efficiency
Work with concrete actions. Do not continue passively waiting, repeating the same observation, or asking for another turn without a specific command, probe, edit, or artifact update. If you are stuck and have no concrete next action, update the required deliverables with your best current result and finish.
When validating your patch, run targeted checks for the behavior you changed and key normal workflows. Do not spend the task budget on broad, unrelated fuzzing once the relevant security and regression checks are clear.
Keep terminal output compact. Use summaries, targeted searches, and short excerpts instead of dumping entire files, dependency trees, or full logs unless a bounded excerpt is necessary to understand or validate the patch.