fix(saml): exempt ACS endpoint from CSRF Origin enforcement#666
Merged
Conversation
The SAML POST binding delivers the assertion via an auto-submitting form from the IdP's own origin — a legitimate cross-origin POST the Origin allow-list always rejected with 403, making the shipped SAML SP unusable for real browser flows (found while building the with-org-saml example, verified live). ACS defends itself with XML signature validation, InResponseTo binding, and the replay cache — same rationale as the /oauth_callback/ exemption. Exemption is suffix-scoped to /acs; a regression test proves other /oauth/saml/ POSTs stay protected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Found while live-verifying the new
with-org-samlexample against a dockerized Keycloak IdP: the CSRF middleware has no exemption forPOST /oauth/saml/:org_slug/acs, so the IdP's auto-submitting form POST (SAML POST binding, IdP origin, form-urlencoded) gets403 csrf_validation_failed— the shipped SAML SP feature is unusable for real browser flows (headless scripts only worked by faking allow-listedOriginheaders).Fix
Exempt
/oauth/saml/*/acs(prefix + suffix scoped) from Origin enforcement — the same rationale as the existing/oauth_callback/exemption: the ACS handler defends itself with XML signature validation, InResponseTo binding, and the assertion replay cache; CSRF Origin checks cannot apply to a flow whose legitimate POST is always cross-origin.Testing
TestCSRFExemptsSAMLACS: cross-origin IdP form POST reaches the ACS handler; other/oauth/saml/POST routes (e.g./login) remain CSRF-protected — exemption doesn't leak.go build, gofmt clean.Related: the MAI follow-ups memory lists "SAML handler-level tests" as a deferred item — this is the first regression from that gap.