Practice library / Web applications and APIs
Workbook · Easy · 2 hours
Introduction to Web Applications
A hands-on tour of the client-server model, HTTP, cookies, sessions and the same-origin policy.
On this page 14 sections
- ·Prerequisites
- ·Lab setup
- 1Start the app and send the first request
- 2Read the front end
- 3Watch the traffic in DevTools
- 4Log in and catch the cookie
- 5Prove that the session ID is your identity
- 6Test the same-origin policy
- 7Show why client-side values cannot be trusted
- 8Map the attack surface
- ·Check
- ·Practice questions
- ·Key terms
- ·Clean-up
Web applications move data between a browser and a server, and almost every modern business depends on them. A tester must see both sides clearly before touching one, because an attack is any request a developer did not expect. This workbook sets the ground: HTTP requests and responses, cookies and server-side sessions, the same-origin policy, and the attack surface that each part exposes. The practice app runs on your own machine, so you can read every line of code, change it, and see what the server trusts. You also meet the trust boundary between client and server, which is a core idea in web security. Each later web lab, from Burp Suite Basics to Web Application Recon, assumes you know the content of these eight steps.
What You'll Learn
- Name the roles of the browser, the web server, the application code and the data store
- Read an HTTP request and an HTTP response with curl and browser DevTools
- Explain how a cookie and a server-side session keep a user logged in
- Show why the same-origin policy limits what a web page can read
- Prove that a server must check every value that the client sends
- List the inputs, trust boundaries and login points of a web application
A web tester must know how a web application works before breaking one. In this workbook you run a small web application on your own computer. You send it requests, read the answers, and find the places where a bug can hide. Each step teaches one idea and ends with a command you run yourself.
Prerequisites
Finish these items first:
- Linux for Beginners: you must open a terminal, change directory and edit a file with
nano. - Kali Linux Environment Setup: you need a working Kali machine with an updated browser and terminal.
HTML & CSS Basics helps in Step 2. You can read it later.
Lab setup
| Item | What you need |
|---|---|
| Machine | Kali Linux (or any Linux) with python3, curl and Firefox or Chrome |
| Target | The practice app in this workbook. You start it yourself on 127.0.0.1 |
| Ports | 8080 for the app, 8081 for a second origin in Step 6 |
| Terminals | Three: one for the app, one for commands, one for Step 6 |
| Accounts | student with password lab-pass. The app also holds a second user, bob |
Legal note. Every command in this workbook targets the practice app on 127.0.0.1, a machine that you own. Never send these requests to a site that you do not own or have written permission to test. The app is weak on purpose. Do not expose it to a network.
Create the practice app. Make a folder, open a new file and paste the code below.
mkdir -p ~/webapp-lab && cd ~/webapp-lab
nano lab_app.py#!/usr/bin/env python3
"""Practice app. Listens on 127.0.0.1 only. Teaching sample, not production code."""
import json
import secrets
import sys
from http.cookies import SimpleCookie
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import parse_qs, urlparse
USERS = {"student": "lab-pass", "bob": "bob-pass"}
NOTES = {1: "student: my lab notes", 2: "bob: private note"}
PRICES = {"widget": 49}
SESSIONS = {} # session ID -> user name. This is the server-side state.
PAGE = """<!doctype html>
<html>
<head><title>Practice Shop</title></head>
<body>
<h1>Practice Shop</h1>
<!-- TODO: remove the test account (student) before release -->
<form method="post" action="/login">
<input name="username" placeholder="username">
<input name="password" type="password" placeholder="password">
<button>Log in</button>
</form>
<form method="post" action="/api/checkout">
<input type="hidden" name="item" value="widget">
<input type="hidden" name="price" value="49">
<button>Buy widget (49 USD)</button>
</form>
<p id="who">Checking session...</p>
<script>
fetch("/api/profile")
.then(r => r.json())
.then(d => {
document.getElementById("who").textContent =
d.user ? "Logged in as " + d.user : "Not logged in";
});
</script>
</body>
</html>"""
class App(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def reply(self, code, body, ctype="text/html; charset=utf-8", headers=()):
data = body.encode()
self.send_response(code)
self.send_header("Content-Type", ctype)
self.send_header("Content-Length", str(len(data)))
for name, value in headers:
self.send_header(name, value)
self.end_headers()
self.wfile.write(data)
def reply_json(self, code, obj, headers=()):
self.reply(code, json.dumps(obj), "application/json", headers)
def current_user(self):
jar = SimpleCookie(self.headers.get("Cookie", ""))
morsel = jar.get("sid")
return SESSIONS.get(morsel.value) if morsel else None
def read_form(self):
size = int(self.headers.get("Content-Length", 0))
fields = parse_qs(self.rfile.read(size).decode())
return {name: values[0] for name, values in fields.items()}
def do_GET(self):
url = urlparse(self.path)
user = self.current_user()
if url.path == "/":
self.reply(200, PAGE)
elif url.path == "/robots.txt":
self.reply(200, "User-agent: *\nDisallow: /admin\n", "text/plain")
elif url.path == "/api/profile":
if user:
self.reply_json(200, {"user": user, "role": "user"})
else:
self.reply_json(401, {"error": "login required"})
elif url.path == "/api/notes":
if not user:
self.reply_json(401, {"error": "login required"})
return
try:
note_id = int(parse_qs(url.query).get("id", ["0"])[0])
except ValueError:
self.reply_json(400, {"error": "id must be a number"})
return
# Flaw on purpose: the code never checks who owns the note.
if note_id in NOTES:
self.reply_json(200, {"id": note_id, "note": NOTES[note_id]})
else:
self.reply_json(404, {"error": "no such note"})
elif url.path == "/admin":
if user:
self.reply_json(403, {"error": "admin only"})
else:
self.reply_json(401, {"error": "login required"})
else:
self.reply_json(404, {"error": "not found"})
def do_POST(self):
path = urlparse(self.path).path
user = self.current_user()
if path == "/login":
form = self.read_form()
name = form.get("username", "")
if name in USERS and USERS[name] == form.get("password"):
sid = secrets.token_hex(16)
SESSIONS[sid] = name
cookie = f"sid={sid}; HttpOnly; SameSite=Lax; Path=/"
self.reply(302, "", headers=[("Location", "/"), ("Set-Cookie", cookie)])
else:
self.reply_json(401, {"error": "bad credentials"})
elif path == "/logout":
morsel = SimpleCookie(self.headers.get("Cookie", "")).get("sid")
if morsel:
SESSIONS.pop(morsel.value, None)
self.reply_json(200, {"ok": True})
elif path == "/api/checkout":
if not user:
self.reply_json(401, {"error": "login required"})
return
form = self.read_form()
item = form.get("item", "")
if item not in PRICES:
self.reply_json(400, {"error": "unknown item"})
return
try:
price = int(form.get("price", "")) # Flaw on purpose: trusts the client.
except ValueError:
self.reply_json(400, {"error": "price must be a number"})
return
self.reply_json(200, {"user": user, "item": item, "charged_usd": price})
else:
self.reply_json(404, {"error": "not found"})
if __name__ == "__main__":
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
print(f"Practice app on http://127.0.0.1:{port} (press Ctrl+C to stop)")
ThreadingHTTPServer(("127.0.0.1", port), App).serve_forever()Save the file (Ctrl+O, Enter, Ctrl+X). Then check the syntax:
python3 -m py_compile lab_app.py && echo "syntax ok"Example output:
syntax okThe app uses only the Python standard library. It has two flaws that you will find on purpose. Each flaw has a comment in the code.
Step 1: Start the app and send the first request
A web application has two sides. The client (your browser or curl) sends a request. The server (the program that listens on a port) sends back a response. HTTP is the language of that conversation.
Most real applications have four parts. The practice app has the same four, in one file.
| Part | Real application | Practice app |
|---|---|---|
| Client | Browser or mobile app | Browser and curl |
| Web server | nginx, Apache | Python http.server |
| Application code | Django, Express, Laravel | The App class |
| Data store | PostgreSQL, MySQL | The USERS, NOTES and SESSIONS dictionaries |
Start the app and read one request and one response
Run the app in Terminal 1. Leave it running. Send a request from Terminal 2.
cd ~/webapp-lab
python3 lab_app.pyExample output:
Practice app on http://127.0.0.1:8080 (press Ctrl+C to stop)cd ~/webapp-lab
curl -sv http://127.0.0.1:8080/ -o /dev/null 2>&1 | grep -E '^[<>]'The flag -v prints the request and the response headers. The flag -s hides the progress meter. The grep keeps only the lines that start with > (sent) or < (received).
Example output (the version numbers and the date differ on your machine):
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/8.5.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: BaseHTTP/0.6 Python/3.13.5
< Date: Tue, 03 Jun 2025 10:15:42 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 778
<Read the output in four parts:
- Request line:
GET / HTTP/1.1. The method isGET. The path is/. - Request headers:
Host,User-AgentandAcceptdescribe the client. - Status line:
HTTP/1.1 200 OK. The code200means success. - Response headers:
Servernames the software.Content-Typetells the browser how to read the body.
Now look at Terminal 1. The server logs each request it handles.
Example output:
127.0.0.1 - - [03/Jun/2025 10:15:42] "GET / HTTP/1.1" 200 -Why it matters. Every web attack is a request that the developer did not expect. You must be able to read both sides of the conversation. The Server header also leaks the software and version. Testers use this to look for known flaws.
Step 2: Read the front end
The front end is the code that runs in the browser. It has three parts:
- HTML gives the page its structure (forms, links, text).
- CSS gives the page its style.
- JavaScript gives the page its behaviour.
The server sends all three to the client. So the user can read all three. The back end is the code that runs on the server.
Read the page source
Print the page that the server sends. Then open the same page in your browser and view its source.
curl -s http://127.0.0.1:8080/Example output:
<!doctype html>
<html>
<head><title>Practice Shop</title></head>
<body>
<h1>Practice Shop</h1>
<!-- TODO: remove the test account (student) before release -->
<form method="post" action="/login">
<input name="username" placeholder="username">
<input name="password" type="password" placeholder="password">
<button>Log in</button>
</form>
<form method="post" action="/api/checkout">
<input type="hidden" name="item" value="widget">
<input type="hidden" name="price" value="49">
<button>Buy widget (49 USD)</button>
</form>
<p id="who">Checking session...</p>
<script>
fetch("/api/profile")
...
</script>
</body>
</html>In the browser, open http://127.0.0.1:8080/. Press Ctrl+U to view the source. It matches the curl output.
Find three things in the output:
- A comment. The comment names a test account. Developers leave comments like this by mistake.
- Hidden fields.
itemandpriceare in the page, but the user does not see them in the form. - A script. The script calls
/api/profile. This is a path that the page does not link to.
Why it matters. The browser is under the user's control. A user can read the source, change a hidden field and edit the script. A tester starts here because the front end shows what the back end accepts.
Step 3: Watch the traffic in DevTools
An API is a set of paths that return data instead of pages. The page in Step 2 calls one API path. The browser developer tools (DevTools) show that call.
Find the API call and read its status code
Open DevTools in the browser. Reload the page. Read the request to /api/profile.
- Open
http://127.0.0.1:8080/in Firefox or Chrome. - Press
F12to open DevTools. - Select the Network tab.
- Press
F5to reload the page. - Click the row
profile. Read its Status and its Headers.
You see the row / (the page) and the row profile (the API call to /api/profile). The browser can also request favicon.ico. The app has no icon and returns 404 for it. Ignore that row. The status of /api/profile is 401. You have not logged in yet.
Send the same request with curl:
curl -si http://127.0.0.1:8080/api/profileThe flag -i prints the response headers and the body. Do not use -I. The practice app does not accept the HEAD method.
Example output:
HTTP/1.1 401 Unauthorized
Server: BaseHTTP/0.6 Python/3.13.5
Date: Tue, 03 Jun 2025 10:16:10 GMT
Content-Type: application/json
Content-Length: 27
{"error": "login required"}The body is JSON, a text format for data. It is not HTML. The server decides what to send. The front end only shows it.
The status code tells you what the back end decided:
| Code | Meaning | Where you see it in this app |
|---|---|---|
200 | Success | / and /api/profile after login |
302 | Redirect to another path | /login after a good password |
400 | The request is not valid | /api/notes?id=abc, sent with a session cookie |
401 | You are not logged in | /api/profile with no cookie |
403 | You are logged in, but not allowed | /admin for student |
404 | The path or object does not exist | /api/notes?id=9, sent with a session cookie |
Why it matters. The back end does the real work: it checks who you are, reads the data and builds the answer. Status codes tell you which check you passed or failed. You will use them in every web test.
Step 4: Log in and catch the cookie
HTTP has no memory. The server treats each request as new. So after a login, the server must give the client a proof of the login. That proof is a cookie. A cookie is a small value that the server sets. The browser sends it back on every request to that site.
Send the login request and read Set-Cookie
Send the form fields with the POST method. Save the cookie in a file.
curl -si -c cookies.txt -d "username=student&password=lab-pass" http://127.0.0.1:8080/loginThe flag -d sends form data and makes the request a POST. The flag -c cookies.txt saves the cookies that the server sets.
Example output (your sid value differs):
HTTP/1.1 302 Found
Server: BaseHTTP/0.6 Python/3.13.5
Date: Tue, 03 Jun 2025 10:17:03 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Location: /
Set-Cookie: sid=95c021abe921c1654a9ab82b2f014bdc; HttpOnly; SameSite=Lax; Path=/Look at the line Set-Cookie. It has one value and three attributes:
| Part | Meaning |
|---|---|
sid=95c0... | The session ID: a long random value that names your login |
HttpOnly | JavaScript cannot read this cookie |
SameSite=Lax | The browser does not send the cookie on most cross-site requests |
Path=/ | The browser sends the cookie for every path on the site |
The app does not set Secure, because the lab uses plain HTTP. A real site must set Secure, so the browser sends the cookie only over HTTPS.
Read the cookie file:
cat cookies.txtExample output:
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
#HttpOnly_127.0.0.1 FALSE / FALSE 0 sid 95c021abe921c1654a9ab82b2f014bdcThe prefix #HttpOnly_ is how curl marks an HttpOnly cookie. It is not a comment.
Now send a wrong password and compare the result:
curl -si -d "username=student&password=wrong" http://127.0.0.1:8080/login | head -1Example output:
HTTP/1.1 401 UnauthorizedA wrong password gives 401 and no cookie. A right password gives 302 and a cookie.
Now check the HttpOnly attribute in the browser:
- Open
http://127.0.0.1:8080/. - Enter
studentandlab-pass, and select Log in. The page showsLogged in as student. - Press
F12and select the Console tab. If Firefox blocks pasting, typeallow pastingand pressEnter. - Run
document.cookie.
Example output:
""The result is empty. HttpOnly hides the sid cookie from JavaScript. Open the Storage tab (Firefox) or the Application tab (Chrome). Select Cookies. The sid cookie is there, and its HttpOnly column is checked.
Why it matters. The login form is the first authentication point: the place where the app checks who you are. It is the target of password attacks. You can practise them in Step 4 of Hydra Brute Force.
Step 5: Prove that the session ID is your identity
A session is the server-side record that links a session ID to a user. In the practice app it is the SESSIONS dictionary. The cookie only holds the key. The server holds the rest.
Replay, fake and end a session
Send the cookie with a request. Then show that the server reads only the session ID.
# 1. Send the saved cookie
curl -s -w '\n' -b cookies.txt http://127.0.0.1:8080/api/profile
# 2. Send the same session ID by hand
SID=$(awk '$6 == "sid" {print $7}' cookies.txt)
curl -s -w '\n' -H "Cookie: sid=$SID" http://127.0.0.1:8080/api/profile
# 3. Send a made-up session ID
curl -s -w '\n' -H "Cookie: sid=0000" http://127.0.0.1:8080/api/profileThe awk command reads the 7th column of the row sid in cookies.txt and stores it in the shell variable SID. The flag -w '\n' adds a line break after the JSON, so each answer has its own line.
Example output:
{"user": "student", "role": "user"}
{"user": "student", "role": "user"}
{"error": "login required"}Request 2 works without curl reading the cookie file. So the server trusts the session ID and nothing else. Anyone who holds a valid session ID is that user. This is why a stolen session ID is an account takeover, and why HttpOnly, Secure and HTTPS matter.
Request 3 fails. The server does not know 0000. A real session ID is long and random, so a tester cannot guess it.
Now end the session on the server:
curl -s -w '\n' -b cookies.txt -X POST http://127.0.0.1:8080/logout
curl -s -w '\n' -b cookies.txt http://127.0.0.1:8080/api/profileExample output:
{"ok": true}
{"error": "login required"}The cookie file still holds the same session ID. But the server deleted the record. So the old ID no longer works. A correct logout must destroy the session on the server, not only delete the cookie in the browser.
Why it matters. The session is the second authentication point. If an attacker reads or steals the session ID, the password does not matter. Many attacks, such as cross-site scripting, aim to steal this one value. A later lab covers them: Cross-Site Scripting (XSS).
Step 6: Test the same-origin policy
An origin is the scheme, the host and the port of a URL: http://127.0.0.1:8080 is one origin. http://127.0.0.1:8081 is a different origin, because the port differs. So is http://localhost:8080, because the host differs.
The same-origin policy (SOP) is a browser rule. A page from one origin can send a request to another origin, but it cannot read the response. Without this rule, any page that you open could read your mail or your bank account in another tab.
Read a response from a different origin
Serve a page from a second origin. Then ask that page to read the app on port 8080.
Open Terminal 3. Serve an empty folder on port 8081. Use an empty folder, so the server does not list your cookies.txt file.
mkdir -p ~/webapp-lab/empty && cd ~/webapp-lab/empty
python3 -m http.server 8081 --bind 127.0.0.1Example output:
Serving HTTP on 127.0.0.1 port 8081 (http://127.0.0.1:8081/) ...First, test the same origin. Open the tab at http://127.0.0.1:8080/. Check that it shows Logged in as student. If it does not, log in again. Then open the Console and run:
fetch("/api/profile").then(r => r.text()).then(console.log)Example output:
{"user": "student", "role": "user"}The read works. The page and the API share one origin.
Now test a different origin. Open a new tab at http://127.0.0.1:8081/. Open its Console and run:
fetch("http://127.0.0.1:8080/api/profile").then(r => r.text()).then(console.log)The error message names CORS (Cross-Origin Resource Sharing). CORS is a set of response headers with which a server allows other origins to read its responses. This request has none, so the browser blocks the read.
Example output (the wording depends on the browser):
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8080/api/profile. (Reason: CORS header 'Access-Control-Allow-Origin' missing). Status code: 401.Chrome prints this instead:
Access to fetch at 'http://127.0.0.1:8080/api/profile' from origin 'http://127.0.0.1:8081' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.The browser blocked the read. Check Terminal 1. The request still reached the server.
Example output:
127.0.0.1 - - [03/Jun/2025 10:25:31] "GET /api/profile HTTP/1.1" 401 -The status is 401, not 200. A cross-origin fetch does not send cookies unless the page asks for it and the server allows it. So the browser did not send your sid cookie.
Last, show that SOP is a browser rule and not a server rule. In Terminal 2, send a request with a foreign Origin header:
curl -si -H "Origin: http://127.0.0.1:8081" http://127.0.0.1:8080/api/profile | head -1Example output:
HTTP/1.1 401 Unauthorizedcurl reads the answer without any block. SOP protects the browser user. It does not protect the server from a tester or an attacker who uses their own tool.
Cookies follow different rules from origins. A cookie belongs to a host, not to a port. So 127.0.0.1:8080 and 127.0.0.1:8081 share cookies in one browser.
Why it matters. The same-origin policy is the base rule of browser security. A server can relax the policy with CORS. The header Access-Control-Allow-Origin names the origins that can read the response. A wrong CORS setting can let a malicious page read private data. A later, advanced lab covers CORS flaws: Modern Web Exploitation.
Step 7: Show why client-side values cannot be trusted
The browser runs on the user's computer. So the user controls every value that the browser sends. The back end must not believe those values. This is a common design mistake in web applications.
The page in Step 2 has a hidden field price with the value 49. The form sends it to /api/checkout.
Change a hidden field and send it to the server
Log in again. Buy the widget with the normal price. Then buy it with a price that you choose.
# Log in again (Step 5 ended the old session)
curl -s -c cookies.txt -o /dev/null -d "username=student&password=lab-pass" http://127.0.0.1:8080/login
# Buy with the price from the form
curl -s -w '\n' -b cookies.txt -d "item=widget&price=49" http://127.0.0.1:8080/api/checkout
# Buy with a price that you choose
curl -s -w '\n' -b cookies.txt -d "item=widget&price=1" http://127.0.0.1:8080/api/checkoutExample output:
{"user": "student", "item": "widget", "charged_usd": 49}
{"user": "student", "item": "widget", "charged_usd": 1}The server charged 1 USD. The mistake is in this line of lab_app.py:
price = int(form.get("price", "")) # Flaw on purpose: trusts the client.You did not break anything. You sent a request that the form does not offer, and the server did not check it. This flaw is called parameter tampering.
Now fix the flaw. The old code is this five-line block in the /api/checkout branch:
try:
price = int(form.get("price", "")) # Flaw on purpose: trusts the client.
except ValueError:
self.reply_json(400, {"error": "price must be a number"})
returnThe new code is this single line. Keep the same indentation:
price = PRICES[item] # The server decides the price.Apply the fix:
- Press
Ctrl+Cin Terminal 1 to stop the app. - Run
nano lab_app.py. - Replace the five-line
tryblock with the single line. - Save the file.
- Run
python3 lab_app.pyin Terminal 1. - Run the two commands below in Terminal 2.
The restart clears all sessions, so the first command logs you in again.
curl -s -c cookies.txt -o /dev/null -d "username=student&password=lab-pass" http://127.0.0.1:8080/login
curl -s -w '\n' -b cookies.txt -d "item=widget&price=1" http://127.0.0.1:8080/api/checkoutExample output:
{"user": "student", "item": "widget", "charged_usd": 49}The server now ignores the price field. The price comes from the PRICES dictionary, which only the server can change.
Why it matters. Client-side checks (required, maxlength, hidden fields, JavaScript rules) help the user. They do not protect the application. The rule for every developer and tester: validate on the server. Many flaws in later labs come from this one mistake.
Step 8: Map the attack surface
The attack surface is every place where an outsider can send input or reach a function. A trust boundary is the line between data that you control and data that you do not. In a web application, the network is that line. Everything that crosses it is untrusted.
Find hidden paths and a missing access check
Probe three places that the page does not show. Then write down the full attack surface.
You know /api/notes from the code in lab_app.py. A real tester finds such paths with Web Application Recon.
# 1. A file that lists paths for search engines
curl -s http://127.0.0.1:8080/robots.txt
# 2. The path that the file names
curl -si -b cookies.txt http://127.0.0.1:8080/admin | grep -E '^(HTTP|\{)'
# 3. Your own note, then the note with the next number
curl -s -w '\n' -b cookies.txt "http://127.0.0.1:8080/api/notes?id=1"
curl -s -w '\n' -b cookies.txt "http://127.0.0.1:8080/api/notes?id=2"Example output:
User-agent: *
Disallow: /admin
HTTP/1.1 403 Forbidden
{"error": "admin only"}
{"id": 1, "note": "student: my lab notes"}
{"id": 2, "note": "bob: private note"}Read each result:
robots.txtasks search engines to skip/admin. It also tells a tester that/adminexists. A hidden path is not a protected path./adminreturns403, not401. The server knows who you are (authentication passed) and refuses you (authorisation failed). This is correct behaviour.id=2returns the note ofbob, a user that you are not. The code never checks who owns a note. This is a missing authorisation check, called an insecure direct object reference (IDOR). The app has this flaw on purpose.
Now write down what you found. Use this table as your model:
| Surface | Found in this app | Risk |
|---|---|---|
| Form fields | username, password | Password guessing |
| Hidden fields | item, price | Parameter tampering (Step 7) |
| Query parameter | id in /api/notes | IDOR |
| Cookie | sid | Session theft |
| Request headers | Cookie, Origin, Host | The client controls them |
| Response headers | Server | Software and version leak |
| Page source | Comment that names student | Information leak |
| Paths not linked in the page | /admin, /api/notes | Missing or weak access control |
| Paths found in the page script | /api/profile | Needs an authentication check |
| Login points | /login, /logout | Password guessing |
| Trust boundary | The network between browser and server: every form field, header, cookie and query parameter | Validate on the server |
Why it matters. A tester does not start with an attack. A tester starts with a map. The longer this table, the more places to test. A defender uses the same table to decide where to add checks.
Check
You have finished this workbook when you can show all six results below. Run the Check after Step 7. Log in again first. Scroll up in Terminal 1 to see the earlier log lines.
- Terminal 1 shows
GET /api/profile ... 401andPOST /login ... 302lines in its log. curl -si http://127.0.0.1:8080/api/profilereturns401. The same request with-b cookies.txtafter a login returns{"user": "student", "role": "user"}.- The Console command
document.cookiereturns""while you are logged in, andcurl -si -d "username=student&password=lab-pass" http://127.0.0.1:8080/login | grep -i set-cookieshowsHttpOnly. - After
POST /logout, the old session ID returns401. - The
fetchfrom127.0.0.1:8081to127.0.0.1:8080fails in the console, while the samefetchfrom127.0.0.1:8080works. - After your fix,
price=1returns"charged_usd": 49.
Practice questions
1. A page runs on https://shop.example.com. Which of these URLs share its origin?
https://shop.example.com/carthttp://shop.example.comhttps://shop.example.com:8443https://www.example.com
Answer
Only https://shop.example.com/cart has the same origin. The path does not count. The second URL has a different scheme, the third a different port and the fourth a different host.
2. The login response has Set-Cookie: sid=abc; HttpOnly. What can a script on the page do with that cookie?
Answer
The script cannot read it. document.cookie does not list an HttpOnly cookie. The browser still sends the cookie with each request to the site.
3. A user logs out. The browser deletes the cookie. The server keeps the session record. Why is this a flaw?
Answer
Anyone who copied the session ID before logout can still use it. The server must delete the session record at logout.
4. A form has a field <input type="hidden" name="role" value="user">. What must the server do with the value of role?
Answer
The server must not trust it. A user can change the value. The server must take the role from its own records, such as the user's session.
5. GET /invoice?id=1042 returns your invoice. What request do you send to test for an IDOR, and what result shows the flaw?
Answer
Send GET /invoice?id=1043 with your own session. If the server returns an invoice that belongs to another user, the server does not check ownership. Test this only on an application that you own or are allowed to test.
6. /admin returns 401 for a visitor and 403 for student. What is the difference?
Answer
401 means the server does not know who you are (authentication is missing). 403 means the server knows who you are and refuses the action (authorisation failed).
Key terms
| Term | Meaning |
|---|---|
| Client, server | The program that sends a request, and the program that answers it |
| Request, response | One message each way in HTTP |
| Status code | The three-digit result of a request (200, 401, 404) |
| Cookie | A value that the server sets and the browser returns on each request |
| Session | The server-side record linked to a session ID |
| Origin | Scheme, host and port of a URL |
| Same-origin policy | The browser rule that blocks reading a response from another origin |
| CORS | Headers with which a server allows other origins to read its responses |
| Authentication | Proving who you are |
| Authorisation | Checking what you are allowed to do |
| Attack surface | All inputs and functions that an outsider can reach |
| Trust boundary | The line between data you control and data you do not |
Clean-up
- Press
Ctrl+Cin Terminal 1 and in Terminal 3 to stop both servers. - Delete the cookie file and the empty folder:
cd ~/webapp-lab
rm -f cookies.txt
rmdir empty- Keep
lab_app.pyif you want to repeat the steps. Delete the whole folder withrm -r ~/webapp-labwhen you are done.
Workbook complete. You can now read a request, follow a session and map an attack surface. Next, learn to intercept and change requests with Burp Suite Basics. Then map a real target with Web Application Recon. To go deeper into the missing access check from Step 8, read Insecure Direct Object References (IDOR).
Sign in to track progress and send feedback.
Related
This workbook is extra practice for the course Web applications and APIs. Do the lessons first.Open the course