Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The current implementation for SAML SSO cannot handle IDP initiated SSO. The SAML callback handler (in SAML speak: ACS - Assertion Consumer Service) assumes a state (in SAML speak: RelayState) that is created by the Hanko backend and reflected in the callback response from the IDP on SP initated SSO only.
Implementation
Changes to the SAML Relay State on SP initiated flows
Changes to the SAML callback handler
github.com/russellhaering/gosaml2
library. But the SAML core specification and SAML security considerations indicate that we also should prohibit using SP initated responses as unsolicited IDP responses and replay of (IDP initiated) SAML responses. Both of these measures require access to some nodes/values of the SAML response that the above mentioned library unfortunately does not provide in an easily accessible manner through its API. As a result these changes parse the response in addition to the parsing (and validation) done by the library to extract information that help implement these protections.Protecting against SP initated response use
InResponseTo
attribute. If it does, then we assume it originates from a SP initated flow and hence should not be accepted.Protecting against replay attacks
saml_idp_initated_requests
is added for this purpose. It stores the ID of a SAML response and the issuer/provider entity ID discernible from the response. For any incoming IDP initated request, the ID attribute of the root SAML Response node is extracted. Thesaml_idp_initated_requests
is queried for this ID and the response issuer/provider entity ID. If an entry already exists the request is considered a replay. If it is not a new record in the table is persisted.Changes to SAML callback redirect URL
saml_hint
to indicate that the token exchange occurs in an IDP initated flow context.Hanko elements uses this hint to initiate a token exchange flow (see next section for this new flow).
Changes to built-in flows
thirdparty
state offering only anExchangeToken
action. A handler for this flow is only applied if SAML is enabled in the configuration.Changes to Hanko Elements
saml_hint
to determine if it must initialize and advance the new token exchange flow.Changes to ExchangeToken action
Email.RequireVerification
configuration. But the current implementation of theExchangeToken
action only checks the latter configuration in order to determine if a verification is required after exchaning a token. These changes modify the behaviour so that if the SAML provider for the identity is configured withskip_email_verification
set totrue
no email verification process is triggered.How to test
You can use https://mocksaml.com for testing locally without having to configure "real" IDP.
Start the backend with the following configuration:
or to test email verification changes:
Start an example app from the
frontend/examples
folder.Trigger SP initiated login by entering an email address with the configured domain as a login identifier in the frontend example app or go to https://mocksaml.com, click "Test IdP Login" and then provide
http://localhost:8000/saml/callback
as theACS URL
andhttp://localhost:8000
as theAudience
.