Skip to content

fix: Reject SAML logins without an email and default the SAML email mapping (OHE-4202) - #1447

Merged
tofarr merged 1 commit into
mainfrom
saml-require-email-and-default-mapping
Nov 18, 2026
Merged

tofarr merged 1 commit into
mainfrom
saml-require-email-and-default-mapping

Conversation

@tofarr

@tofarr tofarr commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

  • A human has tested these changes.

I tested locally - see screenshots and video.

AGENT:


Why

A SAML provider with no email mapping (and a non-email NameID, e.g. Keycloak's persistent G-<uuid>) logs users in with email=None. UserStore.create_user then creates the personal org with contact_email=NULL, and /api/organizations fails with a 500 (OrgResponse.contact_email is a required str). The admin sees a generic "Could not load your workspaces" error and nothing points at the provider config.

Summary

  • saml_acs now returns a 400 when no email can be resolved (mapped attribute or email-typed NameID), before any user/org is created. The message tells the admin to map the IdP's email attribute; a warning log lists the attribute names the assertion carried.
  • The SAML preset in the super-admin "create provider" flow now defaults attribute_mapping to { email: "email" }.
  • Existing providers are not modified; the login guard covers them. Linked users whose assertions have no email are now rejected with the 400 instead of hitting the 500 later.

Issue Number

N/A

How to Test

  • uv run pytest tests/unit/server/routes/test_saml_routes.py (26 pass; run with --noconftest in a sandbox with no Docker, since these tests mock the stores)
  • cd frontend && npx vitest run __tests__/components/features/super-admin/super-admin-auth-providers.test.tsx __tests__/components/features/super-admin/super-admin-auth-provider-edit.test.tsx (72 pass)
  • Manually: create a SAML provider from the preset and confirm the attribute mapping field is prefilled with email=email. Clear it, log in with an IdP that sends a persistent NameID, and confirm the ACS returns the 400 instead of creating a user.

The root cause was found on app.shared-2.replicated.all-hands-testing.dev, where adding {"email": "email"} to the provider fixed login.

Video/Screenshots

New SAML Idps set up their attribute mappings to include email by default and SAML Works...

Screen.Recording.2026-11-18.at.4.05.34.PM.mov

If I deliberately break it...

image

Then I get an error on login...

image

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • Not addressed here: OrgResponse.contact_email still rejects None, and the "Could not load your workspaces" wording lives in the Agent Canvas SPA (OpenHands/OpenHands).
  • The OAuth v2 callback path has the same no-email gap; left out of scope.

This PR was created by an AI agent (OpenHands) on behalf of Tim.

@tofarr can click here to continue refining the PR


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-cf38b87

Co-authored-by: openhands <openhands@all-hands.dev>
@tofarr tofarr changed the title Reject SAML logins without an email and default the SAML email mapping Reject SAML logins without an email and default the SAML email mapping (OHE-4202) Nov 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  server/routes
  saml.py 337-343
Project Total  

This report was generated by python-coverage-comment-action

@tofarr
tofarr marked this pull request as ready for review November 18, 2026 16:13
@tofarr tofarr changed the title Reject SAML logins without an email and default the SAML email mapping (OHE-4202) fix: Reject SAML logins without an email and default the SAML email mapping (OHE-4202) Nov 18, 2026
@github-actions github-actions Bot added the type: fix A bug fix label Nov 18, 2026

@hieptl hieptl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙏

@tofarr
tofarr merged commit 3d5e48c into main Nov 18, 2026
34 of 38 checks passed
@tofarr
tofarr deleted the saml-require-email-and-default-mapping branch November 18, 2026 16:17
@openhands-release-bot openhands-release-bot Bot added the released: 1.95.0 Shipped in 1.95.0 label Nov 19, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.95.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.95.0 Shipped in 1.95.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants