Skip to main content
IDOR, Path Traversal and Core Web Attacks
Lesson 6 of 18

IDOR, Path Traversal and Core Web Attacks

Identify how core web vulnerabilities such as SQL injection, XSS, CSRF, IDOR, path traversal, XXE, and SSRF work and apply OWASP-aligned defences to stop them.

Intermediate 26 min Web security
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Map core web attack classes to the OWASP Top 10 (2021) categories
  • Explain how injection flaws including SQLi, OS command injection, and XSS arise from untrusted input
  • Differentiate client-side forgery (CSRF) from server-side forgery (SSRF) and access control failures (IDOR, path traversal)
  • Apply concrete server-side defences such as parameterized queries, object-level authorization, path canonicalization, and outbound URL allow-lists

Recommended first: HTTP Request/Response, Cookies & Session Management

#Why this matters

Web applications expose business logic, databases, and internal APIs over HTTP. Because every request carries user-controlled headers, parameters, cookies, and file names, one missing server check can turn a normal feature into a data breach. In the OWASP Top 10 (2021), A01:2021 - Broken Access Control ranks first (covering IDOR and path traversal), A03:2021 - Injection (SQLi, OS command injection, and XSS) ranks third, A05:2021 - Security Misconfiguration includes XXE, and A10:2021 - Server-Side Request Forgery (SSRF) has its own category.

#Injection flaws: SQLi, command injection, and XSS

Injection occurs when untrusted input is concatenated into an interpreter command rather than kept strictly separate as data.

  • SQL Injection (SQLi): Raw input inside a SQL string lets attackers alter query logic. Classic SQLi returns output directly, Blind SQLi infers data via true/false responses, and Time-Based SQLi measures server delays. Always use parameterized queries (prepared statements) so values are bound strictly as data.
  • OS Command Injection: Passing unsanitized input into a shell wrapper like system() lets attackers run server commands. Avoid shell invocation and use native APIs or fixed argument arrays.
  • Cross-Site Scripting (XSS): Rendering untrusted data without context-aware encoding lets attacker JavaScript execute in a victim's browser. Reflected XSS bounces back from a crafted URL, Stored XSS persists in a database for every visitor, and DOM-based XSS executes entirely inside the browser when client-side JavaScript writes untrusted data into the DOM without server involvement. Defend with context-aware output encoding, a strict Content Security Policy (CSP), and HttpOnly cookies.
python
# Vulnerable: raw concatenation allows SQL injection
# cursor.execute(f"SELECT id, email FROM users WHERE id = {user_id}")

# Safe: parameterized query binds user_id as data
cursor.execute("SELECT id, email FROM users WHERE id = %s", (user_id,))

#Access control failures: IDOR, path traversal, and file uploads

Under A01:2021 - Broken Access Control, the server fails to verify that the authenticated user owns or may access the requested resource.

  • IDOR (Insecure Direct Object Reference): Requesting /api/orders?id=1002 returns another user's record because the server skips ownership checks. Enforce server-side object-level authorization on every request.
  • Path Traversal: Prepending ../ sequences to a filename lets attackers escape the target folder and read sensitive files such as /etc/passwd on Linux or win.ini on Windows. Map allowed files by safe IDs or canonicalize paths and verify the result stays inside the base directory.
  • File Upload flaws: Checking only file extensions or client MIME types risks web shell uploads. Store files outside the web root, generate random names, check magic bytes, and disable script execution in upload folders.

#Request forgery and parser flaws: CSRF, SSRF, and XXE

CSRF vs SSRF
CSRF (Cross-Site Request Forgery)
  • Abuses victim browser trust
  • Browser auto-sends session cookies
  • Fixed by CSRF tokens and SameSite
SSRF (Server-Side Request Forgery)
  • Abuses server network trust
  • Server fetches attacker-chosen internal URLs
  • Fixed by URL allow-lists, IP blocks, and IMDSv2
  • CSRF: When an authenticated user visits a malicious page, the browser automatically attaches session cookies to matching cross-site requests. HttpOnly stops JavaScript cookie theft, not automatic browser submission. Use unpredictable CSRF tokens and SameSite=Strict or SameSite=Lax cookies.
  • SSRF (A10:2021): When a server fetches a user-supplied URL, an attacker can target internal hosts (10.10.10.0/24) or cloud metadata endpoints. Enforce a strict domain allow-list, block private IP ranges after DNS resolution, disable or re-validate redirects, and require IMDSv2 on AWS.
  • XXE (XML External Entity): Parsers resolving external entities (such as PHP's LIBXML_NOENT) can read local files or trigger SSRF. Disable external entity parsing, avoid LIBXML_NOENT, and prefer JSON where possible.
SSRF targeting an internal lab serviceSSRF targeting an internal lab serviceClientWebAppInternalAPIPOST /preview url=http://10.10.10.5/statusGET /status200 OK (internal data)Preview exposing internal responseEnforce URL allow-lists and block private IP ranges

#Authorized web testing tools

In authorized labs (lab.local), testers pair manual inspection with focused tools: Burp Suite and OWASP ZAP (intercepting proxies with Repeater), Gobuster and ffuf (wordlist-based path discovery), and SQLmap (automated SQLi verification).

Enumerating hidden paths on an authorized lab target
$ gobuster dir -u https://lab.local -w wordlist.txt
/admin                (Status: 302)
/api                  (Status: 200)
/uploads              (Status: 403)

#Defending and common mistakes

  • Trusting client checks or secret URLs: Always validate inputs and permissions on the server.
  • Confusing XSS and CSRF defences: HttpOnly mitigates XSS cookie theft, not CSRF; deploy both CSP/encoding and CSRF tokens/SameSite.
  • Following redirects blindly in SSRF filters: Re-validate resolved IPs after every redirect or disable redirects.
  • Leaving debug mode on in production: Disable debug output, enforce HTTPS/HSTS, and log authentication and authorization failures.

#Summary

  • OWASP Top 10 (2021) ranks Broken Access Control (A01) first, Injection (A03) third, and SSRF (A10) tenth.
  • Separate code from data using parameterized queries, shell-free OS calls, and context-aware output encoding plus CSP against Reflected, Stored, and DOM-based XSS.
  • Enforce server-side object authorization for IDOR, canonical path checks against ../, and strict file upload validation.
  • Protect against CSRF, SSRF, and XXE with CSRF tokens/SameSite, URL allow-lists plus private-IP blocking and IMDSv2, and disabled XML external entities (no LIBXML_NOENT).

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge