Skip to content

fix(lab-ops-hub): validate and bound the /crawl request-body read (#7036) - #8705

Merged
dezren39 merged 1 commit into
mainfrom
queue/11478-7036-crawl-body-read
Nov 11, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/11478-7036-crawl-body-read

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Closes #7036.

What

POST /crawl in pkgs/lab-ops-hub/container/app.py trusted Content-Length outright: int(header) fed straight into rfile.read(length) on a single-threaded HTTPServer. A negative length reads until EOF and an oversized one waits for a body that may never finish — either wedges every later request, and malformed values surfaced as the catch-all 502.

  • do_POST now validates the header before reading a single byte: missing, non-integer, negative, or over-cap values get a prompt 400 JSON error naming the problem. The cap is the named constant _CRAWL_REQUEST_MAX_BODY_BYTES = 65_536 (the payload is a small {"url": ...} object).
  • The body read is bounded by _read_request_body: exactly length bytes under one absolute deadline (_CRAWL_REQUEST_READ_TIMEOUT_SECONDS = 10, mirroring _fetch_crawl's deadline style), with the socket timeout restored afterwards. A stalled in-cap body gets a 408 attempt and, either way, the handler returns so the server answers the next request.
  • validate_crawl_url, _fetch_crawl, and the Worker's side are untouched.

Tests

New TestCrawlContentLength in pkgs/lab-ops-hub/test/test_container_validate.py runs the real Handler over a real socket (validator/fetcher stubbed at the module): negative, oversized, and non-numeric lengths and a missing header each get a prompt 400 with a following GET / still answering; a stalled in-cap body times out (408) and the server recovers; the well-formed control still returns 200.

Suite: 77 tests — the 6 new ones pass; the only failure is the pre-existing test_returns_idn_hosts_in_alabel_form error, reproduced identically on clean main with this environment's idna build (unrelated to this change).

Task 11478, lane any-d.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 14:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T14:30:12.725884Z ec9d1b6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dcb032b6-9de7-44e1-9206-c44e6eec6c4d
Commits

Reviewing files that changed from the base of the PR and between 071a1f2 and ec9d1b6.

Files selected for processing: 2

  • pkgs/lab-ops-hub/container/app.py
  • pkgs/lab-ops-hub/test/test_container_validate.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 merged commit 930283a into main Nov 11, 2026
1 of 13 checks passed
@dezren39
dezren39 deleted the queue/11478-7036-crawl-body-read branch November 11, 2026 14:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec9d1b6e31

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1492 to +1493
self.connection.settimeout(left)
chunk = self.rfile.read(min(remaining, _CRAWL_READ_CHUNK_BYTES))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use single-read chunks to enforce the absolute body deadline

If a client declares an in-cap body and keeps sending bytes less than 10 seconds apart, this call can block far beyond the intended deadline: self.rfile is a buffered reader whose read(n) repeatedly receives until all n bytes arrive, with the socket timeout applying separately to each underlying receive. Because the entire allowed body fits in one chunk, the loop cannot recheck the deadline while those bytes trickle in, leaving every subsequent request blocked on the single-threaded server for potentially days. Use read1() and recheck the absolute deadline between reads, as _fetch_crawl already does.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant