Sandor Molnar created KNOX-3626:
-----------------------------------

             Summary: KnoxIDF: Allow the refresh_token grant without 
client_secret for public (PKCE) clients
                 Key: KNOX-3626
                 URL: https://issues.apache.org/jira/browse/KNOX-3626
             Project: Apache Knox
          Issue Type: Improvement
          Components: KnoxIDF
            Reporter: Sandor Molnar
            Assignee: Sandor Molnar
             Fix For: 3.1.0


h3. Problem
The KnoxIDF authorization server metadata advertises {{"none"}} in 
{{token_endpoint_auth_methods_supported}}, and the authorization_code grant 
honours it: a client that presents a valid PKCE {{code_verifier}} gets tokens 
without a {{client_secret}} ({{TokenResource#validateAuthCode}}).

The refresh_token grant does not honour it. 
{{TokenResource#validateRefreshTokenGrant}} always calls 
{{isValidClientSecret}}, which returns false for a blank secret, so every 
secretless refresh fails with {{invalid_grant}} ("Invalid grant: client 
authentication failed", audited as {{reason=validation_failed}}).

Per RFC 8414, {{token_endpoint_auth_methods_supported}} describes the token 
endpoint as a whole, not individual grants. A public client that relies on the 
advertised {{"none"}} method therefore connects successfully, then loses access 
when its first access token expires (after {{knoxidf.knox.token.ttl}}), because 
it can never refresh.

h3. Steps to reproduce
# Register a client via KnoxIDF client registration.
# Use it as a public client: authorization_code + PKCE (S256), no 
{{client_secret}}. The token request succeeds and returns an access token and a 
refresh token.
# Call the token endpoint with {{grant_type=refresh_token}}, {{client_id}} and 
the refresh token, without {{client_secret}}.

*Expected:* new access token and rotated refresh token.
*Actual:* HTTP 400 {{invalid_grant}}. The refresh token is valid (enabled, not 
expired, matching {{client_id}}).

Workaround: send the {{client_secret}} from the registration response as 
{{client_secret_post}} on the refresh call.

h3. Proposed fix
Removing the secret check unconditionally is not acceptable: it guards against 
redeeming a stolen refresh token from a confidential client, since the 
JWTFederationFilter Bearer path forwards to the token endpoint without checking 
{{client_secret}}. Instead, bind the client-authentication method to the 
refresh token server-side:
# On the authorization_code grant, record how the client authenticated (PKCE 
only vs. {{client_secret}}) in the issued refresh token's metadata, e.g. 
{{client_auth=none|client_secret_post}}.
# On the refresh_token grant, skip {{isValidClientSecret}} only when the 
presented refresh token's stored metadata says {{none}}; otherwise keep 
requiring the secret. Carry the value forward on every rotation.
# Never derive this from a request parameter, so a refresh token from a 
secret-authenticated chain cannot be downgraded to secretless redemption.

Behaviour for confidential clients is unchanged. Do not remove {{"none"}} from 
the metadata: the PKCE-only authorization_code path is correct and used.

h3. Related hardening (can be split out)
RFC 9700 ยง4.14.2 allows secretless refresh for public clients when refresh 
tokens are sender-constrained or rotated with reuse detection. KnoxIDF already 
rotates refresh tokens single-use ({{consumeToken}}), but a replayed token only 
gets {{invalid_grant}}; the descendant token stays valid. Revoking the 
refresh-token chain on detected reuse would make the public-client path fully 
compliant.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to