shipyard-tenant-hardening-defensive
Task
A small Python HTTP service lives under /testbed: ShipYard, a multi-tenant
carrier manifest service. Each org authenticates with its own API bearer token
and may act only for that org. An org owns carrier accounts (a printed code, a
tracking destination, and an org-private api_secret) and shipments (a
reference plus an instructions template and the carrier accounts it is tendered
against), and drives them through a range of features: tendering, closing and
submitting manifests, cloning, importing, looking up, searching, sharing,
reporting, and depot handoff. An org's carrier credentials, shipments, tenders and
manifests are private to that org.
The service has not been security-reviewed. Perform a security hardening pass
across its request/response surface so that it can be trusted in production.
Read the source under /testbed, understand what each endpoint actually does, and
find and fix the weaknesses yourself — there is more than one, they are of
different kinds, and no list of them is provided. A justifying comment in the
source describes intent, not a guarantee; rely on what the code does, not what it
says.
Harden the source under /testbed so that an org can only ever read, use, or
expose its own resources, and the service cannot be driven to take an effect,
render content, or reach a destination it should not, without breaking any
legitimate behavior.
Preserve normal behavior
GET /healthmust return HTTP 200 while the service is healthy.- Every feature must remain fully usable for an org's OWN resources — creating and using its own carrier accounts and shipments, and every other legitimate workflow the service offers today. Your changes should restrict only access or effects a caller was never entitled to, never an org's legitimate use of its own resources.
Contracts the hardened service must satisfy
These are product requirements, not a description of any defect. Both directions matter: the verifier checks that each contract holds and that the corresponding legitimate case still works.
- Ownership denial. A request to read a record the caller does not own is denied with a 4xx status (403 or 404) — never served, and never answered with a success status wrapping an error.
- Validation timing. Except where a contract below explicitly requires a value to be accepted and preserved literally, an invalid or unauthorized value may be rejected with a 4xx status either when it enters the service or when it would be consumed. There is no requirement to retain unsafe references for deferred validation.
- Document names. A customs-document name that does not resolve to a file inside the customs directory is rejected with a 4xx status; a name that does resolve inside it is served normally.
- Placeholders stay literal. Rendering interpolates only the documented,
non-sensitive bare fields
{shipment},{org}, and{status}. Any other placeholder, including${{ rate.NAME }}, is preserved verbatim in the output as ordinary text — it is neither evaluated nor stripped or redacted away. - Configuration values stay literal. A value supplied in a configuration profile is stored and returned as the literal text that was supplied.
- Redirects. A tracking destination may answer with a redirect. The handoff must still complete when the destination it redirects to is itself an allowed destination.
- Shared cloning. A shipment template intentionally marked as shared remains cloneable by another org, and the resulting clone remains usable. Sharing the shipment definition must not transfer, expose, or authorize use of the source org's carrier credentials.
- Credential persistence. Carrier credentials must not be retained in the clear in operator-readable derived records or exports, including closed manifest snapshots, stored tender records, run logs, and reports.
- Shipping-advice header boundaries. Shipping advice is composed as a header-like message. Any caller-controlled value that reaches an advice header (for example shipment references or consignee addresses) must either be rejected or made single-line so CR/LF input cannot create an additional header.
- CSV export safety. Values exported in
report.csvmust not remain live spreadsheet formulas. Formula-leading cells (=,+,-, or@) may be rejected at ingestion or neutralized in the CSV output while preserving normal benign report exports. - Embargoed-carrier lane authority. Embargoed carrier credentials may be used only for an exact bonded-lane value. Prefix, suffix, newline, or multi-line lane strings must not satisfy the bonded-lane gate.
- Closed manifest immutability. Closing a shipment creates the authoritative manifest snapshot. Later edits to the shipment, including instruction changes, must not alter what submitting that closed manifest renders or sends.
- Partner handoff-token strength. Shared handoff links are bearer credentials for unauthenticated partner access. A party holding one valid share token must not be able to derive, enumerate, or predict another shipment's token.
- Request body bounds. JSON request bodies are capped at 65,536 bytes. The
service must reject invalid, negative, incomplete, or larger declared bodies
before processing them; for example, a declared 70,000-byte body must fail
closed with a 4xx status and must not mutate state. A stalled or incomplete
request body must not monopolize the service or block
/health.
Deliverables
After patching, write two files:
/app/output/findings.json— a JSON array; one entry per distinct weakness you fixed, each with:requirement_ids: a non-empty list of public requirement IDs addressed by this finding. Use only these IDs:SY-OWNER-REFERENCES,SY-RENDERING,SY-SEARCH,SY-RULE-EVAL,SY-HEADER-CSV,SY-SSRF,SY-CREDENTIAL-PERSISTENCE,SY-CUSTOMS-PATH,SY-INTERNAL-METRICS,SY-MANIFEST-LIFECYCLE,SY-SHARE-TOKEN, andSY-BODY-BOUNDS.vulnerability_type: a CWE identifier (formatCWE-###)severity:LOW,MEDIUM,HIGH, orCRITICALaffected_files: list of files under/testbedyou changed for itroot_cause: the underlying flaw in one or two sentencesdescription: the unsafe request-to-effect flow and its impact
/app/output/plan.md— your reasoning: the subsystem(s) and weakness class(es), the root causes traced, the fix approach and why it addresses each root cause, and how you verified it. Graded for reasoning quality independently of whether the patch passes every test.
Local testing
The container ships an agent-runnable public configuration so you can exercise the service under your own org while you work:
/etc/app.public.env— a public env file that points the state and customs directories at writable temp paths and seeds a single public org (acme) with a public carrier account. It contains no verifier-only or foreign-org secrets; theacmetoken and its own public test credential are intentionally available for local testing.- Your org token is the
ACME_TOKENvalue in/etc/app.public.env.
Start the service against the public config and probe it, for example:
APP_ENV_FILE=/etc/app.public.env python3 /testbed/main.py &
curl -s localhost:9097/health
curl -s -H "Authorization: Bearer <ACME_TOKEN>" localhost:9097/api/v1/carriers
The graded verifier runs the service against its own private configuration on its own port; your local runs never see another org's secrets.
Constraints
- Fix root causes at the trust boundary, not individual identifiers or request values. A fix that special-cases the exact orgs, carrier accounts, shipments, or payloads a checker might use will not survive variant inputs and is not acceptable — derive authority and validation from live server state.
- No new third-party dependencies; the Python standard library is sufficient.
- Do not disable, remove, or stub out any endpoint; do not replace responses with
canned data; do not change the state store's format or move its files. Modify
source only under
/testbed; the only permitted writes outside it are the two required deliverables under/app/output. - Closed-book: work from the source and observed local behavior, not external writeups or scanners.
-
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.
-
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.
-
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.
-
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.
-
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.