Skip to content

studio/frontend: hide Current password input on first boot - #5545

Merged
danielhanchen merged 3 commits into
mainfrom
studio-frontend-hide-current-password-on-first-boot
May 18, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-frontend-hide-current-password-on-first-boot

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

#5490 added a third Current password input to the change-password form so the admin-forced must_change_password reset path could supply a current password (the bootstrap is empty in that path). The side effect is that the dominant first-boot UX, where window.__UNSLOTH_BOOTSTRAP__ is injected by the backend and silently fed into currentPassword, now shows three visible inputs instead of the two it had before that PR.

Render the Current password input only when window.__UNSLOTH_BOOTSTRAP__?.password is absent. The loadBootstrap effect already seeds the password state from the bootstrap and currentPassword keeps the bootstrap fallback, so handleSubmit sees the same value as before. On admin-forced resets where the bootstrap is undefined, the Current password input still appears so the user can type their actual current password.

Net effect:

Security

UI-only change. What goes on the wire is unchanged: handleSubmit still POSTs { current_password, new_password } to /api/auth/change-password with the bootstrap-derived access token, the backend still validates current_password against the stored hash, and the form-level guards (invalidChangePasswordForm, the if (!currentPassword) short-circuit) are untouched. The bootstrap value is not newly exposed; it was already in window.__UNSLOTH_BOOTSTRAP__ and on disk at studio/auth/.bootstrap_password. Before #5490 the bootstrap password was never written into a visible form field, and this PR restores that posture on first boot (the eye toggle in #5490's input could reveal the bootstrap password as plaintext; the dot-rendered length already leaked character count). CSP nonce wiring on the inline bootstrap script is unchanged.

Test plan

Installed locally with bash install.sh --local against UNSLOTH_STUDIO_HOME=$WS/studio and drove the page with Playwright.

  • npm run typecheck clean
  • npm run build clean (frontend rebuilt by install.sh --local)
  • First boot (bootstrap injected): document.querySelectorAll('input[type="password"]').length === 2, IDs new-password and confirm-password, no #current-password in the DOM
  • First boot end-to-end: typed an 8+ char new password into both fields, clicked Change password, landed on /chat with the Studio sidebar (Chat, Compare, Train, Recipes, Export, Account). POST /api/auth/change-password and the chained POST /api/auth/login both 200; zero console errors
  • Admin-forced reset path (bootstrap suppressed by an init script that defines window.__UNSLOTH_BOOTSTRAP__ as a non-writable, non-configurable property before navigation): three inputs render, #current-password present with label "Current password", #new-password and #confirm-password still present, submit button stays disabled until all three are filled

PR #5490 added a third Current password input to the change-password form
so the admin-forced must_change_password reset path could supply a current
password (the bootstrap is empty in that path). The side effect is that the
dominant first-boot UX, which has window.__UNSLOTH_BOOTSTRAP__ present and
silently fed into currentPassword, now shows three visible inputs instead
of the two it had before.

Render the Current password input only when window.__UNSLOTH_BOOTSTRAP__
is absent. The loadBootstrap effect already seeds the password state from
the bootstrap and currentPassword keeps the bootstrap fallback, so
handleSubmit sees the same value as before. On admin-forced resets where
the bootstrap is undefined, the Current password input still appears so
the user can type their actual current password.

Verified end-to-end against a local install via UNSLOTH_STUDIO_HOME +
install.sh --local with Playwright driving the page: bootstrap present
renders two inputs (New, Confirm) and completes change-password into
/chat; bootstrap suppressed via a non-configurable property descriptor
init script renders the three inputs (Current, New, Confirm) and keeps
the #5490 fix intact.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request modifies the AuthForm component to conditionally render the 'Current password' input field. By introducing the hasBootstrapPassword constant, the form now detects if a bootstrap password is provided by the backend and hides the current password field accordingly, facilitating a smoother first-boot experience. As there are no review comments provided, I have no further feedback to offer.

danielhanchen and others added 2 commits May 18, 2026 10:57
Pure-source pytest covering the change-password JSX contract. No
browser, no Studio boot, no JS toolchain -- runs on any CI runner.
Complements the Playwright probe in tests/studio/playwright_chat_ui.py
which exercises the same contract end to end.

Pins seven invariants with explicit failure reasons:

  1. hasBootstrapPassword is derived from window.__UNSLOTH_BOOTSTRAP__
     so a future swap to a localStorage flag or prop cannot silently
     drift from the backend's _inject_bootstrap contract in
     studio/backend/main.py.
  2. Exactly one !hasBootstrapPassword conditional exists; multiple
     would split rendering into branches these tests cannot reason
     about.
  3. The Current password input sits inside that conditional, so it
     never renders on first boot (the regression PR #5490 introduced
     and that this fix reverses).
  4. The New password input sits outside it, so it always renders in
     change-password mode (admin-forced reset still works).
  5. Confirm password: same as New.
  6. The change-password JSX subtree declares exactly current /
     new / confirm; a fourth password input would almost certainly
     break the 2-input first-boot contract.
  7. The login JSX subtree declares exactly one password input.

Verified the tests fail loudly on the pre-fix auth-form.tsx at
c4575ca (5/7 fail with descriptive reasons) and pass on the fixed
version (7/7).
@danielhanchen

Copy link
Copy Markdown
Member Author

Additional commit on this branch: tests/studio/test_auth_form_input_count.py. Pure-source pytest (no Studio boot, no browser, no JS toolchain) that pins seven structural invariants on the JSX so the 2-input first-boot UX cannot be regressed by a future cleanup pass. Each assertion carries an explicit failure reason. Verified the tests fail on pre-fix auth-form.tsx (5/7 fail with descriptive reasons) and pass on the fixed version (7/7).

The Playwright runtime side was also exercised on real ubuntu-latest, macos-14, and windows-latest runners via a throwaway staging branch on a fork: danielhanchen#125. All three OSes green:

  • Linux: 2m32s
  • macOS: 6m0s
  • Windows: 7m9s

The staging workflows install Studio with install.sh --local --no-torch (Linux/macOS) or install.ps1 --local --no-torch (Windows) plus UNSLOTH_API_ONLY=1, then drive Studio twice with Playwright + Chromium: once with the bootstrap as the backend serves it (assert exactly 2 inputs, no #current-password, then complete the form and confirm /chat is reached), and once with an addInitScript that suppresses window.__UNSLOTH_BOOTSTRAP__ via a non-writable, non-configurable property descriptor (assert 3 inputs including #current-password so the #5490 admin-forced-reset path is still intact).

@danielhanchen
danielhanchen merged commit 2bf39de into main May 18, 2026
10 of 33 checks passed
@danielhanchen
danielhanchen deleted the studio-frontend-hide-current-password-on-first-boot branch May 18, 2026 11:27
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.

1 participant