Skip to content

fix(auth): skip the passkey challenge when an account cannot use a password - #363

Open
camarigor wants to merge 21 commits into
ZL154:mainfrom
camarigor:fix/passkey-reason-without-password-sign-in-on-347
Open

camarigor wants to merge 21 commits into
ZL154:mainfrom
camarigor:fix/passkey-reason-without-password-sign-in-on-347

Conversation

@camarigor

Copy link
Copy Markdown
Contributor

Summary

This is the second part of #360, from the reporter's follow-up comment. For an account that cannot sign in with a password at all, the "Ask for a second factor after password sign-in" preference no longer makes the account require a sign-in challenge. The rule applies only when all of these hold: the account has no local password, Block sign-in with an empty password is on, the account signs in through this plugin's own provider, and that provider delegates password checks to Jellyfin's built-in provider. The stored preference is never changed and applies again as soon as the account gets a password.

Mandatory scope, a verified authenticator app and pending emergency recovery still require the challenge (recovery is reported with a new recovery reason). Setup hides the switch for such an account and shows "Password sign-in is unavailable for this account. Your passkey preference is saved for when password sign-in becomes available." in all eight languages. MyStatus, the admin Users list and the user export report the same effective reason. On Quick Connect, an approval only creates verified trust for the new session when the approving session itself carries proof.

Depends on #347. This branch is stacked on #347 because both change the same policy line: the new rule sits inside #347's PasskeyPolicy.HasUsable check, and #347's disable guard passes the new argument explicitly. The first 8 commits are #347; this PR adds the 13 commits after e1d9871. Please merge #347 first, and I will rebase this branch onto main right after.

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (existing behaviour, config, or API changes)
  • Security fix
  • Documentation only
  • CI / build / tests only
  • Refactor (no functional change)

Related issues

Refs #360 (the redirect part is in #361). Depends on #347.

How was this tested?

  • Added or updated unit tests
  • Added or updated integration tests
  • Tested manually against a running Jellyfin server (state version)

Server tested against: Jellyfin 10.11.11 and 12.4.0 (official Docker images, disposable containers), with packages built from #347 alone (e1d9871) and from this branch (52c31d7) for each ABI.
Clients tested with: Jellyfin Web in headless Chromium 159.0.8154.6 with a CDP virtual authenticator for the passkey, driven by a script against those running servers.

  • On both servers I signed in a user with Remember Me, registered a passkey, removed the user's password, assigned the user to the plugin's provider and restarted the server. With feat(passkey): add a setting to turn passkeys off (#345) #347 alone the restored session was challenged (403 with twoFactorRequired, portal, ChallengeIssued). With this branch it was not: every protected request succeeded, no audit entry or verified mark was created for the restored token, and the stored preference stayed on.
  • Controls with this branch: giving the account a password again, turning Block sign-in with an empty password off, and setting emergency recovery each restored the challenge. With passkeys turned off, feat(passkey): add a setting to turn passkeys off (#345) #347's guard refused the save and named the account.
  • Setup for that account hid the switch, showed the sentence above and made no write.
  • The policy, capability, session start, portal, native response, Quick Connect, export and Setup changes have unit and integration tests, including accounts on another provider, a provider listed before the built-in one, a same-named provider from another assembly, user directory lookup failures, and the combination with passkeys turned off.

Checklist

  • My code follows the existing style (run dotnet format if unsure)
  • I've added comments only where the why isn't obvious from the code
  • I've updated the README / SECURITY.md / docs if behaviour or config changed
  • I've considered backwards compatibility (config migration, file formats, on-disk state)
  • I've checked the security implications (auth bypass, secret handling, input validation)
  • CI passes (dotnet build + dotnet test green)

Screenshots / log slices

Live results, password removed, account on the plugin's provider, server restarted:

Version #347 alone (e1d9871) This branch (52c31d7) Controls on this branch
10.11.11 Restored session challenged Not challenged, protected requests 2xx Password, gate off and recovery challenged again
12.4.0 Restored session challenged Not challenged, protected requests 2xx Password, gate off and recovery challenged again

Local checks on the stacked branch:

Release build: 0 warnings, 0 errors
.NET: 2001 passed, 0 failed, 0 skipped (includes #347's tests)
Node: 189 executions, 0 failed, 0 skipped

Additional notes

Trade-off: for an eligible account, an OIDC or proxy sign-in with its bypass turned off, and a session restored after a restart, no longer get the passkey-only challenge. That challenge protected a password sign-in the account cannot make.

Scope: the plugin can confirm this only for accounts that sign in through its own provider, so accounts assigned directly to Jellyfin's default provider keep today's behavior. An installation with any other authentication provider (for example an LDAP plugin) also keeps today's behavior, even when that provider is disabled or listed after the built-in one.

This branch has textual overlaps with #361 (README) and #352 (Plugin.cs). I will resolve them by rebasing whichever is merged later.

Keep existing installations enabled by default and make the sign-in policy and self-service factor decisions honor the server setting without changing stored credentials.

Refs ZL154#345
Refuse passkey ceremonies before side effects, reject passkey sign-in bridge tokens, and share the effective challenge inventory across the provider, middleware and portal. Keep saved credentials visible for removal while reporting effective coverage and self-service eligibility.

Refs ZL154#345
Check the exact configuration Jellyfin is about to save after the step-up gate and return a conflict listing users who still depend on passkeys. Reuse the challenge inventory for imports and inspect full-import replacement records before writing either configuration or user data.

Refs ZL154#345
Keep each existing sign-in entry point compatible with the enabled default. Use the shared usable-method inventory only for the new disabled state and its turn-off guard, so upgrading does not normalize unrelated legacy challenge behavior.

Refs ZL154#345
EmergencyLockout rearms PasskeyRequiresSecondFactor again from the
stored credentials, as ZL154#343 did. Rearming only adds protection; tying it
to the new switch left an opted-out passkey in place during an emergency
taken while passkeys were off, and that passkey would skip the challenge
once they were turned back on.

Rename PasskeyPolicy.HasEnrolled to HasUsable: it returns false for a
user with enrolled passkeys while the server has them off, so the old
name misled exactly where the distinction matters.

Document PasskeysEnabled, point HideBuiltInPasskeyButton to it, comment
the public-config field, say when SignInFactors uses the shared
inventory, and fix the whitespace of the new test files.

Refs ZL154#345
…in pages

The server refuses passkeys while PasskeysEnabled is off, so the pages
stop offering them. inject.js leaves out the passkey sign-in button. The
Setup page drops the registration controls, the ZL154#343 switch and the
passkey option of its step-up prompt, and keeps saved passkeys listed
with a notice so users can still remove them. The admin page gets the
"Allow passkeys" setting next to email codes, offers the passkey in its
step-up modal only while passkeys are allowed, and reads that again
after a save.

A save the server refuses with 409, because some users would be left
without another way to verify their sign-in, now names those users as
text in the page language and leaves the form as the admin left it. A
refused save no longer ends in an uncaught promise rejection.

The challenge page needs no change: it offers the passkey only when the
server lists it, which a new test pins. New strings in all eight
bundles, Node tests for each page, and the two new test files in CI.

Refs ZL154#345
Explain what turning passkeys off does on the server and on the pages,
why turning it off is refused while a user depends on a passkey, the
two ways out, and how it differs from hiding the passkey button. Point
to it from the passkey section and from the hide-buttons section.

Refs ZL154#345
The turn-off guard only looked for users with nothing left to answer the
sign-in challenge. Two other ways the switch could quietly drop a second
factor slipped through:

- an email or recovery code answers the challenge but never makes it
  required, so a user whose passkey choice was the only reason password
  sign-in asked for a second factor would be left with the password alone;
- a recovery code or a Telegram chat answers the challenge but is not a
  self-service factor, so the Setup page step-up would stop asking for
  proof.

The guard now lists a user with stored passkeys when any of the three
holds, through the challenge inventory, the sign-in challenge policy
(with the user's administrator status for the enforcement scope) and the
self-service factor list as they are. The refusal, the settings help text
and the README now say that these users rely on a passkey for their
second factor.

Also drop a needless cast and simplify an assertion in the save tests.

Refs ZL154#345
…e sign-in

Restore the original session fault handling and leave structural recovery for a separate change.
return providers.Count == 0
|| (providers is [Type other]
&& other.Assembly == serverAssembly
&& other.FullName == "Jellyfin.Server.Implementations.Users.InvalidAuthProvider");
if (condition == "scope") fixture.Config.EnforcementScope = EnforcementScope.All;
if (condition == "totp") await fixture.Store.MutateAsync(fixture.User.Id, d => d.TotpEnabled = d.TotpVerified = true);
if (condition == "password") fixture.User.Password = "stored";
if (condition == "missing") fixture.Users.GetUserById(fixture.User.Id).Returns((User?)null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants