policy-export-isolation-defensive

defensivedefensivesource-auditapplication-hardeningpythonauthorizationweb-applicationrewardkit

Task

A small Python HTTP service under /testbed implements a multi-tenant policy export service: tenant administrators request redacted policy bundles assembled from on-disk primary and supplemental documents, then download prepared exports using a ticket issued at creation time.

Operations reports recurring inconsistencies: some internal fields appear concealed in a first download while others from the same bundle do not; downloading again with the same ticket sometimes returns a wider payload than the first retrieval; batch exports include columns that single exports omit; and tenant administrators occasionally receive export content that does not match their tenant boundary expectations.

Review the source and harden any place where export bundles are assembled, download credentials are honored on retrieval, or tenant boundaries are applied 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 both 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.

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.

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.

Preserve normal behavior:

  • GET /health returns HTTP 200 while the service is healthy.
  • Authenticated tenant administrators can create single and batch exports for their tenant and read export metadata.
  • Authenticated platform support agents can use the support relay during an active support window to retrieve export bundles they are authorized to hand off.
  • Catalog status polling and administrator profile reads remain available for authenticated administrators.
  • Exports intended for external distribution must not contain internal-only policy fields after processing completes.
  • Download tickets must not retrieve bundle content without valid authorization for the requesting tenant and scope, including on token reuse and when no API key is supplied. Tickets remain bound to the grant profile under which they were minted.
  • Re-downloading with the same ticket must not expose additional internal fields beyond what a correctly processed first download would include, including when later catalog or profile metadata polls occur or when request metadata on a follow-up fetch differs from the first retrieval.
  • Cross-tenant export retrieval must not succeed.
  • 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, field name blocklists used only in tests, or disabling export routes.

Environment

  • Source lives in /testbed across multiple Python modules.
  • Runtime configuration is seeded through /etc/app.env.
  • Tenant API keys live in /etc/policy-export/api-keys.json.
  • Policy catalog and export job state live outside /testbed under /var/lib/policy-export/.
  • The verifier starts the service on localhost:9090.
  • Do not modify files outside /testbed.
  • Do not delete or modify runtime state files under /var/lib/policy-export/ 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 document processing, ticket validation, batch assembly, catalog metadata trust, support relay, and export pipeline boundaries — not individual magic identifiers. Field-specific deny lists that only remove strings the tests probe 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.