claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] MCP HTTPS: a trust anchor with an iPAddress name constraint fails with UNSUPPORTED_CONSTRAINT_TYPE (NODE_EXTRA_CA_CERTS is honoured)

Open fredshino opened this issue 1 month ago • 2 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Edit (2026-10-30), added after filing. The original report below is unchanged.

Root cause: the Claude Code binary is built on Bun (v1.4.4 in 2.1.314), and Bun ships BoringSSL. BoringSSL's name-constraint matcher has no iPAddress case (nc_match_single). It also checks every CA's constraints against the certs below it (check_name_constraints). OpenSSL has the case, which is why plain Node accepts these chains. So the fix is either in Bun's BoringSSL or in Claude Code's own certificate handling.

Two things follow, both measured on 2.1.314 (9-row table in this comment). Moving the iPAddress subtree from the root to an intermediate fails the same way. And the error only fires when the leaf carries an IP SAN. A DNS-only leaf under an IP-constrained root connects, which is a second workaround if the server can be reached by name.

Also, naming the anchor's subject in the error, not just the unsupported form, would make the stale-root case much easier to find.

Claude Code can't connect to an HTTP MCP server when its certificate chains to a private root that carries a critical Name Constraints extension with an iPAddress subtree. claude mcp list reports:

✘ Failed to connect — UNSUPPORTED_CONSTRAINT_TYPE: unsupported name constraint type

NODE_EXTRA_CA_CERTS is honoured. The extra anchor loads, and the name-constraint type is what fails. #55760 attributed a similar MCP TLS failure to the variable being ignored; that is not what happens here.

There are four throwaway roots. Each one signs a leaf with SAN DNS:mcp.catest.local + IP:127.0.0.1, served by a local TLS stub that answers 404, with NODE_EXTRA_CA_CERTS=<root>.pem:

Root's permitted subtrees Claude Code 2.1.314 (Windows 11) and 2.1.310 (Ubuntu, WSL2) openssl verify
DNS:catest.local + IP:127.0.0.1/32 UNSUPPORTED_CONSTRAINT_TYPE OK
IP:127.0.0.1/32 only UNSUPPORTED_CONSTRAINT_TYPE OK
DNS:catest.local only TLS succeeds ("MCP endpoint not found", the stub's 404) OK
none TLS succeeds OK

Also measured (2.1.310, Windows and WSL, 2026-10-25):

  • SSL_CERT_FILE loads the anchor the same way. NODE_OPTIONS=--use-system-ca and NODE_USE_SYSTEM_CA=1 change nothing.
  • A DNS-only root over the same key, offered beside the IP-constrained one (either order), still fails. The verifier appears to stop at the first anchor it picks for the issuer.
  • OpenSSL, Python ssl, rustls and plain Node (--use-system-ca) accept the same IP-constrained chains.

RFC 5280 §4.2.1.10 lets a verifier that does not process a name form reject a certificate that uses it, so the failure is permitted. However, every other stack on the same machine processes iPAddress constraints. Name-constrained private roots that also permit 127.0.0.1 are a common way to scope a home-lab or corporate CA.

What Should Happen?

iPAddress subtrees are processed as Node/OpenSSL process them, so the first two rows connect as the last two do. Failing that, the error could name the unsupported form (iPAddress) so users know to re-issue the root without it.

Error Messages/Logs

UNSUPPORTED_CONSTRAINT_TYPE: unsupported name constraint type

Steps to Reproduce

pip install cryptography
python3 - <<'PY'
import datetime as dt, ipaddress
from cryptography import x509
from cryptography.x509.oid import NameOID, ExtendedKeyUsageOID
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import ec
now = dt.datetime.now(dt.timezone.utc)
def pem(c): return c.public_bytes(serialization.Encoding.PEM)
ip = x509.IPAddress(ipaddress.ip_network("127.0.0.1/32")); dns = x509.DNSName("catest.local")
for name, sub in {"dnsip": [dns, ip], "iponly": [ip], "dnsonly": [dns], "none": None}.items():
    ck = ec.generate_private_key(ec.SECP256R1()); cn = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, "probe-ca")])
    b = (x509.CertificateBuilder().subject_name(cn).issuer_name(cn).public_key(ck.public_key())
         .serial_number(x509.random_serial_number()).not_valid_before(now - dt.timedelta(days=1))
         .not_valid_after(now + dt.timedelta(days=30))
         .add_extension(x509.BasicConstraints(ca=True, path_length=0), critical=True)
         .add_extension(x509.KeyUsage(False, False, False, False, False, True, True, False, False), critical=True)
         .add_extension(x509.SubjectKeyIdentifier.from_public_key(ck.public_key()), critical=False))
    if sub: b = b.add_extension(x509.NameConstraints(sub, None), critical=True)
    ca = b.sign(ck, hashes.SHA256())
    lk = ec.generate_private_key(ec.SECP256R1())
    leaf = (x509.CertificateBuilder().subject_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, "mcp.catest.local")]))
            .issuer_name(cn).public_key(lk.public_key()).serial_number(x509.random_serial_number())
            .not_valid_before(now - dt.timedelta(days=1)).not_valid_after(now + dt.timedelta(days=30))
            .add_extension(x509.SubjectAlternativeName([x509.DNSName("mcp.catest.local"), x509.IPAddress(ipaddress.ip_address("127.0.0.1"))]), critical=False)
            .add_extension(x509.ExtendedKeyUsage([ExtendedKeyUsageOID.SERVER_AUTH]), critical=False)
            .add_extension(x509.AuthorityKeyIdentifier.from_issuer_public_key(ck.public_key()), critical=False)
            .sign(ck, hashes.SHA256()))
    open(f"{name}.ca.pem", "wb").write(pem(ca)); open(f"{name}.crt", "wb").write(pem(leaf))
    open(f"{name}.key", "wb").write(lk.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption()))
PY
cat > stub.py <<'PY'
import http.server, ssl, sys
class H(http.server.BaseHTTPRequestHandler):
    def do_POST(self): self.send_response(404); self.end_headers()
    do_GET = do_DELETE = do_POST
    def log_message(self, *a): pass
s = http.server.HTTPServer(("127.0.0.1", 8443), H)
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER); ctx.load_cert_chain(sys.argv[1], sys.argv[2])
s.socket = ctx.wrap_socket(s.socket, server_side=True); s.serve_forever()
PY
export CLAUDE_CONFIG_DIR=$(mktemp -d)   # keeps the registration out of your real config
claude mcp add -s local --transport http catest https://127.0.0.1:8443/mcp
for s in dnsip iponly dnsonly none; do
  python3 stub.py $s.crt $s.key & P=$!; sleep 1
  echo "$s: $(NODE_EXTRA_CA_CERTS=$PWD/$s.ca.pem claude mcp list 2>&1 | grep catest)"
  kill $P; wait $P 2>/dev/null
done

Claude Model

Other

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.314 (Windows 11), 2.1.310 (Ubuntu on WSL2)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

Related: #55760 (closed and locked; it attributed a similar MCP TLS failure to NODE_EXTRA_CA_CERTS being ignored).

Workaround: Re-issue the root over the same key with only DNS subtrees, and remove the IP-constrained root from every store the CLI reads (both can't be present).

fredshino avatar Oct 30 '26 03:10 fredshino

The row that matters most in your table is the one in the notes: a DNS-only root over the same key, offered beside the IP-constrained one in either order, still fails. That is a second defect hiding inside the first.

A verifier that does not implement a name form is allowed to reject a chain that uses it, as you say, quoting RFC 5280 4.2.1.10. But anchor selection is supposed to be a search. Candidate anchors for the issuer get tried, and one that fails for an unrelated reason should not mask a sibling that would succeed. Your measurement says the first anchor picked for the issuer decides the outcome, which puts the refusal in anchor pre-screening, before path building. That is worth filing as its own item, because it also explains a symptom your workaround does not cover: a user who has already re-issued the root correctly is still broken by a stale constrained root elsewhere in the same store, and nothing tells them which anchor won.

One probe splits the two, and you already have the harness for it: move the iPAddress subtree off the root and onto an intermediate. Root unconstrained, intermediate with permittedSubtrees = IP:127.0.0.1/32, leaves issued under the intermediate.

  • Fails the same way: the constraint type is refused wherever it is encountered during validation, so fixing anchor selection alone will not help.
  • Passes: the refusal is confined to the anchor pre-screen, which makes it a much smaller fix, and it gives you a workaround you can publish today, since a sub-CA carrying the IP constraint can be dropped in under an existing DNS-constrained root.

The other thing worth stating in the issue is how this lands for people running an MCP server on a home lab or an internal CA. Your workaround, re-issue DNS-only and remove the IP-constrained root from every store the CLI reads, is correct and is also the part that will bite: on a shared machine there are several stores, the remove step is manual, and the error names nothing. Having the message name both the unsupported form and the anchor subject would turn a hunt into a one-line fix, and that may be worth doing even after the constraint processing is fixed.

Ben-Home avatar Oct 30 '26 12:10 Ben-Home

Ran your intermediate probe on 2.1.314 (Windows). It fails the same way.

CA layout Leaf SAN URL host Claude Code mcp list openssl verify
root, no constraints DNS + IP 127.0.0.1 TLS OK (stub's 404) OK
root IP:127.0.0.1/32 DNS + IP 127.0.0.1 UNSUPPORTED_CONSTRAINT_TYPE OK
root none, intermediate none DNS + IP 127.0.0.1 TLS OK OK
root none, intermediate DNS:localhost DNS + IP 127.0.0.1 TLS OK OK
root none, intermediate IP:127.0.0.1/32 DNS + IP 127.0.0.1 UNSUPPORTED_CONSTRAINT_TYPE OK
root DNS:localhost, intermediate IP:127.0.0.1/32 DNS + IP 127.0.0.1 UNSUPPORTED_CONSTRAINT_TYPE OK
root, no constraints DNS + IP localhost TLS OK OK
root DNS:localhost + IP:127.0.0.1/32 DNS + IP localhost UNSUPPORTED_CONSTRAINT_TYPE OK
root DNS:localhost + IP:127.0.0.1/32 DNS only localhost TLS OK OK

The source explains it. Claude Code is a Bun binary (Bun v1.4.4 in 2.1.314) and Bun ships BoringSSL. BoringSSL's nc_match_single has no iPAddress case, so it returns X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE (v3_ncons.cc). check_name_constraints applies every CA's constraints to the certs below it (x509_vfy.cc), so moving the subtree down the chain doesn't help. OpenSSL has an iPAddress case, which is why plain Node accepts these chains.

It only fires when the leaf has an IP SAN. A DNS-only leaf under the same root connects (last row). That's a second workaround if you can reach the server by name.

On the second defect, I don't think it's a pre-screen. OpenSSL-style verifiers build one chain and check constraints after, and a constraint failure doesn't send them back to try another anchor. I'd rather not file that separately.

Agree on the error message though. Naming the form and the anchor would've saved me a lot of digging.

Thanks!

fredshino avatar Oct 30 '26 12:10 fredshino