{"id":"94c78f58c78e2ec6","repo":"pypa/pip","slug":"label-too-long","errorCode":null,"errorMessage":"Label too long","messagePattern":"Label too long","errorType":"validation","errorClass":"IDNAError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/idna/core.py","lineNumber":116,"sourceCode":"\ndef check_bidi(label: str, check_ltr: bool = False) -> bool:\n    \"\"\"Validate the Bidi Rule from :rfc:`5893` for a single label.\n\n    The Bidi Rule constrains how bidirectional characters (Hebrew, Arabic,\n    etc.) may appear within a label. By default the check is only applied\n    when the label contains at least one right-to-left character (Unicode\n    bidirectional categories ``R``, ``AL``, or ``AN``); set ``check_ltr``\n    to ``True`` to apply it to LTR-only labels as well.\n\n    :param label: The label to validate, as a Unicode string.\n    :param check_ltr: If ``True``, apply the rules even when the label\n        contains no RTL characters.\n    :returns: ``True`` if the label satisfies the Bidi Rule.\n    :raises IDNABidiError: If any of Bidi Rule conditions 1-6 are violated,\n        or if the directional category of a codepoint cannot be determined.\n    \"\"\"\n    if len(label) > _max_input_length:\n        raise IDNAError(\"Label too long\")\n    # Bidi rules should only be applied if string contains RTL characters\n    bidi_label = False\n    for idx, cp in enumerate(label, 1):\n        direction = unicodedata.bidirectional(cp)\n        if direction == \"\":\n            # String likely comes from a newer version of Unicode\n            raise IDNABidiError(f\"Unknown directionality in label {label!r} at position {idx}\")\n        if direction in _bidi_rtl_categories:\n            bidi_label = True\n    if not bidi_label and not check_ltr:\n        return True\n\n    # Bidi rule 1\n    direction = unicodedata.bidirectional(label[0])\n    if direction in _bidi_rtl_first:\n        rtl = True\n    elif direction == \"L\":\n        rtl = False","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/idna/core.py#L98-L134","documentation":"Raised by idna.check_bidi when the input label handed to the Bidi Rule check exceeds _max_input_length (1024 characters). It is a defensive guard placed at the top of check_bidi to reject pathologically long inputs before any per-codepoint work, distinct from the DNS 63-octet label limit enforced elsewhere.","triggerScenarios":"Calling idna.encode/decode/check_bidi/alabel/ulabel with a single label longer than 1024 chars; passing an unsplit full domain string (with no dot separators) into a code path that ends in check_bidi.","commonSituations":"User input or scraped data containing a huge unbroken token being treated as a hostname; a bug in a URL parser that fails to split labels before IDNA encoding; fuzzing / property-based tests feeding arbitrary long strings.","solutions":["Validate the input length before calling idna: reject or truncate labels longer than 63 characters (the real DNS limit) rather than 1024.","Split the domain into labels on '.' (and the Unicode dot equivalents) and encode each label separately.","Sanitize upstream so hostnames come from a bounded, trusted source."],"exampleFix":"# before\nidna.encode(user_supplied_long_string)  # Label too long\n\n# after\nif len(label) > 63:\n    raise ValueError('label exceeds DNS 63-octet limit')\nidna.encode(label)","handlingStrategy":"validation","validationCode":"MAX_LABEL = 63\ndef validate_label(label: str) -> str:\n    if len(label) > MAX_LABEL:\n        raise ValueError(f'label too long ({len(label)} > {MAX_LABEL})')\n    return label","typeGuard":"def is_valid_label_length(label: str) -> bool:\n    return 0 < len(label) <= 63","tryCatchPattern":"from idna import IDNAError\ntry:\n    idna.check_bidi(label)\nexcept IDNAError as e:\n    if 'too long' in str(e).lower():\n        raise ValueError('label exceeds length limit') from e\n    raise","preventionTips":["Enforce a 63-char per-label cap at the input boundary, well below idna's 1024 defensive guard.","Split multi-label domains on '.' before IDNA rather than passing the whole domain as one label.","Reject unbounded user text as hostnames; hostnames come from trusted, bounded sources."],"tags":["idna","dns","validation","input-length","pip"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}