Skip to content

fix(lab-ops-hub): fetch userinfo URLs with Basic auth in the container crawler - #634

Merged
dezren39 merged 1 commit into
mainfrom
sweep/622-userinfo-fetch
Oct 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
sweep/622-userinfo-fetch

Conversation

@dezren39

@dezren39 dezren39 commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #622

Problem

_fetch_crawl handed validated URLs straight to urllib.request. urllib never strips userinfo: Request.host keeps user@host / user:pass@host whole, http.client is built with it as the hostname, and getaddrinfo fails — so every userinfo target both validators accept (plain http://user@example.com/, password-bearing, and the percent-encoded forms #616/#619 polished) 502'd in the container before any request was sent, while the Worker fallback fetched it and recorded the wrong source.

Reproduced on main 00bb59d5 with the app's own _fetch_crawl against a local server: control URL → 200; user@, user:pa%3Ass@, caf%C3%A9@, @, user:@ → all URLError: [Errno -2] Name or service not known, no request received.

Solution

  • New _split_userinfo(url) / _apply_userinfo_auth(req) in container/app.py: strip the userinfo from the URL handed to urllib and send its credentials the way WHATWG fetch does — an Authorization: Basic header built from the percent-decoded username/password (UTF-8). A URL only "includes credentials" when username or password is non-empty, so bare @ / :@ sends no header (which also makes user:@ fetch exactly as user@).
  • _fetch_crawl applies it to the start request.
  • _ValidatingRedirectHandler.redirect_request applies it to every followed request, re-deriving the header from the target's own userinfo: urllib copies the previous request's headers onto redirects, so without this a credentialed start URL's Authorization would leak to a plain redirect target, and a credentialed target would be fetched with the previous hop's credentials (or none). Per-hop SSRF re-validation is unchanged.

Tests

  • Python: 3 new tests — a 10-spelling fetcher battery end-to-end against a local recording server (plain, password, %3A password, non-ASCII credentials, empty-password, :pass, bare @, :@, no userinfo), a redirect integration test (userinfo target gets its own auth; credentialed start does not leak to a plain target), and a redirect-handler unit pin. 50/50 pass (was 47).
  • TS: 1 new pin that the Worker helper fetches userinfo start/redirect URLs in their validated form. 36/36 pass (was 35).
  • Ablation: with only app.py reverted, exactly the 3 new Python tests fail.
  • ruff format clean; biome format (treefmt's TS formatter) reports no fixes.
  • Local differential note: Bun's own fetch is not the reference here (it silently drops password-bearing userinfo with no Authorization header and fails username-only URLs); the implementation follows the WHATWG fetch rule the issue's acceptance criteria specify, which is what the Cloudflare Workers fallback implements.

Single-repo: no validate_crawl_url / _fetch_crawl copy exists in the opencode, openchamber or nix clones (grep-verified).


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

…r crawler (#622)

_fetch_crawl handed validated URLs straight to urllib, which keeps
'user@host' as the hostname: getaddrinfo failed before any request
was sent, so every userinfo target both validators accept 502'd in
the container while the Worker fallback fetched it.

Split the userinfo off before fetching and send its credentials the
way WHATWG fetch does: Authorization: Basic built from the
percent-decoded username/password (UTF-8). A userinfo with empty
username and password ('@', ':@') sends no header. The redirect
handler re-derives the header from each target's own userinfo, so a
credentialed target fetches with its credentials and a plain target
never inherits the previous hop's Authorization.

Tests: 3 new Python tests (10-spelling fetcher battery end-to-end
against a local server, redirect-to-userinfo integration, redirect
handler unit pin) + 1 TS pin that the Worker fetches userinfo URLs
in validated form. Python 50/50, TS 36/36; ablation with app.py
reverted fails exactly the 3 new Python tests.
@dezren39
dezren39 requested a review from a team as a code owner October 23, 2026 02:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T02:11:11.837386Z 22bdbe7 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 Oct 23, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ 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: 728914cf-4f33-45b2-afe9-dc6671d4716b
📥 Commits

Reviewing files that changed from the base of the PR and between 00bb59d and 22bdbe7.

📒 Files selected for processing: 3
  • pkgs/lab-ops-hub/container/app.py
  • pkgs/lab-ops-hub/test/lib.test.ts
  • pkgs/lab-ops-hub/test/test_container_validate.py
+---------------------+
| Git gud or git out. |
+---------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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.

@dezren39
dezren39 merged commit 5a84351 into main Oct 23, 2026
4 of 5 checks passed
@dezren39
dezren39 deleted the sweep/622-userinfo-fetch branch October 23, 2026 02:08

@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: 22bdbe74e9

ℹ️ 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 +848 to +849
if req.has_header("Authorization"):
req.remove_header("Authorization")

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 Preserve credentials across relative redirects

When a credentialed URL responds with a relative Location such as /landing, the initial _apply_userinfo_auth has already removed the userinfo from req.full_url, so urllib resolves the target without credentials; this second call then removes the copied Authorization header because _split_userinfo finds no @. The authenticated first hop therefore becomes an unauthenticated second hop, breaking common canonical/login redirects and diverging from the Worker path in src/lib.ts, where new URL(location, current) inherits the credentials from current. Retain the URL credentials as redirect metadata or preserve the header for relative same-origin redirects while still clearing it when an explicit target omits credentials.

Useful? React with 👍 / 👎.

Comment on lines +827 to +828
username = unquote(username)
password = unquote(password)

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 Preserve non-UTF-8 credential bytes

For accepted userinfo containing percent-encoded bytes that are not valid UTF-8, unquote silently replaces those bytes with U+FFFD before the value is re-encoded. For example, http://%FF@example.com/ is accepted, but this produces credentials b'\xef\xbf\xbd:' (Basic 77+9Og==) rather than the percent-decoded bytes b'\xff:' (Basic /zo=), so such targets receive the wrong password material and distinct credential spellings can collapse to the same header. Decode the userinfo with unquote_to_bytes and construct the Basic payload from the username and password byte sequences directly.

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