Skip to content

Auth password hashing - #160

Open
uniejo wants to merge 8 commits into
Yancy-app:masterfrom
uniejo:auth-password-hashing
Open

uniejo wants to merge 8 commits into
Yancy-app:masterfrom
uniejo:auth-password-hashing

Conversation

@uniejo

@uniejo uniejo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

test Unicode passwords

Add tests for passwords with emoji (which the old Digest hashing could
not handle), for composed and decomposed characters matching after
normalization, and for old Digest hashes made from UTF-8 bytes.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

uniejo and others added 8 commits October 1, 2026 10:10
Yancy::Controller::Yancy was renamed to Yancy::Controller::Model, and
Yancy::Plugin::File was removed in favor of Yancy::Storage. Update the
controller test and give the default editor a Yancy::Storage rooted at
public/uploads instead of loading the missing file plugin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new password auth template now uses the `l` helper for its labels,
and Yancy::Auth loads the I18N plugin if the app does not have it yet.
This lets t/i18n.t use Yancy::Auth::Password instead of the deleted
auth plugin roles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yancy::Auth->start_session only redirected, so logging in did nothing.
Add start_session, current_user, and end_session to Yancy::User, using
the sessions table with the session ID stored in the Mojolicious
session. Yancy::Auth now starts a session for the user after a
successful login, and Yancy::User keeps the auths registered with it.

Also fix two bugs in Yancy::Auth::Password's login check: logging in
as an unknown user no longer looks up attributes for an undefined user
ID, and upgrading a password digest calls set_password instead of the
missing _set_password.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The editor API and storage routes were open to anyone, giving full
read/write access to every schema and to file storage.

Yancy::Plugin::Editor now requires either a `users` model (a
Yancy::User) or an explicit `allow_anonymous => 1`. With a users model,
requests from anyone who is not logged in get a 401 from the API and
storage routes, and the editor page redirects to the first registered
auth's login page.

Mojolicious::Plugin::Yancy only adds its default editor when one of
those options is given in `editor`, and logs a warning otherwise.

The development apps set `allow_anonymous => 1`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The return_to check only rejected URLs starting with a scheme or `//`,
so `/\evil.example` (which browsers treat as `//evil.example`) could
redirect users to another site after logging in. An unsafe return_to
also caused a 500 error instead of being ignored.

Add Yancy::Auth->is_local_path, which only allows paths starting with a
single `/` without backslashes or control characters. return_to and
start_session skip unsafe values and fall back to a safe default.

Also add a `/auth/logout` route that ends the session and redirects to
a local return_to path, or `/`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yancy::Auth::Password hashed passwords with a single unsalted Digest
pass (the docs and tests used SHA-1), and compared hashes with `eq`.

Passwords are now hashed with Crypt::Passphrase, using Argon2id with
the `interactive` profile by default. Each hash gets its own random
salt, and verification is constant-time. The encoder can be changed
with the new `passphrase` option.

Existing Digest hashes (`base64$Type`) still verify, using a
constant-time compare, and are re-hashed with the current settings the
next time the user logs in. The `digest` option is no longer used, and
logs a warning if given.

Logins with an unknown user also check a dummy hash, so failed logins
take about the same time whether or not the user exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Crypt::Passphrase gives validators the password as UTF-8 bytes, but the
old Digest hashes were made by adding the password characters, which
Digest hashes as Latin-1 bytes. Users with characters like "æøå" in
their password could not log in with their old hash. Try both the UTF-8
and Latin-1 bytes when checking an old hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add tests for passwords with emoji (which the old Digest hashing could
not handle), for composed and decomposed characters matching after
normalization, and for old Digest hashes made from UTF-8 bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@preaction

Copy link
Copy Markdown
Collaborator

Thanks! I've moved Auth to its own project and have created an e-mail and a Webauthn Passkeys auth. These changes to the password auth I will port over: The e-mail auth uses the same Crypt::Passphrase + Argon2 module, so now it's all the same dependencies for hashing.

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