Skip to content

fix(search): strip wildcard and leading dots before IDNA encoding in source_filter - #3300

Open
Sinfinal wants to merge 1 commit into
HKUDS:devfrom
Sinfinal:fix/search-wildcard-idn-domains
Open

Sinfinal wants to merge 1 commit into
HKUDS:devfrom
Sinfinal:fix/search-wildcard-idn-domains

Conversation

@Sinfinal

@Sinfinal Sinfinal commented Dec 6, 2026

Copy link
Copy Markdown

Problem

In deeptutor/services/search/source_filter.py, _domains() normalized wildcard entries with raw = raw[1:], stripping only * and leaving a leading . (e.g., *.münchen.de became .münchen.de).

Calling .encode("idna") on any string starting with . always raises UnicodeError: label empty or too long, causing _domains() to fall back to the raw Unicode string ("münchen.de") instead of Punycode ("xn--mnchen-3ya.de"). Because _rejection_reason() compares against the IDNA-encoded hostname (sub.xn--mnchen-3ya.de), wildcard and leading-dot IDN domain rules never matched:

  • blocked_domains=["*.münchen.de"] silently allowed https://sub.münchen.de/a and https://xn--mnchen-3ya.de/b through.
  • trusted_domains=["*.münchen.de"] rejected both URLs as untrusted_domain.

Fix

Strip *. (raw = raw[2:]) and any leading dots (raw = raw.lstrip(".")) before calling .encode("idna") in _domains().

Verification

  • Added test_source_filter_normalizes_wildcard_and_leading_dot_idn_domains in tests/services/search/test_web_search_runtime.py covering both *.münchen.de and .münchen.de in blocked_domains and trusted_domains against Unicode and Punycode URLs (failed before fix, passes after).
  • Ran python -m pytest -q tests/services/search/test_web_search_runtime.py: 32 passed, 0 failed.
  • Ran ruff check and ruff format --check on both modified files: all checks passed.

@github-actions github-actions Bot added backend Python runtime, capabilities, tools, API & CLI bug Something isn't working labels Dec 6, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Python runtime, capabilities, tools, API & CLI bug Something isn't working

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant