#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
HttpOnlycookies.
# 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=1002returns 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/passwdon Linux orwin.inion 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
- Abuses victim browser trust
- Browser auto-sends session cookies
- Fixed by CSRF tokens and SameSite
- 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.
HttpOnlystops JavaScript cookie theft, not automatic browser submission. Use unpredictable CSRF tokens andSameSite=StrictorSameSite=Laxcookies. - 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, avoidLIBXML_NOENT, and prefer JSON where possible.
#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).
$ 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:
HttpOnlymitigates 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 (noLIBXML_NOENT).