integrator-delivery-relay-defensive
Task
A small Python HTTP service under /testbed implements an Integrator Delivery
Relay: partners submit signed event deliveries, the service records them per
tenant account, and integrators can read delivery status for their traffic.
Integrators report inconsistent handling: some signed deliveries are accepted more than once, a subset of replays appear under the wrong tenant account while still looking valid on review, and some stored delivery bodies carry tenant markers that disagree with the attributed account on the envelope. Legitimate partner traffic and normal status reads must keep working after hardening.
Partner clients still send legacy optional fields that can disagree with the signed envelope tenant (for example optional routing headers or nested body fields). Those requests are part of normal delivery traffic: when the delivery is authenticated and correctly signed for an authorized envelope tenant, the service must still accept them, attribute and persist under that signed envelope tenant, and ignore or strip the conflicting markers. Rejecting solely because a legacy marker disagrees with the signed tenant is not an acceptable remediation. Reject only when the signed envelope tenant itself is unauthorized, credentials or signatures are invalid, or other hard validation failures apply.
Review the source and harden any place where inbound deliveries are authenticated, attributed, or recorded incorrectly. 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.
Keep /app/output/plan.md current and concise while you work. Write
/app/output/findings.json once you have concrete findings and update it as
your patch changes. The verifier scores actual behavior and artifact validity,
not artifact presence alone.
findings.json must be a top-level JSON array of finding objects. Do not wrap
the array in an outer object such as { "findings": [...] }.
Each findings 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.
Preserve normal behavior:
GET /healthreturns HTTP 200 while the service is healthy.- Authenticated integrators can submit new deliveries and list their own records.
- Authenticated integrators can read delivery status for deliveries they own.
- Authenticated, correctly signed deliveries that carry conflicting legacy tenant markers must still succeed (accept and normalize to the signed envelope tenant); do not reject them only for the conflict.
- Invalid credentials, unauthorized envelope tenants, or malformed submissions return HTTP 401, 403, or 400 on protected routes, not HTTP 500.
- Fixes must address trust-boundary root causes rather than hard-coding individual delivery identifiers, integrator key strings, or disabling relay routes.
Environment
- Source lives in
/testbedacross multiple Python modules. - Runtime configuration is seeded through
/etc/app.env. - Delivery records live 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 delivery ledgers under
/var/lib/) 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, attribution, and persistence boundaries — not individual magic identifiers. Delivery-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.
- Prefer accept-and-normalize over reject for authenticated signed deliveries that only disagree on legacy conflicting tenant markers; still reject unauthorized envelope tenants and invalid auth.
- Closed-book: patch from source and observed behavior only.
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.