Sandor Molnar created KNOX-3611:
-----------------------------------

             Summary: KnoxIDF: federated login issues authorization codes 
without user consent
                 Key: KNOX-3611
                 URL: https://issues.apache.org/jira/browse/KNOX-3611
             Project: Apache Knox
          Issue Type: Bug
          Components: KnoxIDF
            Reporter: Sandor Molnar
            Assignee: Sandor Molnar
             Fix For: 3.1.0


h2. Problem

On the local login path, {{AuthorizeResource#authorize}} checks {{hasConsent}}. 
If the user hasn't consented yet and {{knoxidf.auto.consent.enabled}} is off, 
Knox redirects to {{/authConsent}}. The user then approves the client and its 
scopes, and only after that does Knox issue an authorization code.

The federated login path never gets to this check. When the external OP 
redirects back, {{AuthorizeResource#authCallback}} validates the OP's 
{{id_token}}, resolves the federated identity and calls {{getAuthCodeFromKnox}} 
right away. There's no consent check and no consent page. Federated login 
therefore acts as if {{knoxidf.auto.consent.enabled=true}}, whatever the 
topology says.

The user isn't asked anywhere in the flow:
* The Knox login page lists the federated OPs, but doesn't say which client is 
asking.
* Any consent screen at the external OP is about Knox, as the OP's client, 
getting the user's identity. It says nothing about the downstream Knox client 
or the Knox scopes it asked for.
* If the user already has a session at the OP, the OP usually redirects 
straight back to Knox without prompting.

h3. Impact

The local path's consent page exists to block consent phishing. On the 
federated path it can happen:
# An attacker registers a client with a {{redirect_uri}} they control.
# They send a victim an authorize link for that client.
# The victim picks an OP on the Knox login page.
# If the victim already has an OP session, the OP returns without a prompt.
# Knox issues an authorization code for the victim to the attacker's 
{{redirect_uri}}.
# The attacker redeems the code for Knox tokens carrying the victim's identity 
and the requested scopes.

What limits it:
* The client must be registered, and its {{redirect_uri}} must match the 
registered one.
* The federated OP access token isn't persisted or passed to the client.

So how serious this is depends on who may register clients. It is worst where 
registration is open to any authenticated user, or to anonymous users 
({{knoxidf.client.registration.anonymous.allowed}}).

h3. Documentation is inaccurate

The broker flow in {{knox-site/docs/knoxidf/federation.md}} (sequence diagram 
and step 1) says Knox "checks consent" when the client calls {{/authorize}}, 
before redirecting to the OP. That isn't what happens. Without a Knox session, 
{{SSOCookieFederationFilter}} redirects to the login page before 
{{authorize()}} runs. Consent records are also keyed by the Knox subject, and 
on this path the subject is only known after the callback resolves the 
federated identity.

h2. Proposed solution

Apply the same consent decision on the federated path as on the local one, 
after the federated identity is resolved in {{authCallback}}:
* *Consent check:* if {{hasConsent}} returns true for the resolved Knox 
subject, or auto-consent is enabled, issue the code as today. Otherwise, store 
the authorize request together with the resolved subject under a new single-use 
consent state, using the {{KnoxIDFAuthzFlowStateService}} from KNOX-3606. Then 
redirect to the consent page.
* *Accepting consent without a Knox session:* the user has no Knox session 
after a federated login. {{consentAccepted}} currently binds consent to 
{{SubjectUtils.getCurrentEffectivePrincipalName()}}, and the consent page and 
{{consentAccepted}} sit behind the SSO cookie provider. Options:
** *(a) Bind the consent state to the browser:* set a short-lived, HttpOnly, 
Secure cookie holding a random value. Store its hash with the consent state, 
and require a match when consent is accepted. This needs a federated consent 
page and an accept endpoint reachable without a Knox session. Don't open up the 
existing local {{consentAccepted}}, which depends on the session subject check.
** *(b) Establish a Knox SSO session* for the federated subject after the 
callback, and reuse the existing consent page. This is a bigger change, because 
it affects SSO semantics for every federated topology.
* *Single use and integrity:* consuming the federated consent state must be 
single-use cluster-wide, with the same guarantees as the local consent state. A 
request without the browser binding, or with the wrong one, must be rejected.
* *Consent denied:* return {{access_denied}} to the client's {{redirect_uri}} 
(RFC 6749 4.1.2.1), as on the local path.
* *Audit:* audit the federated consent prompt, grant and denial in the same way 
as the local path. Also, codes issued on the federated path are currently 
audited with {{subject=ANONYMOUS}}, because the stored authorize metadata has 
no subject on this path. Audit the resolved Knox subject instead.
* *Docs:* correct the broker flow in {{federation.md}}, and say that 
{{knoxidf.auto.consent.enabled}} applies to federated logins.

h2. Workaround

Until this is fixed:
* Limit client registration on federated topologies to administrators. Don't 
allow anonymous or self-service registration.
* Treat federated login as auto-consent: only register clients that are trusted 
to receive tokens without asking the user.

h2. Acceptance criteria

* With {{knoxidf.auto.consent.enabled=false}}, a federated login for a client 
the user hasn't consented to shows the consent page before Knox issues any 
authorization code.
* After consent is accepted, later federated logins for the same client, 
subject and scopes skip the consent page, as on the local path.
* With {{knoxidf.auto.consent.enabled=true}}, the federated flow behaves as 
today.
* Each federated consent state is single-use. It can't be accepted from another 
browser or replayed, and an expired state is rejected.
* Denying consent redirects to the client with {{error=access_denied}}, and 
Knox issues no code.
* Federated code issuance and the consent events are audited with the resolved 
Knox subject.
* {{federation.md}} describes the actual flow.
* Unit tests cover the callback's consent decision. The federation integration 
tests (the {{test-federation}} label) cover consent prompt, grant and deny.




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

Reply via email to