Sandor Molnar created KNOX-3601:
-----------------------------------
Summary: 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
Fix For: 3.1.0
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)