Repository navigation
fix(auth): @moq/auth refuses the keys moq-auth refuses - #8804
Conversation
Quest-Claim: 8bb684819ad3cfe1
@moq/auth parses keys and key sets with a JSON parser that refuses what serde_json does (a repeated member it reads, nesting past 127, a lone surrogate, a number out of range) and decodes key fields as moq-auth's strict base64url decoder does. moq-auth now refuses a repeated RSA private member too, which it kept the last of. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 20 minutes. View limit details
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. |
There was a problem hiding this comment.
ℹ️ One parity gap left. It's in
KeySet, notKey.
Reviewed changes
This review covers the full PR: a strict JSON parser and base64url decoder for @moq/auth, the Rust fix for repeated RSA private members, and the corpus cases that pin both.
json.tsparser: refuses what serde_json refuses: nesting deeper than 127, lone surrogates, and non-finite numbers. A repeated member parses asREPEATED, which zod then refuses or strips.Key.parse/KeySet.parse: trim only where Rust trims, decode the encoded form unpadded with strict UTF-8, and parse throughJson.parse.decodeBase64url: matchesdecode_base64url(URL_SAFE_NO_PAD, or canonicalURL_SAFE, with no trailing bits). This replacesdecodeBase64Flexible.deserialize_rsa_private: a map visitor that refuses a repeatedd/p/q/dp/dq/qi.- Corpus: a string case is now raw text. This adds 15
jwkcases and 2setscases, and the fuzz seeds use the raw text too.
I checked the base64 edge cases (AA=, A===, ====, padding with nonzero trailing bits) against the base64 crate's URL_SAFE and URL_SAFE_NO_PAD engines, and they agree. The trim and BOM handling also match str::trim and String::from_utf8. bun test js/auth/src passes all 196 tests.
claude-opus-5-5 | 𝕏
…fuse in a key KeySet read a plain RawKeySet, so serde_json skipped an unknown top-level member through ignore_value, checking only its syntax: 1e400, a lone surrogate, or nesting past the recursion limit got through, while @moq/auth's KeySet.parse refuses them. A flattened catch-all buffers every member as a key's own members are, so both refuse them. A repeated unread member stays accepted in both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This review covers the one commit added since the prior Pullfrog review (9c0dcbb..e265fae).
RawKeySetcatch-all:rs/moq-auth/src/set.rsflattens aHashMap<String, IgnoredAny>, so serde buffers unread top-level members throughdeserialize_any.KeySet::from_strnow refuses an out-of-range number, a lone surrogate, or nesting past 127 there, asKeySet.parsedoes.- Corpus: four new
setscases pin a repeated unread member (accepted), an out-of-range unread member, a lone-surrogate unread member, and an over-deep unread member (all refused).
The earlier KeySet parity thread is resolved.
claude-sonnet-5-5 | 𝕏

Finishes quest/m1/auth-key-strictness.md (deleted here).
Problem
Fuzzing the key parsers (moq-dev/moq#8707) found JWKs that only
@moq/authaccepts.JSON.parsekeeps the last copy of a repeated member, anddecodeBase64Flexibleaccepted whitespace, the standard alphabet, nonzero trailing bits, and a padded or standard-base64 encoded key. A random sweep found more: nesting past serde_json's 127 limit, lone surrogates, numbers out of range, andString.trimstripping a BOM that Rust'sstr::trimkeeps.Rust had its own gap too: a repeated RSA private member (
d,p,q,dp,dq,qi) went through aserde_json::Mapand kept the last copy, while every other field refused the repeat. AndKeySetskipped an unread top-level member through serde_json'signore_value, which checks only syntax, so a set accepted1e400, a lone surrogate, or nesting past 127 there, which a key refuses in its own members.Approach
js/auth/src/json.ts: a small internal JSON parser that refuses what serde_json refuses. A repeated member parses as a sentinel symbol. Every schema refuses it where it reads that member and strips it where it doesn't. serde does the same thing: it refuses a repeated field it reads and ignores repeated unknown members.Key.parseandKeySet.parseuse it.Key.parsetrims the way Rust'sstr::trimdoes (\p{White_Space}) and decodes UTF-8 strictly, keeping a BOM.KeySet.parseno longer trims, matchingKeySet::from_str.decodeBase64urlmirrorsmoq-auth'sdecode_base64url: unpadded, or with canonical padding, and refuses whitespace,+//, and nonzero trailing bits. An encoded key is unpadded only, asKey::from_strreads it.moq-auth:deserialize_rsa_privaterefuses a repeated private member.moq-auth:KeySet'sRawKeySetgets a flattenedIgnoredAnycatch-all, so serde buffers every top-level member throughdeserialize_anyand refuses what it refuses in a key. A repeatedkeysis still refused and a repeated unread member still accepted.jwk/jwkscase given as a JSON string is now its raw text, so it can spell a repeated member. There are 15 newjwkcases and 6 newsetscases, which both languages replay, and the fuzz seeds use the raw text.Impact
@moq/authstops loading the keys above, including a key encoded in standard (+//, padded) base64, which an old test had pinned as accepted.moq-authstops loading an RSA key that repeats a private member, and a key set whose unread top-level member is out of range, holds a lone surrogate, or nests past 127. A key written by either CLI never does any of these.Decisions (taken while AFK; a review can undo each)
Repeated unread members (
{"note":1,"note":2,...}) stay accepted in both, because serde ignores them. The quest's plan said to refuse a repeat at any depth. That would have made JS stricter than Rust and needed a raw-JSON pre-scan in Rust. Exact agreement is the Goal, so I followed serde.Fixed the Rust RSA private-member leniency here, not as a follow-up, since the Goal is exact agreement.
Also matched serde_json's recursion limit, lone-surrogate, and number-range refusals, plus the trim and BOM differences, which the random sweep found beyond the quest's list.
Replaced the
parse - accepts a JWK in standard padded base64test with one that refuses it. That test came from a dependency swap (moq-dev/moq#6053) that kept the old behavior, not from a requirement.JWKS unread top-level members: ✅ make
moq-authrefuse them as@moq/authnow does (rejected: give the JS parser a lax mode for unread members). Pullfrog found the disagreement (r4578188565). Strict follows the fail-loudly rule and matches how a key's own members already parse in both.Alternatives
JSON.parse. It can't see repeated members.Validation
just checkpasses (the Rust and JS tests include the corpus replay).cargo test -p moq-auth --all-featuresgives 255 passed, andbun testinjs/authgives 200 passed.Key::from_str/KeySet::from_strandKey.parse/KeySet.parse. Result: 0 disagreements, with about 35% of the inputs accepted. The pre-changeKey.parsedisagreed with Rust on 3,317 of 8,000.Caused by
JSON.parseand the lenient standard-base64 fallback toKey.parse(found by check: fuzzing).serde_json::Map, which keeps the last of a repeat (found by check: differential sweep).Follow-ups
None.
Models
Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)
Implementer: Claude Code, claude-opus-5-5, medium effort (iterate, S, arm A)
Review
Rewritten by
quest reviewafter each round.Head: e265fae
Base: origin/main at 527e301
Risk: high,
The change tightens authentication key parsing, a security boundary relied on by applications and relays, so rejected key sets could prevent authentication until configuration is corrected or the change is reverted.Classified: medium by default
Reviewer: Codex, gpt-6.1-sol, medium effort
Session:
01a1def8-7ef8-7200-a354-cbbc336a417c, round 2Score: 9/10,
No actionable defects were found in the incremental changes, which align Rust's handling of unread JWKS members with JavaScript; builds and tests were not run as instructed.Raised the risk to high:
The change tightens authentication key parsing, a security boundary relied on by applications and relays, so rejected key sets could prevent authentication until configuration is corrected or the change is reverted.Rounds: 2; first round 0; findings 0: fixed 0, refuted 0, open 0
Findings: none