]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.25] crypto/x509: prevent HostnameError.Error() from consuming...
authorNicholas S. Husin <nsh@golang.org>
Mon, 24 Nov 2025 19:56:23 +0000 (14:56 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 2 Dec 2025 15:48:36 +0000 (07:48 -0800)
commitf7bce4bd6f7b13de8d9f06f7f262e3b60381e7e9
tree8b617fd1406a57b62ef10d55e8a83894526a4305
parent287017acebd27203aa3218abbd11ed65c2280cf8
[release-branch.go1.25] crypto/x509: prevent HostnameError.Error() from consuming excessive resource

Constructing HostnameError.Error() takes O(N^2) runtime due to using a
string concatenation in a loop. Additionally, there is no limit on how
many names are included in the error message. As a result, a malicious
attacker could craft a certificate with an infinite amount of names to
unfairly consume resource.

To remediate this, we will now use strings.Builder to construct the
error message, preventing O(N^2) runtime. When a certificate has 100 or
more names, we will also not print each name individually.

Thanks to Philippe Antoine (Catena cyber) for reporting this issue.

Updates #76445
Fixes #76461
Fixes CVE-2025-61729

Change-Id: I6343776ec3289577abc76dad71766c491c1a7c81
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/3000
Reviewed-by: Neal Patel <nealpatel@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/3200
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/725800
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
src/crypto/x509/verify.go
src/crypto/x509/verify_test.go