Find a course

Module 3: Common VulnerabilitiesLesson 6 of 1016 min

Web Application Vulnerabilities

Learn the OWASP Top 10 idea, then see how broken access control, SQL injection and cross-site scripting work and how developers prevent each one.

Step 1 of 11Learn

Why web apps are the front line

Most organizations expose far more web applications than anything else: customer portals, online stores, APIs for mobile apps, internal tools reachable from home. Web apps are complex, change constantly and are written by developers under deadline pressure, so they're a rich source of vulnerabilities.

The OWASP Top 10, published by the nonprofit Open Worldwide Application Security Project, is the best-known list of the most critical web application security risks. It's updated every few years from data contributed by testing firms and organizations. The 2021 edition included, among others:

  • Broken access control: users can act outside their intended permissions. It was the number one category in 2021.
  • Cryptographic failures: sensitive data exposed through missing or weak encryption.
  • Injection: untrusted input interpreted as commands, including SQL injection and cross-site scripting.
  • Insecure design: flaws in the design itself, not just the code.
  • Security misconfiguration: default settings, verbose error messages, unnecessary features enabled.
  • Vulnerable and outdated components: libraries and frameworks with known flaws.
  • Identification and authentication failures: weak login, session and password handling.
  • Server-side request forgery (SSRF): tricking a server into making requests on the attacker's behalf, often to internal systems.

The Top 10 is an awareness document, not a complete checklist. The OWASP Web Security Testing Guide covers the full range. But the list captures where real breaches keep coming from.

Step 2 of 11Learn

Broken access control and IDOR

Authentication asks who are you? Authorization, or access control, asks what are you allowed to do? Broken access control means the application doesn't properly enforce the second question.

The most common form is the insecure direct object reference (IDOR). You log in to a store and view your invoice at:

https://shop.example/invoices?id=58231

What happens if you change the number to 58230? If the server returns someone else's invoice, it's checking that you're logged in, but not that the invoice belongs to you. With a simple script, an attacker could download every customer's invoices. Breaches of this kind have exposed millions of records at banks, telecoms and government services.

Other access control failures include:

  • Hiding an admin page from the menu but not protecting the page itself, so anyone who guesses the URL can use it.
  • Enforcing rules only in the browser's JavaScript, which users fully control, instead of on the server.
  • Letting a user change a hidden form field such as role=user to role=admin.

The fix is a principle: every request must be authorized on the server, every time, by checking that the authenticated user is allowed to perform that action on that specific object. Deny by default, and use unpredictable identifiers as an extra layer, not as the only protection.

How an IDOR leaks someone else’s dataLogged in asyouAsks for id58230 (notyours)Logged in?Yes, allowedOwner check:missingAnothercustomer’sinvoicereturned

Step 3 of 11Practice · What would you do?

What would you do?

During an authorized test of a health portal, you log in as test patient A and see your lab results at /results/7781. Changing the URL to /results/7780 shows another patient's results. How do you handle this?

Step 4 of 11Learn

SQL injection

Many applications build database queries from user input. Here's a dangerous way to do it, joining strings together:

query = "SELECT * FROM users WHERE username = '" + name + "' AND password = '" + pw + "'"

If a user types alice and their password, the query works as intended. But the database can't tell which parts of the final string came from the programmer and which came from the user. If someone enters a username containing a quote character followed by SQL code, such as ' OR '1'='1' --, the input changes the structure of the query. The condition becomes always true, the rest is commented out, and the login check is bypassed. More elaborate inputs can read entire tables, modify data and sometimes run commands on the server.

This is SQL injection, a classic member of the injection family: untrusted data is mixed with code and interpreted as code. Despite being well understood for over two decades, it still appears regularly, often in older or hastily built applications, and has been behind many large data breaches.

The fix is parameterized queries (prepared statements): the query structure is sent to the database separately, with placeholders, and user input is passed only as data:

SELECT * FROM users WHERE username = ?

No matter what characters the input contains, it can't change the query's structure. Additional layers help: input validation, least-privilege database accounts and modern frameworks that parameterize by default. Trying to filter out dangerous characters by hand is fragile and frequently bypassed.

Step 5 of 11Compare

String-built query vs parameterized query

AspectString-built (vulnerable)Parameterized (safe)
How the query is madeUser input is glued into the SQL textSQL structure is sent with ? placeholders; input goes separately
Input: aliceWorks as intendedWorks as intended
Input: ' OR '1'='1' --Rewrites the condition; login bypassedTreated as a strange username; no match
Can input change the structure?YesNo
Extra layersHand-made character filters (often bypassed)Input validation, least-privilege DB accounts

Step 6 of 11Practice · Spot the mistake

A developer's login code is reviewed. Select the line that creates a SQL injection vulnerability.

Step 7 of 11Learn

Cross-site scripting (XSS)

Cross-site scripting is injection into web pages. If an application includes user input in a page without properly encoding it, an attacker can make the page run their JavaScript in other users' browsers.

Imagine a product review feature that displays reviews exactly as typed. An attacker submits a review containing a script tag. Every visitor who views that product now runs the attacker's script, inside the trusted site, with access to whatever the page can do: reading information shown on the page, performing actions as the logged-in user, or showing a fake login form.

Three main types:

  • Stored XSS: the malicious input is saved by the server, like the review, and served to every visitor. Usually the most damaging.
  • Reflected XSS: the input comes from the request, such as a search term in a link, and is echoed back immediately. The attacker must trick a victim into clicking a crafted link.
  • DOM-based XSS: the browser-side JavaScript itself inserts untrusted data into the page unsafely.

Defenses work in layers:

  • Output encoding: convert special characters like the less-than sign into harmless text equivalents, matched to the context (HTML, attribute, JavaScript or URL). Modern frameworks like React and Angular do this by default unless developers bypass it.
  • Content Security Policy (CSP): an HTTP header telling the browser which script sources are allowed, blocking injected inline scripts.
  • HttpOnly cookies: session cookies flagged so JavaScript can't read them, limiting what a successful XSS can steal.
Stored cross-site scripting, step by stepAttacker postsa review witha scriptServer storesit unencodedVictim opensthe productpageScript runs inthe victim’sbrowser

Step 8 of 11Practice · Match the pairs

Match each vulnerability to its primary defense.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. SQL injection
  2. Cross-site scripting
  3. Insecure direct object reference
  4. Vulnerable outdated library

Step 9 of 11Note

Step 10 of 11Practice · True or false

Hiding the admin button from normal users in the browser is enough to prevent them from using admin functions.

Step 11 of 11Practice · Select all that apply

Which of these are effective defenses against cross-site scripting? Select all that apply.

Select all that apply.