Celtrix icon indicating copy to clipboard operation
Celtrix copied to clipboard

[Security] NoSQL Injection Vulnerability in Auth Controllers

Open afnan0304 opened this issue 6 months ago • 2 comments

Description:

While reviewing the authentication boilerplate generated by Celtrix (authController.js), I noticed that the login/signup logic trusts the email field directly from req.body without strict type validation (User.findOne({ email })).

Technical Details:

Because Express parses incoming JSON directly into objects, a user can pass a MongoDB query operator instead of a string. For example, if a user sends {"email": {"$gt": ""}, "password": "..."}, it bypasses the exact-match requirement. Mongoose interprets the operator object, resulting in a classic NoSQL Injection that can lead to authentication bypass in the apps developers are building with Celtrix.

Proposed Solution

Update the generated authentication templates The fix implements a strict type-guard before the database query execution. By ensuring that the email and password inputs from req.body are strictly primitive strings, we prevent Express and Mongoose from parsing and executing malformed JSON objects (like {"$gt": ""}) as query operators.

afnan0304 avatar May 15 '26 09:05 afnan0304

Hey, @JoeCelaster I'm ready to work on this. Could you please assign this issue to me for GSSoC'26.

afnan0304 avatar May 15 '26 09:05 afnan0304

sure @afnan0304 , assigned !

JoeCelaster avatar May 21 '26 14:05 JoeCelaster