Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def validate_crawl_url(raw):
if u.scheme not in ("http", "https"):
raise ValueError("only http: and https: URLs may be crawled")
host = (u.hostname or "").lower()
# A single trailing dot is the DNS root dot (the FQDN spelling of the
# same host: "localhost." is "localhost", "127.0.0.1." is 127.0.0.1);
# strip it before the checks so the dotted spelling cannot evade
# them, matching the Worker's validateCrawlUrl (#466).
if host.endswith("."):
host = host[:-1]
if not host:
raise ValueError("url has no host")
if host == "localhost" or host.endswith(_BLOCKED_SUFFIXES):
Expand Down
6 changes: 5 additions & 1 deletion pkgs/lab-ops-hub/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ export function validateCrawlUrl(raw: string): { ok: true; url: string } | { ok:
}
// WHATWG URL normalises integer/hex IPv4 forms (e.g. 2130706433,
// 0x7f.1) to dotted-quad, and keeps IPv6 literals bracketed.
const host = u.hostname.toLowerCase();
// A single trailing dot is the DNS root dot (the FQDN spelling of the
// same host: "localhost." is "localhost"); strip it before the checks
// so the dotted spelling cannot evade them (#466).
const rawHost = u.hostname.toLowerCase();
const host = rawHost.endsWith(".") ? rawHost.slice(0, -1) : rawHost;
if (!host) return { ok: false, error: "url has no host" };
if (host === "localhost" || BLOCKED_HOST_SUFFIXES.some((s) => host.endsWith(s))) {
return { ok: false, error: `refusing to crawl local host ${host}` };
Expand Down
10 changes: 10 additions & 0 deletions pkgs/lab-ops-hub/test/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ test("validateCrawlUrl refuses loopback / private / link-local targets (#441)",
}
});

test("validateCrawlUrl refuses trailing-dot spellings of blocked hosts (#466)", () => {
const blocked = ["http://localhost./", "http://foo.localhost./", "http://printer.local./", "http://nas.internal./"];
for (const u of blocked) {
assert.equal(validateCrawlUrl(u).ok, false, u);
}
// A public name keeps its fully-qualified spelling.
assert.equal(validateCrawlUrl("http://example.com./").ok, true);
});

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
function stubFetcher(routes: Record<string, { status: number; location?: string }>) {
const seen: string[] = [];
const fetchFn = async (url: string): Promise<Response> => {
Expand Down Expand Up @@ -73,6 +82,7 @@ test("fetchFollowingValidatedRedirects refuses redirects to non-public targets (
"http://192.168.1.1/",
"https://[::1]/",
"http://localhost:8787/",
"http://localhost./",
"file:///etc/passwd",
]) {
const { fetchFn, seen } = stubFetcher({
Expand Down
Loading