mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-18 11:15:12 +00:00
fix(login): resolve unknownContext error on password page caused by inconsistent ignoreUnknownUsernames handling (#12512)
# Which Problems Are Solved The `/password` page (and related password pages) can show the `unknownContext` error even though the user was resolved correctly and login completes fine. Two causes: 1. `sendLoginname` used two different `ignoreUnknownUsernames` sources: session creation was gated on the **user's org** login settings, while the redirect's `loginName` masking and enumeration guards were gated on a **caller-supplied flag** reflecting the request context (instance or org scope). Whenever the two diverge — e.g. `ignoreUnknownUsernames` enabled on the instance but not on the user's org, or the reverse — the redirect carries a `loginName` that doesn't match the session cookie (or no session is created at all), so the `/password` page can't load the session and renders `unknownContext`, while password submission still succeeds via its user-search fallback. This affects every caller of `sendLoginname` — the manual `/loginname` form as well as the server-side `login_hint` resolution; it was most reproducible with `login_hint`, since that path resolves context settings at the instance level, maximizing the chance of divergence with an org-level policy. 2. The password pages tried to re-derive "was enumeration protection applied?" from login settings to suppress the error — but they resolve settings from a different context than `sendLoginname` (falling back to the default organization instead of the instance), so any org-level custom policy made the suppression misfire. More fundamentally, the alert was keyed on a failed session lookup, which is not an error state: under enumeration protection no session exists by design, and the forms recover without one (`sendPassword` falls back to user search; `/password/set` works via code + userId). # How the Problems Are Solved `sendLoginname` no longer accepts `ignoreUnknownUsernames` from the caller. It derives a single constant server-side from the request-context login settings it already fetches and uses it for every decision in the flow: session creation, `preventUserEnumeration`, the multiple-users branch, the INITIAL-user check, the organization reset, the auth-method guards, and the IdP redirect after domain discovery. Redirect params use `session?.factors?.user?.loginName ?? command.loginName`: when a session exists, its loginName goes in the URL so the next page always finds the session cookie; when protection applies, no session (and no session cookie) is created and the raw input is echoed, keeping known and unknown users fully indistinguishable — including the previously observable `Set-Cookie` difference. `UsernameForm` and `resolveLoginHint` stop forwarding the flag, which also removes the redundant `getLoginSettings` call in `resolveLoginHint`. The password pages no longer consult login settings or the session lookup for the `unknownContext` error and instead warn only when required input is actually missing (matching the existing pattern on the passkey/mfa/u2f pages): `/password` and `/password/change` when no `loginName` searchParam is present, `/password/set` when neither `loginName` nor `userId` is present. A missing session alone no longer triggers the error. Verified against a live instance in all four settings combinations (uniform on/off, both divergence directions) including a known-vs-unknown `login_hint` comparison producing byte-identical responses under protection; full unit suite passes. --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
parent
9070b537d2
commit
464d1cb655
@@ -498,7 +498,7 @@ describe("handleOIDCFlowInitiation — org-scoped session filtering", () => {
|
||||
expect(location).not.toContain("submit=true");
|
||||
});
|
||||
|
||||
test("should forward ignoreUnknownUsernames from login settings when resolving loginHint", async () => {
|
||||
test("should resolve loginHint without forwarding enumeration settings (derived server-side by sendLoginname)", async () => {
|
||||
mockGetAuthRequest.mockResolvedValue({
|
||||
authRequest: {
|
||||
id: "abc123",
|
||||
@@ -509,9 +509,9 @@ describe("handleOIDCFlowInitiation — org-scoped session filtering", () => {
|
||||
},
|
||||
});
|
||||
|
||||
// Org has enumeration protection enabled: sendLoginname must receive the
|
||||
// flag so an unknown hint still redirects to the (fake) /password step.
|
||||
mockGetLoginSettings.mockResolvedValue({ ignoreUnknownUsernames: true });
|
||||
// Enumeration protection is derived inside sendLoginname from the request-context
|
||||
// login settings; resolveLoginHint only passes the hint and the org context, and
|
||||
// an unknown hint still redirects to the (fake) /password step.
|
||||
mockSendLoginname.mockResolvedValue({
|
||||
redirect: "/password?loginName=unknown%40example.com",
|
||||
});
|
||||
@@ -521,7 +521,11 @@ describe("handleOIDCFlowInitiation — org-scoped session filtering", () => {
|
||||
expect(mockSendLoginname).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
loginName: "[email protected]",
|
||||
ignoreUnknownUsernames: true,
|
||||
}),
|
||||
);
|
||||
expect(mockSendLoginname).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
ignoreUnknownUsernames: expect.anything(),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user