Network Security Essentials

Know the common attacks and defences interviewers ask about: firewalls, VPNs, DDoS, man-in-the-middle, XSS, CSRF, SQL injection and secure authentication.

Intermediate · about 4 hours · difficulty 2/5

Learn first: HTTP, HTTPS and TLS

You do not need to be a security engineer, but SDE interviews and system design rounds often include a "how would you secure this?" follow-up. A clear mental model of attacks and defences is enough.

Network-level

  • Firewalls filter traffic by rules on IPs, ports and protocols; stateful firewalls track connections.
  • VPNs create an encrypted tunnel so traffic appears to come from another network.
  • Man-in-the-middle (MITM): an attacker intercepts traffic. Defence: TLS with proper certificate validation.
  • DDoS: flooding a service with traffic from many machines. Defences: rate limiting, CDNs, scrubbing services, autoscaling.
  • SYN flood: exhausting half-open TCP connections; mitigated with SYN cookies.

Application-level (the OWASP favourites)

  • SQL injection: user input concatenated into queries. Fix with parameterised queries.
  • XSS: injected scripts run in other users' browsers. Fix with output encoding and a Content Security Policy.
  • CSRF: a malicious site triggers requests using a logged-in user's cookies. Fix with CSRF tokens and SameSite cookies.
  • Broken authentication: store passwords with slow hashes (bcrypt, Argon2) plus salt, never plain or MD5.

Principles

  • Defence in depth, least privilege, and never trusting client input.
  • Authentication (who are you) vs authorization (what may you do).
  • Hashing vs encryption vs encoding: hashing is one-way, encryption is reversible with a key, encoding (Base64) is not security at all.

Good enough to move on: for any feature you build, you can list the top three attacks it faces and the standard fix for each.

Key concepts

  • Firewalls and VPNs
  • MITM and certificate validation
  • DDoS and SYN floods
  • SQL injection
  • XSS and CSRF
  • Password hashing and salting
  • Hashing vs encryption vs encoding
  • OWASP Top 10

Mini project

Take a small login and comments app you built, deliberately add SQL injection and stored XSS bugs, exploit them yourself in a local environment, then fix them with parameterised queries, output encoding and bcrypt password hashing.

Check yourself

Why does a CSRF attack work even though the attacker never sees the victim's cookies, and how does a SameSite cookie stop it?

Free resources