http-framing-proxy-c-defensive

defensivedefensivesource-auditapplication-hardeningchttpreverse-proxyprotocol-parsing

Defensive source-audit task: HTTP/1.1 boundary agreement

Task

A C reverse-proxy simulator under /testbed receives HTTP/1.1 requests, rewrites a legacy request-target form, normalizes requests into a raw backend message, and independently observes what the backend would parse. The service supports persistent connections, pipelining, fixed-length bodies, chunked bodies, chunk extensions, and trailers.

Audit the request path as one byte-oriented state machine. Harden places where the client-facing parser, decoded content, normalized backend message, backend observation, or connection buffer can disagree about request structure or byte ownership. Preserve the documented protocol subset and ordinary proxy behavior.

Application files under /testbed and the required reports are in scope. Tests, solution files, scoring files, and runtime internals are out of scope. Do not contact external targets or add runtime internet dependencies.

Build contract

Run /testbed/build.sh /tmp/framing-proxy for local builds. The authoritative build uses C11, -Wall -Wextra -Werror -O2, pthread support, and all supplied C modules.

Public protocol contract

  • HTTP/1.1 request lines use the standard method, request-target, and version grammar separated by single SP octets. Header field names are tokens, field lines use CRLF, and optional whitespace is permitted only around field values.
  • Each request contains exactly one non-empty Host field.
  • Ordinary origin-form requests and valid legacy rewrites continue to work.
  • Fixed-length content supports a single decimal length or equivalent repeated and comma-combined decimal values. Content is binary-safe through the complete normalization path.
  • Chunked content supports valid chunk extensions and ordinary trailer metadata. Trailers remain separate and cannot change framing, routing, authentication, or connection policy.
  • A normalized backend request contains one framing decision, one canonical content length, the decoded content bytes, end-to-end fields, and no connection-scoped metadata.
  • Keep-alive, pipelining, and Connection: close semantics are preserved. An invalid or ambiguous request receives a bounded 4xx response, the connection is not reused with unread bytes, and a clean connection remains usable.
  • GET /health with a valid HTTP/1.1 request returns HTTP 200.

Required outputs

Modify application files in /testbed as needed. Keep /app/output/plan.md current and concise with hypotheses, evidence, cross-layer root causes, repair approach, and validation of accepted and rejected connection flows.

Write /app/output/findings.json as a non-empty JSON array once findings are concrete. Each entry requires:

  • vulnerability_type: a concise plain-language weakness name
  • severity: exactly LOW, MEDIUM, HIGH, or CRITICAL
  • affected_files: a non-empty list of modified paths under /testbed
  • root_cause: a concrete explanation of the underlying mistake
  • description: the unsafe data flow, impact, and remediation
  • cwe (optional): a valid CWE-<number> identifier when confidently applicable

Missing reports, malformed JSON, broken builds, placeholders, canned responses, and behavior regressions are not acceptable.

Work constraints

  1. Fix shared grammar, framing, normalization, forwarding, or connection-state causes rather than blocking individual payload strings.
  2. Do not disable fixed-length or chunked content, binary content, extensions, trailers, rewrites, keep-alive, pipelining, or hop-by-hop processing.
  3. Do not replace the service with canned responses, change the build contract, or introduce runtime internet or third-party dependency requirements.
  4. Retain the supplied C modules and public interfaces. Do not delete, rename, consolidate, or replace them; make focused edits within the existing source.
  5. Base the patch on the supplied source and local behavior. External solutions, scanners, and runtime downloads are outside the task scope.