mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.71k stars 846 forks source link

SECURITY.md explained #768

Closed ertygiq closed 1 month ago

ertygiq commented 1 month ago

In the SECURITY.md file it's mentioned that the following code is insecure:

app.get('/', (req, res) => {
    res.render('index', req.query);
});

Could you explain why?

mde commented 1 month ago

Because you are not checking what inputs are going into the render method. You are blindly passing end-user inputs into EJS, which means (depending on what's in your template) they could run arbitrary (and potentially malicious) JavaScript code on your server. It's a very similar security problem as SQL injection.