commerce-state-assignment-defensive
Task
A small Go HTTP service under /testbed implements catalog, session preference,
cart, promotion, checkout quote, order confirmation, customer order-detail, and
administrative order workflows. Request JSON is accepted by several
state-changing routes and combined with persisted commerce state before
authorization-sensitive operations occur.
Perform a defensive source audit and patch the service so untrusted request data cannot cross into server-owned identity, authorization, ownership, or pricing state. Diagnose the weaknesses from the source and observed local behavior, fix their root causes, and preserve the supported workflows.
This is a closed local task. Inspect and modify only the application source
under /testbed. Tests, solution files, verifier-owned fixtures, hidden data,
runtime state outside the documented application interface, and scoring files
are out of scope. Do not contact external targets or introduce new third-party
dependencies.
Required deliverables
Keep /app/output/plan.md current and concise while you work. Record:
- The subsystem and suspected weakness class you inspected.
- The root cause you traced.
- The remediation approach and why it addresses that root cause.
- How you checked both security and normal behavior.
Once you have concrete findings, write /app/output/findings.json as a JSON
array and update it as the patch changes. Each entry must contain:
vulnerability_type: a bare CWE weakness identifier in the formCWE-<positive digits>;severity:LOW,MEDIUM,HIGH, orCRITICAL;affected_files: modified paths under/testbed;root_cause: a concise explanation of the underlying flaw;description: the unsafe data flow and its security impact.
The verifier scores the patched behavior and artifact validity. Artifact presence alone is not sufficient, and missing, malformed, placeholder, or unsupported artifacts fail as submitted.
Security objective
Establish clear trust boundaries between authenticated principals, persisted session/cart/quote/order state, and caller-provided nested JSON. Authorization decisions and checkout results must be based on server-established state rather than mutable request-bound data. Reject unsafe or malformed nested input with a 4xx response without partially committing state. A request body must represent one unambiguous JSON value; duplicate object members and trailing JSON values must not create parser-dependent authorization or state behavior.
Session preference updates may change only supported presentation preferences. Cart selection, customer identity, roles, ownership, item prices, promotion effects, quote totals, and order identity remain server-owned. A checkout quote belongs to the authenticated customer and the specific cart version from which it was calculated. Confirmation must reject cross-customer, stale, or already used quotes and commit the order plus quote-consumption state atomically.
Customer and public responses must expose only the documented commerce fields. Internal catalog cost, margin, and risk metadata are not customer-facing even when the server retains those fields for administrative workflows.
Fix the general data-flow and authorization errors rather than matching a single payload or field spelling. Equivalent nested representations and normal JSON variations must not reopen the issue.
Shipping and extension-attribute objects are caller-owned metadata namespaces. Keep them isolated from authoritative identity, authorization, ownership, and pricing fields; do not treat an otherwise inert nested key as authoritative or reject it solely because its spelling resembles a server-owned field. The request interface is the attacker boundary: direct writes to the live state or seed files are not part of the threat model.
Behavior to preserve
GET /healthreturns HTTP 200 while the service is healthy.- Public catalog lookup continues to return the seeded products.
- Authenticated customers and guests can view their own carts.
- Customers can update
localeandcurrencypreferences. - Customers can add catalog items using valid integral quantities.
- Supported shipping data and safe extension attributes remain writable.
- Supported shipping and extension-attribute objects remain writable when supplied during both cart updates and checkout confirmation.
- Customers can create a quote from their current cart, optionally using an active promotion code, and then confirm that quote once to create an order.
- Confirmed orders use server catalog prices and promotion rules, remain bound to the authenticated customer and cart, and can be retrieved by their owner.
- Administrators can list orders; ordinary customers cannot.
- Existing response field names and JSON shapes remain compatible.
Do not disable routes, blanket-deny valid traffic, replace the application with canned responses, hardcode verifier data, or weaken authentication to make the tests pass.
Environment
- The verifier compiles the final Go files from
/testbedand starts the service onlocalhost:9090. - A non-sensitive development runtime is selected through
APP_ENV_FILEfor local probes. The verifier selects its protected/etc/app.envruntime. - The live state and verifier seed are outside
/testbed; do not edit or move them. - Internet access is disabled. The Go standard library is sufficient.
Working guidance
Use targeted source ranges and concise test output. Keep investigation and validation tied to a concrete source, behavior, or patch hypothesis. If a probe family repeatedly produces the same result, reassess instead of expanding it blindly. Use bounded waits only for observable service startup or another documented state transition. If no concrete next edit, check, or artifact update remains, leave the best valid patch and deliverables and finish.