Skip to content

Include the trust anchors' keys in the trust chain cache key - #224

Open
topperge wants to merge 1 commit into
go-oidfed:mainfrom
topperge:fix/trust-chain-cache-key-jwks
Open

topperge wants to merge 1 commit into
go-oidfed:mainfrom
topperge:fix/trust-chain-cache-key-jwks

Conversation

@topperge

Copy link
Copy Markdown
Contributor

Fixes #216.

TrustResolver.hash() is the key of the trust_tree_chains cache. It now covers each trust anchor's keys as well as its entity ID. The keys enter as a fingerprint: the sorted RFC 7638 SHA-256 thumbprints of its JWKS, or none without keys.

Before this change, a chain resolved and verified with one JWKS was returned from the cache, without verification, for the same trust anchor ID with a different JWKS. This happened:

  • after a re-pin;
  • after the TAJWKSRefresher dropped a retired key;
  • for a caller holding other keys for the same trust anchor.

Changes:

  • trustanchor.go: unexported (*TrustAnchor).keysFingerprint(). A key whose thumbprint can't be computed contributes its JSON form instead, so it still changes the fingerprint.
  • trustresolver.go: hash() includes the fingerprints.

The hash input is internal, so nothing changes for callers. Cached chains stay valid as long as the trust anchors' keys are unchanged. When the keys change, the next resolution builds and verifies the chain again.

Test (trustresolver_cache_key_test.go): resolve rp → ia → ta with the trust anchor's JWKS, which yields a chain. Then resolve with an unrelated JWKS for the same trust anchor ID, which must yield no chain. Then resolve with the real JWKS again, which yields a chain. The second step fails on main, where the cached chain is returned, and passes with this change. go test ./... and go test -race . pass. go vet reports the same five copylocks warnings as on main.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QYDqsx3UGxpCKvCiUxShZq

TrustResolver.hash(), the key of the trust_tree_chains cache, covered the
starting entity, the trust anchors' entity IDs, the entity types and the
hints mode, but not the trust anchors' keys. A chain resolved and verified
with one JWKS was therefore returned from the cache, without verification,
for the same trust anchor ID with a different JWKS that would not verify
it: after a re-pin, after the TAJWKSRefresher dropped a retired key, or for
a caller holding other keys for the same trust anchor.

The key now also covers each trust anchor's keys, as the sorted RFC 7638
SHA-256 thumbprints of its JWKS ("none" without keys).

Fixes go-oidfed#216

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYDqsx3UGxpCKvCiUxShZq
@deepsource-io

deepsource-io Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

DeepSource Code Review

We reviewed changes in be2f2ed...58c0cf6 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Go Nov 12, 2026 3:50p.m. Review ↗
Code coverage Nov 12, 2026 4:20p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

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.

TrustResolver: the trust chain cache key ignores the trust anchors' JWKS

1 participant