Skip to content

fix(login): hide the password form before first paint and honor Remember Me for OIDC - #364

Open
camarigor wants to merge 10 commits into
ZL154:mainfrom
camarigor:fix/password-gate-before-first-paint
Open

camarigor wants to merge 10 commits into
ZL154:mainfrom
camarigor:fix/password-gate-before-first-paint

Conversation

@camarigor

@camarigor camarigor commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When Disable password sign-in applies to the browser's address, the plugin now hides Jellyfin Web's stock username, password and sign-in button before the login form first paints, instead of about half a second after the form has appeared. Jellyfin's Remember Me checkbox stays next to the remaining sign-in options, and a change to it now also applies to OIDC sign-in.

It also carries przeniek's two fixes from #366, cherry-picked with his authorship: the Sign in with a password instead link follows a translation bundle that loads after it, and the reveal link and the SSO buttons go into the login view on screen when Jellyfin Web keeps an earlier login view hidden.

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

Fixes #362
Includes the two commits of #366 by przeniek.

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 on loopback), with plugin packages built from main (721b6c0) and from this branch for each ABI.
Clients tested with: Jellyfin Web in headless Chromium 159.0.8154.6, driven by a script that sampled every animation frame and tried to focus the password field.

  • With password sign-in off for the browser's address, main showed the password field visible and focusable after first paint on every load, for 552 to 573 ms on 10.11.11 and 518 to 582 ms on 12.4.0. With this branch the field was never visible and never accepted focus in any sampled frame, and Tab never reached a credential field or the sign-in button. With password sign-in on, the form appeared and took focus as before.
  • Browsers with constructed stylesheets but without :has() (Chromium 73 to 104, which covers many TV web views, and Firefox 101 to 120), simulated in the same Chromium by rejecting :has() before any page script ran: before the :has() follow-up the password stayed visible and focusable, because the stock form starts with a heading block and the positional fallback matched only the username. With the follow-up, the password was never visible or focusable, including in a second login view opened from the header logo and after going back. See the second table below.
  • Cached login views and late translations, after the two fix(login): keep the SSO button and password link on the visible login view, and translate the link #366 commits: on 12.4.0 the reveal link and the SSO buttons stayed in the view on screen after the header logo, four switches, a minute without interaction and Back, under the server's policy (password visible in 0 of 739 observations) and under style-src 'self' with both engine profiles (0 of 1,215), where the revision before the fix(login): keep the SSO button and password link on the visible login view, and translate the link #366 commits left them in the hidden view. A German bundle held back for 1.5 seconds translated the reveal link, which stayed English before those commits. 10.11.11 gave the same result for the cached views.
  • The live checks ran both with and without a style-src 'self' Content-Security-Policy across the revisions of this branch. The first table below comes from the revision before the follow-up commits, under that policy, and the second covers the :has() follow-up.
  • The admin's Sign in with a password instead link restored the form and focused the username. Quick Connect, the OIDC button, the passkey button and the Remember Me checkbox stayed visible.
  • With a local OIDC provider stub, I unticked and then ticked Remember Me before clicking the OIDC button. In both cases enableAutoLogin matched the checkbox when the browser left the page. I also checked the embedded device flow with the box cleared, with the WebView signal simulated in the browser.
  • The served script is the embedded inject.js with one boolean line in front, and it keeps its no-store headers.
  • New rendered browser tests in tests/oidc-bridge.test.mjs use the stock form order and cover first paint, the strict style policy with and without constructed stylesheets, engines with constructed stylesheets but without :has() (including a remount), a cached second login view with the poll stopped (with and without a style policy that blocks Jellyfin Web's inline .hide rule), the reveal link translation with a bundle that arrives late (the real tfa-i18n.js and de.json), a second server selected through the URL or the active client while its policy response is held across paint (allowed, restricted, failed and late answers), entering login without a URL change, the per-server reveal, remounts, and older engines without URLSearchParams, a working URL constructor or Array.prototype.find. Two unit tests check which of the two gate paths an engine takes. A C# theory checks that the script and the public config give the same answer for the same request (six cases, including a LAN client, an exempt range and the plugin turned off).
  • Locally: Release build with 0 warnings and 0 errors for both ABIs, 1,217 .NET tests passed, and every Node command from CI passed (184 executions, 169 distinct tests).

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 runs under style-src 'self' before the follow-up commits, three fresh browser sessions per row:

Jellyfin Password sign-in for this address Frames with the password field in the page Visible Accepted focus
10.11.11 Off 230 0 0
12.4.0 Off 235 0 0
10.11.11 On 183 183 183
12.4.0 On 177 177 177

The :has() follow-up, same policy, Chromium 159 rejecting :has() before any page script ran, password sign-in off, one session per row. The 12.4.0 rows include a second login view opened from the header logo and a return with Back:

Jellyfin Revision Password field observations Visible Accepted focus
12.4.0 Before the follow-up 608 608 608
12.4.0 This branch 607 0 0
10.11.11 Before the follow-up 49 49 49
10.11.11 This branch 49 0 0

Without the simulation, this branch still hides the fields through one stylesheet: on 12.4.0 the password was visible in 0 of 1,418 observations across the same navigation.

Additional notes

How it works:

  • The anonymous /TwoFactorAuth/inject script, which Jellyfin Web already loads synchronously in the head, now starts with window.__tfaPasswordLoginDisabled = true; or false;. The value comes from the same per-request helper that sets passwordLoginDisabled in the public config, and the index HTML keeps its current caching.
  • Before the stock form exists, inject.js sets a root class. When the browser supports :has(), it applies narrowly scoped rules through a constructed stylesheet. Otherwise it hides the elements directly, from a mutation observer that also covers remounts. When the bootstrap value is missing (for example an older cached script), the existing public config gate still applies.
  • When the selected server is not the one that served the page, its credentials stay hidden until that server's own public config answers, for up to 2.5 seconds. A failed or slow request releases the form, and a later restrictive answer hides it again. The admin reveal is remembered per server and mount for the life of the page.
  • A change to Remember Me is saved to enableAutoLogin, as Jellyfin's own submit does, before the browser leaves for an OIDC provider, including the embedded device flow. The passkey path and the one-load hand-off for unchecked users are unchanged.
  • From fix(login): keep the SSO button and password link on the visible login view, and translate the link #366: the reveal link and the SSO buttons are placed in the login view that is on screen, and a copy left in an earlier, hidden view is removed so it can be placed again. On top of fix(login): keep the SSO button and password link on the visible login view, and translate the link #366, the view the router selected (the one without hide) wins over a hidden view that keeps a layout box, which happens under a style-src 'self' policy because Jellyfin Web's own .hide rule is inline. The reveal link carries data-i18n-key, so the translation bundle re-translates it when it loads after the link.
  • The helper now also returns false when the plugin is disabled. That matches LockoutMessageMiddleware, which skips the password check in that case.
  • The controller diff also re-indents three existing lines in a catch block (whitespace only).

Limits: the fields are hidden, not removed, so a password manager extension can still find them in the page. przeniek tested Bitwarden on Jellyfin 12.4.0 and reported that its autofill panel no longer appears until the reveal (#362). I did not test a physical WebView, a native app or a real older browser; the older engines above are simulated. If a client restored a cached login view after the route change, with no DOM change and after the first minute, its reveal link and SSO buttons would stay missing until the next page event runs an injection pass; Jellyfin Web 10.11.11 and 12.4 did not show that order in my runs. The server keeps enforcing its own password policy either way. Under the strict style policy, Jellyfin Web's own tmla-mask element sat over the login page whether or not the gate was active and caught mouse clicks, so in those runs I activated the reveal with the keyboard.

This branch merges cleanly with #361, #363, #347, #349 and #365. The two commits of #366 are included here. When it is combined with #361, the loading document mock in tests/login-button.test.mjs needs document.createElement and a few related stubs for the new bootstrap. I will add them in whichever of the two is merged second.

camarigor and others added 5 commits November 22, 2026 15:45
The stock Jellyfin Web login form (10.11.11 and 12.4) starts with a
heading div, so the positional fallback
.inputContainer:nth-of-type(-n+2) matched only the username wrapper.
Engines with constructed stylesheets but no :has() (Chromium 73 to 104,
Firefox 101 to 120) adopted that rule, skipped the element fallback and
left the password field visible. Adopt the stylesheet only when :has()
is supported and let the element fallback hide the exact controls,
including on remounts. The rendered tests now use the stock form order.
…e loads

The "Sign in with a password instead" link is created with T(), which
returns the English fallback while tfa-i18n.js is still loading. Unlike the
other injected login elements it carried no data-i18n-key, so the
'tfa-i18n-ready' hook never re-translated it and it stayed English on a
non-English Jellyfin.

Adapted to the ZL154#364 password gate, which takes the custom label from the
per-server config it resolves for the login route, not from _tfaPublicCfg.

(cherry picked from commit f300059)
…ogin view

jellyfin-web keeps earlier views in the DOM, hidden. Opening login again
under a different route (e.g. the header logo -> #/login?serverid=...) builds
a second #loginPage while the first one stays hidden. The document-wide id
guards then found the nodes injected into the hidden view, so the visible
form got no SSO button and no password reveal link until a full reload.

Resolve the login view that is on screen, look the form up inside it, and
drop injected nodes stranded in a hidden view so they are injected again.

Adapted to the ZL154#364 password gate by scoping its reveal link and
.manualLoginForm lookups to the visible view, leaving its policy unchanged.

(cherry picked from commit 9ad7150)
Jellyfin Web keeps the earlier views of a route in the DOM and hides them.
Render two cached login views the way the header logo creates them, then
go back and forward with the plugin poll turned off, so every pass comes
from the page's own events. After each step the document holds exactly
one reveal link and one provider list, both rendered in the visible view,
with that view's credentials hidden. The reveal is clicked in the second
view, which is not the first match in the document, and must show and
focus that view's own fields.

Render the reveal link while the German bundle is held back. The default
label carries data-i18n-key and reads German once tfa-i18n-ready fires.
A custom label carries no key and keeps its text.

The document double in stockLoginPage gains setAttribute, which the reveal
link now calls. The Chromium runner moves into renderInChromium, shared by
the existing rendered modes and the new pages.
…eep a box

Jellyfin Web ships its .hide rule as an inline style. Under a
style-src 'self' policy the browser blocks it, so the cached login
views the router marks .hide keep their layout box. visibleLoginRoot()
took the first view with a box, which was the stale one: after the
header logo and after Back the provider button and the reveal link
stayed there while the selected view had neither.

Prefer the first login view without .hide that has a box, since
viewContainer leaves only the selected or restored view unmarked, and
keep the first view with a box, then the document, as fallbacks. The
cached view test now also runs under style-src 'self'.
@camarigor

Copy link
Copy Markdown
Contributor Author

I pushed five commits after checking przeniek's report on #362.

  1. Browsers without :has(). On browsers that support constructed stylesheets but not :has() (Chromium 73 to 104, which covers many TV web views, and Firefox 101 to 120), the fallback rule .inputContainer:nth-of-type(-n+2) matched only the username wrapper, because the stock login form in 10.11.11 and 12.4 starts with a heading block. Those browsers hid the username and the sign-in button but left the password field visible, and the element fallback never ran. The stylesheet is now used only when :has() is supported. Other browsers use the existing element fallback, which hides the exact controls, including when a view is mounted again. The rendered tests now use the stock form order.
  2. przeniek's fixes from fix(login): keep the SSO button and password link on the visible login view, and translate the link #366. fix(login): keep the SSO button and password link on the visible login view, and translate the link #366 changes the same lines of the gate, so I cherry-picked its two commits here with przeniek as the author. The reveal link now carries its translation key, so it follows a bundle that loads after it. The reveal link and the SSO buttons now go into the login view that is on screen when Jellyfin Web keeps an earlier one hidden. I adapted them to the per-server gate and left out the generic form fallback, since the gate only hides .manualLoginForm. A test commit covers the cached views and the late translation. It also gives the test document double a setAttribute, which the picked commits call, so on their own those two commits fail three mock tests. A last commit makes the view selection prefer the view Jellyfin Web's router selected, the one without hide: under a style-src 'self' policy the browser blocks Jellyfin Web's inline .hide rule, so hidden views keep their layout box and the first view with a box can be a stale one. The cached view test now runs under both policies.
  3. Verification. I checked the :has() fix on Jellyfin 12.4.0 and 10.11.11 with Chromium 159 made to reject :has() before any page script ran. On 12.4.0 the password was visible and accepted focus in all 608 sampled observations before the fix, and in none of 607 with it, including after the header logo opened a second login view and after going back. On 10.11.11 it went from 49 of 49 to 0 of 49. With all five commits on 12.4.0, the reveal link and the SSO buttons stayed in the view on screen after the header logo, four switches, a minute without interaction and Back, under the server's policy and under style-src 'self', where the revision before the fix(login): keep the SSO button and password link on the visible login view, and translate the link #366 commits left them in the hidden view. The password was never visible or focusable before the reveal (0 of 739 observations with the server's policy, 0 of 1,215 under the strict policy with both engine profiles). The late German bundle now translates the reveal link. Every Node command from CI passes (184 executions). I could not run a real older browser or a TV, so those engines are simulated.

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.

[bug] Password-login gate runs after first paint - password managers attach to the fields, and the remember-me checkbox is left behind

2 participants