Skip to content

Research password reset: reset-code regex is too strict (rejects lowercase) #1580

Open

Description

@AnthonyRonning

The reset-code field on the Research Confirm Password Reset form rejects codes that are typed in lowercase.

PasswordResetConfirmForm.tsx has:

pattern="[A-Z0-9]{8}|[A-Z0-9]{32}"
title="8- or 32-character alphanumeric code"

Typing 4mi1aupg shows the browser's "Please match the requested format" message. The hint says "alphanumeric" and never mentions capitals, so the user can't tell what's wrong.

The backend has the same problem

opensecret builds codes only from A–Z0–9 (generate_alphanumeric_code in services/opensecret/src/main.rs). confirm_password_reset then looks the code up by an HMAC of the exact string the user submitted (password_reset_code_mac), with no case conversion. So if the form let a lowercase code through, the backend would still refuse it with a generic "Failed to reset password," and that failed try counts against the reset request's attempt limit.

Future formats

If reset codes move to UUIDs, the current regex rejects them: UUIDs are usually lowercase hex with hyphens. The regex already had to change once for the 32-character expansion in #1550.

Direction

We should loosen the client-side check a lot. The backend is the real validator, and the form only needs to block obviously empty input. Some ways to do it:

  • Drop pattern completely, or keep only a loose length or character check.
  • Clean up input before submitting: trim it, remove spaces, and maybe convert to uppercase. Converting to uppercase is only safe while codes are uppercase-only, so it would break lowercase UUIDs.
  • Have the backend normalize the code (e.g. to_ascii_uppercase and trim before the MAC), so case doesn't matter no matter which client sent it. This one needs an enclave deploy.
  • Small input fixes either way: autoCapitalize, autoComplete="one-time-code" and spellCheck={false}.

The right choice depends on where the reset-code format is going, so I'm leaving it to you.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions