Web security · Lesson 2 of 2

Common web vulnerabilities

Broken access control, SQL injection and cross-site scripting explained for beginners, with a safe in-browser demo and how developers fix each one.

⏱ 18 min🎯 Beginner🧪 Hands-on✅ 4-question quiz🎬 Video✓ Completed

By the end, you’ll be able to…

  • Explain what the OWASP Top 10 is and why it matters
  • Describe broken access control, SQL injection and XSS in plain language
  • Explain how developers prevent each one

Key words

OWASP
The Open Worldwide Application Security Project: a non-profit that publishes free web security guidance.
Access control
The rules that decide who is allowed to see or do what.
Injection
When user input is treated as code or commands instead of plain data.
SQL
The language web apps use to talk to many databases.
XSS
Cross-site scripting: tricking a website into running an attacker’s JavaScript in other people’s browsers.
Parameterized query
A safe way to build database queries where user input is always treated as data, never as code.

See all 127 words in the glossary →

The OWASP Top 10

OWASP is a non-profit that publishes free guidance for building safer software. Its best-known project, the OWASP Top 10, is a list of the most important kinds of web application security risk. It’s updated every few years based on data from real applications. Developers, testers and defenders all use it as a shared vocabulary.

This lesson covers three classic risks. For each one you’ll learn what goes wrong and how it’s fixed, because that’s what the job is actually about.

1. Broken access control

Access control means checking “is this user allowed to do this?” on every request. When a check is missing, users can see or change things they shouldn’t.

https://shop.example/siteorderspage?id=1041which order
If changing 1041 to 1042 shows someone else’s order, the server forgot to check who owns it.

That example has a name: an IDOR (insecure direct object reference). The fix: the server checks ownership or permissions on every request, and denies by default. Hiding a button in the page isn’t a fix, because users control the front end.

2. Injection (SQL injection)

Many sites store data in a database and ask it questions using SQL. A login check might look like this:

SELECT * FROM users WHERE name = 'alice' AND password_hash = '…'

The danger comes when a developer builds that query by gluing user input straight into the text. Then a user can type characters, like a quote mark ', that change the meaning of the query. The input stops being data and becomes code. Try it safely in the practice section below.

✅ Safe: parameterized query
  • Query and data are sent separately
  • Input is always treated as plain data
  • WHERE name = ? → value: alice
⛔ Unsafe: string gluing
  • User input is pasted into the SQL text
  • A ' can end the string early
  • The attacker’s text becomes part of the query
Parameterized queries (also called prepared statements) are the standard fix, in every language.

3. Cross-site scripting (XSS)

XSS happens when a site takes something a user typed, like a comment, and puts it into a page as HTML without making it safe. If the text contains a script, other visitors’ browsers run it as if the site wrote it. That script could read the page, act as the user, or show fake login forms.

  1. Attacker posts a commentcontaining a script
  2. Site saves itwithout cleaning it
  3. You view the pageyour browser gets the comment
  4. Script runs as the sitewith your session
The fix: encode output so the browser shows the text instead of running it, and add a Content Security Policy as a backup.

The fix: output encoding, which turns characters like < into &lt; so the browser displays them as text. Modern frameworks do this automatically. A Content Security Policy adds a second layer by telling the browser which scripts are allowed. (This site uses one!)

The pattern behind all three

Notice the theme: trusting input. Access control trusts the ID in the URL. Injection trusts text sent to the database. XSS trusts text shown on the page. The defender’s habit is to treat every input as untrusted: check it, separate it from code, and encode it on the way out.

Where to practise legally

Never test these on real websites. Use labs built to be attacked: PortSwigger Web Security Academy (free, in your browser) or OWASP Juice Shop running on your own computer. Many companies run bug bounty programmes, but only test within their published rules.

🤔 Something not clicking?

🧪 Hands-on

Practice

This simulated login builds a database query from what you type. Watch how a single quote changes the query, then switch on the fix.

Now spot the issue in each situation:

🎬 Watch

Video: Running an SQL Injection Attack

Web securityRunning an SQL Injection AttackComputerphile · Watch on YouTube

Video by Computerphile, hosted on YouTube. It loads only when you press play.

✅ Check yourself

Quick quiz

Every answer comes with an explanation, right or wrong. Your best score is saved in this browser.

Q1. A site hides the ‘Delete user’ button from normal users but doesn’t check permissions on the server. What’s the problem?
Q2. What is the standard fix for SQL injection?
Q3. Which defence stops a comment like <script> from running in other people’s browsers?
Q4. Where is it legal to practise SQL injection?

What’s next

Up next · new track: Defensive securityBlue team basics: logs, alerts & detection →How defenders spot attacks: logs, SIEMs, alerts, true and false positives, and open-source tools like Zeek and Suricata, explained for beginners.⏱ 16 min