Repository navigation
providers/saml: handle XML declarations in unified endpoint - #22455
Conversation
The unified SAML endpoint decodes redirect-binding payloads to a Unicode string and then passes that string to lxml. When an SP sends an XML declaration with an encoding, lxml raises before authentik can detect whether the message is an AuthnRequest or LogoutRequest, and the endpoint reports an unknown SAML message type. Encode decoded redirect payloads back to bytes before XML parsing so lxml can honor the declaration. Add regression coverage for redirect-binding AuthnRequest and LogoutRequest payloads with XML declarations. Validation: .venv/bin/python -m pytest authentik/providers/saml/tests/test_views_unified.py; uv run ruff check authentik/providers/saml/views/unified.py authentik/providers/saml/tests/test_views_unified.py Agent-thread: https://sdko.org/internal/threads/019e3d5c-1579-7533-813c-1d7da8b7b01b Co-authored-by: Agent <[email protected]>
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22455 +/- ##
=======================================
Coverage 93.29% 93.29%
=======================================
Files 1032 1033 +1
Lines 60062 60075 +13
Branches 400 400
=======================================
+ Hits 56032 56047 +15
+ Misses 4030 4028 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
authentik PR Installation instructions Instructions for docker-composeAdd the following block to your AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-5852e1b70a174fe3d28ffdc79415a139cc11e8a4
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)sAfterwards, run the upgrade commands from the latest release notes. Instructions for KubernetesAdd the following block to your authentik:
outposts:
container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
image:
repository: ghcr.io/goauthentik/dev-server
tag: gh-5852e1b70a174fe3d28ffdc79415a139cc11e8a4Afterwards, run the upgrade commands from the latest release notes. |
Move the inline SAML request XML into fixtures so the unified endpoint tests use reusable request bodies while preserving XML declaration coverage. Agent-thread: https://sdko.org/internal/threads/019e431d-86e3-7200-8079-e8bcb390183b Co-authored-by: Agent <[email protected]>
|
🍒 Cherry-pick to |
…ick #22455 to version-2026.5) (#22539) providers/saml: handle XML declarations in unified endpoint (#22455) * providers/saml: handle XML declarations in unified endpoint The unified SAML endpoint decodes redirect-binding payloads to a Unicode string and then passes that string to lxml. When an SP sends an XML declaration with an encoding, lxml raises before authentik can detect whether the message is an AuthnRequest or LogoutRequest, and the endpoint reports an unknown SAML message type. Encode decoded redirect payloads back to bytes before XML parsing so lxml can honor the declaration. Add regression coverage for redirect-binding AuthnRequest and LogoutRequest payloads with XML declarations. Validation: .venv/bin/python -m pytest authentik/providers/saml/tests/test_views_unified.py; uv run ruff check authentik/providers/saml/views/unified.py authentik/providers/saml/tests/test_views_unified.py Agent-thread: https://sdko.org/internal/threads/019e3d5c-1579-7533-813c-1d7da8b7b01b * providers/saml: Use fixtures for unified request tests Move the inline SAML request XML into fixtures so the unified endpoint tests use reusable request bodies while preserving XML declaration coverage. Agent-thread: https://sdko.org/internal/threads/019e431d-86e3-7200-8079-e8bcb390183b --------- Co-authored-by: Dominic R <[email protected]> Co-authored-by: Agent <[email protected]>
* main: (28 commits) events: fix certificate typo (#22542) website/release: Release notes updates (#22543) providers/saml: handle XML declarations in unified endpoint (#22455) web: bump @sentry/browser from 10.52.0 to 10.53.1 in /web in the sentry group across 1 directory (#22472) core: bump library/golang from 1.26.2-trixie to 1.26.3-trixie in /lifecycle/container (#22516) core: bump sentry-sdk from 2.59.0 to 2.60.0 (#22513) core: bump github.com/go-openapi/runtime from 0.29.5 to 0.30.0 (#22511) core: bump djangorestframework-stubs[compatible-mypy] from 3.16.9 to 3.17.0 (#22512) website/docs: release notes: add absorb lms to integrations (#22534) core: bump library/node from 24 to 26 in /lifecycle/container (#22517) website/docs: document npm install-script blocking (#22461) ci: add dependency-review workflow (#22464) root: bind-mount .npmrc into Dockerfile npm ci stages (#22462) website/docs: add global to values.yaml snippets and update version (#22524) website/integrations: add absorb LMS (#22328) core: bump astral-sh/uv from 0.11.5 to 0.11.15 in /lifecycle/container (#22515) core: bump library/nginx from 1.29-trixie to 1.31-trixie in /website (#22520) ci: bump codecov/codecov-action from 6.0.0 to 6.0.1 in /.github/actions/test-results (#22522) core: bump aws-cdk-lib from 2.253.1 to 2.254.0 (#22514) core: bump goauthentik/fips-python from 3.14.3-slim-trixie-fips to 3.14.5-slim-trixie-fips in /lifecycle/container (#22518) ...
…tik#22455) * providers/saml: handle XML declarations in unified endpoint The unified SAML endpoint decodes redirect-binding payloads to a Unicode string and then passes that string to lxml. When an SP sends an XML declaration with an encoding, lxml raises before authentik can detect whether the message is an AuthnRequest or LogoutRequest, and the endpoint reports an unknown SAML message type. Encode decoded redirect payloads back to bytes before XML parsing so lxml can honor the declaration. Add regression coverage for redirect-binding AuthnRequest and LogoutRequest payloads with XML declarations. Validation: .venv/bin/python -m pytest authentik/providers/saml/tests/test_views_unified.py; uv run ruff check authentik/providers/saml/views/unified.py authentik/providers/saml/tests/test_views_unified.py Agent-thread: https://sdko.org/internal/threads/019e3d5c-1579-7533-813c-1d7da8b7b01b Co-authored-by: Agent <[email protected]> * providers/saml: Use fixtures for unified request tests Move the inline SAML request XML into fixtures so the unified endpoint tests use reusable request bodies while preserving XML declaration coverage. Agent-thread: https://sdko.org/internal/threads/019e431d-86e3-7200-8079-e8bcb390183b Co-authored-by: Agent <[email protected]> --------- Co-authored-by: Agent <[email protected]>
Summary
RCA
The unified SAML endpoint decodes redirect-binding
SAMLRequestpayloads withdecode_base64_and_inflate(), which returns a Unicode string. Some service providers include an XML declaration with an encoding, for example<?xml version="1.0" encoding="UTF-8"?>. Passing that Unicode string directly todefusedxml.lxml.fromstring()raises before authentik can identify the message type. The broad exception handler then reportsUnsupported SAML message type: unknowninstead of routing the request to SSO or SLO handling.Encoding the decoded XML back to bytes before parsing lets lxml consume the declaration correctly and keeps the existing SSO/SLO delegation behavior intact.
Context
Slack: https://authentiksecurity.slack.com/archives/D09DHA650QH/p1779152665243569
Validation
.venv/bin/python -m pytest authentik/providers/saml/tests/test_views_unified.pyuv run ruff check authentik/providers/saml/views/unified.py authentik/providers/saml/tests/test_views_unified.py