Avoid sending unsanitized user input in response

Metadata

ID: javascript-express/xss-vulnerability

Language: JavaScript

Severity: Warning

Category: Security

CWE: 79

Description

Returning unsanitized user input in a send or write method can increase your application’s risk of cross-site scripting attacks.

Learn More

Non-Compliant Code Examples

app.get("/", (req, res) => {
    res.send(req.body.foo);
    res.send({ title: "foo", message: req.body.foo });
    res.write(req.body.foo);
    res.write({ title: "foo", message: req.body.foo });
})

Compliant Code Examples

app.get("/", (req, res) => {
    res.send("foo");
    res.send({ title: "foo", message: 'foo' });
    res.write("foo");
    res.write({ title: "foo", message: 'foo' });
})
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: Cyril-Bouchiat/add-vm-package-explorer-doc