Web Application Attacks
Summary
Web applications are exposed to anyone on the internet and process untrusted input, so they are frequent targets. Session management flaws, cross-site scripting (XSS) and SQL injection (SQLi) remain among the most common web vulnerabilities. Input validation, output encoding and parameterized queries are the core defenses.
In plain words
Web apps are reachable by anyone on the Internet, so weak input validation, misconfigurations and old software are quickly abused. Session problems include predictable session IDs, session fixation and session hijacking. Cross-site scripting (XSS) abuses the browser's trust in a site to run injected script: reflected XSS comes through a crafted link, stored XSS is saved in the site's data, and DOM-based XSS lives in client-side scripts. SQL injection abuses unsafe query building to read or change database data. Defenses: validate input, encode output, use parameterized queries, manage sessions securely, and add a WAF.
Detailed explanation
-
Session management: Tracking a user across requests with session tokens, because HTTP itself is stateless.
- Weaknesses: Predictable tokens, tokens in URLs, missing expiry and tokens sent without TLS can allow session hijacking.
- Defenses: Random tokens, Secure and HttpOnly cookie flags, timeouts and new tokens after sign-in.
-
Cross-site scripting (XSS): Injecting script into a web page so it runs in other users' browsers.
- Reflected XSS: The script comes from the current request, such as a crafted link. Also called nonpersistent.
- Stored XSS: The script is saved on the server, such as in a comment, and runs for every visitor. Also called persistent.
- DOM-based XSS: The flaw is in client-side code that writes untrusted data into the page.
- Impact: Session theft, defacement and actions performed as the victim.
- Defenses: Output encoding, input validation and a content security policy (CSP).
-
SQL injection (SQLi): Inserting SQL code into input that is passed to a database query, which can expose or change data.
- Indicators: Unexpected quotes, SQL keywords or comment characters in input fields and logs.
- Defenses: Parameterized queries (prepared statements), stored procedures, input validation, least-privilege database accounts and a WAF.
Important terms
taken from the text above- Session management
- Tracking a user across requests with session tokens, because HTTP itself is stateless.
- Cross-site scripting (XSS)
- Injecting script into a web page so it runs in other users' browsers.
- Reflected XSS
- The script comes from the current request, such as a crafted link. Also called nonpersistent.
- Stored XSS
- The script is saved on the server, such as in a comment, and runs for every visitor. Also called persistent.
- DOM-based XSS
- The flaw is in client-side code that writes untrusted data into the page.
- SQL injection (SQLi)
- Inserting SQL code into input that is passed to a database query, which can expose or change data.
Examples & real-world scenarios
- Parameterized queries so user input is never treated as SQL code.
- Output encoding so user-supplied text is shown, not executed.
- Random session IDs with the HttpOnly and Secure cookie flags.
Scenario
Reviewing web server logs, an analyst sees form submissions containing database query syntax in a name field. That's an indicator of attempted SQL injection. The fix is parameterized queries in the code, with a WAF as an extra layer.
Common mistakes
- Mixing up stored XSS (saved on the server) and reflected XSS (delivered through a link).
- Relying on client-side validation alone. It can be bypassed, so the server must validate too.
Practical skills
- Explain XSS and SQL injection and their main defenses.
- Recognize injection indicators in web logs.
What I should remember
- XSS: Malicious script runs in victims' browsers.
- Stored XSS: Persists on the server and affects every visitor.
- SQL injection: Untrusted input changes a database query.
- Parameterized queries: The main defense against SQL injection.
- Output encoding: The main defense against XSS.