Cybersecurity Web Security & OWASP Top 10

Defending Against the OWASP Top 10 Vulnerabilities

⏱ 16 min read • Level: Intermediate • Updated: Sep 30, 2026

Introduction: The OWASP Top 10 Threat Landscape

The Open Web Application Security Project (OWASP) Top 10 represents the authoritative industry consensus on the most critical security risks facing web applications. Organizations worldwide rely on the OWASP Top 10 to establish defensive development baselines, compliance standards, and penetration testing scopes. This lesson examines the primary vulnerability classes and provides production-grade remediation patterns.

Core Vulnerabilities & Defensive Engineering

1. Broken Access Control (A01)

Broken access control allows unauthorized users to act outside of their intended permissions. Common manifestations include Insecure Direct Object References (IDOR), where an attacker modifies an ID in a request (e.g., /api/user/102/invoice to /api/user/103/invoice) and accesses another user’s records without tenant validation.

Remediation: Enforce server-side record ownership checks on every request. Never rely on the client to dictate permissions.

2. Injection Vulnerabilities (A03 — SQLi, Command Injection)

Injection occurs when untrusted user data is concatenated directly into a query or command interpreter without contextual escaping or parameterized bindings.

-- VULNERABLE: Direct string concatenation
SELECT * FROM users WHERE email = 'user_input' AND password = 'password';

-- SECURE: Parameterized query (Prepared Statements)
SELECT id, email, password_hash FROM users WHERE email = ?;

3. Cross-Site Scripting (XSS)

XSS occurs when malicious JavaScript is injected into trusted web applications and executed in the victim’s browser:

  • Stored XSS: Malicious payload is persisted in a database (e.g. in a comment field) and executed whenever other users view the page.
  • Reflected XSS: Payload is reflected off the web server via URL parameters without sanitization.
  • DOM-based XSS: Vulnerability exists entirely client-side when JavaScript reads user input from sources like location.search and writes it to sinks like innerHTML.

Defensive Code Implementation: Sanitization and Prepared Statements

// Secure Database Access with PDO Prepared Statements
$stmt = $pdo->prepare('SELECT id, username, email FROM accounts WHERE tenant_id = :tenant AND id = :id');
$stmt->execute([
    ':tenant' => $current_user->tenant_id, // Tenant isolation prevents IDOR
    ':id'     => (int) $_GET['id']
]);
$account = $stmt->fetch();

// Preventing XSS via Contextual Output Encoding
// Always encode output before rendering into HTML context
echo '<div class="user-bio">' . htmlspecialchars($account['bio'], ENT_QUOTES | ENT_HTML5, 'UTF-8') . '</div>';

Cross-Site Request Forgery (CSRF) & SameSite Cookies

CSRF tricks an authenticated user’s browser into executing unwanted actions on a trusted site. Mitigations include:

  • Synchronizer Token Pattern (Nonces): Generating unique, cryptographically random, session-bound tokens submitted with state-changing requests.
  • SameSite Cookie Attribute: Setting cookies with SameSite=Lax or SameSite=Strict prevents the browser from attaching session cookies on cross-origin requests.

Deep Dive: Anatomy of Broken Access Control (A01:2021)

Broken Access Control is currently ranked as the number one risk in the OWASP Top 10. Unlike technical vulnerabilities such as buffer overflows that can be detected by static signature scanners, access control flaws represent logical flaws in business rules and authorization policies. The most devastating variation is Insecure Direct Object References (IDOR).

An IDOR occurs when an application exposes a direct database primary key or record identifier in a client-facing endpoint (such as GET /api/v1/invoices/10492) without verifying that the authenticated user actually owns or is permitted to view that specific record. An attacker simply increments the integer ID in an automated script to download confidential invoices belonging to every customer in the system.

To eliminate IDOR vulnerabilities, enterprise architectures adopt two mandatory patterns:

  • Indirect Reference Mapping: Instead of exposing sequential database auto-increment integers, applications use cryptographically random UUIDv4 identifiers or tenant-scoped hashids that cannot be guessed or enumerated sequentially.
  • Enforced Contextual Ownership Checks: Every data access layer query must bind the tenant or user context directly into the SQL query: SELECT * FROM invoices WHERE id = :invoice_id AND organization_id = :current_user_org_id. If the record exists but belongs to another customer, the query returns zero rows, resulting in an immediate 404 Not Found response.

Mitigating Server-Side Request Forgery (SSRF – A10:2021)

Server-Side Request Forgery occurs when a web application accepts an arbitrary URL from an end user (such as a profile avatar image URL or a webhook target) and issues a server-side HTTP request to fetch that resource without sufficient validation. In cloud environments (such as AWS, GCP, or Azure), an attacker supplies the link-local cloud metadata service IP address: http://169.254.169.254/latest/meta-data/iam/security-credentials/. The vulnerable server fetches the URL and returns the response, handing full IAM administrative credentials directly to the attacker.

A complete SSRF defense requires layered controls:

  1. DNS Resolution Validation: Resolve the supplied domain to an IP address before connecting, and reject any address belonging to RFC 1918 private subnets (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), loopback (127.0.0.0/8), or link-local metadata ranges (169.254.0.0/16).
  2. Prevent DNS Rebinding: Ensure that the HTTP client connects directly to the validated IP address rather than re-resolving the hostname, preventing time-of-check to time-of-use (TOCTOU) DNS rebinding attacks.
  3. IMDSv2 Enforcement: On AWS EC2 instances, enforce IMDSv2, which requires a session token obtained via an HTTP PUT request with custom headers, neutralizing standard SSRF GET requests.

Common Mistakes & Practical Pitfalls

  • Blacklist-Based Input Filtering: Attempting to strip malicious strings like <script> using regular expressions. Attackers bypass blacklists effortlessly using case variation (<sCrIpt>) or alternate tags (<img src=x onerror=alert(1)>). Always use parameterized inputs and contextual output encoding.
  • Misconfigured CORS Headers: Setting Access-Control-Allow-Origin: * alongside Access-Control-Allow-Credentials: true exposes authenticated endpoints to malicious cross-origin scripts.
  • Relying on Content-Type Headers for File Uploads: Checking only the MIME type provided in the Content-Type header allows attackers to upload executable PHP scripts disguised as images. Always validate magic bytes and store uploads outside document root.

Exam Connection: Certification Blueprint Alignment

This module aligns directly with the Web Security & OWASP Top 10 topic on the Cybersecurity Fundamentals Assessment:

  • Identifying SQL Injection attack strings (e.g. ' OR 1=1 --) and the appropriate architectural defense.
  • Differentiating between Stored, Reflected, and DOM-based Cross-Site Scripting.
  • Understanding CSRF prevention via nonces and SameSite cookie attributes.
  • Recognizing Broken Access Control / IDOR vulnerability scenarios.

Key Takeaways

  • Prepared statements completely neutralize SQL injection by separating code from data.
  • Contextual output encoding prevents browser interpreters from executing user data as script.
  • Access control checks must verify record ownership on the server for every state-changing request.

Knowledge Check

  1. Why do parameterized queries (prepared statements) prevent SQL injection?
    Answer: The database engine treats parameters strictly as data literals, never executing parameter values as executable SQL syntax regardless of input contents.
  2. What is the primary difference between Stored and Reflected XSS?
    Answer: Stored XSS persists the malicious payload in a database or server storage; Reflected XSS immediately reflects the payload back in the HTTP response without persistence.
  3. How does the SameSite=Lax cookie attribute mitigate CSRF?
    Answer: It instructs the browser not to send the cookie on cross-site subrequests (such as image loads or cross-site POST submissions).

Next Step

Proceed to module 3: Network Security, Cryptography, and Secure Access Controls, or test your skills on the Cybersecurity Fundamentals Assessment.

Visual Learning

Watch & Learn

Curated video tutorials and deep-dives illustrating these concepts in practice.

Primary Specifications

Official Documentation

Authoritative references and documentation directly from language and standard maintainers.

Curated Articles

Recommended Reading

Hand-picked engineering articles, tutorials, and practical perspectives on this topic.

Formative Practice

Test Your Understanding of Web Security & OWASP Top 10

Apply what you just learned with curated practice questions and in-depth explanations.

Practice Questions →
Advertisement