Skip to content

Web application security cheat sheet

How SQL injection, broken access control and cross-site scripting work, how to test for them on systems you are allowed to test, and the fix for each.

Test only applications you own or have written permission to test. The course's targets are built for it.

SQL injection

Signinput reaches a query as text: ' OR '1'='1 changes the result, a lone ' causes a database error
Login bypassadmin' -- in the username field turns the password check into a comment
Read data' UNION SELECT username, password FROM users -- (column count must match: try ORDER BY 3 -- )
Fixparameterised queries: cur.execute("SELECT * FROM users WHERE name = %s", (name,)). Never build SQL by string concatenation. Least-privilege database user

Broken access control

IDORchange /orders/1041 to /orders/1042: someone else's order means the server checks login but not ownership
Tamperinga cookie or hidden field such as role=user or is_admin=0 that the server trusts
Forced browsing/admin, /backup.zip, /.git/ reachable without the right role
Fixcheck on the server, on every request, that this user may touch this object: WHERE id = ? AND owner_id = ?. Keep roles server-side; sign or encrypt anything the client holds

Cross-site scripting (XSS)

Reflecteda parameter echoed into the page: ?q=<script>alert(1)</script>
Storedthe same, saved (a comment, a name) and shown to every visitor
ContextsHTML body, an attribute (" onmouseover="…), JavaScript (';alert(1)//), a URL (javascript:)
Fixencode for the context on output (templates do it by default: do not switch it off), validate input, a Content-Security-Policy without 'unsafe-inline', HttpOnly cookies

Tools

CommandWhat it does
curl -i 'http://target/item?id=1'see the raw response and headers
curl -b 'session=…' URLsend a cookie
curl -X POST -d 'user=a&pass=b' URLsend a form
Browser dev tools → Networksee and replay every request
sqlmap -u 'http://target/item?id=1'automated injection testing (authorised targets only)

Headers worth checking

Content-Security-Policy · Set-Cookie: …; HttpOnly; Secure; SameSite=Lax · X-Content-Type-Options: nosniff · Strict-Transport-Security. Decode a token with the JWT decoder; it runs in your browser.

Practise it on a real machineWeb Application Security course
Open the lab