Skip to content

[Bug]: NoSQL Injection in verifyEmail allows arbitrary account verification and bypass #1551

Description

@Dev1822

Bug Description

The /api/auth/verify-email endpoint extracts the token directly from req.query.token. Express uses the qs library by default, which parses query parameters like ?token[$ne]=null into a JSON object { "$ne": "null" }. This object is passed directly to User.findOne({ emailVerificationToken: token }). An attacker can mass-verify random accounts by sending this NoSQL injection payload, as findOne will simply match the first user whose token is not null.

Steps to Reproduce

  1. Create a new unverified user account.
  2. Send a GET request to /api/auth/verify-email?token[$ne]=null.
  3. Observe that an arbitrary user account (the first one matching the query) becomes verified and its verification token is nulled out.
  4. Repeat to blindly verify other accounts in the database.

Expected Behavior

The token query parameter should be strictly validated using Zod or explicitly cast to a string (String(req.query.token)) before being used in database queries to prevent object injection.

Actual Behavior

The parameter is passed directly into the MongoDB query, resulting in a severe NoSQL injection vulnerability.

Severity

Critical

Screenshots / Screen Recording

No response

Browser

No response

Operating System

No response

Additional Context

Located in backend/controllers/authController.js.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingclaimedThis issue has been claimed by a contributor

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions