Access Denied - Please log in to view this lesson.

Cross-Site Scripting (XSS)

Imagine a website that allows you to write a comment, and when someone else views it, your comment runs code in their browser. That’s basically what XSS is.

What is XSS?

XSS is a vulnerability that lets attackers inject JavaScript code into a website. When the site shows this code to other users, their browsers will run it, even if it’s malicious.

How XSS Happens

Real-Life Example

Let’s say you leave this comment: <script>alert("Hello from Ahmed!")</script>. If the site doesn’t protect itself, other users will see a pop-up. That’s a very basic example, but attackers can do worse: steal cookies, redirect to fake login pages, or control your actions.

Types of XSS

Why Is It Dangerous?

How To Prevent XSS

Key Idea

XSS is not about the hacker doing something complicated. It’s about the developer trusting user input too much. And when the browser runs that input like it’s safe, attackers take over.