Javascript Marsdb Nosql Injection
Description
This detector identifies NoSQL injection vulnerabilities in JavaScript applications using the MarsDB library. NoSQL injection occurs when user-controlled data is directly passed to database queries without proper validation or sanitization, allowing attackers to manipulate query logic and potentially access unauthorized data or perform malicious operations.
Detection Strategy
• The code must import or reference the MarsDB library (either directly as 'marsdb' or through an alias)
• User-controlled data (from request parameters, form inputs, URL parameters, etc.) must be passed directly to MarsDB query methods without proper validation or sanitization
• The vulnerable pattern occurs when external input flows into MarsDB collection operations like find(), findOne(), update(), remove(), or similar query methods
• The detector specifically looks for cases where the query object or query parameters contain unsanitized user input that could modify the intended database operation
Vulnerable code example
const MarsDB = require('marsdb')
const users = new MarsDB.Collection('users')
module.exports = function login(req, res) {
// Vulnerable: user input passed directly to query
users.findOne(req.body.credentials)
}✅ Secure code example
const MarsDB = require('marsdb')
const users = new MarsDB.Collection('users')
module.exports = function login(req, res) {
// Safe: validate and sanitize input before query
const { username, password } = req.body.credentials || {}
...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.