Skip to content

Harden chain depth bounds and parser input validation#10209

Draft
ColtonWilley wants to merge 1 commit intowolfSSL:masterfrom
ColtonWilley:harden-chain-depth-and-parser-bounds
Draft

Harden chain depth bounds and parser input validation#10209
ColtonWilley wants to merge 1 commit intowolfSSL:masterfrom
ColtonWilley:harden-chain-depth-and-parser-bounds

Conversation

@ColtonWilley
Copy link
Copy Markdown
Contributor

@ColtonWilley ColtonWilley commented Apr 13, 2026

Early PR for review — tests still needed.

Summary

  • Enforce MAX_CHAIN_DEPTH limits in OCSP chain processing (SendCertificateStatus, ProcessChainOCSPRequest), certificate loading (ProcessUserChain), and TLS 1.3 certificate sending (SendTls13Certificate). Add idx bounds checks to chain accessors in ssl.c.
  • Harden SNI extension parser (TLSX_SNI_GetFromBuffer) with length validation preventing buffer overreads on malformed ClientHello. Require exact listLen == extLen - OPAQUE16_LEN match to prevent extension boundary misalignment.
  • Fix off-by-one in TLSX_CSR_Free (<= to <) — csr->requests is a count, and a full-depth chain with leaf OCSP could push the free loop one past the request.ocsp[] array.
  • Add remaining-buffer bounds checks to PKCS7 decoders: DecodeEnvelopedData and DecodeAuthEnvelopedData (encryptedContentSz, authTagSz), DecodeEncryptedData (two sites), SignedData null signature tag, and PwriKek_KeyUnWrap cekLen off-by-4.

Test plan

  • Existing PKCS7 test suite passes (enveloped, auth-enveloped, encrypted, signed data)
  • TLS 1.3 OCSP stapling tests pass with WOLFSSL_TLS_OCSP_MULTI
  • SNI callback tests pass
  • Chain depth at MAX_CHAIN_DEPTH accepted; MAX_CHAIN_DEPTH + 1 rejected with MAX_CHAIN_ERROR
  • Fuzz/malformed input: truncated PKCS7 AuthEnvelopedData returns BUFFER_E instead of OOB read

Enforce MAX_CHAIN_DEPTH limits in OCSP chain processing
(SendCertificateStatus, ProcessChainOCSPRequest), certificate loading
(ProcessUserChain), and TLS 1.3 certificate sending
(SendTls13Certificate). Add idx bounds checks to chain accessors
in ssl.c.

Harden SNI extension parser (TLSX_SNI_GetFromBuffer) with length
checks preventing buffer overreads on malformed ClientHello.

Fix off-by-one in TLSX_CSR_Free where <= should be < since
csr->requests is a count, not a max index.

Add remaining-buffer bounds checks to PKCS7 decoders:
DecodeEnvelopedData, DecodeAuthEnvelopedData (encryptedContentSz
and authTagSz), DecodeEncryptedData, SignedData null signature tag,
and PwriKek_KeyUnWrap cekLen validation.
@ColtonWilley ColtonWilley marked this pull request as draft April 13, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant