]> Cypherpunks repositories - gostls13.git/commit
crypto/x509: prevent HostnameError.Error() from consuming excessive resource
authorNicholas S. Husin <nsh@golang.org>
Mon, 24 Nov 2025 19:56:23 +0000 (14:56 -0500)
committerRoland Shoemaker <roland@golang.org>
Tue, 2 Dec 2025 20:22:04 +0000 (12:22 -0800)
commitc1acdcb34560b20291cf55c988d0f883a38e8bbf
tree599cb3d093d24fdd8d22f5e49b1dc6bc01f50c2a
parent8ae5d408ed62d234cb72adebb9a23e08da1cedc6
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.

Fixes #76445
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-review.googlesource.com/c/go/+/725920
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
src/crypto/x509/verify.go
src/crypto/x509/verify_test.go