Skip to content

Treat a malformed username domain as no matching organization - #53122

Open
cipherprofessor wants to merge 1 commit into
keycloak:mainfrom
cipherprofessor:fix-53100-malformed-org-domain
Open

cipherprofessor wants to merge 1 commit into
keycloak:mainfrom
cipherprofessor:fix-53100-malformed-org-domain

Conversation

@cipherprofessor

Copy link
Copy Markdown

Closes #53100

A malformed domain in the username at the organization identity-first step (user@example;com, user@example.com., and so on) made getByDomainName() throw ModelValidationException, and the user got the generic error page. With this change it's treated as no matching organization, the way LoginActionsService.configureOrganization() already handles broker emails, so the flow continues to the password step as it did in 26.6.

The catch is only at the lookup in Organizations.resolveOrganization. Admin-side domain validation is unchanged. The same line also covers the untrimmed login_hint path and users whose stored email has a malformed domain.

Tests added to OrganizationAuthenticationTest: the five typo shapes from the issue, the organization-without-domain case, and login_hint. They fail without the fix and pass with it.

AI disclosure: this change (code and tests) was produced with Claude Code (an AI agent) from a prompt, then reviewed and verified locally.

A typo in the domain part of the username at the organization
identity-first step made getByDomainName() throw
ModelValidationException, which ended in the generic error page instead
of continuing to the password step. Treat it as no match, as
LoginActionsService already does for broker emails.

Closes keycloak#53100

Signed-off-by: Mohsin Manzoor Bhat <mohsinmanzoor1913@gmail.com>
@cipherprofessor
cipherprofessor requested a review from a team as a code owner September 23, 2026 15:43
Copilot AI balanced review requested due to automatic review settings September 23, 2026 15:43

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified, and the regression paths are covered by tests.

Review effort: Balanced
Findings: None

What changed in this PR

Treats malformed username domains as having no matching organization, allowing authentication to continue normally.

Changes:

  • Handles domain validation failures as lookup misses.
  • Adds regression coverage for malformed domains, login_hint, and organizations without domains.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​organization/​authentication/​OrganizationAuthenticationTest.java Tests malformed-domain authentication scenarios.
services/​src/​main/​java/​org/​keycloak/​organization/​utils/​Organizations.java Converts invalid domain lookup failures into no-match results.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Organizations: malformed domain in login username (e.g. user@example;com) causes unhandled ModelValidationException ('Invalid domain format')

2 participants