Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"cors": "^2.8.6",
"dotenv": "^17.4.2",
"express": "^5.2.1",
"express-mongo-sanitize": "^2.2.0",
"express-rate-limit": "^8.5.2",
"google-auth-library": "^10.6.2",
"helmet": "^8.1.0",
Expand Down
9 changes: 9 additions & 0 deletions backend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cookieParser from "cookie-parser";
import helmet from "helmet";
import rateLimit from "express-rate-limit";
import compression from "compression"; // <-- Clean & Simple Import
import mongoSanitize from "express-mongo-sanitize"; // FIX #576: NoSQL injection protection
import path from "path";
import { fileURLToPath } from "url";
import crypto from "crypto";
Expand Down Expand Up @@ -46,6 +47,14 @@ app.use(helmet({ contentSecurityPolicy: false }));
// GSSoC Issue #35 Fix
app.disable("x-powered-by");
app.use(express.json({ limit: "5mb" }));
/**
* SECURITY MIDDLEWARE: NoSQL Injection Prevention (Fix #576)
* Strips MongoDB query operators ($where, $gt, $ne, etc.) from all incoming
* request bodies, query strings, and params — preventing attackers from
* injecting malicious operators like { "email": { "$gt": "" } }.
* replaceWith: '_' replaces dangerous keys with safe underscores.
*/
app.use(mongoSanitize({ replaceWith: "_" }));
app.use(cookieParser()); // Must precede CSRF to parse incoming cookies

/**
Expand Down