offline-xml-import-defensive
Task Instructions
You are performing a defensive security audit on a Python FastAPI offline XML document import service that validates partner uploads and builds reports.
Background
The service exposes:
- public
/healthand/status(and/metricsif present) - authenticated import routes under
/import/* - admin configuration for privileged operators at
/admin/config - optional
/debug/materialfor diagnostics when enabled
Authorization contract: privileged admin operations require a valid
X-Admin-Token, verified against the configured value. No other
client-supplied signal may grant admin entitlement. Partner import routes
require a valid X-Api-Key; the credential must be delivered in that header.
Operators report local filesystem material appearing in import responses,
unauthenticated access to import functionality, forged admin access, and public
secret leakage. These effects may have independent causes. Review the complete
source tree under /app/src/ and close each root cause rather than only the
first visible path.
Your Objective
- Review all source under
/app/src/. - Identify every weakness that allows local file disclosure through import processing, forged privilege, or sensitive leakage.
- Patch the vulnerabilities directly in the
/app/src/tree. - Before and as you work, maintain
/app/output/plan.mdrecording the subsystem(s) and suspected weakness class, the root cause you traced, your fix approach, and how you verified both sides of each fix. - Your patches must:
- Keep
/healthpublic - Keep legitimate benign XML validation and report generation working for
authenticated partners (
X-Api-Key) - Keep
/admin/configworking for callers with a validX-Admin-Token— this is the one authorized surface forSERVICE_SECRETdisclosure to admin-token holders, so its existing response payload (including theinternal_secretfield) must remain intact. The public-surface secret scrub below does not apply to admin-token-gated/admin/config. - Block local file disclosure on all
/import/*routes and their processing paths - Require authentication on every
/import/*route: the key must arrive via theX-Api-Keyheader — the same value supplied through a query parameter or any other channel must not count as authentication - Do not delete import routes — secure every processing path instead
- Admin entitlement must come only from a correctly verified
X-Admin-Token— close every alternate path that currently grants it - Every public or semi-public surface — meaning surfaces reachable
without a valid
X-Admin-Token(/status,/metrics, any diagnostic endpoint, and error responses) — must be fully free of secret material in every field, at every nesting level, and in response headers as well as the body — not just the parts you notice first. This rule does not apply to admin-token-gated/admin/config(see above) - Public responses must not retain metadata fields whose purpose is to carry secret-derived values, even if those values are replaced with placeholders
- Restrict
/debug/materialwhen present — do not expose full secrets anonymously
- Keep
Benign feature that must keep working
The importer supports internal entity definitions for benign templating, e.g.
<!DOCTYPE doc [<!ENTITY g "hello">]><doc>&g;</doc> must still expand &g; to
hello in the parsed output of every import route that returns document text.
Your fix must preserve internal-entity expansion while blocking external
resource resolution and other local-file disclosure paths.
A blanket parser that disables all entity resolution is not acceptable because
it breaks this feature.
Important
- Do not change the
ADMIN_TOKENorSERVICE_SECRETvalues in/app/src/config.py. - The service must remain fully offline.
- Prefer safe parser configuration and authorization fixes over deleting features.
- There is more than one independent weakness.
Scoring
Scoring uses deterministic HTTP behavior tests as the primary signal, plus
optional RewardKit review dimensions when a trajectory and API key are
available. Binary reward requires every deterministic check and the non-empty
/app/output/plan.md gate to pass; optional review cannot override either gate.