Skip to content

crypto/x509: CertPool.Subjects exposes mutable internal subject slices #79865

Description

@jvdprng

Description

CertPool.Subjects allocates a new outer slice but returns inner byte slices that alias the pool's internal rawSubject storage. A caller that mutates a returned subject slice can mutate the pool metadata observed by later calls.

This requires the application to mutate its own returned data.

Specification or documentation

This is a Go API aliasing issue. The Subjects documentation says it returns a list of DER-encoded subjects, but it does not warn that mutating the returned inner slices mutates pool internals.

Code references

  • go/src/crypto/x509/cert_pool.go:257 through go/src/crypto/x509/cert_pool.go:262 documents and defines Subjects.
  • go/src/crypto/x509/cert_pool.go:263 allocates a new outer slice.
  • go/src/crypto/x509/cert_pool.go:264 through go/src/crypto/x509/cert_pool.go:266 returns lc.rawSubject directly.
  • go/src/crypto/x509/cert_pool.go:40 through go/src/crypto/x509/cert_pool.go:45 defines rawSubject as internal metadata.

Test case

This should be a Go unit test: add a certificate to a pool, call Subjects, mutate a returned inner slice, call Subjects again, and assert that the pool's subject bytes did not change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions