Repository navigation
Description
Problem Description
is_local_or_reserved_domain (src/devops_cli/security/reference_extractor.py) reads the public suffix of a name with tldextract. tldextract decodes each label that starts with xn-- through idna.decode, which uses the punycode codec of the standard library. For a label with many digits, such as xn--11111111111111111111a, the codec of CPython 3.14.10 raises OverflowError and not UnicodeDecodeError. tldextract does not catch that error, so the classifier raises OverflowError. Its callers catch no such error: classify_network_target, the reference extractor and the check of a web search query (_guard in src/devops_cli/ai/web_search.py). So web_search raises OverflowError for a query that holds such a word, and sends no request.
Reproduction Steps
- Run
uv run python -c "('1' * 20 + 'a').encode().decode('punycode')". The result isOverflowError: Python int too large to convert to C ssize_t. - Run
uv run python -c "from devops_cli.security.reference_extractor import is_local_or_reserved_domain as f; f('xn--' + '1' * 20 + 'a')". The result is the same error. - Run the second command with
'1' * 12in place of'1' * 20. The result is no error, and the function returns False.
Expected vs Actual Behavior
- Expected: the classifier returns False for a name with a label that is no punycode, whatever the length of the label.
- Actual: the classifier raises
OverflowErrorfor a label of 20 digits and a letter.
Proposed Fix
Find where the error belongs: the codec of CPython, _decode_punycode of tldextract, or the one call of the extractor in the classifier. Report it upstream where it belongs. Until a release holds the fix, the classifier reads a name whose label the codec cannot decode as a name with no public suffix. A test gives the label.
Acceptance Criteria
- Test first:
is_local_or_reserved_domain("xn--" + "1" * 20 + "a")returns False. The test fails on the base. - A test:
web_searchraises no error other thanSearchQueryRefusedfor a query that holds the wordxn--11111111111111111111a.
Environment Diagnostics
devops-cli 0.223.0, Python 3.14.10, tldextract 5.4.0, idna 3.20.
Dependencies
None.
Source
Source: #7332
Alternatives check of 2026-11-26: none.
Tool: none found.
Reason: Searches found only tldextract and idna, the libraries in the failing path; their latest releases still let OverflowError escape the punycode codec, and tldextract's docs say it does not validate labels. No tool removes the need for a local guard.
Lacks:
- No PSL library catches OverflowError from the punycode codec
- tldextract does not validate or canonicalize labels
- idna decode path still lets the arithmetic error escape
- web_search guard needs its own refusal handling
Proposed design
Problem statement
A punycode label with many digits makes the punycode codec raise OverflowError on CPython 3.14.10. tldextract does not catch it. The domain classifiers and the web search guard do not catch it either. web_search fails before it sends a request. The fix reads a name whose label the codec cannot decode as a name with no public suffix.
Acceptance criteria
Requirement: Long punycode label
is_local_or_reserved_domain SHALL return False for a host whose punycode label the codec cannot decode.
Scenario: Long punycode label
- WHEN the test calls
is_local_or_reserved_domain("xn--" + "1" * 20 + "a") - THEN the function returns
Falseand raises no error; the test fails on the base withOverflowError.
Requirement: Example domain classifier
is_example_or_invalid_domain SHALL return False for a host whose punycode label the codec cannot decode.
Scenario: Long punycode example
- WHEN the test calls
is_example_or_invalid_domain("xn--" + "1" * 20 + "a") - THEN the function returns
Falseand raises no error.
Requirement: Network target classifier
classify_network_target SHALL return NetworkTargetClass.DOMAIN for a host whose punycode label the codec cannot decode.
Scenario: Long punycode target
- WHEN the test calls
classify_network_target("xn--" + "1" * 20 + "a") - THEN the function returns
NetworkTargetClass.DOMAINand raises no error.
Requirement: Web search guard
web_search SHALL raise no error other than SearchQueryRefused for a query that holds xn--11111111111111111111a.
Scenario: Query with long punycode word
- WHEN the test calls
web_search("xn--11111111111111111111a")with a fake provider that returns one hit - THEN the call returns that hit and raises no
OverflowError.
Requirement: Pending a person after the merge
After the merge, a person SHALL report the OverflowError to the upstream project that owns the failing punycode decode.
Scenario: Upstream report
- WHEN the pull request merges
- THEN a person files the report and links it on the issue.
Existing Tool Considered
The alternatives check in the issue body gives the verdict none; it names no tool to adopt. The change builds a local guard in src/devops_cli/security/reference_extractor.py. Cost: about 3,000 tokens to write the helper and the tests, about 500 tokens for each later fix, and about 2 hours of elapsed time.
Key questions
- Where should the code catch the
OverflowErrorfrom tldextract?: In one suffix helper insrc/devops_cli/security/reference_extractor.py. Bothis_example_or_invalid_domainandis_local_or_reserved_domaincall it.web_searchstays unchanged. (best practice) [sources: src/devops_cli/security/reference_extractor.py, src/devops_cli/ai/web_search.py]- Rejected: Catch in
_guardofweb_search. It leaves the same error inclassify_network_targetand in the reference extractor. - Rejected: Catch in each caller. It duplicates the guard and misses a new caller.
- Chosen: Catch in one suffix helper. Both domain classifiers use the helper, so each caller gets the fix.
- Rejected: Catch in
- Which exception should the suffix helper catch?: Catch
OverflowErroronly. The issue shows that CPython 3.14.10 raises this error for the long label. tldextract already handles a decode error. (best practice) [sources: src/devops_cli/security/reference_extractor.py]- Chosen: Catch
OverflowErroronly. It is the error that the failing label raises, and the catch stays narrow. - Rejected: Catch
OverflowErrorandUnicodeError. tldextract already handles decode errors, and the wider catch can hide another fault. - Rejected: Catch
Exception. It hides defects and breaks the rule against swallowed errors.
- Chosen: Catch
- What should the suffix helper return when the codec cannot decode a label?: An empty suffix.
is_example_or_invalid_domainandis_local_or_reserved_domainthen returnFalse.classify_network_targetreturnsNetworkTargetClass.DOMAIN. (best practice) [sources: src/devops_cli/security/reference_extractor.py]- Chosen: Return an empty suffix. It matches the expected behavior: the name has no public suffix.
- Rejected: Treat the name as local. It would refuse a public search query and change the classifier's meaning.
- Rejected: Re-raise the error. It keeps the
web_searchfailure that the issue fixes.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 26, 2026
Both work on is_local_or_reserved_domain, but 887 redesigned the classification to use tldextract while the candidate fixes a crash in that code's error handling.devops-cli-service commentedon Nov 26, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (10)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 28, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Nov 29, 2026
Released in v0.242.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.242.0
devops-cli-service commentedon Nov 29, 2026
Live since 2026-11-29 03:13 UTC