Every web application holds something worth protecting: accounts, payments, messages, or simply the trust of the people who use it. Web security is the work of keeping that application and its data from being misused. Privacy is the related but separate work of deciding what personal data the application should hold at all, and how it treats the people that data describes. This first lesson gives you the vocabulary and the mental model the rest of this series builds on.
Before you start
You need no security background. It helps to know what a web request is (a browser asks a server for a page, the server answers) and to have built or edited a small website or app. Code examples in this series use TypeScript, JavaScript, SQL, and raw HTTP, and every one of them is meant to run against your own machine or a system you are allowed to test.
What web security means
Security people often describe their goals with three words, known as the CIA triad:
- Confidentiality: only the right people can read the data. A stranger shouldn't be able to open your invoices by changing a number in the URL.
- Integrity: data and code change only in authorized ways. Nobody should be able to edit another user's profile, or slip a script into your page.
- Availability: the service works when people need it. A single expensive request shouldn't be able to take the site down.
Most security bugs break one of these. A leaked database dump breaks confidentiality. A forged money transfer breaks integrity. A login form that can be flooded until the server falls over breaks availability.
The four words you'll use every day
Security discussions get muddled when people mix up these terms, so it's worth being precise from the start.
- An asset is anything of value: user accounts, personal data, API keys, your domain name, the reputation of your product.
- A threat is something that could harm an asset: a criminal reusing leaked passwords, a careless employee, a buggy dependency.
- A vulnerability is a weakness that a threat can use: a SQL query built by string concatenation, a missing permission check, an admin panel with a default password.
- Risk combines how likely harm is and how bad it would be. A vulnerability on an internal page nobody can reach is lower risk than the same bug on your public login form.
You can't remove every threat, because you don't control attackers. You can remove vulnerabilities, and you can reduce the impact when something goes wrong. That's most of what security engineering is.
A realistic example
Imagine a small booking site for a cooking school. Its assets include customer names and phone numbers, booking history, the admin account, and the payment provider's API key. One realistic threat is credential stuffing: attackers try millions of email and password pairs leaked from other websites. The vulnerability that lets it succeed is a login form with no rate limiting and no second factor for the admin. The risk is high, because the attack is automated, cheap, and common, and an admin takeover exposes every customer.
The fix isn't one magic product. It's a few deliberate choices: limit login attempts, require multi-factor authentication for the admin, and keep the payment key on the server where the browser never sees it. Later lessons cover each of these in detail.
What privacy means for developers
Privacy is about people, not systems. It asks questions such as: what personal data do we collect, why, who can see it, how long do we keep it, and does the person know? A system can be perfectly secure and still be bad for privacy, for example if it securely stores every user's precise location history for years without a reason.
Privacy laws turn some of these questions into obligations. The European Union's General Data Protection Regulation (GDPR), for example, requires that personal data be processed lawfully and transparently, for specified purposes, and limited to what those purposes need. Many countries have data protection laws built on similar principles, which trace back to the OECD Privacy Guidelines first published in 1980. Lesson 4, Understanding Personal Data, Privacy, and Data Minimization, goes into these principles.
Security and privacy are related, not the same
The two overlap heavily. Access control, encryption, and breach response serve both. But they can also pull in different directions. Detailed security logs help you investigate attacks, yet logs full of email addresses and IP addresses are personal data that must be protected and eventually deleted. A good engineer holds both questions at once: "how do we keep this safe?" and "should we have this at all?"
The cheapest privacy and security control is often the same one: don't collect what you don't need. Data you never stored can't leak, can't be subpoenaed, and doesn't need to be encrypted, backed up, or deleted.
Recommendations, optional controls, and legal requirements
You'll meet three kinds of "should" in this series, and it's important to keep them apart:
- Security recommendations come from bodies such as OWASP and NIST. They describe good practice. They aren't laws, though contracts and regulators sometimes point to them.
- Optional controls are extra layers that make sense for some applications and not others, such as hardware security keys for every user or a web application firewall.
- Legal requirements come from laws and regulations, such as data protection laws or rules for payment card data. They depend on where you operate, who your users are, and what data you process. This series explains common principles, but it isn't legal advice; for real obligations, consult the law itself, the regulator's guidance, or a lawyer.
No checklist, standard, or tool makes an application "secure" once and for all, and following one doesn't by itself make you compliant with a law. Security is a property you keep maintaining as the code, the dependencies, and the threats change.
Where vulnerabilities come from
Most vulnerabilities aren't exotic. They come from a handful of everyday causes:
- Trusting input. Data from the browser, an API client, a file, or another service is treated as safe when it isn't.
- Missing checks. The code assumes the user is allowed to do something because the button was hidden in the interface.
- Unsafe defaults. A framework, database, or cloud bucket ships with a setting that is convenient but open.
- Outdated components. A library with a known, published vulnerability stays in production for months.
- Secrets in the wrong place. API keys end up in client-side code, in a Git repository, or in logs.
The OWASP Top 10 (opens in a new tab), updated in 2025, groups the most common and impactful of these into ten categories. Lesson 6 walks through it.
// INSECURE TEACHING EXAMPLE: never trust a role sent by the browser.
app.post("/api/admin/delete-user", (req, res) => {
if (req.body.isAdmin === true) {
deleteUser(req.body.userId);
}
res.sendStatus(204);
});Anyone can send isAdmin: true in a request body; the browser isn't the only client that can talk to your server. The server must decide who the user is from its own session data:
app.post("/api/admin/delete-user", requireSession, (req, res) => {
// The role comes from the server-side session, never from the request.
if (req.session.user.role !== "admin") return res.sendStatus(403);
deleteUser(String(req.body.userId));
res.sendStatus(204);
});Thinking like a defender
You don't need to think like a criminal to write secure code, but you do need to ask a few questions about every feature:
- What could go wrong if someone sends a request I didn't expect?
- Who should be allowed to do this, and where exactly is that checked?
- What personal data does this touch, and do we need all of it?
- If this part failed or leaked, what would the damage be, and how would we know?
These questions are the seed of threat modeling, covered in depth in lesson 11.
Common mistakes and troubleshooting
- "We're too small to be a target." Most attacks are automated and indiscriminate. Bots scan every reachable server for known weaknesses within minutes of it going online.
- Relying on hidden buttons. Hiding a feature in the interface isn't access control. Check permissions on the server.
- Treating HTTPS as the whole answer. HTTPS protects data in transit. It does nothing about a missing permission check or an SQL injection.
- Confusing compliance with security. Passing an audit means you met a set of criteria on a given day. It doesn't mean attackers can't get in.
- Collecting "just in case". Every extra field is extra risk. If you can't name the purpose, don't collect it.
If you're unsure whether something is a security problem, describe the asset, the threat, and the vulnerability in one sentence each. If you can't fill in all three, you may be looking at a bug, a design concern, or a privacy question instead, and those deserve attention too.
Practical exercise: map one feature
Pick one feature of an application you work on, such as sign-up, checkout, or a contact form. Write down:
- the assets it touches (accounts, personal data, money, secrets);
- two realistic threats (for example, a bot or a curious logged-in user);
- one vulnerability that would let each threat succeed;
- the personal data it collects, and the purpose of each field;
- one change that would reduce risk, and one field you could stop collecting.
Keep this note. You'll extend it in lesson 5's audit and lesson 11's threat model.
Key takeaways
- Security protects confidentiality, integrity, and availability; privacy decides what personal data you should hold and how you treat it.
- Use asset, threat, vulnerability, and risk precisely; you fix vulnerabilities and reduce impact.
- Recommendations, optional controls, and legal requirements are different things, and no checklist alone makes you secure or compliant.
- The server must make every security decision; the browser is just one client.
- Collecting less data is a security control and a privacy control at once.
References
- OWASP Top 10:2025 (opens in a new tab)
- OWASP Application Security Verification Standard (ASVS) (opens in a new tab)
- NIST Cybersecurity Framework 2.0 (opens in a new tab)
- European Commission: Data protection in the EU (GDPR) (opens in a new tab)
- OECD Privacy Guidelines (opens in a new tab)
- MDN: Website security (opens in a new tab)
What's next
Next, How HTTPS, TLS, Cookies, and Browser Security Work looks at the layer every web application sits on: how data is protected on its way between the browser and your server, and how the browser itself keeps sites apart.

