Skip to content

lab-ops-hub(container): POST /crawl trusts Content-Length — a negative or oversized length wedges the single-threaded crawler in an unbounded body read #7036

Closed

Description

@developing-today

Summary

The lab-ops-hub container crawler (pkgs/lab-ops-hub/container/app.py) reads its
POST /crawl request body with no validation of Content-Length and no read
bound, on a single-threaded server. A negative or oversized declared length
wedges the whole crawler service in rfile.read() until the client socket
closes — every other crawl (and the health GET /) starves behind it.

Evidence (verified this run, laptop @08dd577848)

pkgs/lab-ops-hub/container/app.py, Handler.do_POST (:1473-1478):

length = int(self.headers.get("content-length", "0"))
url = json.loads(self.rfile.read(length))["url"]

served by the single-threaded server at :1507-1508:

HTTPServer(("0.0.0.0", 8080), Handler).serve_forever()
  • Content-Length: -1 → rfile.read(-1) reads until EOF: as long as the
    client holds the socket open, the handler never returns.
  • Content-Length: 10000000 with a small body actually sent → read() blocks
    awaiting bytes that never arrive.
  • There is no cap and no socket deadline on this read. The response side of
    the same file is carefully bounded by contrast: _fetch_crawl caps the
    fetched body at _CRAWL_MAX_BODY_BYTES = 2_000_000 (:1358) under one
    absolute 20 s deadline (_CRAWL_TIMEOUT_SECONDS, :1357, :1362-1367),
    explicitly so "a peer that keeps dribbling bytes cannot renew the budget".
    The request side has neither protection.
  • Secondary: a non-numeric Content-Length raises ValueError out of
    int(...) and is answered by the catch-all as 502 (a container
    failure), not 400 — and per the lab-ops-hub: POST /api/crawl shape-trusts the container crawler response — JSON null 500s after the R2 archive write, a JSON string silently stores an all-null crawls row, wrong-typed fields bind as-is #7018 contract a 502 is what makes the
    Worker treat the crawl as a container failure and fall back, so a client
    error is indistinguishable from a dead crawler.

Reproduction (probe, real module, validation/fetch stubbed — the read loop is what is under test)

Probe: ~/git/fleet/probe-labops-bodyread/probe.py on the laptop (real
app.py Handler over a real socket; validate_crawl_url/_fetch_crawl
stubbed, idna stubbed as the sandbox python lacks it):

  • Control POST /crawl with a well-formed length → 200; control GET / → 200.
  • POST /crawl with Content-Length: -1, partial body, socket held open →
    no response within 3 s; a concurrent GET / on a new connection also gets
    no response within 3 s (the single-threaded server is wedged); after the
    client socket closes (EOF), GET / answers 200 again.
  • POST /crawl with Content-Length: 10000000 and a partial body, socket
    held open → same wedge and same starvation of the concurrent GET /.

Why it matters

The container is a separate service with its own release cadence (the premise
of #7018); the hub Worker is its only caller today and sends well-formed
lengths, but any client bug, proxy quirk, or future caller that stalls a body
mid-request takes the crawler out for every subsequent crawl until the
connection dies — there is no server-side deadline that releases it, and the
container's sleepAfter idle shutdown never engages while a handler is stuck
in a read. It is the one unbounded input left in a file that otherwise bounds
every byte and second it spends.

Acceptance criteria

  • do_POST validates Content-Length before reading: a missing,
    non-integer, negative, or over-cap value is rejected with a 400 JSON
    error without reading the body (the cap should be sized for the actual
    payload — a {"url": ...} JSON object — and named as a constant, in
    the style of _CRAWL_MAX_BODY_BYTES).
  • The body read itself is bounded: the handler cannot block indefinitely
    on a client that declares an in-cap length but never finishes sending
    (e.g. a socket/read deadline consistent with the crawl deadline
    machinery), and the server answers other requests afterwards.
  • Malformed-length requests are answered 400, not the catch-all 502, so
    client errors stay distinguishable from container failures.
  • Regression coverage in the container test suite
    (pkgs/lab-ops-hub/test/test_container_validate.py or a sibling):
    negative length, oversized declared length with a partial body, and
    non-numeric length each get a prompt 400 and the server still answers
    a following GET /; the well-formed control still returns 200.
  • Existing container + worker suites still pass.

Related: #7018 (the Worker-side shape validation of this container's
responses), #6975 (the hub's POST bind validation). This issue covers the
container's request side, which neither touched.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/lab-ops-hubPackage/app: lab-ops-hub (pkgs/ or apps/ in this repo)
    on Nov 8, 2026
  2. developing-today commented on Nov 8, 2026

    @developing-today
    ContributorAuthor

    🤖 Agent note · filed

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 10, 2026
  4. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    agent-note:v1
    task: 11478
    lane: code-j
    stage: handed_off
    Execution lane is opencode (lane row 3671). Handed off to the opencode claimant; lane code-j parks task 11478 for the claimant. Issue #7036 revalidated OPEN with no hard-stop labels 2026-11-10T00:48Z.

  5. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    🤖 Agent note · handed off

  6. 3 remaining items

  7. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    🤖 Agent note · handed off

  8. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    Lane code-o picked up task 11478 (issue #7036) — handed off to opencode claimant.

  9. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    🤖 Agent note · handed off

  10. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    🤖 Agent note · done (bookkeeping, §1c)

  11. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    🤖 Agent note · handed off

  12. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    🤖 Agent note · handed off (task 11478, lane code-u)

  13. added
    priority/lowNice to have; do when convenient
    and removed
    priority/normalOrdinary priority (the default)
    on Nov 11, 2026
  14. added a commit that references this issue on Nov 11, 2026
  15. dezren39 commented on Nov 11, 2026

    @dezren39
    Member

    Agent note — task 11478 done (fixed_merged)

  16. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/lab-ops-hubPackage/app: lab-ops-hub (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions