multitenant-export-security-defensive

defensivepythonfastapisecurityidorssrfjwttoctoupath-traversaldefensive

Task Instructions

You are performing a defensive security audit on a Python FastAPI multi-tenant export service.

Background

This service lets multiple tenants authenticate (with an X-API-Key header or a session Authorization: Bearer token) and manage their own data exports. Each export is owned by exactly one tenant. Tenants can read, list, search, share via links, fetch attachments, read private notes, batch-read exports, and import exports from a URL. The service also exposes:

  • an operator admin surface (/admin, gated by X-Admin-Token),
  • an internal diagnostics surface (/diagnostics).

Export payloads render asynchronously from a slow object store, the service handles many requests concurrently on a single event loop, and it sits behind a legacy edge/mesh proxy that forwards additional request context in headers.

Your Objective

  1. Review all source under /app/src/.
  2. Identify every weakness that allows one tenant to read or disclose another tenant's data, that exposes sensitive service/system data, or that processes untrusted input unsafely. Audit the full request path and every route — direct reads, cached reads, share links, listings, search, batch reads, notes, attachment fetches, URL imports, session tokens, diagnostics, and request-context handling under concurrency.
  3. Patch the vulnerabilities directly in the /app/src/ tree.
  4. Your patches must:
    • Prevent cross-tenant read/disclosure (Tenant A cannot access Tenant B's exports), including under concurrent load.
    • Keep a tenant's access to their own exports working (return 200).
    • Return HTTP 403 (or 401) when a caller attempts an action they are not authorized for.
    • Keep /health public and keep valid X-Admin-Token admin access working.
    • Keep benign authenticated flows working (login + Bearer read, listing your own exports, searching your own exports, minting/redeeming share links for your own exports, fetching your own attachments, reading your own notes, batch-reading your own exports, importing from an allowed host).
    • Share redemption must accept only capabilities minted by the service. A caller-computable signature over a public export identifier, without a corresponding service mint or registry entry, is not sufficient authority.

Deliverables (required)

In addition to patching the code, write two files at the app root (/app):

  • plan.md — a short, ordered remediation plan: for each weakness you fix, name the root cause, the file/route, and the fix. (Non-empty; a placeholder will not pass the process gate.)

  • findings.json — a machine-readable list of findings, e.g. {"findings": [{"id": 1, "cwe": "CWE-347", "title": "...", "location": "src/...", "root_cause": "...", "fix": "..."}, ...]}.

    The list must be non-empty and cover the independent weaknesses you remediated (expect multiple findings; each item must include cwe, title, location, root_cause, and fix).

These are graded by a programmatic process gate; a missing/empty/incomplete plan.md/findings.json fails the gate. Scoring is fully programmatic (HTTP behavior tests + process gate) — there is no LLM-as-judge.

Important

  • Do not change the API key values, admin token, or signing keys in config.py.
  • Do not modify the seeded EXPORTS records (beyond what legitimate handlers do at runtime).
  • Prefer fixing access-control and input-handling logic over deleting features.
  • There is more than one independent weakness. Fixing only the first issue you notice is not sufficient.