How web applications work: requests, sessions, and where trust is decided

A browser request from DNS to database and back, the parts of an HTTP exchange a tester reads first, and the server-side decisions that most web vulnerabilities come down to.

Lesson 4 of 69 · 13 min read · practice only with authorization

Diagram

One request through a typical stack

Follow the path. One example at a time.

Step 1 of 4

Browser

Builds the request: method, URL, headers, cookies, body.

Illustration: Browser
GET /api/orders/1042 HTTP/2
Host: shop.example.test
Cookie: session=8f3c...
Accept: application/json

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. The client is not a control

    What fails
    Anything in the browser, from hidden fields to disabled buttons, can be changed by the user.
    Who is affected
    Every user whose data the server trusts the client to protect.
    What you would notice
    Authorization decided by which buttons the page shows.
    What you change
    Enforce every rule on the server for every request.
  2. Sessions carry identity

    What fails
    After sign-in, a cookie or token stands in for the password on every request.
    Who is affected
    The account owner if the token is stolen or predictable.
    What you would notice
    Session cookies without HttpOnly, Secure, or SameSite.
    What you change
    Set the flags, rotate on sign-in, and expire sessions server-side.
  3. Interpreters are the risky sinks

    What fails
    SQL, shells, templates, XML parsers, and file paths interpret strings.
    Who is affected
    Whoever owns the data those interpreters can reach.
    What you would notice
    User input concatenated into any of them.
    What you change
    Use parameterized APIs and allow-lists at each sink.

Reading an HTTP exchange

Start with the method and path, then the Host header, then authentication (Cookie or Authorization), then the body and content type. In the response, read the status code, Set-Cookie flags, caching headers, and security headers such as Content-Security-Policy and Strict-Transport-Security before the body.

HTTP/2 200
content-type: application/json
set-cookie: session=8f3c...; Path=/; Secure; HttpOnly; SameSite=Lax
cache-control: private, no-store
strict-transport-security: max-age=31536000; includeSubDomains

{"id":1042,"status":"shipped","total":"58.20"}

Watching it yourself

Browser developer tools show every request in the Network tab. A testing proxy such as Burp Suite or OWASP ZAP sits between the browser and the application you are authorized to test, records the history, and lets you replay a request with one change. Use a lab browser profile for the proxy certificate.

Where the classic flaws live

Map the failure classes on this path to the step where they happen, so a review can be organized by step instead of by a list of names.

  • Input reaching SQL, shell, template, or XML: injection classes
  • Object ids without an owner check: IDOR and broken object authorization
  • Cookie-only state changes: CSRF
  • Server fetching a caller URL: SSRF
  • Untrusted text in HTML: cross-site scripting

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

A page hides the “Delete user” button for non-admins. What protects the delete endpoint?

Go deeper

Specific techniques, exercises, and glossary cards for this topic.

  1. 01Second-order SQL injectionText that was stored safely can still change a later query if that job concatenates the stored value into SQL. Includes the diagram and a defensive fix.
  2. 02Query builders that still concatenateAn ORM or a query builder is safe only when the SQL text stays under your control. Includes the diagram and a defensive fix.
  3. 03DOM XSS: sinks in the browserA page can be safe on the wire and still treat a URL, a message, or a stored string as HTML once script already on the page assigns it. Includes the diagram and a defensive fix.
  4. 04Stored XSS in rich textA comment, a profile, or a document that allows formatting is stored and later parsed as HTML for someone else. Includes the diagram and a defensive fix.
  5. 05CSRF on JSON APIsA JSON API is not immune to cross-site request forgery if the browser will attach the session cookie and the server changes state without a token. Includes the diagram and a defensive fix.
  6. 06Login CSRFA login is a state change. Includes the diagram and a defensive fix.
  7. 07Metadata and link-local fetchesA server that fetches a caller-influenced address can reach link-local services, including a cloud metadata endpoint the caller cannot open from their own machine. Includes the diagram and a defensive fix.
  8. 08Checking every hop of a server-side fetchAn allow-list that only looks at the first URL loses when that host redirects the server somewhere else. Includes the diagram and a defensive fix.
  9. 09IDOR in exports and batch endpointsA list of ids is still a list of objects. Includes the diagram and a defensive fix.
  10. 10Nested object authorizationA check on the parent record does not authorize every child id inside the request. Includes the diagram and a defensive fix.
  11. 11Archive extraction that leaves the directoryA name inside a zip or a similar archive is still a path. Includes the diagram and a defensive fix.
  12. 12Normalize the path before you open itFilters that delete a few character sequences lose to encodings, extra separators, and links. Includes the diagram and a defensive fix.
  13. 13Argument injection without a shellSkipping the shell is necessary and not sufficient. Includes the diagram and a defensive fix.
  14. 14Filenames that become commandsAn upload’s original name is data. Includes the diagram and a defensive fix.
  15. 15XInclude and XML features that fetchTurning off one entity switch is not the whole parser. Includes the diagram and a defensive fix.
  16. 16XML parsers you did not configureA dependency can parse XML with its own defaults even when your code’s parser is hardened. Includes the diagram and a defensive fix.
  17. 17Sandboxed templates are not a guaranteeA sandbox flag is a claim about an engine. Includes the diagram and a defensive fix.
  18. 18Templates in email and PDFA message body or a PDF layout is still a template. Includes the diagram and a defensive fix.
  19. 19Breached passwords and credential stuffingA password reused from another site will be tried on yours. Includes the diagram and a defensive fix.
  20. 20Password reset tokensA reset token is a password that expires. Includes the diagram and a defensive fix.
  21. 21A defender's map of web riskThe web bugs in the lesson library still exist. Includes the diagram and a defensive fix.
  22. 22API security as an environmentModern products are APIs with a few front ends. Includes the diagram and a defensive fix.
  23. 23SQL injection: how it happens, how testers confirm it, and the fix that holdsHow concatenated queries let input change SQL, the error, boolean, time, and out-of-band behaviors testers look for in an authorized test, what scanners like sqlmap report, and parameterization plus least privilege as the fix. Includes the diagram and a defensive fix.
  24. 24Cross-site scripting: reflected, stored, and DOM-based, and the defenses that stackHow untrusted text becomes script in another user’s browser, how to tell reflected, stored, and DOM-based XSS apart in a review, and why output encoding, a strict CSP, and HttpOnly cookies work together. Includes the diagram and a defensive fix.
  25. 25Cross-site request forgery: when the browser’s cookie is the only proofHow another site can make a signed-in browser send a state-changing request, how SameSite cookies changed the picture, where CSRF still appears, and how to verify tokens and Origin checks in a review. Includes the diagram and a defensive fix.
  26. 26Server-side request forgery: fetchers, internal targets, and allow-lists that holdHow features that fetch a URL — webhooks, previews, importers, PDF renderers — can be pointed at internal services, how testers confirm SSRF safely with a canary host, and how to build an allow-list that survives redirects and DNS tricks. Includes the diagram and a defensive fix.
  27. 27IDOR and broken object-level authorization: ids without an owner checkHow changing an id in a URL or API body returns someone else’s record, why it tops the OWASP API list, how to test it with two accounts you own, and the ownership-scoped query that fixes it. Includes the diagram and a defensive fix.
  28. 28OS command injection: when input reaches a shellHow features that call system tools — ping, image conversion, PDF generation, archive handling — pass user input to a shell, how to recognize it in code and in an authorized test with a timing probe, and how argument arrays and libraries remove the shell. Includes the diagram and a defensive fix.
  29. 29Path traversal: when a filename parameter walks out of its folderHow file download and upload features turn user-supplied names into filesystem paths, how traversal sequences and encodings escape the intended folder, what content-discovery tools such as DirBuster and gobuster actually find, and how to fix it with identifiers and canonical path checks. Includes the diagram and a defensive fix.
  30. 30File inclusion: when a parameter chooses which code or template runsLocal and remote file inclusion in PHP-style apps and modern template loaders, why it is worse than reading a file, how to recognize it in code and responses, and the allow-list fix. Includes the diagram and a defensive fix.
  31. 31HTTP headers in security testing: which ones the server trusts and which ones protect usersRequest headers that applications wrongly trust (Host, X-Forwarded-For, X-Original-URL, Referer), response headers that protect users (CSP, HSTS, frame-ancestors), and how to audit both with curl and a proxy. Includes the diagram and a defensive fix.
  32. 32Server-side template injection: user text compiled as a templateHow SSTI happens when user input becomes template source instead of template data, how to recognize it with a harmless arithmetic probe in an authorized test, and why passing data to a fixed template is the fix. Includes the diagram and a defensive fix.
  33. 33XML external entities: parsers that fetch and read on behalf of a documentHow DTD entity features let an XML document make the parser read local files or fetch URLs, where XML hides (SOAP, SAML, SVG, Office files), and how to disable DTDs in common parsers. Includes the diagram and a defensive fix.
  34. 34Broken authentication and login bypass: the flaws that let someone sign in as someone elseThe authentication failures behind most account takeovers — logic flaws in login and reset flows, missing rate limits, weak MFA enrollment, verbose errors, and default credentials — and a checklist to review a login flow end to end. Includes the diagram and a defensive fix.
  35. 35LDAP injection: filters built from user input against a directoryHow applications that search Active Directory or OpenLDAP build filters, how special characters change a filter’s logic, and how escaping, bind design, and least-privilege service accounts prevent it. Includes the diagram and a defensive fix.
  36. 36GraphQL security: introspection, resolver authorization, and query costWhere GraphQL APIs go wrong — missing authorization in resolvers, unbounded nested queries, batching that defeats rate limits, and injection in resolver code — and how to review a schema and test it with a tool like InQL or graphql-cop. Includes the diagram and a defensive fix.
  37. 37Host header injection: when the server builds links from a header the client choseHow applications use the Host header to build password-reset links, redirects, and cache keys, how a changed Host poisons those, and how to pin the public hostname in configuration. Includes the diagram and a defensive fix.
  38. 38Hop-by-hop headers: when a client can make a proxy drop the headers that carry trustHow the Connection header lets a client ask a proxy to strip named headers, why that matters when a backend trusts a header the proxy adds, and how to test and configure proxies so it cannot remove security headers. Includes the diagram and a defensive fix.
  39. 39HTTP request smuggling and desync: when two servers disagree where a request endsHow front-end and back-end servers can parse Content-Length and Transfer-Encoding differently, letting one request carry the start of another; response queue poisoning and HTTP/2 downgrades; and the configuration that prevents desync. Includes the diagram and a defensive fix.
  40. 40Open redirects: trusted links that send users somewhere elseHow redirect parameters after login or logout send users to any site, why that helps phishing and can leak OAuth codes, and how to validate redirect targets with relative paths or an allow-list. Includes the diagram and a defensive fix.
  41. 41Clickjacking: framing a real page under a fake oneHow a hostile page loads your site in an invisible frame to capture clicks on real buttons, which actions are worth the trouble, and how frame-ancestors and X-Frame-Options stop it. Includes the diagram and a defensive fix.
  42. 42Session hijacking and cookie theft: how sessions are stolen and how to make them worthlessThe ways a session token leaves the user — network sniffing, script access, infostealers, logs, and fixation — how cookie flags and server-side session design limit each one, and how to read a session in a capture or proxy. Includes the diagram and a defensive fix.
  43. 43Web shells and remote code execution: how servers get taken over and how defenders find itThe bug classes that lead to code execution on a web server, what a web shell is and how it is planted, the file, process, and log evidence defenders hunt for, and how to respond. Includes the diagram and a defensive fix.
  44. 44Subdomain takeover: dangling DNS records and how to find yours firstHow a CNAME or NS record left pointing at a deleted cloud resource lets someone else claim it and serve content on your subdomain, how to inventory your DNS for dangling records, and how to clean up for good. Includes the diagram and a defensive fix.
  45. 45Content Security Policy: writing, testing, and enforcing a strict policyHow CSP tells the browser which scripts, styles, frames, and connections a page may use, how to build a nonce-based strict policy, how to roll it out with report-only mode, and how to read violation reports. Includes the diagram and a defensive fix.
  46. 46CORS explained: what it allows, what it does not protect, and the misconfigurations to look forHow the browser’s same-origin policy and CORS headers decide whether a page on one origin can read a response from another, why CORS is not authentication, and the reflected-origin and null-origin mistakes that expose APIs. Includes the diagram and a defensive fix.
  47. 47JSON Web Tokens: structure, validation, and the mistakes that make them forgeableWhat a JWT’s header, payload, and signature contain, how to decode one safely, the validation checks a server must do (algorithm, signature, issuer, audience, expiry), and the classic failures such as alg none and key confusion. Includes the diagram and a defensive fix.
  48. 48Rate limiting and unrestricted resource consumption: protecting expensive endpointsWhich endpoints need limits (login, OTP, search, export, uploads, AI calls), how to choose keys and budgets, the 429 response and Retry-After, and how to test limits in staging without hurting production. Includes the diagram and a defensive fix.

Exercises

  1. 01Evidence deskRead a query review and a server-side fetch that were already collected. Name the failure and the fix.
  2. 02Terminal lab: API traceA scoped host. Read the invoice request and name why one account received another tenant’s record.
  3. 03Tenant deskTwo companies, one API. Turn the ownership check on and off and watch who can open a record.
  4. 04Control benchOne drill is an invoice id with no ownership check. Choose the control that checks the caller.
  5. 05Parameterized vs concatenated queriesBuild the same product search three ways and watch the token view: concatenation lets input change the query, bound parameters and allowlists keep it a value.
  6. 06Output encoding sandboxOne display name lands in page text, an attribute, an inline script, and a link. Pick the encoder each place needs and test it with probe values.
  7. 07CSRF token flowFollow a CSRF token from form to server check, then pick SameSite and server checks until four forged requests fail and your own three still work.
  8. 08SSRF allowlist evaluatorAn image import feature fetches URLs on the server. Combine host matching, address checks, redirect checks, and pinning until nine test URLs behave.

Glossary

  1. 01SQL injectionUntrusted input changes a database query, exposing or altering records the caller should not reach.
  2. 02Cross-site scriptingA page treats attacker-controlled text as code in someone else's browser, which can steal sessions or rewrite the UI.
  3. 03Cross-site request forgeryA browser that is already logged in is tricked into sending a state-changing request the user did not intend.
  4. 04Server-side request forgeryThe server is induced to fetch a URL the attacker chooses, which can reach internal services the attacker cannot see directly.
  5. 05Insecure direct object referenceChanging an identifier in a request returns or edits another user's object because the server never checks ownership.
  6. 06Session hijackingA bearer token or cookie is copied and replayed, so the server treats the attacker as the signed-in user.
  7. 07Path traversalA file path built from user input escapes the intended directory and reads or writes elsewhere on the host.
  8. 08Command injectionUser input is concatenated into a shell command, so the server runs instructions the developer did not plan.
  9. 09Server-side template injectionUser input is evaluated by the server's template engine, which can leak configuration or run template-side code.
  10. 10Open redirectA trusted domain sends the browser to an attacker-controlled site, which makes phishing links look legitimate.
  11. 11ClickjackingA transparent frame places your site's buttons under a decoy page so a click does something else.