partner-data-gateway-defensive

defensivedefensivesource-auditapplication-hardeningpythonauthorizationweb-applicationrewardkit

Task

A small Python HTTP service under /testbed implements a partner data gateway: partners register outbound data exports, retrieve their own export metadata, and occasionally rely on platform operators to reach exports through a short maintenance relay window when direct partner paths are constrained.

Partner clients still send legacy optional fields that can disagree with the authenticated partner identity (for example optional partner-hint headers or transit metadata on otherwise authorized partner calls). Those requests are part of normal partner traffic: when the caller is an authenticated partner acting on their own exports, the service must still accept the request, attribute ownership from the authenticated principal, and ignore or strip the conflicting markers. Rejecting solely because a legacy marker disagrees with the authenticated partner is not an acceptable remediation. Reject only when credentials are invalid, the caller is out of scope, or other hard authorization failures apply.

Outbound partner-facing export metadata must not retain nested platform/ops-only fields after processing. Harden any place where inbound requests are authenticated, scoped, relayed, or authorized incorrectly, or where export records can be read across partner boundaries without satisfying the intended access rules. 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 partners can create exports and view their own export metadata.
  • Authenticated operators who are authorized for cross-partner inspection may retrieve that export metadata either by calling the normal export endpoints directly or through the maintenance relay during an active maintenance window.
  • Maintenance courier passes issued for follow-up operator reads remain bound to the grant profile under which they were minted. Reusing a pass, or reading the same export after an authorized first redeem, must not widen authorization beyond that minting grant.
  • Authenticated, correctly authorized partner calls that carry conflicting legacy partner or transit markers must still succeed (accept and normalize to the authenticated partner); do not reject them only for the conflict.
  • Outbound partner-facing export metadata must not expose nested platform/ops-only fields after processing on both inventory and detail reads, while retaining ordinary contact labels that are meant for partners.
  • Published export metadata must not be widened by later client transit markers on an otherwise authorized partner read.
  • Repeat partner reads of the same export must not expose additional internal fields beyond a correctly processed first response, including when the backing export record later carries maintenance or platform diagnostics.
  • Authenticated auditors can list export metadata across partners.
  • Read-only partner credentials must not create exports.
  • Cross-partner export reads must not succeed without proper authorization.
  • 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 export IDs, API key strings, or disabling gateway routes.

Environment

  • Source lives in /testbed across multiple Python modules.
  • Runtime configuration is seeded through /etc/app.env.
  • Partner API keys and export state 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 export records under /var/lib/partner-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, relay, presentation, redelivery, and export access boundaries — not individual magic identifiers. 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. Prefer accept-and-normalize over reject for authenticated partner calls that only disagree on legacy conflicting partner or transit markers; still reject cross-partner and unauthorized access.
  5. Closed-book: patch from source and observed behavior only.

Efficiency

When inspecting source and test behavior, use targeted file ranges and concise test output. Avoid dumping entire files, dependency trees, or full logs unless a bounded excerpt is necessary to understand or validate the patch.

Keep terminal output compact. Use summaries, targeted searches, and short excerpts instead of dumping large logs or repeated setup output.