Repository navigation
helpers: do not trim whitespace bytes off DER input - #1465
Open
lukevalenta wants to merge 1 commit into
Open
lukevalenta wants to merge 1 commit into
lukevalenta wants to merge 1 commit into
Conversation
ParseCSR and ParseCertificatesDER ran bytes.TrimSpace on DER input. The last byte of a DER encoding is a signature or key byte, so about 1 in 75 valid inputs ended in a byte that TrimSpace removes (0x09 to 0x0d, 0x20) and then failed to parse, for example with "asn1: syntax error: data truncated". Both functions now remove only whitespace that follows a complete sequence of DER elements, as well as leading whitespace. Input that is not a sequence of DER elements is trimmed on both sides as before.
This was referenced Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ParseCSRandParseCertificatesDERranbytes.TrimSpaceon DER input. The last byte of a DER encoding is a signature or key byte, so about 1 in 75 valid inputs ended in a byte thatTrimSpaceremoves (0x09 to 0x0d, 0x20) and then failed to parse, for example withasn1: syntax error: data truncated.On master, every DER input I generated that ended in such a byte failed: 8 of 8 CSRs and 5 of 5 certificates.
Change
Both functions now remove only leading whitespace and whitespace that follows a complete sequence of DER elements. Input that is not a sequence of DER elements is trimmed on both sides as before. PEM handling is unchanged.
ParseCertificatesDERstill accepts several concatenated certificates, as the existingx509.ParseCertificatescall did.Tests
The new tests fail on master. Reverting each part of the fix (either function, the leading trim, or the trailing trim) fails at least one test.
go test ./helpers ./csr ./bundler/... ./cli/... ./api/bundle/... ./api/generator/...passes. I did not runscan, which also callsParseCertificatesDER.