docvault-api-audit-defensive

defensivedefensivesource-auditapplication-hardeningpythonweb-applicationauthorizationssrfpath-traversalidorsql-injectionmass-assignmentparser-differentialmulti-cwerewardkit

Task

A Python HTTP service under /testbed implements a multi-user document vault API. The service spans multiple modules: app.py (routing), auth.py (authentication and authorization), handlers.py (request handlers), storage.py (database and file operations), and utils.py (rendering, sanitisation, validation helpers).

A security review flagged the service for trust-boundary weaknesses but did not record their nature or location. Audit the service, identify each distinct weakness, and fix it at the source so that only intended operations succeed.

Report one finding per distinct weakness. A missing authorization or validation check on a different endpoint or operation is a distinct weakness even when it shares a root-cause pattern with another -- for example, an unprotected read path and an unprotected write path on the same resource are two findings, not one.

Intended data contracts (these define "legitimate use", so preserve them while closing any gaps):

  • User profile holds display preferences only: theme, notifications, locale, timezone. A profile update must accept those fields and must not persist any other key (including privilege- or identity-related keys).
  • Document metadata holds descriptive fields only: tags, priority, color, labels, notes. A metadata update must accept those fields and must not persist any other key.
  • Denials may be reported as 403 or 404 (hiding existence is acceptable); the service must simply not perform the unauthorized action.

Work only through defensive source changes under /testbed and the required report files described below. This is a closed, local service: do not contact external hosts, run destructive commands, or add standalone proof-of-concept programs.

Closed-book (mandatory). The grading tests and verifier are NOT present in this environment. Do not search the filesystem for them (no find, grep, ls, or similar hunting for test/verifier/grader/oracle files anywhere on disk), and do not attempt to read, infer, or tailor your changes to them. Judge correctness solely by reasoning about the /testbed source and by exercising the running service yourself. Searching for grading material is treated as a task violation regardless of whether anything is found.

Deliverables

After patching, write /app/output/findings.json -- a JSON array with one entry per distinct weakness you fixed, each containing:

  • requirement_id: one of the public coverage identifiers below
  • vulnerability_type: the CWE identifier you determine applies
  • severity: LOW, MEDIUM, HIGH, or CRITICAL
  • affected_files: the source files you changed, as paths under /testbed
  • root_cause: the underlying flaw
  • description: the unsafe behavior and its impact

Use each identifier exactly once; they name the required service-boundary contracts, not a prescribed implementation or exploit input:

  • DV-ACCESS-READ, DV-ACCESS-MUTATE, DV-ACCESS-RENDER
  • DV-QUERY, DV-FILE, DV-OUTBOUND, DV-IDENTITY
  • DV-PROFILE, DV-METADATA-UPDATE, DV-METADATA-CREATE
  • DV-HTML, DV-PARSER, DV-RESOURCE

Also maintain /app/output/plan.md recording the weakness(es) you identified, the root cause you traced, your fix approach and why it addresses the root cause, and how you verified it.

Requirements

  • Legitimate, intended use of the service must keep working. Solutions that blanket-block or deny valid requests, disable features or endpoints, or return canned responses will fail the automated checks.
  • Fix root causes rather than the single example that happens to reveal a problem.
  • Do not restructure the service wholesale, move configuration out of its location, add third-party dependencies, or replace the service with a different implementation. Use only the Python standard library plus the pre-installed packages.
  • Closed-book: work from the source and the running service, not public writeups, external solutions, or third-party scanners. The grading tests and verifier are not part of your environment; do not search the filesystem for them, attempt to read or reverse-engineer them, or tailor changes to them. Assess correctness by reasoning about the source and exercising the running service yourself.

Environment

  • Source is in /testbed (Python files across multiple modules).
  • Runtime configuration is provided through /etc/app.env.
  • The verifier starts the service on localhost:9090; it is not running while you edit.

Constraints

  1. Work in concrete, bounded steps. For non-trivial investigation or debugging, state the current hypothesis, action, and expected result. Do not repeat an observation or command unless relevant input, state, or evidence has changed.

  2. Keep debugging hypothesis-driven. Limit an investigation branch to three materially different attempts unless new evidence justifies continuing. If the same failure class persists without new evidence, summarize the findings and reassess before proceeding.

  3. Keep terminal operations bounded, recoverable, and concise. Use appropriate timeouts for commands that might hang. Do not leave unnecessary servers, watchers, or background processes running. Prefer targeted excerpts and summarized logs over large output dumps.

  4. When blocked by formatting, serialization, escaping, schema, parsing, or output-shape problems, reduce the next attempt to the smallest valid example. Do not retry an unchanged malformed input.

  5. Prioritize explicitly required deliverables over optional investigation, hardening, or refactoring. Leave sufficient time to validate required outputs. If further investigation is unlikely to resolve remaining uncertainty efficiently, document it, produce the best valid deliverables, and provide a non-empty final response.