Skip to content

🐛 fix(url): judge strict language subdomain on canonical host - #2273

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/lang-filter-host
Nov 16, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/lang-filter-host

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

The strict language filter in clean_url() and extract_links() decided on the subdomain label of a host as the URL spelled it (clean() before the fix, strict label check). Two spellings of one host could get different decisions, and a decision could follow a label that a browser never opens, so the links a crawler keeps depended on how the host was written. 🔗 Now every spelling of a host gets the same decision, based on the host a browser opens. Fixes #2244.

The label came from the spelled host

The URL host parser percent-decodes the host, maps it to ASCII with UTS #46 and lowercases it before a browser opens it. The old code lowercased the spelled host and passed it to the strict check, which reads the label before the first dot. That label was taken before the decoding and mapping steps ran.

One canonical host decides and is emitted

canonical_host() runs the checked host parser that the output already used, and clean() computes it once per web URL. The language check and normalize_parts() both take that host, so the label that decides a URL and the host written to the output come from one computation. A host that does not canonicalize is not fetchable and is dropped, as before. The strict label check in url.c is unchanged and now receives the canonical host.

Behavior changes

  • With strict=True and a language, a link is judged on the subdomain label of its canonical host. A link whose spelled host had a different label can now be kept or dropped where it was not before.
  • Without strict, the language check reads no host label, so its result does not change.
  • URLs that do not use the language filter produce the same output. The host is still lowercased once, now as part of canonicalization.

The strict language filter took its subdomain label from the host as
spelled in the URL, before percent-decoding, IDNA mapping and
lowercasing. A browser resolves those spellings to another label, so
spellings of one host could get different decisions. The cleaner now
canonicalizes the host once and uses that host for both the language
check and the output, so every spelling gets the same decision.

Fixes tox-dev#2244
@gaborbernat gaborbernat added the bug Something isn't working label Nov 16, 2026
@gaborbernat
gaborbernat merged commit 27c6390 into tox-dev:main Nov 16, 2026
1 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strict language filter reads the subdomain label from the spelled host

1 participant