Performance: Why security is critical
Security impacts the reliability and trustworthiness of a web application, indirectly affecting user experience and site availability.
const userInput = req.query.name;
const query = 'SELECT * FROM users WHERE name = ?';
db.query(query, [userInput]);const userInput = req.query.name;
const query = `SELECT * FROM users WHERE name = '${userInput}'`;
db.query(query);| Pattern | Server Load | Response Time | Security Risk | Verdict |
|---|---|---|---|---|
| Unsafe input handling | High due to potential attacks | Slow or unstable | High risk of injection | [X] Bad |
| Parameterized queries | Low and predictable | Fast and stable | Minimal risk | [OK] Good |
const helmet = require('helmet');
const express = require('express');
const app = express();
app.use(helmet());
app.get('/', (req, res) => res.send('Hello'));
console.log(app._router.stack.length);app.post('/login', (req, res) => {
const { username, password } = req.body;
if (username === 'admin' && password === 'admin123') {
res.send('Welcome admin');
} else {
res.status(401).send('Unauthorized');
}
});Pass the test and this pattern moves unknown