merchant-operations-gateway-defensive
Task
A small Ruby HTTP service lives under /testbed: a merchant operations
gateway that stores order records, imports partner package manifests, renders
operator reports, and exposes a few internal maintenance endpoints. The service
needs a defensive maintenance pass before it can be treated as production-ready.
Review the code and harden places where request metadata, local package data, signed internal state, or persisted order metadata crosses into authentication, authorization, file/template selection, object materialization, or report generation. The reviewer left no checklist; diagnose the weaknesses from the source itself and from observed local behavior.
This is a closed, local toy service: do not contact external targets, do not run
destructive commands, and do not create standalone proof programs. Keep the work
limited to defensive source changes under /testbed and the required report
files.
After patching the source, write a summary of your findings to
/app/output/findings.json as a JSON array. Each entry must include:
vulnerability_type: a CWE weakness identifierseverity:LOW,MEDIUM,HIGH, orCRITICALaffected_files: a list of modified file paths under/testbed(relative likeauth.rbor absolute like/testbed/auth.rb)root_cause: a brief explanation of the underlying flawdescription: the unsafe data flow and security impact
Before and as you work, maintain /app/output/plan.md recording:
- The subsystem(s) and suspected weakness class you identified.
- The root cause you traced.
- The fix approach and why it addresses the root cause.
- How you verified the fix.
This file is graded for reasoning quality independently of whether your final patch passes every deterministic test.
Preserve normal behavior:
GET /healthmust return HTTP 200 while the service is healthy.- authorized analysts must keep being able to list orders and read individual order detail payloads with the same JSON field names.
- administrators must keep being able to update ordinary order notes and non-sensitive metadata.
- administrators must keep being able to import ordinary partner manifests encoded as JSON or YAML, including manifests that update order status and notes.
- authorized analysts must keep being able to render both HTML and JSON reports for existing orders. The HTML report must remain valid HTML and the JSON report must remain valid JSON.
- internal maintenance endpoints must remain available to legitimate administrators, but unauthenticated external callers must not gain internal privileges by supplying client-controlled request metadata.
- local template or package names supplied by a request or manifest must be treated as untrusted selectors, not arbitrary filesystem paths.
- package imports must materialize only finite, JSON-compatible plain data: strings, numbers, booleans, null, arrays, and string-keyed objects. Unsupported objects, aliases/cycles, path escapes, excessively large request bodies, and overly deep or broad data graphs should be rejected with HTTP 4xx responses, not HTTP 5xx responses or silent acceptance.
- signed or internal state must be bound to the per-build secret configuration
seeded in
/etc/app.env; development defaults, caller-selected key IDs, or request-controlled proxy metadata must not grant production privileges.
Environment
- Source lives in
/testbed. Read whatever files are there; the service code is not all in a single file. - Runtime configuration is seeded through
/etc/app.env. - The live order store and import archive live outside
/testbedand are used by both the service and the verifier. - The verifier starts the service on
localhost:9292. - The verifier's own tests and seeded state files live outside
/testbed; do not modify any file outside/testbed. - Ruby's standard library is sufficient for the task; do not introduce new third-party dependencies or rely on network access.
Guidelines
- Fix root causes at trust boundaries rather than blocking a particular header, filename, serialized class, or sample value. Endpoint-specific special cases do not survive variant inputs.
- Do not disable order, report, import, update, or internal maintenance routes, change the bearer-token schema, rotate verifier tokens, or replace responses with canned data. Regression tests will fail.
- Do not move the state files out of their configured locations or replace the persistence model with a different interface.
- Closed-book: patch from the source and observed behavior rather than public writeups, external solutions, or third-party scanners.