Security
Learn the attacks every web developer meets by reading the code that falls to them and the fix that stops each one. Hashing and keys, injection and XSS, logins and permissions, then the habit of asking what could go wrong.
- Intermediate
- 4 units, 12 lessons, 156 exercises
- Text, Python, SQL
- Builds on Networking, Databases
Unit 01 · 3 lessons
Cryptography you use
Know what hashes, keys and certificates each promise
- 01Hashes
Fingerprints, salts and why password hashes must be slow
- 02Shared keys and key pairs
Encrypt, sign, HMAC, and why base64 is none of them
- BOSSWho are you talking to
Certificates, the man in the middle and what a padlock means
Read the unit guide
You will almost never write cryptography, and you should not. You will choose it constantly, so know what each tool promises. A hash is a fingerprint: the same input always gives the same fixed-size output, a tiny change gives an unrelated one, and nobody can run it backwards. That is all it promises.
Passwords are stored as hashes, never as text and never encrypted. Give each user a random salt so equal passwords get different hashes and precomputed tables are useless. Use a hash built to be slow (argon2, bcrypt, scrypt): the server pays that cost once per login, an attacker pays it once per guess.
Symmetric encryption uses one shared key to lock and unlock. It is fast, but both sides need the key first. A key pair solves that: anyone can encrypt to your public key, only your private key decrypts. Signing runs the other way: you sign with the private key and anyone checks with the public one.
A plain hash proves nothing about who sent a message, because an attacker can change the message and recompute it. An HMAC mixes a secret key into the hash, so only key holders can make or check the tag. Encoding such as base64 is a change of format with no key at all: it hides nothing.
TLS puts these together. A certificate, signed by an authority your browser already trusts, ties a public key to a hostname. The handshake proves the server holds the matching private key and agrees a symmetric key for the rest of the conversation. The padlock says who you are connected to and that nobody in between can read or alter it. It says nothing about whether that site is honest.
Unit 02 · 3 lessons
Web attacks
Recognise injection, XSS and CSRF in code, and fix each one
- 01Injection
When user input is run as SQL, shell or a file path
- 02Cross-site scripting
User text that runs as script in other people's browsers
- BOSSThe request you did not make
Cookies ride along: tokens, SameSite and the same-origin policy
Read the unit guide
Most web attacks are one mistake in different clothes: text from a user is glued into something a machine will interpret, and the machine cannot tell the user's part from the developer's part. Data becomes code.
SQL injection is the classic. A query built with string concatenation lets a quote in the input end the value early, and whatever follows is run as SQL. The fix is not cleverer escaping. Use parameterized queries: the SQL goes with ? placeholders, the values travel separately, and the database never parses them. Where a placeholder cannot go (a column name, a sort direction), accept only values from a fixed list. Shell commands and file paths break the same way and are fixed the same way: pass arguments as a list with no shell, and tidy a path before checking it is still inside its folder.
Cross-site scripting (XSS) is injection into a page. User text pasted into HTML runs in every visitor's browser with the site's full power. Escape on output, every time, for the place the text lands in; template engines do this by default, so be suspicious of anything that switches it off. A Content-Security-Policy and HttpOnly cookies limit the damage when a bug slips through. They do not fix the bug.
Cross-site request forgery (CSRF) abuses the fact that a browser attaches your cookies to requests another site's page started. The attacker cannot read anything, but can make you send a transfer. Require a random token that only your own pages contain, and set SameSite on session cookies. Never let a GET request change anything.
Behind these sits the same-origin policy: a page may send requests to other origins but may not read their replies. CORS is how a server chooses to relax that rule, so it is a thing to configure carefully, never a defence in itself.
Unit 03 · 3 lessons
Who can do what
Prove identity, check permission on every request, and keep secrets out of code
- 01Authentication
Sessions, tokens and second factors: proving who you are
- 02Authorization
Logged in is not the same as allowed
- BOSSThe key in the repo
A leaked secret, from the first minute to never again
Read the unit guide
Two questions guard every request. Authentication: who are you? Authorization: are you allowed to do this, to that? They are separate checks, and the second is the one that gets forgotten.
After login the server needs a way to recognise you again, because HTTP itself remembers nothing. A session is a long random id in a cookie, with the real data kept on the server; deleting the row logs you out at once. A token such as a JWT carries signed claims the server can verify without a lookup, which scales nicely but cannot be taken back before it expires. Its payload is only encoded, so anyone can read it: the signature stops changes, not reading. Keep tokens short-lived and never put secrets in them.
Passwords leak, so add a second factor: something you have (a phone, a security key) beside something you know.
Authorization happens on the server, on every request, for the specific object asked for. Hiding a button is not a check. If /invoices/1040 shows a stranger's invoice when you change the number, the server authenticated you and then forgot to ask whose invoice it was. Start from deny: list what each role may do, and treat anything unknown as a no. Give every user, job and key the least privilege that lets it work, so one bug cannot reach everything.
Secrets (API keys, database passwords, signing keys) do not belong in source code. Git keeps every version forever, so a secret that was pushed is leaked, even if the next commit deletes it. The fix is always to rotate: revoke the old secret and issue a new one. Load secrets from the environment or a secret manager, scope each key to one job, and keep them out of logs.
Unit 04 · 3 lessons
Thinking like a defender
Find what can go wrong in a system before someone else does
- 01Threat modeling
Assets, attackers, trust boundaries and ranking risks
- 02The usual suspects
The weaknesses found most often in real applications
- BOSSReview a small app
Find, rank and fix the flaws in a login-and-upload service
Read the unit guide
Security is not a feature you add at the end. It is a habit of asking, for every piece of a system: what is this protecting, who would want it, and what happens if this part fails?
Threat modeling makes the habit concrete. Write down the assets (data, money, access), the likely attackers, and the entry points. Draw how data flows and mark the trust boundaries: the places where data moves from something you do not control to something you do. Everything crossing a boundary is a wish, not a fact, and must be checked there. STRIDE is a checklist for the "what can go wrong" step: spoofing, tampering, repudiation, information disclosure, denial of service, elevation of privilege.
You cannot fix everything, so rank. Risk is likelihood times impact. A bug that bots try daily and that exposes every user beats an exotic attack on a page nobody can reach. Plan for the attacker you will actually meet: automated, patient, working from lists of leaked passwords and known flaws.
No single control holds forever, so build in layers. That is defence in depth: the injection is prevented, and the passwords are slowly hashed anyway, and the database account is read-only anyway, and someone is alerted anyway. Keep the attack surface small: every open port, endpoint and dependency is one more thing to defend.
The OWASP Top 10 lists the weaknesses that show up most in real applications. They are rarely clever: missing permission checks, default settings, unpatched libraries, input run as code, and nobody watching the logs.
Reviewing code is following data: where does input come in, and where does it end up? For every endpoint ask who may call it and on which objects. Then prove each fix with a test, and automate the check so the same bug cannot quietly return.
Learn Security on your phone.
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.