Skip to content

fix: enforce password policy for new passwords #203

@dcadenas

Description

@dcadenas

Summary

Keycast should enforce a shared password policy whenever a new password is created, while continuing to allow existing users to log in with passwords they already set.

Environment

  • Service: Keycast API
  • Endpoints: /api/headless/register, /api/auth/register, /api/auth/reset-password, authenticated change-password endpoint

Steps to Reproduce

  1. Register a new account with a weak password such as 1234 or password123.
  2. Or reset a password to a similarly weak value.
  3. Observe that some paths hash and accept the password without policy checks.

Actual Result

Registration and reset-password paths hash the submitted password directly. The authenticated change-password path enforces only a minimum length check. Existing password handling is inconsistent across endpoints.

Expected Result

New passwords are checked against one shared server-side policy before they are accepted. Existing password hashes remain valid for login so current users are not forced out or blocked by the new policy.

Regression?

No. This is a hardening and UX improvement.

Evidence

Relevant code inspected:

  • api/src/api/http/headless.rs: headless_register hashes req.password directly.
  • api/src/api/http/auth.rs: register queues bcrypt for req.password directly.
  • api/src/api/http/auth.rs: reset_password hashes req.new_password directly.
  • api/src/api/http/auth.rs: change_password checks only new_password.len() < 8.

Acceptance Criteria

  • A shared password policy is used for all new-password creation paths.
  • /api/headless/register rejects weak new passwords.
  • /api/auth/register rejects weak new passwords.
  • /api/auth/reset-password rejects weak new passwords.
  • Authenticated change-password uses the same policy.
  • Existing users can still log in with passwords that were accepted before this change.
  • Obvious weak passwords like 1234, password, and password123 are rejected for new submissions.
  • Responses include stable error codes/messages that clients can map.
  • Tests cover registration, reset-password, change-password, and legacy login compatibility.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions