Skip to content

endpoints/agent: return 400 instead of 500 for invalid Platform SSO token requests - #24588

Merged
PeshekDotDev merged 1 commit into
mainfrom
endpoints/agent-psso-token-errors
Jul 31, 2026
Merged

PeshekDotDev merged 1 commit into
mainfrom
endpoints/agent-psso-token-errors

Conversation

@PeshekDotDev

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

Two error-handling fixes in the Platform SSO token endpoint:

  • validate_request_token() used the result of a .first() lookup without checking it. An
    assertion whose kid matches no AgentDeviceConnection raised
    AttributeError: 'NoneType' object has no attribute 'connector'. It now logs the
    unmatched key ID and returns None, and post() turns that into a 400.
  • TokenView is a plain Django View, so DRF's exception handler never runs and the
    ValidationErrors raised throughout the class escaped as HTTP 500. A dispatch()
    override now catches them and returns 400.

Why is this change needed?

Both cases are client errors — an unknown key ID, a device with no Secure Enclave key
registered, a replayed nonce — but they surfaced as 500s. That points debugging at the
server rather than at the device's registration state, and it makes them indistinguishable
from genuine faults in logs and monitoring.

How was this tested?

Observed against a live macOS 26.6 device with authentik Agent 0.50.5: a device whose
binding carried no enclave key produced
POST /endpoints/agent/psso/token/ -> 500 with ValidationError('Invalid request'), from
Could not find device user binding or independent enclave for user.

Two regression tests were added to TestAppleToken: one for an assertion signed with an
unknown kid, one for a device with no enclave key registered. Both assert 400.

Linked issues


Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)

@PeshekDotDev
PeshekDotDev requested a review from BeryJu July 31, 2026 16:52
@PeshekDotDev PeshekDotDev self-assigned this Jul 31, 2026
@PeshekDotDev
PeshekDotDev requested a review from a team as a code owner July 31, 2026 16:52
@PeshekDotDev PeshekDotDev added the backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 label Jul 31, 2026
@PeshekDotDev PeshekDotDev added the backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 label Jul 31, 2026
@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 6764c57
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a6cd2b67ed43200088251ba
😎 Deploy Preview https://deploy-preview-24588--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.

@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 6764c57
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a6cd2b6c0854800088a7b4e
😎 Deploy Preview https://deploy-preview-24588--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 Jul 31, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 6764c57
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a6cd2b6cc66ce00081fadef
😎 Deploy Preview https://deploy-preview-24588--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 Jul 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.16%. Comparing base (00c751d) to head (6764c57).
⚠️ Report is 12 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24588      +/-   ##
==========================================
- Coverage   91.20%   91.16%   -0.04%     
==========================================
  Files        1128     1128              
  Lines       70501    70526      +25     
  Branches     3798     3798              
==========================================
- Hits        64302    64297       -5     
- Misses       6164     6194      +30     
  Partials       35       35              
Flag Coverage Δ
conformance 35.16% <7.69%> (-0.02%) ⬇️
e2e 39.94% <7.69%> (-0.03%) ⬇️
integration 31.25% <7.69%> (-0.48%) ⬇️
rust 37.78% <ø> (ø)
unit 92.88% <100.00%> (+<0.01%) ⬆️
unit-migrate 92.91% <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 Harness.
📢 Have feedback on the report? Share it here.

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core Jul 31, 2026
@PeshekDotDev
PeshekDotDev enabled auto-merge (squash) July 31, 2026 17:16
@PeshekDotDev
PeshekDotDev merged commit a30fd62 into main Jul 31, 2026
125 checks passed
@PeshekDotDev
PeshekDotDev deleted the endpoints/agent-psso-token-errors branch July 31, 2026 17:18
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Jul 31, 2026
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

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

@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.8 created: #24593

@github-actions

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-6764c57577c78ae8065fdc47ba410f8ff9d34ee7
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-6764c57577c78ae8065fdc47ba410f8ff9d34ee7

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

PeshekDotDev added a commit that referenced this pull request Jul 31, 2026
…oken requests (cherry-pick #24588 to version-2026.8) (#24593)

endpoints/agent: return 400 instead of 500 for invalid Platform SSO token requests (#24588)

Co-authored-by: Connor Peshek <[email protected]>
PeshekDotDev added a commit that referenced this pull request Jul 31, 2026
…oken requests (cherry-pick #24588 to version-2026.5) (#24592)

endpoints/agent: return 400 instead of 500 for invalid Platform SSO token requests (#24588)

Co-authored-by: Connor Peshek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants