Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions .github/mutation/mutants.json
Original file line number Diff line number Diff line change
Expand Up @@ -6391,5 +6391,186 @@
],
"run": "^TestExchangeBackchannelAuthenticationDPoPProofAtMTLSAlias$",
"why": "a CIBA token request checks a DPoP proof against the URL its request's route names"
},
{
"id": "strictjson-conflicting-object-skips-case-variant-names",
"file": "internal/strictjson/members_conflict.go",
"old": "if first, ok := seen[key]; ok {",
"new": "if first, ok := seen[key]; ok && false {",
"module": "root",
"packages": [
"./internal/strictjson"
],
"run": "^TestCheckConflictingObject$",
"why": "CheckConflictingObject refuses two member names that differ only in case"
},
{
"id": "strictjson-conflicting-object-skips-values",
"file": "internal/strictjson/members_conflict.go",
"old": "if err := CheckConflictingMembers(nested); err != nil {",
"new": "if err := CheckConflictingMembers(nested); err != nil && false {",
"module": "root",
"packages": [
"./internal/strictjson"
],
"run": "^TestCheckConflictingObject$",
"why": "CheckConflictingObject refuses a member value repeating a member with differing copies"
},
{
"id": "strictjson-conflicting-object-checks-value-unnested",
"file": "internal/strictjson/members_conflict.go",
"old": "nested := slices.Concat([]byte(\"[\"), value, []byte(\"]\"))",
"new": "nested := slices.Concat(value)",
"module": "root",
"packages": [
"./internal/strictjson"
],
"run": "^TestCheckConflictingObject$",
"why": "CheckConflictingObject checks a value's nesting as it is inside the object, one level deeper"
},
{
"id": "strictjson-conflicting-object-skips-json-validity",
"file": "internal/strictjson/members_conflict.go",
"old": "\t\tif !json.Valid(value) {\n\t\t\treturn name,",
"new": "\t\tif false && !json.Valid(value) {\n\t\t\treturn name,",
"module": "root",
"packages": [
"./internal/strictjson"
],
"run": "^TestCheckConflictingObject$",
"why": "CheckConflictingObject refuses a member value that isn't one JSON value"
},
{
"id": "server-granted-id-token-claims-skip-conflict-check",
"file": "server/granted_id_token_claims.go",
"old": "if name, err := strictjson.CheckConflictingObject(claims); err != nil {",
"new": "if name, err := strictjson.CheckConflictingObject(claims); err != nil && false {",
"module": "root",
"packages": [
"./server"
],
"run": "^(TestCompleteAuthorizationRejectsInvalidGrantedIDTokenClaims|TestCompleteBackchannelAuthenticationRejectsInvalidGrantedIDTokenClaims)$",
"why": "CompleteAuthorization/CompleteBackchannelAuthentication refuse IDTokenClaims repeating a member with differing copies or as a case variant"
},
{
"id": "token-issue-skips-parameter-conflict-check",
"file": "internal/token/issue.go",
"old": "if name, err := strictjson.CheckConflictingObject(parameters); err != nil {",
"new": "if name, err := strictjson.CheckConflictingObject(parameters); err != nil && false {",
"module": "root",
"packages": [
"./internal/token",
"./server"
],
"run": "^(TestIssueRefusesParametersItsParsersRefuse|TestExchangeAuthorizationCodeRefusesConflictingIdentityClaims)$",
"why": "ID tokens and JWT access tokens are never signed with parameters their parsers refuse as repeating a member"
},
{
"id": "requestobject-create-skips-conflict-check",
"file": "internal/requestobject/create.go",
"old": "if name, err := strictjson.CheckConflictingObject(claims); err != nil {",
"new": "if name, err := strictjson.CheckConflictingObject(claims); err != nil && false {",
"module": "root",
"packages": [
"./internal/requestobject"
],
"run": "^TestCreateRefusesParametersParseRefuses$",
"why": "a request object is never signed with parameters Parse refuses as repeating a member"
},
{
"id": "server-sign-userinfo-skips-conflict-check",
"file": "server/userinfo.go",
"old": "if name, err := strictjson.CheckConflictingObject(claims); err != nil {",
"new": "if name, err := strictjson.CheckConflictingObject(claims); err != nil && false {",
"module": "root",
"packages": [
"./server"
],
"run": "^TestSignUserInfoResponseRefusesConflictingMembers$",
"why": "SignUserInfoResponse refuses claims repeating a member with differing copies or as a case variant"
},
{
"id": "server-claims-parameter-skips-conflict-check",
"file": "server/claims_parameter.go",
"old": "if err := strictjson.CheckConflictingMembers(object); err != nil {",
"new": "if err := strictjson.CheckConflictingMembers(object); err != nil && false {",
"module": "root",
"packages": [
"./server"
],
"run": "^(TestValidateClaimsParameter|TestMalformedClaimsParameterIsRefused)$",
"why": "a plain claims parameter repeating a member with differing copies or as a case variant is invalid_request"
},
{
"id": "serverresource-userinfo-claims-skip-conflict-check",
"file": "serverresource/userinfo.go",
"old": "if name, err := strictjson.CheckConflictingObject(claims); err != nil {",
"new": "if name, err := strictjson.CheckConflictingObject(claims); err != nil && false {",
"module": "root",
"packages": [
"./serverresource"
],
"run": "^TestUserInfoClaimsRefusesConflictingMembers$",
"why": "UserInfoClaims refuses source claims repeating a member with differing copies or as a case variant"
},
{
"id": "federation-resolve-response-skips-conflict-check",
"file": "federation/resolve_issue.go",
"old": "if entityType, err := strictjson.CheckConflictingObject(metadata); err != nil {",
"new": "if entityType, err := strictjson.CheckConflictingObject(metadata); err != nil && false {",
"module": "root",
"packages": [
"./federation"
],
"run": "^TestResolveIssuerResponseRefusesConflictingMetadata$",
"why": "ResolveIssuer.Response refuses metadata repeating a member with differing copies or as a case variant"
},
{
"id": "client-authorization-details-skip-repeat-check",
"file": "client/begin_authorization.go",
"old": "if json.Valid(detail) && strictjson.CheckDuplicateMembers(detail) != nil {",
"new": "if json.Valid(detail) && strictjson.CheckDuplicateMembers(detail) != nil && false {",
"module": "root",
"packages": [
"./client"
],
"run": "^TestAuthorizationDetailsRefusedWithRepeatedMembers$",
"why": "the client refuses AuthorizationDetails entries repeating a member name"
},
{
"id": "client-begin-authorization-skips-details-check",
"file": "client/begin_authorization.go",
"old": "if detailsErr := checkAuthorizationDetails(req.AuthorizationDetails); detailsErr != nil {",
"new": "if detailsErr := checkAuthorizationDetails(req.AuthorizationDetails); detailsErr != nil && false {",
"module": "root",
"packages": [
"./client"
],
"run": "^TestAuthorizationDetailsRefusedWithRepeatedMembers$",
"why": "BeginAuthorization refuses AuthorizationDetails entries repeating a member name"
},
{
"id": "client-backchannel-skips-details-check",
"file": "client/backchannel.go",
"old": "if detailsErr := checkAuthorizationDetails(req.AuthorizationDetails); detailsErr != nil {",
"new": "if detailsErr := checkAuthorizationDetails(req.AuthorizationDetails); detailsErr != nil && false {",
"module": "root",
"packages": [
"./client"
],
"run": "^TestAuthorizationDetailsRefusedWithRepeatedMembers$",
"why": "BeginBackchannelAuthentication refuses AuthorizationDetails entries repeating a member name"
},
{
"id": "client-client-credentials-skips-details-check",
"file": "client/client_credentials.go",
"old": "if err := checkAuthorizationDetails(req.AuthorizationDetails); err != nil {",
"new": "if err := checkAuthorizationDetails(req.AuthorizationDetails); err != nil && false {",
"module": "root",
"packages": [
"./client"
],
"run": "^TestAuthorizationDetailsRefusedWithRepeatedMembers$",
"why": "RequestClientCredentialsToken refuses AuthorizationDetails entries repeating a member name"
}
]
2 changes: 2 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ jobs:
name: FuzzScanMembersMatchesWalker
- pkg: ./internal/strictjson
name: FuzzCheckConflictingMembersOneReading
- pkg: ./internal/strictjson
name: FuzzCheckConflictingObject
- pkg: ./extension
name: FuzzExtensionValueReadersAgree
- pkg: ./internal/sealedcookie
Expand Down
55 changes: 55 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,61 @@ Most production-assurance changes only affect `Config.Assurance =
AssuranceProduction`. A development-assurance setup built on `memstore`
and `keys/ephemeral` needs only the steps not marked *production only*.

## v0.88.1

### JSON you supply may not repeat a member with differing values (server, serverresource, federation, client)

**Affects:** an application whose own JSON values go into a token,
response or request this module signs or sends, when one of them
repeats a member name with differing copies, or as a case variant
(`{"sub":"a","sub":"b"}`, `{"kid":"a","KID":"a"}`), at any depth, or
when two of its claim names differ only in case (`roles` and `Roles`).
JSON that never repeats a name is unaffected, and so, except in
`authorization_details`, is a repeat whose copies are identical.

**Why:** since v0.87.0 this module's own readers refuse an ID token, JWT
access token, UserInfo response, request object or Resolve Response
carrying such a repeat, and other readers take different values from it
(one keeps the first copy, another the last, a case-insensitive one
merges the variants). A value carrying one could only ever produce a
token or document this module's own peers refuse and others read
inconsistently, so each is now refused where it is handed over.

**What fails:**

- `server.Server.CompleteAuthorization` and
`CompleteBackchannelAuthentication` refuse such a value, or such a pair
of names, in `GrantedAuthorization.IDTokenClaims` with
`invalid_request`, as they refuse invalid JSON there.
- A value an `IdentityClaimsSource` returns for an ID token fails the
token request (authorization code, refresh or CIBA) with
`server_error`, as an identity claim over the ID token claims budget
does. So does a grant stored before this release whose
`IDTokenClaims` carry one, or, with `JWTAccessTokens`, whose
requested UserInfo claim values do.
- `server.Server.SignUserInfoResponse` refuses such a claim with
`server_error`, and `serverresource.UserInfoClaims` returns an error
for one its claims source returns (a claim named `Sub` included,
beside the `sub` it sets).
- A plain (form) `claims` parameter at PAR or the backchannel
authentication endpoint carrying such a repeat is `invalid_request`,
as a request object carrying it already was.
- `federation.ResolveIssuer.Response` refuses `ResolvedEntity.Metadata`
carrying one. A `Resolver`'s own resolution never produces it.
- `client.Client.BeginAuthorization`, `BeginBackchannelAuthentication`
and `RequestClientCredentialsToken` refuse an `AuthorizationDetails`
entry that repeats a member name at all, identical copies included,
with `invalid_request`: a FAPIgo authorization server refuses any
repeat in `authorization_details`, and this client refuses one in a
token response. An `extension.Values` entry that would put such a
repeat in a request object (one named `Scope`, say, beside `scope`)
fails the request as an internal error instead of being signed.

**What to change:** build these values with `json.Marshal` from Go
values, or `extension.RARSet` for authorization details, which never
repeat a name, rather than by hand, and remove the repeat from any you
store.

## v0.88.0

### A DPoP proof is accepted only for the URL that received it (server)
Expand Down
53 changes: 53 additions & 0 deletions client/authorization_details_unescaped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,56 @@ func TestAuthorizationDetailsSentWithoutHTMLEscaping(t *testing.T) {
}
})
}

// TestAuthorizationDetailsRefusedWithRepeatedMembers covers every
// request that carries authorization_details: an entry repeating a
// member, or holding two that differ only in case, at any depth, is
// invalid_request before anything is sent — authorization servers would
// read it differently, and a FAPIgo server refuses it, identical copies
// included — while the same detail without the repeat is sent.
func TestAuthorizationDetailsRefusedWithRepeatedMembers(t *testing.T) {
plain := []json.RawMessage{json.RawMessage(`{"type":"payment_initiation","instructedAmount":{"amount":"1"}}`)}
for name, details := range map[string][]json.RawMessage{
"differing repeat": {json.RawMessage(`{"type":"payment_initiation","instructedAmount":{"amount":"1","amount":"1000"}}`)},
"identical repeat": {json.RawMessage(`{"type":"payment_initiation","type":"payment_initiation"}`)},
"case variant": {plain[0], json.RawMessage(`{"type":"a","actions":[{"x":1,"X":1}]}`)},
} {
for request, send := range authorizationDetailsRequests(t) {
if err := send(plain); err != nil {
t.Fatalf("%s without a repeat: %v", request, err)
}
if code := clientErrorCode(t, send(details)); code != client.ErrorInvalidRequest {
t.Errorf("%s, %s: error code = %q, want %q", request, name, code, client.ErrorInvalidRequest)
}
}
}
}

// authorizationDetailsRequests sends each request that carries
// authorization_details with the details given.
func authorizationDetailsRequests(t *testing.T) map[string]func([]json.RawMessage) error {
return map[string]func([]json.RawMessage) error{
"PAR form": func(details []json.RawMessage) error {
c, _, _ := newTestClient(t, false)
_, err := c.BeginAuthorization(context.Background(), client.BeginAuthorizationRequest{Scope: []string{"openid"}, AuthorizationDetails: details})
return err
},
"PAR request object": func(details []json.RawMessage) error {
c, _, _ := newTestClient(t, true)
_, err := c.BeginAuthorization(context.Background(), client.BeginAuthorizationRequest{Scope: []string{"openid"}, AuthorizationDetails: details})
return err
},
"CIBA request object": func(details []json.RawMessage) error {
c, _, _ := newTestClientWithCIBA(t)
_, err := c.BeginBackchannelAuthentication(context.Background(), client.BeginBackchannelAuthenticationRequest{
Scope: []string{"openid"}, LoginHint: "user@example.com", AuthorizationDetails: details,
})
return err
},
"client_credentials form": func(details []json.RawMessage) error {
c, _ := newTestClientForClientCredentials(t, nil)
_, err := c.RequestClientCredentialsToken(context.Background(), client.ClientCredentialsTokenRequest{Scope: []string{"accounts"}, AuthorizationDetails: details})
return err
},
}
}
8 changes: 7 additions & 1 deletion client/backchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ type BeginBackchannelAuthenticationRequest struct {
// with extension.RARSet, mirroring
// BeginAuthorizationRequest.AuthorizationDetails. Unlike PAR, CIBA
// always signs a request object, so this is embedded as native JSON
// unconditionally, with no plain-parameter path to consider.
// unconditionally, with no plain-parameter path to consider. An
// entry that repeats a member name, or holds two that differ only in
// case, is refused as invalid_request, as BeginAuthorizationRequest's
// is.
AuthorizationDetails []json.RawMessage

// Resource, when not empty, names the resource servers the access
Expand Down Expand Up @@ -304,6 +307,9 @@ func (c *Client) checkBackchannelAuthenticationRequest(req BeginBackchannelAuthe
if resourceErr := checkResources(req.Resource); resourceErr != nil {
return resourceErr
}
if detailsErr := checkAuthorizationDetails(req.AuthorizationDetails); detailsErr != nil {
return detailsErr
}
return nil
}

Expand Down
27 changes: 26 additions & 1 deletion client/begin_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ type BeginAuthorizationRequest struct {
// under every profile (RFC 9396 §2's own form-encoding: a plain
// "authorization_details" parameter's value is itself JSON array
// text, not a bare string), so it works under the baseline profile
// too, not just ProfileFAPISecurityWithMessageSigning.
// too, not just ProfileFAPISecurityWithMessageSigning. An entry that
// repeats a member name, or holds two that differ only in case, at
// any depth, is refused as invalid_request: authorization servers
// would read it differently from one another, and a FAPIgo server
// refuses it.
AuthorizationDetails []json.RawMessage

// Claims requests specific identity claims with the OIDC "claims"
Expand Down Expand Up @@ -787,6 +791,24 @@ func maxAgeSeconds(maxAge time.Duration) (int64, *Error) {
return seconds, nil
}

// checkAuthorizationDetails refuses an AuthorizationDetails entry that
// repeats a member name, or holds two that differ only in case, at any
// depth (strictjson.CheckDuplicateMembers), as invalid_request. An
// authorization server reading it with encoding/json keeps the last
// copy, another the first, so the two would grant different
// authorizations. A FAPIgo server refuses any such repeat in
// authorization_details, identical copies included, and so does this
// client in the authorization_details of a token response. An entry
// that isn't JSON at all is left to encoding the request to report.
func checkAuthorizationDetails(details []json.RawMessage) *Error {
for i, detail := range details {
if json.Valid(detail) && strictjson.CheckDuplicateMembers(detail) != nil {
return newError(ErrorInvalidRequest, fmt.Sprintf("AuthorizationDetails[%d] repeats a member name, or holds two that differ only in case", i), nil)
}
}
return nil
}

// checkBeginRequest checks what BeginAuthorization can before it does
// anything, and returns the redirect URI this authorization goes out
// with: Config.RedirectURI, or that with req.RedirectPort.
Expand All @@ -806,6 +828,9 @@ func (c *Client) checkBeginRequest(req BeginAuthorizationRequest) (string, *Erro
if resourceErr := checkResources(req.Resource); resourceErr != nil {
return "", resourceErr
}
if detailsErr := checkAuthorizationDetails(req.AuthorizationDetails); detailsErr != nil {
return "", detailsErr
}
if _, ok := extension.Snapshot(req.Extensions)[resourceParameter]; ok && len(req.Resource) > 0 {
return "", newError(ErrorInvalidRequest, `"resource" is set both as Resource and as an Extensions value: set it only as Resource`, nil)
}
Expand Down
Loading
Loading