Skip to content

providers/saml: handle XML declarations in unified endpoint - #22455

Merged
dominic-r merged 4 commits into
mainfrom
sdko/fix-saml-unified-xml-declaration
May 21, 2026
Merged

dominic-r merged 4 commits into
mainfrom
sdko/fix-saml-unified-xml-declaration

Conversation

@dominic-r

Copy link
Copy Markdown
Member

Summary

  • Normalize decoded redirect-binding SAML requests to bytes before the unified endpoint parses them with lxml.
  • Add regression coverage for redirect-binding AuthnRequest and LogoutRequest payloads that include XML declarations.

RCA

The unified SAML endpoint decodes redirect-binding SAMLRequest payloads with decode_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 to defusedxml.lxml.fromstring() raises before authentik can identify the message type. The broad exception handler then reports Unsupported SAML message type: unknown instead 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.py
  • uv run ruff check authentik/providers/saml/views/unified.py authentik/providers/saml/tests/test_views_unified.py

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]>
@dominic-r
dominic-r requested a review from a team as a code owner May 19, 2026 01:13
@dominic-r dominic-r self-assigned this May 19, 2026
@dominic-r
dominic-r requested a review from PeshekDotDev May 19, 2026 01:13
@netlify

netlify Bot commented May 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 5852e1b
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a0f0615223eaf0008f8aa26
😎 Deploy Preview https://deploy-preview-22455--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dominic-r dominic-r added area:backend backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 labels May 19, 2026
@netlify

netlify Bot commented May 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 5852e1b
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a0f0615f080020008518414
😎 Deploy Preview https://deploy-preview-22455--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 5852e1b
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a0f0615c66d16000827e760
😎 Deploy Preview https://deploy-preview-22455--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented May 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.29%. Comparing base (a04911c) to head (5852e1b).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ
conformance 36.60% <0.00%> (-0.01%) ⬇️
e2e 41.85% <15.38%> (-0.01%) ⬇️
integration 33.04% <0.00%> (-0.01%) ⬇️
rust 0.00% <ø> (ø)
unit 92.22% <100.00%> (+0.01%) ⬆️
unit-migrate 92.27% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

authentik PR Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

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)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

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-5852e1b70a174fe3d28ffdc79415a139cc11e8a4

Afterwards, 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]>
@dominic-r
dominic-r enabled auto-merge (squash) May 20, 2026 02:07
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core May 21, 2026
@dominic-r
dominic-r merged commit 495076a into main May 21, 2026
162 of 164 checks passed
@dominic-r
dominic-r deleted the sdko/fix-saml-unified-xml-declaration branch May 21, 2026 16:37
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core May 21, 2026
@authentik-automation

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.5 created: #22539

PeshekDotDev pushed a commit that referenced this pull request May 21, 2026
…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]>
kensternberg-authentik added a commit that referenced this pull request May 21, 2026
* 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)
  ...
smirnovsten pushed a commit to smirnovsten/authentik that referenced this pull request Aug 5, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants