Currently, I am in the process of implementing security middleware for my modest MERN web application. Specifically, I have opted to utilize helmet and express-mongo-sanitize to safeguard against NoSQL injection attacks.
In my server.js file, I have configured it as shown below:
const express = require('express')
const helmet = require('helmet')
const mongoSanitize = require('express-mongo-sanitize')
...
app.use(mongoSanitize())
app.use(helmet())
// Routes below
...
To verify its effectiveness, I attempted a simulated sign-up with the following details:
username: {"$gt": ""} password: 'TestPassword'
This resulted in the following req.body:
{
username: '{"$gt": ""}',
password: 'TestPassword'
}
However, despite this input, express-mongo-sanitize did not detect any issues and the data was still passed through to the database. Could it be that I am misunderstanding something? Perhaps the value assigned to the username key is already in the correct format? I acknowledge that I may lack certain knowledge on the subject and appreciate your patience as I continue to learn.