[
https://issues.apache.org/jira/browse/KNOX-3601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18153529#comment-18153529
]
ASF subversion and git services commented on KNOX-3601:
-------------------------------------------------------
Commit 28e818c1589c97be383c61ca95041ac5a02dc829 in knox's branch
refs/heads/v3.0.x from Sandor Molnar
[ https://gitbox.apache.org/repos/asf?p=knox.git;h=28e818c15 ]
KNOX-3601: Reject CLIENTID client secrets presented as access tokens (#1532)
(cherry picked from commit eaca05a8c1abb15ff99cb3cc8cca384ab33ff0e7)
> JWTFederationFilter accepts a CLIENT_ID client_secret as a direct access token
> ------------------------------------------------------------------------------
>
> Key: KNOX-3601
> URL: https://issues.apache.org/jira/browse/KNOX-3601
> Project: Apache Knox
> Issue Type: Improvement
> Components: JWT, KnoxIDF
> Reporter: Sandor Molnar
> Assignee: Sandor Molnar
> Priority: Major
> Fix For: 3.1.0
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> h3. Problem
> Client secrets minted by the CLIENTID service are stored in TokenStateService
> as server-managed passcodes (TokenMetadataType CLIENT_ID). They use the same
> encoded form as API keys: Base64(Base64(tokenId)::Base64(passcode)). On a
> topology with {{{}knox.token.exp.server-managed=true{}}}, JWTFederationFilter
> accepts that secret as {{Authorization: Bearer <client_secret>}} (or
> {{{}Basic Passcode:<client_secret>{}}}) and establishes a full session. The
> intended OAuth flow is mint -> client_credentials grant -> short-lived JWT,
> but here the secret itself works as the access token.
> This does not grant extra privileges, because the subject and roles are the
> same as for the exchanged JWT. It does mean the long-lived secret travels on
> every API call instead of only to the token endpoint, which increases the
> chance of it leaking.
> h3. Steps to reproduce
> # Mint credentials via the CLIENTID API.
> # Call a protected resource on a server-managed JWTProvider topology with
> {{{}Authorization: Bearer <client_secret>{}}}, without calling the token
> endpoint -> 200 as the credential owner.
> # {{client_id}} alone as Bearer -> 401 (expected).
> # After revoke, the same Bearer secret -> 401 (expected).
> # {{grant_type=client_credentials}} with client_id/client_secret (body or
> Basic) -> JWT issued (expected, must keep working).
> h3. Root cause
> In the passcode branch of JWTFederationFilter.doFilter, validateToken()
> checks expiry, enabled state, idle timeout and the passcode, and
> createSubjectFromTokenIdentifier() builds the subject. Neither one
> distinguishes CLIENT_ID from API_KEY metadata when the passcode is the
> caller's own credential.
> h3. Proposed fix
> * After passcode validation succeeds, reject (401) a CLIENT_ID passcode
> unless parseWireToken read it from a client_credentials grant (body
> {{{}client_secret{}}}, or Basic {{<client_id>:<secret>}} with
> {{{}grant_type=client_credentials{}}}). Bearer and Basic {{Passcode:}} are
> both rejected.
> * Record that provenance during parsing, as WireToken already does. Do not
> re-derive it later from {{{}request.getParameter("grant_type"){}}}: otherwise
> {{?grant_type=client_credentials}} on a Bearer request would bypass the check.
> * Apply the check to all CLIENT_ID metadata, regardless of the thirdPartyApp
> flag.
> * Add a provider param, e.g.
> {{knox.token.allow.client.secret.as.access.token}} (default false). Setting
> it to true restores the current behavior for compatibility.
> * Leave API_KEY passcodes, JWT bearer tokens, refresh_token and
> token-exchange unchanged.
> h3. Acceptance criteria
> * CLIENT_ID passcode presented as Bearer or Basic {{Passcode}} -> 401 with a
> clear message (e.g. "exchange client credentials for an access token first").
> * Same request with a {{grant_type=client_credentials}} query param -> still
> 401.
> * client_credentials grant with client_id/client_secret (body or Basic) ->
> 200 + JWT.
> * API_KEY passcode as Bearer -> 200 (unchanged).
> * JWT Bearer -> 200 (unchanged).
> * Opt-in param set to true -> CLIENT_ID passcode as Bearer accepted (current
> behavior).
> * Unit tests cover each case above.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)