Skip to content

fix: Reject non-http(s) URL schemes in HTTP clients#1862

Open
vdusek wants to merge 1 commit intomasterfrom
fix/http-client-url-scheme-validation
Open

fix: Reject non-http(s) URL schemes in HTTP clients#1862
vdusek wants to merge 1 commit intomasterfrom
fix/http-client-url-scheme-validation

Conversation

@vdusek
Copy link
Copy Markdown
Collaborator

@vdusek vdusek commented Apr 28, 2026

Summary

Closes a gap where URLs from untrusted sources (sitemap entries, robots.txt Sitemap: directives, raw strings passed to BasicCrawlingContext.send_request()) reached the HTTP-client backends without scheme validation, letting gopher://, file://, dict://, ftp:// etc. through to libcurl / httpx / impit.

What changed

  • Call validate_http_url(url) at the top of send_request and stream in ImpitHttpClient, HttpxHttpClient, CurlImpersonateHttpClient, and PlaywrightHttpClient. Non-http(s) schemes now raise pydantic.ValidationError before any request is issued.
  • crawl() was already covered, since Request.url is validated by Pydantic on construction.

Tests

  • tests/unit/_utils/test_urls.py — parametrized coverage of other schemes (gopher://, file://, dict://, ftp://, javascript:, no-scheme) against validate_http_url.
  • tests/unit/http_clients/test_http_clients.py — one smoke test per (client × method) verifying each HTTP client wires up the validation, using the canonical PoC URL gopher://127.0.0.1:6379/_PING.

URLs from untrusted sources (sitemap entries, robots.txt `Sitemap:` directives,
scraped HTML passed to `context.send_request()`) reached the HTTP-client backends
as raw strings, letting schemes like `gopher://`, `file://`, `dict://` or `ftp://`
through to libcurl/httpx/impit. Validate the scheme at `send_request` and `stream`
entry points so non-http(s) URLs are rejected before any request is issued.
@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels Apr 28, 2026
@vdusek vdusek self-assigned this Apr 28, 2026
@github-actions github-actions Bot added this to the 139th sprint - Tooling team milestone Apr 28, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Apr 28, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.47%. Comparing base (dc1073a) to head (a7e3702).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1862      +/-   ##
==========================================
+ Coverage   92.43%   92.47%   +0.04%     
==========================================
  Files         158      158              
  Lines       11009    11020      +11     
==========================================
+ Hits        10176    10191      +15     
+ Misses        833      829       -4     
Flag Coverage Δ
unit 92.47% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek requested a review from janbuchar April 28, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants