Reject standalone keys with mismatched IDs - #980
Open
ojspp41 wants to merge 1 commit into
Open
Conversation
Keep fetched key identities aligned with their requested URLs and cache entries. Add regression coverage for both CryptographicKey and Multikey rejection and negative caching while preserving actor lookup behavior. Fixes fedify-dev#963 Assisted-by: Codex:gpt-5
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Background
fetchKey()accepts either an actor document containing keys or a standaloneCryptographicKey/Multikeydocument.The actor branch already checks candidate key IDs against the requested
keyId. The standalone branch previously accepted any object of the requested key class without checking itsid. As a result, a document fetched from one URL could declare a different ID and still be returned and cached under the requested URL.Although this does not let the key impersonate another actor—the owner/controller checks remain responsible for binding a key to an actor—it leaves the fetched key identity inconsistent with its lookup and cache key.
Changes
id, preserving the existing compatibility behavior.idonly when its URL exactly matches the requestedkeyId.iddiffers from the requested URL.@fedify/fedify.Regression coverage
The regression test supplies standalone key documents whose IDs differ from their requested URLs and verifies that:
CryptographicKeyandMultikeydocuments are rejected;{ key: null, cached: false };cached: true.I also confirmed that the new regression test fails against the previous standalone-key behavior and passes with this change.
Existing cache entries
This change validates newly fetched standalone key documents. It does not retroactively validate or evict mismatched key objects that may already exist in a persistent
KeyCachefrom before the upgrade.I kept existing cache-entry handling out of scope because #963 specifically concerns resolving a fetched standalone document, and cache storage and retention are provided by the application. I am happy to add validation or stale-entry handling for cached keys in this PR if the maintainers prefer that behavior.
Testing
The following checks passed locally:
mise exec -- deno test --check --doc --allow-all --unstable-kv --trace-leaks packages/fedify/src/sig/key.test.tsmise run check-each fedifymise run test-each fedify(Deno, Node.js, and Bun)mise run checkFixes #963.
AI usage
Implementation, regression-test drafting, code review, and local verification were assisted by Codex (GPT-5). I reviewed the resulting change and exercised it locally using the Deno, Node.js, and Bun workflows listed above.