Node.jsInterview preparation
Intermediate·Concept·2 min read

How do I prevent injection, XSS, CSRF and SSRF?

Practice this question

Definition:

Injection, XSS, CSRF and SSRF attack different trust boundaries. Injection changes a database command, XSS runs unwanted browser code, CSRF abuses automatically attached credentials, and SSRF makes a server contact an unintended destination. Input validation helps, but each attack also needs controls at the point where the dangerous action happens.

Key points:

  • Injection: use query parameters and validate allowed fields/operators.

  • XSS: use safe output handling; CSRF: protect cookie-authenticated changes with origin checks and CSRF controls.

  • SSRF: restrict outbound destinations and check redirects and resolved addresses.

  • For example, a syntactically valid URL may still point to a private service, so URL-format validation alone does not prevent SSRF.

Interview point:

  • Name the attack, the trusted capability it abuses and the defense applied at that boundary.
Adapted from 02_NODE_EXPRESS_HTTP.md · “How do I prevent injection, XSS, CSRF and SSRF?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.