Skip to content
FORGENO ADS GAMESLifetime Pass $8

Ethical Hacking & Cyber Defense · Unit 5 of 8

Unit 5: Web application security

Sessions and cookies, the OWASP Top 10, and the bugs real tests find most: broken access control, injection, cross-site scripting and login failures, with fixes.

Opens the first lesson of this unit in Ethical Hacking & Cyber Defense. Every lesson is open from the start.

Lesson 1: How web apps work: requests, cookies and sessions

Goal: Explain sessions, cookies and cookie security flags, and how an intercepting proxy is used in an authorized web test.

HTTP has no memory: each request stands alone. To remember that you are logged in, a web app gives your browser a session ID after you log in, usually stored in a cookie. The browser sends that cookie with every request, and the server looks it up to know who you are. Anyone who steals a valid session cookie can act as you until it expires, which is why session handling is a major part of every web test.

Cookie flagWhat it doesWhat it prevents
SecureOnly send the cookie over HTTPSLeaking the session on unencrypted connections
HttpOnlyPage scripts cannot read the cookieScript-based theft of the session if the site has an XSS bug
SameSite=Lax or StrictLimit sending the cookie on requests started by other sitesMost cross-site request forgery
Short expiry and logout that worksSessions end on the server, not just in the browserStolen or forgotten sessions staying valid for days

Web testers work through an intercepting proxy such as Burp Suite or OWASP ZAP. The proxy sits between the browser and the site, so the tester can pause each request, read it and change it before it is sent. Most web vulnerabilities are found this way: changing a number, a hidden field or a parameter the developer assumed nobody would touch. The core lesson of web security follows: everything that comes from the browser can be changed by the user, so the server must check everything again.

The OWASP Top 10 is the best-known list of web application risks, updated every few years from industry data. In the 2025 edition, broken access control is still number one, followed by security misconfiguration and software supply chain failures, with cryptographic failures, injection, insecure design and authentication failures close behind. Knowing the list helps you structure a test and talk with developers in shared terms.

Worked example: the hidden price field

  1. In an authorized test of a shop, the tester adds a $40 item to the cart and intercepts the checkout request in the proxy.
  2. The request contains item=1187&price=40.00. The price comes from the browser.
  3. The tester changes the price to 1.00 in the proxy, and the server accepts the order total of $1.00.
  4. The finding: the server trusts a price sent by the client. The fix: look up the price on the server from the item ID and ignore any price the browser sends.

The page looked fine in a normal browser. The bug only appeared when someone changed what the browser sent, which is exactly what attackers do.

Session ID
A random value a web app gives a logged-in user so it can recognise later requests.
Cookie
A small piece of data a website stores in the browser and receives back with each request.
HttpOnly
A cookie flag that stops page scripts from reading the cookie.
Intercepting proxy
A tool that sits between browser and website so a tester can view and change each request.
OWASP Top 10
The Open Worldwide Application Security Project's list of the most critical web application risks.

Remember: Anything the browser sends can be changed. The server must check it all again.

Lesson 2: Injection and how parameterized queries stop it

Goal: Explain why building commands from user input causes injection, and how parameterized queries and safe APIs prevent it.

Injection happens when an application mixes user input into a command for another system, such as a database query or an operating system command, and the input is treated as part of the command instead of as plain data. If a user can type characters that change the command's meaning, they may read, change or delete data they should never touch. SQL injection is the classic example, and it has caused some of the largest data breaches in history.

// VULNERABLE: the user's text becomes part of the SQL command
query = "SELECT * FROM users WHERE email = '" + email + "'";

// SAFE: a parameterized query; the database treats email as data only
query = "SELECT * FROM users WHERE email = ?";
db.execute(query, [email]);

In the vulnerable version, quote marks and SQL keywords typed into the email box become part of the query, so a crafted input can change the query's logic: return every row, skip the password check, and so on. In the safe version, the query structure is fixed first and the input is sent separately, so whatever the user types is only ever compared as text. Parameterized queries (also called prepared statements) are the real fix. Input validation helps as a second layer, but filtering “bad characters” by hand is easy to get wrong and is not a substitute.

Command injection is the same mistake with the operating system. A web feature that runs ping on an address the user types is dangerous if it builds a shell command from that text. The fix is again to avoid building commands from strings: use a language function that runs a program with a fixed list of arguments, validate that the input really is an IP address, and run the service with the least privilege possible so any mistake does less damage.

Worked example: finding injection in a code review

  1. A developer's search feature builds this: "SELECT * FROM products WHERE name LIKE '%" + term + "%'".
  2. The user's search term is joined straight into the SQL string, so the query's meaning depends on what the user types.
  3. In an authorized test, a single quote in the search box causes a 500 error that shows a database message: strong evidence of injection.
  4. The fix: a parameterized query with the term passed separately, plus generic error pages so database messages never reach users.

The tell-tale sign in code is string concatenation into a query. The tell-tale sign in testing is an input that breaks the query and changes the page's behaviour.

Injection
A flaw where user input is treated as part of a command, letting it change what the command does.
SQL injection
Injection into a database query, which can expose or change data.
Parameterized query
A database query whose structure is fixed, with user input passed separately as data; also called a prepared statement.
Command injection
Injection into an operating system command run by an application.

Remember: Never build a command by gluing in user text. Fixed query, data passed separately.

Lesson 3: Cross-site scripting and cross-site request forgery

