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.
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 orderThat 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.
- Query and data are sent separately
- Input is always treated as plain data
WHERE name = ?→ value: alice
- User input is pasted into the SQL text
- A
'can end the string early - The attacker’s text becomes part of the query
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.
- Attacker posts a commentcontaining a script
- Site saves itwithout cleaning it
- You view the pageyour browser gets the comment
- Script runs as the sitewith your session
The fix: output encoding, which turns characters like < into < 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.
🧪 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
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.
🔗 Go further
Trustworthy resources
- OWASP Top 10 The official list and explanations.
- PortSwigger: SQL injection Free lessons and legal labs.
- PortSwigger: Cross-site scripting XSS explained, with free labs.
- OWASP Cheat Sheet: SQL Injection Prevention How developers stop injection.