How Cross-Site Scripting Works

How Cross-Site Scripting Works

How a comment can run code in your users' browsers, and how escaping and CSP stop it

What you'll learn

  • How injected script tags run as part of your site
  • Stored vs reflected XSS
  • Escaping output, and how frameworks do it for you
  • Content Security Policy and HttpOnly cookies

In this video, we'll look at cross-site scripting (XSS), starting with the 2005 Samy worm that added a million MySpace friends in less than a day. Using a blog with comments, we'll see how a script tag saved as a comment ends up running in every visitor's browser as part of your site.

We'll cover what that injected code can do, the difference between stored and reflected XSS, and the main fix: escaping user text before it goes into the page, which most frameworks do for you. We'll also look at Content Security Policy and HttpOnly cookies as extra layers.

By the end, you'll know where XSS bugs come from and the layers that keep them out.

More videos

30 short explainers so far, with more on the way

View all videos

Join the Community

roadmap.sh is among the top 10 most starred projects on GitHub and is visited by hundreds of thousands of developers every month.

Top 10 out of 28M!

371K

GitHub Stars

Star us on GitHub
Help us reach #1

+90kevery month

+3.2M

Registered Users

Register yourself
Commit to your growth

+2kevery month

52K

Discord Members

Join on Discord
Join the community

RoadmapsGuidesFAQsYouTube

roadmap.shby@nilbuild

Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.

© roadmap.sh·Terms·Privacy·

ThewNewStack

The top DevOps resource for Kubernetes, cloud-native computing, and large-scale development and deployment.