Skip to content

fix(security): host classifier raises OverflowError on a punycode label #7333

Done

Description

@dan-petty

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

  1. Run uv run python -c "('1' * 20 + 'a').encode().decode('punycode')". The result is OverflowError: Python int too large to convert to C ssize_t.
  2. 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.
  3. Run the second command with '1' * 12 in 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 OverflowError for 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_search raises no error other than SearchQueryRefused for a query that holds the word xn--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 False and raises no error; the test fails on the base with OverflowError.

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 False and 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.DOMAIN and 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 OverflowError from tldextract?: In one suffix helper in src/devops_cli/security/reference_extractor.py. Both is_example_or_invalid_domain and is_local_or_reserved_domain call it. web_search stays unchanged. (best practice) [sources: src/devops_cli/security/reference_extractor.py, src/devops_cli/ai/web_search.py]
    • Rejected: Catch in _guard of web_search. It leaves the same error in classify_network_target and 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.
  • Which exception should the suffix helper catch?: Catch OverflowError only. 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 OverflowError only. It is the error that the failing label raises, and the catch stays narrow.
    • Rejected: Catch OverflowError and UnicodeError. 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.
  • What should the suffix helper return when the codec cannot decode a label?: An empty suffix. is_example_or_invalid_domain and is_local_or_reserved_domain then return False. classify_network_target returns NetworkTargetClass.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_search failure that the issue fixes.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    on Nov 26, 2026
  2. dan-petty commented on Nov 26, 2026

    @dan-petty
    OwnerAuthor
  3. added
    scope/security
    source/agent
    status/new
    value/medium
    effort/low
    priority/p2-medium
    on Nov 26, 2026
  4. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    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:

    • tldextract OverflowError punycode decode label, results: 5
    • idna.decode OverflowError Python int too large to convert to C ssize_t punycode, results: 5
    • tldextract github punycode xn-- invalid label exception, results: 5
    • python idna package github punycode overflow label decode error, results: 5
    • idna python package pypi, results: 5
    • tldextract, results: 5
    • tldextract changelog 5.4.1 OverflowError, results: 5
    • python public suffix list library publicsuffixlist punycode, results: 5
    • PublicSuffixList python package publicsuffixlist github, results: 5
    • tldextract _decode_punycode idna.decode UnicodeError source, results: 5

    Sources:

  5. added
    status/ready
    and removed
    status/new
    on Nov 28, 2026
  6. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  9. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 03:13 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/securitysource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions