Security Fundamentals · Study Notes

Web Application & API Security

FIND THE FLAW · BREAK THE LOGIC · LOCK IT DOWN

Almost everything is a web app or an API now, and every one is a bundle of inputs, sessions, objects and trust boundaries waiting to be abused. The attacks are rarely exotic — they're a handful of flaw classes, repeated endlessly. This page covers how web apps and APIs actually work, the OWASP Top 10 for both, each major vulnerability with worked examples and the fix, a testing methodology, and the controls that make an app secure by design.

01 How web apps & APIs work

You can't break what you don't understand — the request/response model

Every interaction is a request from a client (browser, mobile app, script) to a server, which returns a response. HTTP is stateless — each request stands alone — so apps bolt state on top using cookies, sessions and tokens. The security of the whole thing lives in how the server trusts and handles what the client sends.

The anatomy of a request

PartWhat it carriesWhy it matters to an attacker
MethodGET, POST, PUT, DELETE, PATCHVerb tampering can bypass weak access checks
URL & query stringPath + ?id=5&sort=ascParameters are the primary injection point
HeadersCookie, Authorization, Host, User-AgentAuth tokens live here; Host/headers can be forged
BodyForm data, JSON, XML, uploadsWhere most injected payloads and mass-assignment live
The same-origin policy & CORS

Browsers enforce the same-origin policy: script on site-a.com can't freely read responses from site-b.com. CORS headers relax that deliberately — and a misconfigured CORS policy (Access-Control-Allow-Origin: * with credentials) hands an attacker's page the ability to read authenticated responses. It's a common, quiet API flaw.

REST vs GraphQL

Most APIs are REST — resources at URLs (/api/users/5), actions via HTTP verbs. GraphQL exposes a single endpoint where the client specifies exactly what it wants. GraphQL's flexibility is also its risk: deeply nested queries can exhaust the server, and introspection often leaks the entire schema.

02 The OWASP Top 10

The industry-standard map of what goes wrong

The OWASP Top 10 is the reference list of the most critical web application risks, rebuilt every few years from real-world data. The 2021 edition is the current stable release — know it cold:

IDCategoryIn one line
A01Broken Access ControlUsers can act outside their permissions (IDOR, forced browsing)
A02Cryptographic FailuresWeak/missing encryption of data in transit or at rest
A03InjectionUntrusted input interpreted as code (SQLi, command, XSS)
A04Insecure DesignFlaws baked into the architecture, not just the code
A05Security MisconfigurationDefaults, verbose errors, open cloud buckets
A06Vulnerable & Outdated ComponentsKnown-CVE libraries and dependencies
A07Identification & Authentication FailuresWeak login, session and credential handling
A08Software & Data Integrity FailuresUnverified updates, insecure deserialization, supply chain
A09Security Logging & Monitoring FailuresAttacks go unseen and unanswered
A10Server-Side Request Forgery (SSRF)The server is tricked into making attacker-chosen requests
What's coming — the 2025 edition

OWASP released a 2025 draft (being finalised through 2026). The headline changes: Broken Access Control stays at A01; "Vulnerable & Outdated Components" expands into Software Supply Chain Failures; and a new Mishandling of Exceptional Conditions category appears. The 2021 list above remains the stable reference until 2025 is fully adopted — learn 2021 first, then layer the changes on top.

03 Injection & Cross-Site Scripting

A03 — the classic "input treated as code" family

Injection happens whenever untrusted input is mixed into something that gets interpreted — a database query, a shell command, an HTML page. The root cause is always the same: data and code aren't separated.

SQL injection

If a query is built by string concatenation, input becomes query logic:

the flaw vs the fix
# VULNERABLE — input is concatenated into the query query = "SELECT * FROM users WHERE name = '" + name + "'" # input: name = ' OR '1'='1 → returns every row # SAFE — parameterised query; the driver keeps data ≠ code cursor.execute("SELECT * FROM users WHERE name = %s", (name,))
The one fix that matters

Parameterised queries (prepared statements) are the definitive fix for SQLi — the database treats the input as a value, never as syntax, no matter what it contains. Input validation and WAFs help, but parameterisation is the control that actually closes it. The same principle applies to command injection: use safe APIs that take argument arrays, never a shell string.

Cross-Site Scripting (XSS)

XSS is injection into the browser: attacker-controlled input is reflected into a page and runs as JavaScript in the victim's session — stealing cookies, keylogging, or acting as them. Three flavours:

Reflected

Payload bounces straight back from the request (e.g. a search term in the results page). Delivered via a crafted link.

Stored

Payload is saved server-side (a comment, profile field) and runs for every viewer. The most dangerous.

DOM-based

Client-side JS writes untrusted input into the page unsafely — never touches the server.

Fix: context-aware output encoding (HTML-encode on output), a strong Content-Security-Policy header, and framework auto-escaping. Never build HTML by concatenating user input.

04 Broken Access Control & SSRF

A01 & A10 — the top risk, and the one that reaches the cloud

IDOR — Insecure Direct Object Reference

The textbook access-control flaw, and the #1 risk overall. The app trusts an ID in the request without checking whether you are allowed that object:

IDOR — change the number, read someone else's data
GET /api/invoices/1043 → your invoice ✓ GET /api/invoices/1044 → someone else's ← no ownership check = IDOR

The fix is server-side authorisation on every object access — "does the current user own / have rights to this specific record?" — checked on the back end, every time. Never rely on the client hiding the option.

Server-Side Request Forgery (SSRF)

SSRF tricks the server into making a request the attacker chooses. Because that request originates from inside the network, it can reach things the attacker never could directly — internal services, admin panels, and most dangerously cloud metadata endpoints:

SSRF to cloud credentials
# app fetches a user-supplied URL for a "preview" feature POST /api/fetch { "url": "http://169.254.169.254/latest/meta-data/" } # → returns the cloud instance's IAM credentials. Full compromise.
Why SSRF is so high-impact

SSRF was central to the 2019 Capital One breach — an SSRF flaw reached AWS metadata, stole credentials, and exfiltrated 100M+ records. Fix: allow-list permitted destinations, block requests to internal/link-local ranges, and require IMDSv2 on cloud instances.

05 Authentication, sessions & JWT

A07 — proving who you are, and keeping you logged in safely

Two distinct problems, often confused: authentication (are you who you claim?) and authorisation (are you allowed this?). Most breaches exploit a gap in one or the other.

Session management

JSON Web Tokens (JWT)

JWTs are self-contained, signed tokens widely used for API auth — and widely misimplemented:

JWT weaknessWhat goes wrong
alg: noneServer accepts an unsigned token — forge any claims
Algorithm confusionRS256 verified as HS256 using the public key as the secret
Weak signing secretHS256 with a guessable key — crack it offline, sign your own
No expiry / no revocationA stolen token works forever

Defend with MFA, strong password policy + rate limiting (against credential stuffing), proper token expiry/rotation, and pinning the signing algorithm server-side. jwt_tool is the standard tester.

06 API security — why APIs break differently

OWASP API Security Top 10 (2023)

APIs expose logic and data directly, usually without a browser's protections, and often with thin or missing authorisation. OWASP maintains a separate Top 10 for them because the failure modes differ from classic web apps — authorisation dominates the list.

IDRiskWhat it means
API1Broken Object Level Auth (BOLA)IDOR for APIs — the #1 API risk. Accessing objects you don't own
API2Broken AuthenticationWeak or missing token/credential validation
API3Broken Object Property Level AuthExposing or letting you edit fields you shouldn't (incl. mass assignment)
API4Unrestricted Resource ConsumptionNo rate/size limits — DoS and cost-explosion
API5Broken Function Level Auth (BFLA)Calling admin functions as a normal user
API6Unrestricted Access to Business FlowsAutomating a flow (e.g. bulk-buying) beyond intent
API7Server-Side Request ForgeryAs above — common where APIs fetch URLs
API8Security MisconfigurationVerbose errors, missing hardening, open CORS
API9Improper Inventory ManagementForgotten / undocumented / old API versions still live
API10Unsafe Consumption of APIsTrusting third-party API data without validation
Mass assignment — the API-3 classic

If an API binds the whole request body to a model, adding a field the UI never shows can escalate you:

PUT /api/users/me  { "name": "stew", "role": "admin" }
# the app blindly sets role → privilege escalation

Fix: explicitly allow-list which fields a request may set; never bind user input straight to a data model.

07 Testing methodology

How a web/API assessment actually runs
  1. Recon — identify the tech stack, frameworks, hosts and exposed endpoints. Wappalyzer, nuclei, subdomain enumeration.
  2. Map — spider the app, catalogue every parameter, form and hidden API route. Burp Suite's proxy + target map is the core tool here.
  3. Test — work the OWASP classes systematically against each input: access control, injection, XSS, auth, SSRF. ffuf for fuzzing, sqlmap for SQLi.
  4. Exploit — prove real impact safely; chain flaws (e.g. IDOR + mass assignment → account takeover). Never destroy data.
  5. Report — evidence, reproducible steps, risk rating (CVSS), and clear remediation. The report is the deliverable, not the exploit.

08 Defence in depth

Secure by design, not by patching later
ControlCloses
Input validation + parameterised queriesInjection (SQLi, command, NoSQL)
Context-aware output encoding + CSPCross-site scripting (all types)
Server-side authz on every object & functionBroken access control, IDOR, BOLA, BFLA
HTTPS everywhere + security headers (HSTS, CSP, X-Frame-Options)Transport & browser-layer attacks
Secure cookies (HttpOnly, Secure, SameSite) + anti-CSRF tokensSession theft & CSRF
Rate limiting + WAFBrute force, resource consumption, automated abuse
Field allow-listingMass assignment / property-level auth
Dependency scanning (SCA) + patchingVulnerable & outdated components
Logging, monitoring & alertingUndetected attacks (A09)
The mindset

NEVER TRUST INPUT · AUTHORISE EVERY REQUEST · ENCODE EVERY OUTPUT

09 References & further reading

Authoritative sources — go deeper here
  1. OWASP Top 10 (web application risks) — owasp.org
  2. OWASP API Security Top 10 — 2023 — owasp.org
  3. PortSwigger Web Security Academy — free, hands-on labs — portswigger.net
  4. OWASP Cheat Sheet Series — practical secure-coding guidance — cheatsheetseries.owasp.org
  5. OWASP Web Security Testing Guide (WSTG) — owasp.org
  6. OWASP Juice Shop — deliberately vulnerable practice app — owasp.org
  7. HackTricks — web pentesting methodology — book.hacktricks.wiki
  8. Computer Misuse Act 1990 — legislation.gov.uk