Skip to content

fix(lab-ops-hub): container validator refuses numeric-final-label hosts and malformed ports - #503

Merged
dezren39 merged 1 commit into
mainfrom
creator/502-container-validator-parity
Oct 21, 2026
Merged

dezren39 merged 1 commit into
mainfrom
creator/502-container-validator-parity

Conversation

@dezren39

@dezren39 dezren39 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Fixes #502

The container crawler's validate_crawl_url fell through to "a public DNS name" for hosts that parse as neither ipaddress nor inet_aton IPv4, and never inspected the port — so invalid IPv4 spellings (256.1.1.1, 1.2.3.4.5, 4294967296), numeric-final-label names (example.123, example.0x7f) and malformed/out-of-range ports (:abc, :99999, :80abc) were all allowed, while the Worker's WHATWG validator refuses every one (differential probe in #502).

Verification:

  • npm test in pkgs/lab-ops-hub: TS 18/18, Python 9/9 (2 new tests: numeric-final-label hosts, malformed ports; public-target controls extended with dead.beef, a1.beef, 123.example.com, :8080).
  • Ablation: with only app.py reverted, both new tests fail; restored, all pass.
  • Differential probe over ~600 inputs (special IPv4/IPv6 ranges, inet_aton spellings, ports, name forms): TS and Python verdicts now identical on every input.

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

…ts and malformed ports (#502)

validate_crawl_url fell through to 'a public DNS name' for hosts that
parse as neither ipaddress nor inet_aton IPv4 — including invalid IPv4
spellings (256.1.1.1, 4294967296) and names with a numeric final label
(example.123) — and never inspected the port, so :abc/:99999/:80abc
were allowed too. The Worker's WHATWG validator refuses every one.

Mirror it: refuse a host whose final label is numeric (decimal or 0x
hex) when it is not a valid IPv4 address (WHATWG ends-in-a-number),
and read urlparse's .port in the validator so malformed/out-of-range
ports raise there instead of lazily inside the fetcher. Port 0 and
non-numeric-final-label names (dead.beef, 123.example.com) stay
allowed, exactly as on the Worker side.

Differential probe over ~600 inputs now shows full TS/Python parity.
New tests ablation-verified: both fail with only app.py reverted.
@dezren39
dezren39 requested a review from a team as a code owner October 21, 2026 20:25
@coderabbitai

coderabbitai Bot commented Oct 21, 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 35 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
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 27a41946-0665-42fb-9866-fa0d9ae92159
📥 Commits

Reviewing files that changed from the base of the PR and between 1c692fd and 6ff8f35.

📒 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T20:30:41.585135Z 6ff8f35 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.

@dezren39
dezren39 merged commit eaf371c into main Oct 21, 2026
5 checks passed
@dezren39
dezren39 deleted the creator/502-container-validator-parity branch October 21, 2026 20:26

@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: 6ff8f35473

ℹ️ 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".

# refuse it instead of reclassifying it as a public DNS
# name, matching the Worker's validator (#502).
last_label = host.rsplit(".", 1)[-1]
if re.fullmatch(r"0[xX][0-9a-fA-F]+|[0-9]+", last_label):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat a bare hexadecimal prefix as a numeric label

When the container validates a direct request or redirect ending in 0x or 0X (for example, http://example.0x/), this regex requires at least one following hexadecimal digit and therefore accepts the URL as a DNS name. The Worker's WHATWG parser rejects the same URL because a bare hexadecimal prefix still triggers its ends-in-a-number handling, so the validators remain inconsistent and the container proceeds to a DNS fetch that the Worker refuses. Allow the hexadecimal digit portion to be empty or otherwise handle these two labels explicitly.

Useful? React with 👍 / 👎.

Comment on lines +38 to +41
try:
u.port
except ValueError:
raise ValueError("url has an invalid port") from None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle backslashes before validating the port

For a redirect target such as http://example.com:80\\/path, the Worker's WHATWG URL parser treats the backslash as a path separator and accepts it as http://example.com//path, but urlparse leaves the backslash in the port string, so reading u.port now rejects the target. Because redirects are passed through this validator before the container fetches them, an otherwise Worker-valid redirect unnecessarily abandons the container path and breaks the validator-parity goal; normalize special-scheme backslashes or parse with equivalent semantics before applying the port check.

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

Development

Successfully merging this pull request may close these issues.

lab-ops-hub: container crawler treats invalid IPv4 spellings, numeric-final-label hosts and malformed ports as public DNS names

1 participant