<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fajar Sylvana on Medium]]></title>
        <description><![CDATA[Stories by Fajar Sylvana on Medium]]></description>
        <link>https://medium.com/@fajarsylvana?source=rss-d7fea91f9949------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KonRAtjjeSn1ti6RIokPeQ.png</url>
            <title>Stories by Fajar Sylvana on Medium</title>
            <link>https://medium.com/@fajarsylvana?source=rss-d7fea91f9949------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 17:02:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fajarsylvana/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Discovered DOM XSS by Analyzing Javascript Code]]></title>
            <link>https://medium.com/@fajarsylvana/how-i-discovered-dom-xss-by-analyzing-javascript-code-6fa57c680a0e?source=rss-d7fea91f9949------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fa57c680a0e</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[bug-bounty-tips]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[Fajar Sylvana]]></dc:creator>
            <pubDate>Wed, 25 Sep 2024 09:57:08 GMT</pubDate>
            <atom:updated>2024-09-25T09:57:08.679Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="javascript code" src="https://cdn-images-1.medium.com/max/1024/0*Necz19t-8NZClPB6" /><figcaption>Photo by <a href="https://unsplash.com/@rahuulmiishra?utm_source=medium&amp;utm_medium=referral">Rahul Mishra</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم</h3><p>I usually do this when approaching on a new target.</p><p>First thing I do is fire up <strong>Burp Suite</strong> to capture all the requests and responses from the target site. Then I go ahead and click on all the functions and buttons on the website (make sure not to miss a thing). After that, I usually dive into every request and search in the response if there any embeded js script in there.</p><p>One day while I was hunting on a target, while I was going through the code, I stumbled upon an interesting comment:</p><pre>$(window).on(&#39;load&#39;, function() {<br>  // old code for handling errors, due to be deprecated</pre><p>I got really curious, so I started digging deeper. Turns out, there’s an event listener waiting for the page to load:</p><pre>$(window).on(&#39;load&#39;, function() {<br>  // old code for handling errors (deprecated)<br>  var errorCode = decodeURIComponent(getHashValue(&quot;error&quot;));<br>  var uri = window.location.toString();<br><br>  if (uri.indexOf(&quot;#&quot;) &gt; 0) {<br>    var clean_uri = uri.substring(0, uri.indexOf(&quot;#&quot;));<br>    window.history.replaceState({}, document.title, clean_uri);<br>  }<br><br>  if (errorCode != &quot;null&quot;) {<br>    if (errorCode == &#39;2&#39;) {<br>      document.getElementById(&quot;errorMsg&quot;).innerHTML = <br>        &quot;&lt;div class=&#39;alert alert-danger mt-3 d-inline-block&#39; role=&#39;alert&#39;&gt;&quot; + <br>        &quot;&lt;span class=&#39;badge badge-secondary&#39;&gt;Error &quot; + errorCode + <br>        &quot;&lt;/span&gt; - No match with our records.&lt;/div&gt;&quot;;<br>    } else if (errorCode == &#39;1&#39;) {<br>      document.getElementById(&quot;errorMsg&quot;).innerHTML = <br>        &quot;&lt;div class=&#39;alert alert-danger mt-3 d-inline-block&#39; role=&#39;alert&#39;&gt;&quot; + <br>        &quot;&lt;span class=&#39;badge badge-secondary&#39;&gt;Error &quot; + errorCode + <br>        &quot;&lt;/span&gt; - Not valid.&lt;/div&gt;&quot;;<br>    } else {<br>      document.getElementById(&quot;errorMsg&quot;).innerHTML = <br>        &quot;&lt;div class=&#39;alert alert-danger mt-3 d-inline-block&#39; role=&#39;alert&#39;&gt;&quot; + <br>        &quot;Error &quot; + errorCode + &quot; - An unexpected error occurred.&lt;/div&gt;&quot;;<br>    }<br>  }<br>});</pre><p>As you can see, when the page loads, it calls the getHashValue function with &quot;error&quot; as an argument, grabbing the value from the URL fragment and assigning it to the errorCode variable. Here&#39;s the getHashValue function:</p><pre>function getHashValue(key) {<br>  var matches = location.hash.match(new RegExp(key+&#39;=([^&amp;]*)&#39;));<br>  return matches ? matches[1] : null;<br>}</pre><p>The problem is that the errorCode variable can be manipulated by user input from the URL, and then it’s injected straight into the DOM as HTML:</p><pre>document.getElementById(&quot;errorMsg&quot;).innerHTML = <br>  &quot;&lt;div class=&#39;alert alert-danger mt-3 d-inline-block&#39; role=&#39;alert&#39;&gt;&quot; + <br>  &quot;Error &quot; + errorCode + &quot; - An unexpected error occurred.&lt;/div&gt;&quot;;</pre><p>This opens the door for a <strong>DOM based XSS vulnerability</strong>. After thinking for a moment, I then created a payload and injected to URL like this:</p><pre>https://redacted.com/#error=&lt;/div&gt;&lt;/div&gt;&lt;img src=x onerror=alert(0)&gt;</pre><p>As you can see, the payload will trigger the XSS like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*9L0I7GgUxvrXMKeLkXdx3Q.png" /><figcaption>DOM XSS</figcaption></figure><p>See you in the next post, Keep Hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fa57c680a0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>