Goal: Describe stored, reflected and DOM-based XSS and CSRF, their impact, and the defences that stop them.

Cross-site scripting (XSS) happens when a site includes user-supplied text in a page without making it safe, so a browser runs it as code. Because the code runs inside the trusted site, it can do anything the logged-in user can: read what is on the page, make requests as them, or show a fake login form. Stored XSS is saved on the server (for example in a comment) and hits everyone who views it. Reflected XSS bounces off a single request, often through a crafted link. DOM-based XSS happens entirely in the page's own JavaScript.

DefenceHow it helps
Output encodingConvert characters like < and > into harmless text when inserting user data into HTML, so it displays instead of running. Modern frameworks do this by default; danger appears when developers bypass it.
Content Security Policy (CSP)A response header that tells the browser which scripts are allowed to run, blocking injected ones.
HttpOnly cookiesEven if a script runs, it cannot read the session cookie.
Input validationReject data that does not fit the expected shape, as an extra layer.

Cross-site request forgery (CSRF) tricks a logged-in user's browser into sending a request they did not intend, such as changing their email address, because the browser automatically attaches their cookies. The defences are anti-CSRF tokens (a secret value in each form that another site cannot know), SameSite cookies, and asking for the password again before sensitive changes. XSS is the more dangerous of the two: a working XSS bug can usually defeat CSRF protections too.

Worked example: a comment box review

  1. An app shows customer reviews. In an authorized test, the tester submits a review containing HTML formatting tags.
  2. The tags are applied on the page instead of being shown as text. The output is not encoded, so script content would likely run for every visitor: a stored XSS risk.
  3. The tester confirms with a harmless proof agreed in the rules (such as text that changes colour), captures the evidence and goes no further.
  4. The fix: use the framework's default encoding for review text, remove the code that bypassed it, add a Content Security Policy, and mark session cookies HttpOnly.

The root cause was one line that inserted raw HTML. Encoding output by default, and treating any bypass as a code-review red flag, prevents the whole class.

Cross-site scripting (XSS)
A flaw where a site includes user input in a page so that the browser runs it as code.
Stored XSS
XSS where the malicious input is saved on the server and shown to other users.
Output encoding
Converting special characters in user data so a browser displays them as text instead of running them.
Content Security Policy
A response header that tells the browser which scripts and sources a page may load.
CSRF
Cross-site request forgery: tricking a logged-in user's browser into sending an unwanted request.

Remember: Encode output, set a Content Security Policy, use HttpOnly and SameSite cookies, and add CSRF tokens to forms.

Lesson 4: Broken access control and authentication failures

Goal: Recognise insecure direct object references and other access control flaws, and the controls that stop password attacks on logins.

Authentication checks who you are. Authorization (access control) checks what you are allowed to do. Broken access control is the most common serious web flaw: the app knows who you are but fails to check whether *this* record, page or action is yours. The classic form is an insecure direct object reference (IDOR): the page for invoice 1043 is at /invoices/1043, and changing the number to 1044 shows another customer's invoice.

// VULNERABLE: any logged-in user can read any invoice
invoice = db.find(invoiceId)

// SAFE: the record must belong to the user who is asking
invoice = db.find({ id: invoiceId, ownerId: currentUser.id })
if (!invoice) return 404

Other access control failures include ordinary users reaching admin pages because the link was only hidden in the menu, APIs that check permissions for reading but not for changing data, and changing a role value in a request. The defence is the same every time: deny by default and check permissions on the server for every request, using the identity from the session, never from a value the user can edit.

Authentication failures include logins that allow unlimited guesses, weak password rules, missing multi-factor authentication (MFA), session IDs that do not change after login and sessions that never expire. Attackers use credential stuffing (trying username and password pairs leaked from other sites) and password spraying (trying one common password against many accounts to avoid lockouts). The strongest defences are MFA, rate limiting with alerting, checking new passwords against lists of breached passwords, and generic login error messages that do not reveal which usernames exist.

Worked example: testing one access control rule

  1. The rules of engagement provide two test customer accounts, A and B.
  2. Logged in as A, the tester opens A's order at /api/orders/5521. The response shows A's order.
  3. Still logged in as A, the tester requests /api/orders/5522, which belongs to B. The server returns B's name, address and items.
  4. The finding is an IDOR with high impact (private data). The fix is a server-side ownership check on every order endpoint, plus an automated test that uses two accounts.

Using two test accounts is the standard way to prove access control flaws safely, without touching real customers' data.

Hands-on lab in the room: Secure code review. Review short code snippets and spot which ones are vulnerable, and to what.

Authentication
Checking who a user is, for example with a password and a second factor.
Authorization
Checking what an authenticated user is allowed to see and do.
IDOR
Insecure direct object reference: access to someone else's record by changing an ID the server fails to check.
Credential stuffing
Trying username and password pairs leaked from other sites against a login.
Password spraying
Trying one or a few common passwords against many accounts to avoid lockouts.
Multi-factor authentication
Requiring two or more kinds of proof, such as a password and a code from an app, to log in.

Remember: Who are you (authentication) is not what may you touch (authorization). Check ownership on the server, every request.

Practise it in Ethical Hacking & Cyber Defense

Each lesson ends with three questions that check you can use the idea, not just recognise it. Wrong answers explain why and come back in Review. The unit ends with a 6-question quiz; pass it with 80% or more to master the unit. Hands-on lab: Secure code review.

Every lesson is free: no ads, no lives and no paywall.