Part 8 of 9 · 2 min read
Common attacks
Common practice, not from the books.
Common attacks and defences
This section is common practice, not from the books. Each is paired with the standard defence.
| Attack | What happens | Defence |
|---|---|---|
| Man-in-the-middle | An attacker reads or changes traffic on the path | TLS with certificate checks |
| Injection (such as SQL injection) | Input is treated as commands, so a form field alters a database query | Parameterised queries; never join user text into a command |
| Cross-site scripting (XSS) | An attacker's script runs in another user's browser | Escape output; content security policy |
| Cross-site request forgery (CSRF) | A site tricks a logged-in browser into sending a request | Anti-forgery tokens; same-site cookies |
| Credential stuffing and brute force | Many passwords tried, often from leaked lists | Salted hashes, rate limits, lockouts, second factor |
| Denial of service | Flooding a service so real users cannot get in | Rate limiting and load shedding (Level 8), upstream filtering |
| Stolen or leaked secrets | A key found in code or logs | Vaults, rotation, scanning for secrets |
| Unpatched software | A known flaw is used | Regular patching and dependency updates |
A made-up example. A search box builds the query SELECT * FROM items WHERE name = ' plus the typed text plus '. A user types ' OR '1'='1 and gets every row. With a parameterised query, the typed text can only be a value, never part of the command.
Interview angle
Answer in your head first, then open it.
What does TLS give you?
Encryption, authentication of the server (and optionally the client), and integrity of messages.
Authentication versus authorisation?
Who you are versus what you may do.
How should services authenticate to each other?
Not by trusting the network. Options are TLS with client certificates, signed requests or tokens from an identity provider, each with its own credentials.
Where do you keep secrets?
In a vault or secrets store, not in code, images or logs, with rotation.
What is defence in depth?
Layers of protection, so one failure does not expose everything.
Check yourself: 1. Why does a parameterised query stop injection? 2. Which attack does a rate limit help with? 3. Why is patching on the list?
Words you will meet
| Word | Meaning |
|---|---|
| TLS | A protocol that encrypts, authenticates and protects a connection |
| Certificate | A signed document tying a public key to an owner |
| Certificate authority | An entity that issues and signs certificates |
| Authentication | Checking who a principal is |
| Authorisation | Deciding what a principal may do |
| Principal | A person or program that can be authenticated |
| Single sign-on | One login that works across many services |
| Identity provider | The system that authenticates principals for SSO |
| Key vault | A separate store that manages encryption keys |
| Salted hash | A password stored as a one-way hash with a random addition |
| Defence in depth | Layered protections |
| Man-in-the-middle | An attacker who sits between two parties |