<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Tech Cafe - XSS</title>
    <subtitle>Dev adventures, epic bugs, tiny wins, and the occasional meltdown.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://golden-fox.dev/tags/xss/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://golden-fox.dev"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-06-28T00:00:00+00:00</updated>
    <id>https://golden-fox.dev/tags/xss/atom.xml</id>
    <entry xml:lang="en">
        <title>XSS is way simpler (and scarier) than I thought</title>
        <published>2026-06-28T00:00:00+00:00</published>
        <updated>2026-06-28T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Aakriti Agarwal
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://golden-fox.dev/til/xss/"/>
        <id>https://golden-fox.dev/til/xss/</id>
        
        <content type="html" xml:base="https://golden-fox.dev/til/xss/">&lt;p&gt;So today I came across Cross Site Scripting or XSS which honestly sounds like a Counter Strike mode but is actually one of the oldest and most annoying vulnerabilities on the web. Once I understood it, I felt a little unsafe about every comment section I’ve ever used lol.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-it-actually&quot;&gt;What is it actually&lt;&#x2F;h2&gt;
&lt;p&gt;XSS is when a website lets someone sneak their own javascript into a page, and your browser just… runs it. no questions asked, zero trust issues, straight up “sure i’ll run that.” The browser assumes any JavaScript that’s part of the page came from the website itself, so if the site accidentally treats user input as code instead of text, it’ll execute it. It’s not movie hacker stuff, it’s just a website not checking what a user typed before showing it to everyone else.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;example-that-made-it-click&quot;&gt;Example that made it click&lt;&#x2F;h2&gt;
&lt;p&gt;if a site does this to show your comment:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#657B83, #839496); background-color: light-dark(#FDF6E3, #002B36);&quot;&gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt;element&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt;innerHTML&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#859900, #859900);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt; userComment&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and someone comments:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#657B83, #839496); background-color: light-dark(#FDF6E3, #002B36);&quot;&gt;&lt;code data-lang=&quot;html&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#93A1A1, #586E75);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt;script&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#93A1A1, #586E75);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt;alert&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#2AA198, #2AA198);&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#2AA198, #2AA198);&quot;&gt;u got XSSed&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#2AA198, #2AA198);&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#93A1A1, #586E75);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#93A1A1, #586E75);&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt;script&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#93A1A1, #586E75);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;now everyone who opens the page gets a random popup. swap the alert for something stealing session data or cookies that aren’t protected with HttpOnly and it stops being funny real quick.&lt;&#x2F;p&gt;
&lt;p&gt;the fix is one line:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#657B83, #839496); background-color: light-dark(#FDF6E3, #002B36);&quot;&gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt;element&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt;textContent&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#859900, #859900);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#268BD2, #268BD2);&quot;&gt; userComment&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;this makes the browser treat it as text, not code. that’s genuinely most of the fix for simple cases.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-incident-that-made-me-go-wait-what&quot;&gt;The incident that made me go “wait, WHAT”&lt;&#x2F;h2&gt;
&lt;p&gt;In 2005, some guy named &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Samy_Kamkar&quot;&gt;Samy Kamkar&lt;&#x2F;a&gt; found a stored XSS bug on MySpace and turned it into a self replicating JavaScript worm. Anyone who viewed his profile automatically added him as a friend, got the phrase “but most of all, Samy is my hero” added to their profile and unknowingly copied the worm to their own profile too.&lt;&#x2F;p&gt;
&lt;p&gt;result: &lt;strong&gt;over 1 million infected profiles in under 20 hours.&lt;&#x2F;strong&gt; MySpace had to shut the whole site down. he also got an FBI visit after, so respect the execution, not the outcome.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-takeaway&quot;&gt;The takeaway&lt;&#x2F;h2&gt;
&lt;p&gt;Any time you build something that displays user input comments, usernames, profile bios, search results you’re one careless innerHTML away from turning text into executable code. It’s a tiny mistake with surprisingly big consequences and I finally understand why “never trust user input” is one of the first rules of web security.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;try-it-yourself&quot;&gt;Try it yourself&lt;&#x2F;h2&gt;
&lt;p&gt;If you want to actually &lt;em&gt;see&lt;&#x2F;em&gt; XSS in action, check out &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;xss-game.appspot.com&quot;&gt;The XSS Game by Google&lt;&#x2F;a&gt;. It walks you through real scenarios in a safe environment.
If you’re curious, here are the solution for the XSS Game levels: https:&#x2F;&#x2F;pastebin.com&#x2F;hv0h73eC&lt;&#x2F;p&gt;
</content>
        
    </entry>
</feed>
