A security-focused codemod that transforms unsafe MongoDB query construction with user input to safe parameterized queries in Express applications using Mongoose and MongoDB drivers.
Overview
This codemod addresses CWE-943: Improper Neutralization of Special Elements in Data Query Logic by identifying and transforming potentially vulnerable NoSQL injection patterns in Express applications.
Security Context
CWE-943 occurs when user input is directly passed to database operations without proper sanitization, allowing attackers to inject malicious query operators like $where, $regex, or arbitrary JavaScript code.
Installation
bash
# Run from registry
npx codemod@latest run @codemod/express-nosql-injection-to-safe-queries
# Or run locally
npx codemod@latest run -w workflow.yaml