fix(extension): refuse RAR members that differ only in case at any depth - #522
Merged
Merged
Conversation
The case-folded duplicate check from #511 looked at a detail's top-level members only. Its rationale was that DisallowUnknownFields leaves nested duplicates nothing to smuggle, but it matches names case-insensitively too. So {"type":"payment","instructedAmount":{"value":"1000.00","VALUE":"1.00",...}} was accepted. encoding/json, and so the consent page, read 1.00, while a case-sensitive reader of the issued token (which carries these bytes) read 1000.00. A lone "ACTIONS" was likewise actions to one reader and no actions at all to the other. - RARRegistry.Parse and ParseGrantedRAR now refuse a repeated member, compared under Unicode simple case folding, in every object at every depth, as ErrDuplicateMember. - Parse and RARGet refuse a member spelled other than its field's json tag, using strictjson's new CheckTaggedFieldCase. Untagged fields keep encoding/json's matching, so detail types without tags work as before. internal/strictjson compared names with strings.ToLower, which misses the long s: encoding/json reads "iſſ" as "iss". It now uses FoldKey, the same fold encoding/json applies, which moves here from extension. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.



Summary
This fixes the final pre-release security review's Medium. #511 closed the RAR case-variant differential only for a detail's top-level members. Its rationale (
DisallowUnknownFieldsleaves nested duplicates nothing to smuggle) was wrong: that check matches names case-insensitively too. Reproduced againstRARRegistry.Parse:[{"type":"payment","instructedAmount":{"value":"1000.00","currency":"EUR","VALUE":"1.00"}}]Parseaccepted it.encoding/json, and soRARGetand the consent page, read 1.00. The issued token carries these bytes, so a case-sensitive reader (a non-Go resource server, a payment system) read 1000.00."ACTIONS":[...]) was accepted too. It isactionsto Go and no actions to a case-sensitive reader.Fix:
RARRegistry.ParseandParseGrantedRARrefuse a repeated member, compared under Unicode simple case folding, in every object at every depth (ErrDuplicateMember).typemust still be spelled exactly at the top level.ParseandRARGetrefuse a member spelled other than its field'sjsontag, using the newstrictjson.CheckTaggedFieldCase. Untagged fields keepencoding/json's matching, so detail types without tags work exactly as before. That's why this doesn't use the all-fieldsCheckFieldCase.internal/strictjsonfold fix. It folded names withstrings.ToLower, which misses the long s:encoding/jsonreads"iſſ"asiss, while the lowercase compare didn't flag it.FoldKey, the same foldencoding/jsonapplies, now lives instrictjson, and both packages use it. This tightens every JOSE/metadata decode that usesstrictjson.ParseGrantedRAR's andErrDuplicateMember's docs now describe the depth-wide behaviour.This is a
fix: it refuses input that two readers would read differently. Correctly spelled details, tagged or untagged, are unaffected.Tests
TestRARParseRejectsNestedCaseVariants:valuewithVALUE, andvaluetwice;ACTIONS, and a lone nestedVALUE;currency.TestGrantedRARRejectsNestedCaseVariants:ParseGrantedRARrefuses a nested repeat, andRARGetrefuses a lone variant.TestCheckFieldCaseFoldsAsEncodingJSONDoes:"iſſ"forissis refused.TestCheckTaggedFieldCase: a tagged variant is refused, an untagged one is allowed, andCheckFieldCasestill checks every field.Parseor inRARGet, usingToLowerinstead ofFoldKey, or ignoring tagged-only each fails a test.go test -raceacross extension, internal, server, resource and client passes.go test ./cmd/...passes.FuzzRARRegistryParseandFuzzParseGrantedRAR(15 seconds each) are clean.🤖 Generated with Claude Code