Skip to content

Fix: stop a password being stored and deleted in one save - #32

Merged
SandObserver merged 1 commit into
mainfrom
fix/password-toggle-safeguards
Aug 11, 2026
Merged

SandObserver merged 1 commit into
mainfrom
fix/password-toggle-safeguards

Conversation

@SandObserver

Copy link
Copy Markdown
Owner

Summary

  • Add shouldWritePassword beside authEnableBlocked and gate the set-password call on it, so a password typed in the same save that switches protection off is never written; writing it rotated the session secret, signing every other device out, before the toggle deleted it again.
  • Clear the password field when the same save turns protection off, so the box does not read as a password the dashboard now holds.
  • Reject a /api/auth/toggle body whose enabled is not a boolean; {}, null, 0 and "false" were read as off and permanently deleted passwordHash and secret.
  • Lift the sign-out and revoke row sync to module scope and call it after a save clears the password, where the rows could stay visible and the revoke button answered with an error.
  • Attach the toggle's change listener unconditionally. It was guarded on sec-sub, which exists nowhere in the markup, so the listener never ran; the same dead branch wired the password strength meter, which initSecToggle in admin.js already does.
  • Translate the password and Unsplash key status labels through new common.configured and common.notSet keys in all six locales.
  • Record in auth.js that clearing the hash lets anyone who can reach the dashboard while protection is off set a password, which is accepted because protection being off already exposes the whole config.

Testing
All green: 1092 backend, 609 frontend, 94.8% line coverage, lint, format, both typechecks, paths:check and cache-busting. Added 9 tests: six malformed toggle bodies that must change nothing, and the write-password rule.

Checklist

  • Stays within the project constraints: one container, no runtime dependencies, no build step (see CONTRIBUTING.md).
  • Tests added or updated for new logic, and the full suite, lint, and typechecks pass.
  • Docs updated if behavior or configuration changed.
  • CHANGELOG.md updated under Unreleased if the change is user-visible.

Typing a password in the same save that switches Password Protection off
stored it first, which rotates the session secret and signs every other
device out, and the toggle then deleted it a moment later. The save
reported success. The password is now left unwritten, and the field is
cleared so it cannot read as one the dashboard holds.

The toggle route accepts only a real true or false. An empty body, a null
or a string used to be read as off, permanently deleting the stored
password and secret over a request that said nothing.

The sign-out row is resynced after protection is turned off, where it
could stay on screen and answer with an error, and the change listener
that kept it in step is attached again: it hung off an element that does
not exist in the markup, so it never ran. The dead branch also wired the
password strength meter, which admin.js already does.

Password and Unsplash key status labels are translated rather than always
reading in English.
@SandObserver SandObserver added the bug Something isn't working label Aug 11, 2026
@SandObserver
SandObserver merged commit c05ca64 into main Aug 11, 2026
4 checks passed
@SandObserver
SandObserver deleted the fix/password-toggle-safeguards branch August 11, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant