]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.24] 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:51:02 +0000 (07:51 -0800)
commit3a842bd5c6aa8eefa13c0174de3ab361e50bd672
tree58f21995dc5fe90e5e9ac0bd6a249593ad6bb9d6
parent04db77a423cac75bb82cc9a6859991ae9c016344
[release-branch.go1.24] 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 #76460
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/+/3220
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/725820
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
src/crypto/x509/verify.go
src/crypto/x509/verify_test.go