Ir al contenido

NoSQL injection (ARCH3140)

Esta página aún no está disponible en tu idioma.

Key typescript.security.nosql-injection · Severity error · Category security · CWE CWE-943

Passing untrusted objects straight into a NoSQL query allows operator injection such as $gt or $ne and authentication bypass. Always coerce input to primitive types.

app.post("/login", async (req, res) => {
const user = await User.findOne({
username: req.body.username,
password: req.body.password,
});
res.json(user);
});
app.post("/login", async (req, res) => {
const user = await User.findOne({
username: String(req.body.username),
password: String(req.body.password),
});
res.json(user);
});

Coerce query values to primitives (String/Number) or validate with a schema; never pass raw objects.