Performance: CSRF protection
MEDIUM IMPACT
CSRF protection affects the server response time and client-side interaction by adding security tokens to requests, which can slightly increase payload size and processing.
import csurf from 'csurf'; const csrfProtection = csurf({ cookie: true }); app.get('/form', csrfProtection, (req, res) => { res.render('form', { csrfToken: req.csrfToken() }); }); app.post('/submit', csrfProtection, (req, res) => { processForm(req.body); res.send('Form submitted'); });
app.post('/submit', (req, res) => { // No CSRF token validation processForm(req.body); res.send('Form submitted'); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No CSRF Protection | No extra DOM nodes | 0 | 0 | [X] Bad - insecure, no protection |
| CSRF Token in Form (cookie-based) | Adds hidden input for token | 0 | Minimal | [OK] Good - secure with minimal overhead |