edge-gateway-hardening-defensive
Task
This is an authorized, isolated, offline benchmark. /testbed is an HTTP edge
gateway written in C. It sits in front of an
origin: it parses each client request, applies framing and policy, and re-emits
the request to the upstream, while serving some responses from a local cache.
The task's writable surfaces are /testbed and the required files under
/app/output/; the replay does not contact a real network origin.
Layout:
/testbed/thirdparty/— two vendored HTTP parser backends (ihtp,llhttp) and a helper parser (pico). The active backend is chosen at runtime by config./testbed/gw/— the gateway itself: configuration, the backend adapter, a buffer pool, header handling, framing, routing, access control, the response cache, per-connection session state, the request pipeline, and logging./testbed/build.sh— rebuild helper.SANITIZE=1enables AddressSanitizer and UBSan.
The gateway is exercised offline. It reads a config file and a replay
stream of one or more pipelined requests, and prints one MARK: line per
observed decision, the exact bytes it would forward upstream after an
UPSTREAM:<length> line and before --UP--, and REJECT: for anything it
refuses:
/testbed/bin/gw_edge --conf <config> --replay <request-stream>
Each invocation starts a fresh process with fresh configuration, cache, and
connection state. The replay stream is raw HTTP request bytes. Lines beginning with @ between
requests are control directives (for example a configuration reload).
For deterministic bounded replay, an input stream is limited to 8 MiB.
A security hardening pass over the whole request-handling path is required before this gateway is exposed to untrusted clients. Its behavior is configurable (backend, cache, access control, path normalization, body limits, logging), and several weaknesses only manifest under particular configurations or particular sequences of requests on one connection.
Diagnose the weaknesses from the source and from observed behavior. No list of defect classes, affected files, or offending inputs is provided, and a comment describing intent is not a guarantee of behavior. The weaknesses are not all of the same kind, and some are only observable when two parts of the system are considered together.
The properties to guarantee
Across every supported configuration and request sequence, the hardened gateway must hold all of the following. Restrict only what was never valid; do not remove features or refuse traffic wholesale to pass.
- Framing is unambiguous and consistent. Whatever the gateway accepts and the bytes it forwards upstream must agree on where each message begins and ends, regardless of which backend is configured. A request no backend should treat as well-formed must be refused, not forwarded.
- Configured limits and policy actually bind. Body-size limits, access-control decisions, and path-based rules must apply to the request as it is actually routed and forwarded — not to a stale or pre-transformation view of it — and must not be short-circuited by another feature.
- Tenants and requests stay isolated. A cached or buffered response must never be served to a request that was not entitled to it, and no response may carry bytes belonging to another request.
- Memory safety. For any config and any stream, the process must not perform an out-of-bounds read or write, use freed memory, or otherwise corrupt state.
Deliverables
After patching, write two files:
/app/output/findings.json— a JSON array; one entry per distinct weakness you fixed, each with:vulnerability_type: a CWE identifier (formatCWE-###)severity:LOW,MEDIUM,HIGH, orCRITICALaffected_files: list of changed files as paths relative to/testbed, with no leading/(for example,gw/<source-file>.c)root_cause: the underlying flaw in one or two sentencesdescription: the unsafe input-to-effect flow and its impactrequirement_ids: a JSON string, exactly one ofEG-FRAMING,EG-LIMITS,EG-ISOLATION, orEG-MEMORY(for example,"requirement_ids": "EG-FRAMING"). Provide at least one distinct finding for each ID. Every affected file must be a changed source file relative to the supplied baseline, and every changed C/H source file must be named by at least one finding.
/app/output/plan.md— a short free-form note summarizing your approach.
Your patched code is what is graded; these two files are required supporting artifacts.
Local testing
APP_DIR=/testbed SANITIZE=1 /testbed/build.sh
printf 'GET / HTTP/1.1\r\nHost: x\r\n\r\n' > /tmp/r.bin
printf 'backend=native\nacl=on\ncache=on\nnormalize_path=on\nmax_body=1048576\n' > /tmp/c.conf
/testbed/bin/gw_edge --conf /tmp/c.conf --replay /tmp/r.bin
Grading rebuilds /testbed from your .c/.h sources under the sanitizer and
scores observable behavior across many config/stream scenarios. Do not modify
/tests, /solution, or files outside /testbed, except for the two required
deliverables under /app/output.