Repository navigation
fix(federation)!: stop key holders printing or encoding private keys - #986
Merged
Merged
Conversation
… keys The KeyManager NewKeyManagerFromSigners builds printed whatever fmt makes of each signer: an ed25519.PrivateKey is a byte slice, which fmt prints byte by byte under %v, %x, %d and the rest, at any depth. The in-memory ECDH backend printed its *ecdh.PrivateKey's bytes under %s and %q, since a verb a pointer field doesn't take makes fmt print what it points to. Both KeyManagers (with and without declared custody) and the NewInMemoryECDH and NewInMemoryRSA backends now implement fmt.Formatter and slog.LogValuer, printing a shadow in which the key is [REDACTED] and the purposes, algorithms, kids and public keys are as before. The signer KeyManager also holds each backend behind a pointer, so fmt's reflection fallback, which calls no Format method (%w outside Errorf, say), prints only an address where the signer is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An ephemeral KeyManager holding an EdDSA key printed it whenever fmt or log/slog rendered the manager: an ed25519.PrivateKey is a byte slice, which fmt prints byte by byte under %v, %x, %d and the rest. KeyManager now implements fmt.Formatter and slog.LogValuer, printing each signing and decryption purpose's kid and [REDACTED] for its key. Each signer is also held behind a pointer, so fmt's reflection fallback, which calls no Format method (%w outside Errorf, say), prints only an address where the key is. The key-material matrix in fapitest now covers the signer where it moved, and reads the keys it looks for through the pointer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The five issuers' dependencies (HistoricalKeysIssueDependencies, ResolveIssueDependencies, SelfIssueDependencies, SubordinateIssueDependencies and TrustMarkIssueDependencies) hold the entity's Signer, often the private key itself, in an exported field. encoding/json, encoding/xml and log/slog's JSON handler encoded an *ecdsa.PrivateKey or *rsa.PrivateKey there with its private exponent included, and fmt printed an ed25519.PrivateKey byte by byte. Each now implements fmt.Formatter and slog.LogValuer, printing its fields with [REDACTED] for Signer, and refuses encoding through MarshalText and MarshalJSON, which return the new ErrIssueDependenciesSerialization sentinel. MarshalText covers encoding/xml too, which encodes an encoding.TextMarshaler as text rather than walking its fields. This follows keys.SignerSpec, which already refuses encoding with ErrSignerSpecSerialization. BREAKING CHANGE: encoding any of the five federation issuer dependency structs with encoding/json, encoding/xml or another encoder that uses encoding.TextMarshaler now fails with ErrIssueDependenciesSerialization instead of writing the signer's private key. Encode the entity's public JWKS, or the fields you need, instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each federation issuer holds its dependencies, Signer included, in an unexported field, where fmt's reflection fallback calls no Format method: an issuer signing with an ed25519.PrivateKey printed every byte of it under %v, and the dependencies' own redaction never ran. The five issuers now implement fmt.Formatter and slog.LogValuer, printing their config and their dependencies as the dependencies print themselves, with [REDACTED] for Signer, and hold the dependencies behind a pointer, so the fallback (%w outside Errorf, say) prints only an address. The key-material matrix gains a case for the issuers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The signer and ephemeral KeyManagers' EdDSA cases, the in-memory ECDH backend and the federation issuers' dependencies no longer print their keys, so their known-leak markers go, with the descriptions only they used. The SignerSpec EdDSA case runs too, accepting what fmt's reflection fallback prints: SignerSpec is an input type whose exported Signer field the caller fills, and the fallback, which calls none of its methods, prints an ed25519.PrivateKey there as the byte slice it is. Every rendering through SignerSpec's own methods, and every encoder, is still checked. The new inputField records why, as SignerSpec's own rendering test already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds UPGRADING.md sections for the federation issuer dependencies' refusal to be encoded, and for the redacted fmt and log/slog output of the key-holding types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the Format and LogValue of the signer KeyManager (with and without declared custody), the in-memory ECDH and RSA backends, the ephemeral KeyManager and the five federation issuers; the [REDACTED] mask each key holder puts where a key would print, the federation issuers' dependencies' Signer mask included; and the dependencies' MarshalJSON and MarshalText refusals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Go 1.27 prints a json.RawMessage as its text, where earlier releases printed its bytes, so the expected rendering of the dependencies' JWKS field is built with fmt from the json.RawMessage itself rather than from a []byte conversion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
osanderson
force-pushed
the
fix/key-render-redact
branch
from
November 25, 2026 16:33
749d276 to
7f5706b
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
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.



Breaking, but only for code that encodes a federation issuer's dependencies.
This closes the private-key rendering leaks that the key-material matrix in
fapitest(#968) recorded as skipped cases. It also fixes one it didn't list, the federation issuers themselves. Every case in the matrix now runs.Leaks closed
fix(keys)NewKeyManagerFromSigners%v, becauseed25519.PrivateKeyis a byte slice.fix(keys)NewInMemoryECDH%sand%q.fix(keys)ephemeral.NewKeyManagerfix(federation)!*IssueDependenciesstructsencoding/json,encoding/xmland slog's JSON handler.fix(federation)*SelfIssuer,*ResolveIssuer,*SubordinateIssuer,*TrustMarkIssuerand*HistoricalKeysIssuerdepsfield. The matrix's field guard couldn't see this.How each is fixed:
Format, handling every verb and flag, andLogValue, in the stylekeys.SignerSpecand the pairwise derivers already use.NewInMemoryRSAgets the same for consistency; it wasn't leaking.%wand other unsupported verbs call no methods, so without the pointer they would still print the key.*IssueDependenciesstructs also gainMarshalJSONandMarshalText, which refuse with the newErrIssueDependenciesSerialization.MarshalTextalso coversencoding/xml. Encoding one of these structs now fails instead of writing the key. Nothing in this repo, its examples or the interop client encodes them.UPGRADING.md has two sections under v0.86.0. One covers the breaking encoding refusal and what to encode instead. The other covers the redacted fmt and slog output, which changes nothing that should fail.
Still possible, and why
A
keys.SignerSpecholding an Ed25519 key in its exportedSignerfield can still be printed through fmt's reflection fallback, which calls no methods:%p,%woutsideErrorf, or aSignerSpecinside an unexported field. The same goes for an*IssueDependenciesstruct holding an Ed25519 key. Closing this would needSignerto change type, which would break the API. The matrix case accepts only that fallback, asTestSignerSpecPrintsNoKeyalready did.Tests
knownLeakmarker is removed, so each case runs, and a new "federation issuers" case is added. Onmain, five of these cases fail.FormatandLogValuehave their own tests. The encoding refusals are checked witherrors.Isfor json and xml. Each test fails without its fix.Nothing on the wire changes.
🤖 Generated with Claude Code