Skip to content

fix(opensecret): enforce 8-64 character password policy on user-account password boundaries - #1477

Merged
AnthonyRonning merged 1 commit into
masterfrom
fix/opensecret-password-policy
Nov 6, 2026
Merged

AnthonyRonning merged 1 commit into
masterfrom
fix/opensecret-password-policy

Conversation

@w3irdrobot

@w3irdrobot w3irdrobot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The backend accepted any password string — including the empty string — at every user-account password boundary. This PR adds a shared server-side password policy of 8–64 characters and enforces it before any database or seed-wrap effect. (Confirmed empirically before the fix: POST /register and POST /login both succeeded with password: "" over the real encrypted transport.)

The platform routes already validated 8–64 via the validator crate; this closes the same gap for user accounts, using one shared policy module so all boundaries stay in sync.

Functional changes

Endpoint Before After
POST /register (email + guest signup) any password accepted, incl. "" rejected if < 8 or > 64 chars
POST /password-reset/confirm (v1) any new_password accepted same 8–64 rule
POST /protected/change_password any new_password accepted same 8–64 rule
  • Rejections are 400 with a specific message ("Password must be at least 8 characters" / "Password must not exceed 64 characters") so clients that surface error.message show a real reason instead of a generic Bad Request.
  • Validation runs before any side effect: no user row is created on a rejected register, a rejected reset does not consume the one-shot reset request, and a rejected change-password leaves the current credential working.
  • Length counts Unicode characters, not bytes (eight two-byte characters pass; 65 characters fail regardless of encoding).
  • Applies to both v1 and v2 encrypted transports, since validation sits in the handlers.

Intentionally unchanged

  • POST /login is not length-validated: a wrong-length attempt is simply an authentication failure, and existing accounts (including short-password ones) keep working. This stops new bad credentials without locking anyone out.
  • Platform routes — already enforced 8–64; untouched.

Follow-up

The transport-v2 password-reset completion route (/password-reset/v2/complete) lands with #1470 and is not on master yet. Once this PR merges, #1470 should pick up the same one-line validate_password call for its new_password so the policy covers that route too.

Client notes

  • Research's forms only enforce the minimum (8), so a >64-char password typed into web signup now gets a server 400 the client doesn't pre-validate. It surfaces cleanly; a small frontend follow-up can align the forms.
  • Agent's change-password rule (MIN_PASSWORD_LENGTH = 8) matches the new floor; no change needed.

Validation

  • cargo fmt --check clean; clippy -D warnings clean; cargo test --locked --all-features → 1110 passed, 0 failed (includes the source-scanning security_invariants suite).
  • New disposable-database route tests (password_policy_route_tests.rs) prove empty/7-char/65-char passwords are rejected with the exact messages on register and change-password — and that a rejected register creates no user row while a rejected change leaves the old credential authenticating. 2 passed against an isolated temp Postgres cluster (created, migrated, removed).

@w3irdrobot
w3irdrobot force-pushed the fix/opensecret-password-policy branch from 26f7e88 to 4e06407 Compare November 6, 2026 02:44
@w3irdrobot
w3irdrobot changed the base branch from feat/recovery-credentials-integrated to master November 6, 2026 02:46
@AnthonyRonning

Copy link
Copy Markdown
Contributor

something messed up with cicd due to the force push and edit. can you rebase and trigger it again?

…nt password boundaries

The backend accepted any password string - including the empty string -
at every user-account password boundary. Platform routes already
validated 8-64 via the validator crate, but /register,
/password-reset/confirm and /protected/change_password did not.

Add a shared password policy (8-64 Unicode characters, counted per
character like the Agent client) and enforce it before any database or
seed-wrap effect at those three boundaries. Login is intentionally not
length-validated: a wrong-length attempt is an authentication failure,
and existing accounts (including short-password ones) keep working.

Rejects return 400 with a specific message (PasswordTooShort /
PasswordTooLong) so clients can surface the reason. A rejected reset
does not consume the one-shot reset request; a rejected password change
leaves the current credential intact.

Covered by unit tests plus disposable-database route tests proving
rejection without side effects on register and change_password. The
transport-v2 password-reset completion route lands with the recovery
credentials work (#1470) and will pick up the same policy there.
@w3irdrobot
w3irdrobot force-pushed the fix/opensecret-password-policy branch from 4e06407 to d74c663 Compare November 6, 2026 03:35
@w3irdrobot

Copy link
Copy Markdown
Contributor Author

@AnthonyRonning should be good now

@AnthonyRonning
AnthonyRonning merged commit 791f7e6 into master Nov 6, 2026
23 checks passed
@AnthonyRonning
AnthonyRonning deleted the fix/opensecret-password-policy branch November 6, 2026 16:25
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