The Web Vulnerabilities Worth Knowing

The handful of classic web bugs behind most real breaches — injection, XSS, broken access control — explained with the one-line principle that prevents each.

· 2 min read · intermediate

A small set of bug classes accounts for the majority of real web breaches. Understand these and you can both spot them and avoid shipping them.

Injection (SQL and friends)

The bug: untrusted input is concatenated into a command (an SQL query, a shell line) so the input can change the command's structure.

python
# VULNERABLE: the input becomes part of the query
db.execute("SELECT * FROM users WHERE name = '" + name + "'")
# name = "' OR '1'='1"  →  returns every row

The fix, every time: parameterised queries. Keep code and data separate so input is only ever a value:

python
db.execute("SELECT * FROM users WHERE name = ?", [name])

The same principle kills command injection: never build a shell string from input — pass arguments as a list to the process directly.

Cross-Site Scripting (XSS)

The bug: untrusted input is reflected into a page as HTML, so an attacker's <script> runs in other users' browsers — stealing sessions, acting as them.

The fix: escape on output, by context. Treat all user content as text and let your templating engine HTML-encode it. Add a Content-Security-Policy that forbids inline scripts as a strong second layer. (This very site renders all user Markdown through an escaping renderer and ships a strict CSP for exactly this reason.)

Broken access control

The bug — and the most common one in practice: the server trusts the client about what you're allowed to do. Classic form, "insecure direct object reference":

text
GET /invoice/1001   ← yours
GET /invoice/1002   ← someone else's... and the server just returns it

The fix: check authorization on the server for every request, against the logged-in user — never assume a hidden field, a sequential ID, or "they couldn't reach this page" protects anything.

Cross-Site Request Forgery (CSRF)

The bug: another site makes your browser send an authenticated request to a site you're logged into (your cookies ride along), triggering an action you didn't intend.

The fix: anti-CSRF tokens (a secret per form the attacker can't know) and SameSite cookies so your session cookie isn't sent on cross-site requests.

The thread running through all of them

text
Never trust input.     → validate and parameterise
Never trust output.    → escape by context
Never trust the client about permissions. → authorize on the server

Almost every item in the OWASP Top 10 is a variation on one of those three sentences.

Takeaways

  • Injection → parameterise; keep code and data separate.
  • XSS → escape on output by context, and add a strict CSP.
  • Broken access control → authorize every request server-side against the real user.
  • CSRF → anti-CSRF tokens plus SameSite cookies. The meta-rule: never trust input, output, or the client about permissions.

Related

Security intermediate

Crypto You Actually Need as a Developer

Hashing vs encryption, how to store passwords without regret, what TLS gives you, and the one rule that keeps you out of trouble — don't roll your own.

· 2 min read
Security beginner

Setting Up a Safe Home Security Lab

Build an isolated playground of virtual machines where you can break things, run malware safely and practise attacks — with zero risk to the real world.

· 2 min read