Skip to content

Incorrect expiration date validation for _perishable_token_expires_at #9935

Open

Description

@mtrezza

New Issue Checklist

Issue Description

⚠️ Potential issue | 🔴 Critical

Token lookup uses inverted expiry comparator and lacks Auth.maintenance/limit.

  • _perishable_token_expires_at should be greater than “now” for a valid token.
  • Use Auth.maintenance like the email path for consistency.
  • Limit results to 1.

Apply:

-      userResults = await req.config.database.find('_User', {
-        _perishable_token: token,
-        _perishable_token_expires_at: { $lt: Parse._encode(new Date()) },
-      });
+      userResults = await req.config.database.find(
+        '_User',
+        {
+          _perishable_token: token,
+          _perishable_token_expires_at: { $gt: Parse._encode(new Date()) },
+        },
+        { limit: 1 },
+        Auth.maintenance(req.config)
+      );
🤖 Prompt for AI Agents
In src/Routers/UsersRouter.js around lines 454 to 471, the token lookup query
uses the wrong expiry comparator and is missing the same options as the email
path; change the _perishable_token_expires_at check to $gt Parse._encode(new
Date()) so only unexpired tokens match, and call req.config.database.find with
the same options as the email branch: pass { limit: 1 } and
Auth.maintenance(req.config) as the query options so the lookup is limited to
one result and runs under maintenance context.

Reported by @coderabbitai

Activity

  1. parse-github-assistant commented on Nov 17, 2025

    @parse-github-assistant

    🚀 Thanks for opening this issue!

    ℹ️ You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

  2. added
    type:bug
    on Nov 17, 2025
  3. coratgerl commented on Nov 18, 2025

    @coratgerl
    Contributor

    There is a test that seems cover this 'can resend email using an expired reset password token' in ValidationAndPasswordsReset.spec.js. I don't know if this one should be removed or no ?

  4. mtrezza commented on Nov 18, 2025

    @mtrezza
    MemberAuthor

    I haven't validated the issue yet. It may be a false positive. There should be tests for the token expiration we should look for.

  5. dblythy commented on Jul 4, 2026

    @dblythy
    Member

    After investigating, this looks like a false positive — the $lt comparator is intentional, not inverted.

    The token branch of handleResetRequest (POST /requestPasswordReset) is the "resend a password-reset email after your link has expired" flow, so it deliberately matches only expired tokens:

    • git blame on UsersRouter.js (the $lt line) → added intentionally in fix: Remove username from email verification and password reset process #8488.
    • PagesRouter.js (link-expired handling) → when a reset link expires, the page deliberately preserves the expired token in the query params so the user can resend a fresh link from the expired-link page.
    • spec/ValidationAndPasswordsReset.spec.js → 'can resend email using an expired reset password token' → forces the token expired (year 2000), POSTs it to /requestPasswordReset, and asserts a new token is issued (expect(obj._perishable_token).not.toBe(token)).

    Flipping to $gt would break that feature and that test. The bundled sub-suggestions aren't bugs either: { limit: 1 } is cosmetic (perishable tokens are per-user unique), and Auth.maintenance isn't required here (the query works today, as the passing test shows).

    To stop this being re-flagged, I've opened #10533 which adds an inline comment documenting the intent. Recommend closing this as not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions