Performance: Sanitization methods
MEDIUM IMPACT
Sanitization methods affect input processing speed and server response time by adding validation and cleaning steps before data handling.
import { body } from 'express-validator'; app.post('/submit', [ body('input').escape() ], (req, res) => { const sanitized = req.body.input; res.send(`Received: ${sanitized}`); });
app.post('/submit', (req, res) => { const userInput = req.body.input; // Manual string replace for sanitization const sanitized = userInput.replace(/<script.*?>.*?<\/script>/gi, ''); // Proceed with sanitized input res.send(`Received: ${sanitized}`); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual regex sanitization on server input | N/A | N/A | N/A | [X] Bad |
| Using express-validator sanitize middleware | N/A | N/A | N/A | [OK] Good |