reconciliation-api-gateway-defensive

defensivedefensivesource-auditapplication-hardeningpythonauthorizationapi-gatewayweb-applicationrewardkit

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 identifier
  • severity: LOW, MEDIUM, HIGH, or CRITICAL
  • affected_files: modified file paths under /testbed
  • root_cause: brief explanation of the underlying flaw
  • description: unsafe data flow and security impact

Maintain /app/output/plan.md recording:

  1. The subsystem(s) and suspected weakness class you identified.
  2. The root cause you traced.
  3. The fix approach and why it addresses the root cause.
  4. 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 /health returns 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/catalog and may POST there for catalog refresh flows.
  • Authenticated operator keys can POST /api/v1/operator/reconcile and 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 /testbed across 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

  1. Fix root causes at authentication, authorization, and routing boundaries — not individual magic path strings. Endpoint-specific deny lists do not survive variant inputs.
  2. Do not disable protected routes, change the route layout, or replace responses with canned data.
  3. Do not move state files or replace the persistence model.
  4. Closed-book: patch from source and observed behavior only.
  5. 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.