Web SecurityDemonstration content

Introduction to Web Security

A first-principles look at web application security — threat models, common vulnerability classes, and how to think like an attacker before defending.

Introduction to Web Security
Table of contents

Web applications are the most exposed attack surface in modern software: anyone can send any request to your server at any time, without special permission. Web security is therefore not about “closing the door” — it is about keeping the application correct even when it receives wrong, malicious, or bizarre input.

The core idea of web security: never trust input, including input that appears to come from your own application.

Threat modeling

Before the technical details, it helps to be clear about who you are defending against and what you are protecting. A simple threat model answers three questions:

  1. What are the valuable assets? (user data, credentials, admin access)
  2. Who are the attackers? (automated bots, casual users, targeted attackers)
  3. What is the impact if an asset falls? (data breach, account takeover, defacement)

Without a threat model, security testing degrades into a checklist. With one, every finding can be judged: does this actually matter for this application?

The recurring vulnerability classes

The following categories appear again and again in industry reports such as the OWASP Top 10:

Category Quick example Primary mitigation
Broken Access Control Accessing another user’s data by changing the ID in the URL Server-side authorization on every request
Injection SQL query built from user input Prepared statements, ORM, strict validation
XSS User input executed as script in a victim’s browser Output encoding, CSP, sanitization
Authentication failures Weak passwords, sessions that never expire MFA, session policy, rate limiting

SQL injection: the classic example

A common mistake is assembling queries with string concatenation:

# VULNERABLE — never do this
username = request.args.get("username")
query = f"SELECT * FROM users WHERE username = '{username}'"
cursor.execute(query)

If an attacker sends username=admin'--, the resulting query is:

SELECT * FROM users WHERE username = 'admin'--'

Everything after -- is ignored, so the password condition disappears. The fix is simple — separate data from code:

# SAFE — parameterized query
username = request.args.get("username")
cursor.execute(
    "SELECT * FROM users WHERE username = ?",
    (username,),
)

XSS in one paragraph

Cross-site scripting happens when user data reaches the page as code rather than text. The browser cannot distinguish “markup from the server” from “markup from input”, so the only real defense is making sure input never arrives as markup: use the automatic encoding of your template engine, and use innerHTML only with content that has genuinely been sanitized.

Practicing safely

Never test systems you do not own without written permission. Use dedicated practice environments:

  • PortSwigger Web Security Academy — free labs organized per vulnerability.
  • OWASP Juice Shop — an intentionally vulnerable app you can run locally.
  • TryHackMe / Hack The Box — guided labs in isolated environments.

Where to go next

Once the threat model and common vulnerability classes make sense, the natural next topic is how HTTP itself works, because almost every web vulnerability is ultimately manipulated at the level of the HTTP request.

Share
Tags