<?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 Ziyad on Medium]]></title>
        <description><![CDATA[Stories by Ziyad on Medium]]></description>
        <link>https://medium.com/@2iaad?source=rss-8b85979c9e33------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6piC8kgx4-Ag63d4Q_9ejQ.png</url>
            <title>Stories by Ziyad on Medium</title>
            <link>https://medium.com/@2iaad?source=rss-8b85979c9e33------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:45:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@2iaad/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[CORS & SOP: Origin vs Cross-Origin]]></title>
            <link>https://2iaad.medium.com/cors-sop-origin-vs-cross-origin-8cd096099b1c?source=rss-8b85979c9e33------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cd096099b1c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Ziyad]]></dc:creator>
            <pubDate>Sat, 27 Jun 2026 18:15:25 GMT</pubDate>
            <atom:updated>2026-06-27T18:15:25.508Z</atom:updated>
            <content:encoded><![CDATA[<p>The screenshot i took below seems familiar right ? (ik the answer hhhh).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gC6c0kLsSRvszMht_lCHew.png" /></figure><p>The server working. code looking right. But the browser refuses to cooperate. Let’s clear this s*** up.</p><h3>What actually happens on a cross-origin request</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8QA2HjBsHqzJYXLxMKM69g.png" /><figcaption>cors-origin request flow</figcaption></figure><ol><li>The request <strong>leaves the browser and reaches your server.</strong></li><li>Your server <strong>runs its handler and sends a response back</strong>, it doesn’t block anything.</li><li>The browser <strong>receives that response</strong>, then checks for the right CORS headers.</li><li>Then:<br>- Headers present → your JavaScript gets the data.<br>- Headers missing → the browser <strong>blocks your JS from reading it.</strong></li></ol><h3>First: what is an “origin”?</h3><p>An <strong>origin</strong> is made of exactly three parts (Two URLs are <strong>same-origin</strong> only if them three match):</p><pre>scheme  +  host  +  port<br>https://   app.com   :443</pre><p>Examples so you understand the difference between origin &amp; cross-origin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IDm7L48RQjnTLrUbGTnhmg.png" /><figcaption>examples of origin and cross-origin</figcaption></figure><h3>The reason of all of this: the Same Origin Policy</h3><p>Before CORS, there is the <strong>Same-Origin Policy (SOP):<br>-</strong> security rule injected into every browser. Its job: stop JavaScript on one origin from reading responses from another origin.</p><p>Lets say you are:</p><ol><li>logged into your bank acc.</li><li>You visit a site: <strong>https://exploit.com</strong>.</li></ol><p>Without SOP, that site’s JavaScript could call the bank’s API using <em>your</em> logged-in session and read your account data.</p><h3>So where does CORS fit in?</h3><p>Here’s the key insight that makes everything click:</p><blockquote><strong><em>CORS is not security feature you add. It’s used to </em>relax<em> the Same-Origin Policy.</em></strong></blockquote><p>CORS is the mechanism that lets a <strong>server</strong> say: <em>“These specific origins are allowed to read my responses.”</em> It does this with HTTP response headers, the most important being:</p><pre>Access-Control-Allow-Origin: http://localhost:3000</pre><p>When the browser sees that header and it matches your page’s origin, it hands the response to your JavaScript.</p><h3><strong>Common mistakes:</strong></h3><ul><li>Thinking the server “rejected” the request (it didn’t, the <em>browser</em> blocked the JS <strong><em>fetch().. </em></strong>from reading it).</li><li>Confusing CORS with authentication.</li><li>Assuming localhost and 127.0.0.1 are the same origin (they are not).</li><li>Trying to “fix” CORS in the frontend (you can’t — it’s the server’s job).</li></ul><h3>The one-line takeaway</h3><p>The Same-Origin Policy protects your users by default. CORS exists to safely loosen that protection when <em>you</em> choose to.</p><p>So the next time you see that red CORS error, you’ll know: your server is fine, the response made it back, and the browser is just doing its job ;) .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cd096099b1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sessions & Tokens / Cookies & Local storage]]></title>
            <link>https://2iaad.medium.com/sessions-tokens-cookies-local-storage-5a01c730ddda?source=rss-8b85979c9e33------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a01c730ddda</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[localstorage]]></category>
            <category><![CDATA[cookies]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Ziyad]]></dc:creator>
            <pubDate>Thu, 25 Jun 2026 21:40:14 GMT</pubDate>
            <atom:updated>2026-06-25T21:40:14.881Z</atom:updated>
            <content:encoded><![CDATA[<p>Sessions and Tokens are two fundamentally different ways to handle user authentication, while Cookies and Local Storage are just the browser-side storage mechanisms used to hold them</p><h3>Sessions vs Tokens</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*diPmXef2Mgddz15XdCL1Jw.png" /></figure><p>This topic exists because HTTP is stateless. After a user logs in, the server has no memory of them on the next request.</p><p>Sessions/Tokens answers one question: how does the server re-establish “who is this” on every request without asking for the password again.</p><p>They differ in where the answer of ‘‘who is this?’’ lives (client/server).</p><h4>Sessions (stateful)</h4><p>After the user logins and the server successfully validates the credentials, the server:</p><ul><li>creates a session record in a store (Database / Caching system (Redis) / File in the filesystem).</li><li>sends the client a random opaque ID.</li></ul><p>The ID means nothing on its own; it is just a key. On each request the client sends the ID back, the server looks it up, finds the record, and knows who you are. <strong>So the server holds the identity </strong>/ The client holds a pointer to it.</p><p><strong><em>Consequences that follow directly from that:</em></strong></p><ul><li>Revocation is trivial. Delete the record and the session is dead on the next request.</li><li>Every request costs a lookup against the store.</li><li>That (DB, Redis…) must be shared across all your servers, or you need sticky sessions (servers share same DB). which is bad for scaling.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g-ihcNpnnq6xztm_VIzUog.png" /></figure><h4>Tokens (stateless, JWT)</h4><p>After the user logins and the server successfully validates the credentials, the server:</p><ul><li>builds a token containing the identity claims (user ID, roles, expiry), then signs it.</li><li>sends the client the token.</li></ul><p>On each request the client sends the token back, and the server verifies the signature. If the signature is valid and not expired, the server trusts the claims inside, no need to any lookup on the DB, Cashing system..</p><p>this means that the <strong>client holds the identity.</strong> The server holds only the signing key. (Not like the session type).</p><p>Consequences:</p><ul><li>No DB, Redis querying per-request, This is the scaling win, you will only need the Secret.</li><li>Revocation is the weak point. Once issued, a token is valid until it expires. You cannot easily kill it early without adding server-side state, which defeats the reason you went stateless.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mz1v2aUV-8IGNwJZowjULg.png" /></figure><h3><strong>Cookies vs Local Storage:</strong></h3><p>Both store data on the client. For auth the question is <em>“where do you keep the credential proof of the user (session ID or token), and how does it get attached to requests?”</em> It comes down to three things:<br>- who can read it.<br>- how it travels.<br>- what attack it exposes you to.</p><h3>The defining difference: automatic vs manual</h3><p>Cookies are sent automatically. Once set, the browser attaches the cookie to every request to that domain.</p><p>localStorage is manual. It is a key-value store the browser never touches on its own. Your JavaScript reads the value and explicitly puts it on each request, normally as Authorization: Bearer &lt;value&gt;.</p><h3>Who can read it (the XSS attack)</h3><p>localStorage is readable by any JavaScript on the page. If an attacker injects script (XSS), one line steals the credential.</p><p>Cookies can be hidden from JavaScript with the httpOnly flag. Such a cookie cannot be read by document.cookie or any JS. This is the main security reason to prefer cookies.</p><h3>How it travels (the CSRF attack)</h3><p>Cookies expose you to CSRF, i have already explain this in my previous <a href="https://2iaad.medium.com/csrf-when-your-browser-snitches-behind-your-back-f6b4136ced7f"><strong>BLOG</strong></a>.</p><p>localStorage is immune to CSRF. Nothing is sent automatically, so a forged cross-site request carries no credential.</p><h3>The trade, stated plainly</h3><p>You do not pick the safe option. You pick which attack you defend against:</p><ul><li>Cookie (httpOnly): safe from XSS token theft, exposed to CSRF. CSRF has clean, standard defenses.</li><li>localStorage: safe from CSRF, exposed to XSS token theft. XSS theft has no clean defense once it happens; the token is gone.</li></ul><p>Cookies win for browser apps because the attack they expose is well-solved, while the one localStorage exposes is not.</p><h3>Smaller practical differences</h3><p>Size they can hold:<br>- Cookies are capped (~4KB)<br>- localStorage holds more (~5MB)</p><p>Behaviour:<br>- Cookies have built-in expiry (Max-Age/Expires) and scoping (Domain, Path).<br>- localStorage cleanup is entirely your code&#39;s job.</p><h3>The one thing to remember</h3><p>This axis is only about where the credential lives. It is independent of whether the credential is a session ID or a JWT. In a browser, default to an httpOnly + Secure + SameSite cookie, and reach for localStorage only when you have a specific reason and have accepted the XSS exposure.</p><p>Wish you had fun reading, good luck !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a01c730ddda" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSRF: When Your Browser Snitches Behind Your Back]]></title>
            <link>https://2iaad.medium.com/csrf-when-your-browser-snitches-behind-your-back-f6b4136ced7f?source=rss-8b85979c9e33------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6b4136ced7f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Ziyad]]></dc:creator>
            <pubDate>Tue, 23 Jun 2026 01:34:55 GMT</pubDate>
            <atom:updated>2026-06-23T01:34:55.491Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yi5ygdbegg3Qs7B1LNy-iQ.png" /></figure><h3>What are CSRFs ?</h3><p>Cross site request forgery, its an attack that forces a target to execute unwanted actions (changing password, email, username, logout user, changing language ..etc) to a web app that they are currently logged in (authenticated).<br>&gt; its basically remote execution of a script on the server.</p><h4>The pre-requisites:</h4><p>- the target should be already authenticated.<br>- cookie based session handling from the website.<br>- predictable request params (rarely need to be valide).</p><h3>The one fact that makes this CSRF work</h3><h4><strong><em>the vulnerability :</em></strong></h4><p>the browser attaches your cookies to a request <strong>AUTOMATICALLY</strong> based on where the request is going, not where it came from.</p><p>Lets take in consideration that the user is already authenticated and the server already returned a request Header that looks like this:</p><blockquote><strong>Set-Cookie: session_id=xyz123abc; HttpOnly; Path=/;</strong></blockquote><p>Here is a small diagram i made that shows the flow of the exploit from end-to-end + the explanation of the 1,2 and 3rd step below it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_7eGHTtsUGJYGIwzQ23FQ.png" /><figcaption>exploit flow from end to end</figcaption></figure><h3>Whats going on ?</h3><p>When you log into example.com for the first time, the server gives your browser a session cookie. From then on, <strong>every single request </strong>your browser sends to example.com includes that cookie <strong>automatically</strong>.</p><p>It does not care if the request came from example.com itself, or from a website named csrf.com lol!<br> If the destination is example.com, the identification cookie come along for the ride.</p><p>The attacker can’t <em>read</em> the response (the browser’s Same-Origin Policy blocks this part). But they don’t need to. They just need the <strong>POST</strong> request to be executed.</p><p>Let’s walk through the scene.</p><h3>Step 1: You click the link the attacker sent</h3><p>You get a link. Maybe it’s “YOU WON IPHONE 17!” THEN you land on <a href="http://www.csrfcsrf.com./">www.csrfcsrf.com</a>lol<a href="http://www.csrfcsrf.com./">.</a></p><p>The page says <strong>“Hello World!”</strong> and looks like the most boring website ever made.</p><p>The page already did its job before it finished loading, here’s what was actually sitting in the HTML:</p><pre>&lt;html&gt;<br>  &lt;body&gt;<br>    &lt;h1&gt;Hello World!&lt;/h1&gt;<br>    &lt;iframe style=&quot;display:none&quot; name=&quot;csrf-iframe&quot;&gt;&lt;/iframe&gt;<br>    &lt;form action=&quot;https://example.com/email/change&quot;<br>        method=&quot;POST&quot;<br>        target=&quot;csrf-iframe&quot;<br>        id=&quot;csrf-form&quot;&gt;<br>      &lt;input type=&quot;hidden&quot; name=&quot;email&quot; value=&quot;test@test.ca&quot;&gt;<br>    &lt;/form&gt;<br>    &lt;script&gt;<br>      document.getElementById(&quot;csrf-form&quot;).submit();<br>    &lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Notice the iframe with display:none. That&#39;s a hidden room. The form&#39;s target points into that hidden room, so when it submits, nothing visibly happens. No new page, no flash, no &quot;are you sure?&quot; dialog. The whole heist runs backstage while the lobby still says &quot;Hello World!&quot;</p><h3>Step 2: The form submits itself to the real site</h3><p>You didn’t click submit.</p><p>That last line of script handles it for you:</p><pre>document.getElementById(&quot;csrf-form&quot;).submit();</pre><p>The instant the page loads, it auto-submits the form to https://example.com/email/change.</p><p>And here is the part that should make you uncomfortable: because the request is going to example.com, and <strong>you are still logged into </strong><strong>example.com in another tab</strong>, your browser attaches your session cookie with the scripts request:</p><pre>Cookie: xxxxxxxxxxxxxx</pre><h3>Step 3: The server gets a request that looks 100% legit</h3><p>The request lands on the server looking like this:</p><pre>POST /email/change HTTP/2<br>Cookie: xxxxxxxxxxxxxx<br>Content-Type: application/x-www-form-urlencoded</pre><pre>email=test@test.ca</pre><p>Now put yourself in the server’s shoes. What does it see?</p><ul><li>A POST to a real, valid endpoint. Check.</li><li>A valid session cookie belonging to a logged-in user. Check.</li><li>A perfectly well-formed request body. Check.</li></ul><p>From the server’s point of view, <em>this is you</em>. There is nothing in the request that says “by the way, this was actually triggered by a sketchy site while the real user was reading the word ‘Hello’.” The request is indistinguishable from one you’d send yourself.</p><p>So the server does what it’s told. It changes your email. It sends back a polite:</p><pre>HTTP/2 200 OK<br>{ }</pre><p>The attacker never sees that 200 OK (Same-Origin Policy, remember). They don&#39;t care. The email is changed. Now they hit &quot;forgot password,&quot; the reset link goes to <em>their</em> inbox, and your account is gone. All because you read two words on a boring website.</p><h3>So… whose fault is this?</h3><p>The browser is behaving exactly as designed. The fault is the <em>server’s</em> for trusting that “valid cookie” means “the user actually intended this request.”</p><p>A cookie proves <em>who you are </em>AND <strong>CSRF</strong> lives entirely in that gap.</p><h3>How to not get owned (the developer part)</h3><p>If you’re building the server, your job is to demand proof of intent, not just proof of identity. A few standard moves:</p><ul><li><strong>SameSite cookies.</strong> Set your session cookie to SameSite=Strict (or Lax). This tells the browser &quot;do not attach this cookie to requests that originate from another site.&quot;, This alone kills most CSRF and is the single highest-leverage fix.</li><li><strong>Stop using cookies for auth where you can.</strong> If your auth token lives in an Authorization header that <em>your</em> JavaScript has to attach manually, the browser won&#39;t auto-send it cross-site, and the whole CSRF premise falls apart. (This is its own can cause XSS, but it avoids CSRF)</li></ul><h3>The one-line takeaway</h3><p>The fix for CSRF is teaching the server to not recieve the HTTP requests from who ever using Strict in <strong>SameSite cookies </strong>or just never use cookies to identify users :) .</p><p>Good bye, Terrible security model.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6b4136ced7f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference bewteen a normal USB and a Bootable USB]]></title>
            <link>https://2iaad.medium.com/difference-bewteen-a-normal-usb-and-a-bootable-usb-2486fb1edc6e?source=rss-8b85979c9e33------2</link>
            <guid isPermaLink="false">https://medium.com/p/2486fb1edc6e</guid>
            <category><![CDATA[usb]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[bootable-usb]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Ziyad]]></dc:creator>
            <pubDate>Thu, 11 Jun 2026 19:16:17 GMT</pubDate>
            <atom:updated>2026-06-11T19:16:17.146Z</atom:updated>
            <content:encoded><![CDATA[<h3>Difference bewteen normal USB and a Bootable USB</h3><p>Every developer has done it at least once: downloaded an .iso file, flashed it to a USB, and booted into a Linux live environment. But have you ever stopped to think about what actually happens under the hood? How does a simple USB stick become something your computer can boot from? In this post, ill break it down you, because this is more fun the looking for an internship XD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWFMl8rln_iYW-DXW63Mjw.jpeg" /></figure><h4><strong>Normal USB drive:</strong></h4><p>a memory storage drive that has a filesystem like FAT32 where you can store bytes in form of files/folders/images… When you plug it in:</p><ol><li>Who reads it: The running OS as a block device (/dev/sdb on Linux, for example)</li><li>Entry point: the USB is mounted so you access it via filesystem (folders/files)</li><li>How to write to it: copy files into it.</li></ol><p>The OS treats it exactly like a directory on your hard drive. There’s no “startup” logic involved. The BIOS/UEFI doesn’t care about it during boot.</p><h4><strong>Bootable USB drive:</strong></h4><p>same as a normal USB and it also have a filesystem that contains .iso file, installer files, kernel and an OS.</p><p><strong>But</strong> <strong>t</strong>he first 512 bytes are reserved for the MBR (Master Boot Record) and are not linked with that Filesystem (they are just raw bytes).</p><p>the computer BIOS reads this first bytes and directly knows that this stick has an OS that can be run.</p><ol><li>Who reads it: The Firmware aka BIOS (software that lives on motherboard chip) via the bootloader inside the USB.</li><li>Entry point: the BIOS reads first 512 raw bytes that contains the bootloader.</li><li>How to write to it: via ISO flashers like ‘dd’ command / fedora media writer / rufus...</li></ol><blockquote>- the bootloader is a program that loads the OS kernel to the RAM of the computer.<br>- filesystem, the way OS make sense of the raw bytes and put them into files.</blockquote><h3>How is a normal USB converted to a Bootable USB you might ask</h3><p>This happens by using the ‘dd’ command / Rufus / Fedora Media Player.. they are called ISO flashers.</p><p><strong>Hear me out;</strong></p><p>When Fedora releases their OS, they package everything into one .iso file that represents a complete bootable disk image.</p><p>Your USB before getting flashed it cointains a filesystem(FAT32).</p><p>You can’t just put the .iso file in the USB, because it will be considered just like any other file and the BIOS will view it as a storage device (normal USB), right ?</p><h4>Here comes the role of ISO flashers</h4><p>Here is exactly ISO flashers convert a USB to a bootable one (<em>Rufus for ex</em>):</p><p><strong>1. Open the ISO as a file: </strong>Rufus opens it and reads it as raw bytes.</p><p><strong>2. Opens the USB: as a raw device</strong> Rufus doesn’t open the USB through Windows Explorer or the filesystem. It opens the physical device directly. This gives it access to every single block on the drive, including block 0 where the partition table lives.</p><p><strong>3. Writes Into the</strong> <strong>USB:</strong> Rufus reads 512 bytes from position 0 of the ISO, writes those 512 bytes to position 0 of the USB. Then reads 512 bytes from position 512 of the ISO, writes to position 512 of the USB. Repeats this millions of times until the entire ISO is copied.</p><p><strong>4. What ends up at block 0</strong> The ISO was built by Fedora so that its very first 512 bytes contain a valid boot sector with the magic signature 0x55AA at the end. When our BIOS scans the USB and finds 0x55AA there, it says &quot;bootable&quot; and jumps to it.</p><p><strong>5. GRUB sits right after</strong> Immediately after the boot sector, Fedora placed GRUB (the bootloader). The boot sector’s only job is to tell the BIOS “jump to the next section”, where GRUB lives. GRUB then finds the Linux kernel and loads it into RAM.</p><h3>This is the how the Bootable USB will look like in memory:</h3><figure><img alt="Bootable USB drive behind the scenes" src="https://cdn-images-1.medium.com/max/994/1*F6l0F_8VRU2bkdkdzP9fJg.png" /><figcaption>Bootable USB stick memory overview</figcaption></figure><h3>This is exactly what happens after you press the power button</h3><p>im ignoring the CPU waking up, POST aka Power On Self Test that the BIOS do… :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i-eJyodamAMgfbXDMHF20A.png" /></figure><p>And that’s it. Your USB stick isn’t magic, it’s just a drive with the right bytes in the right place at the right time.</p><p>Next time someone asks you “why can’t I just copy the ISO file to the USB?”, you now have a 5 minute explanation ready that will make them regret asking.</p><p>If this helped you understand what’s actually going on when you flash a USB, drop a clap or two. If it didn’t, well… at least your Fedora is installing correctly.</p><p>d3iw m3aya nlqa stage! 🤙</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2486fb1edc6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>