<?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 Youssefemira on Medium]]></title>
        <description><![CDATA[Stories by Youssefemira on Medium]]></description>
        <link>https://medium.com/@youssefemira1?source=rss-eb200196c4fc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RJwu7KoERoXhpY9oV83c7Q.jpeg</url>
            <title>Stories by Youssefemira on Medium</title>
            <link>https://medium.com/@youssefemira1?source=rss-eb200196c4fc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:24:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@youssefemira1/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[“Nonces & CSP: Your Website’s Secret Handshake Against Sneaky Scripts”]]></title>
            <link>https://medium.com/@youssefemira1/nonces-csp-your-websites-secret-handshake-against-sneaky-scripts-7637cdf294de?source=rss-eb200196c4fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/7637cdf294de</guid>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[cyber-security-awareness]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Youssefemira]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 11:27:08 GMT</pubDate>
            <atom:updated>2025-04-17T11:27:08.905Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*DxWZXIOunj5n1KHxFGH-vw.png" /></figure><h3>1. Meet the Problem: XSS Attacks</h3><p>Imagine you’re hosting a VIP party (your website). Suddenly, a stranger slips in, shouting through a megaphone (malicious scripts). Chaos!</p><ul><li><strong>XSS</strong> is that uninvited guest. Hackers inject code to steal data, deface pages, or worse.</li><li><strong>Old defenses?</strong> Either too strict (blocking <em>all</em> scripts) or too lax (<em>“Sure, come on in!”</em>).</li></ul><h3>2. CSP: The Gatekeeper That Needs a Secret Handshake (Nonces)</h3><p>CSP is like a strict bouncer at your website’s door — it blocks all uninvited guests (scripts). But what about the <em>good guys</em> (your own inline scripts)? If CSP locks <em>everyone</em> out, your site breaks.</p><p><strong>Nonces</strong>:<br>Nonces are the <strong>secret handshake</strong> between your CSP and trusted scripts. They let your bouncer say:<br><em>“I don’t trust strangers, but scripts with the magic code? Come on in!”</em></p><h3>3. The Hero: Nonces (No, Not the Chocolate!)</h3><p>A <strong>nonce</strong> (short for “number used once”) is like a <em>VIP wristband</em> for your website’s scripts. It’s a unique, random code your server generates for every visitor. Only scripts wearing this wristband get past security (your browser)!</p><ul><li><strong>How it works</strong>:</li></ul><ol><li>Your server (the bouncer) creates a unique wristband (e.g., X9F9L2) for every visitor.</li><li>It whispers the wristband code to trusted scripts:</li></ol><pre>&lt;script nonce=&quot;X9F9L2&quot;&gt; // Trusted code gets the wristband &lt;/script&gt;  </pre><p>3. The browser (door security) checks every script’s wristband. No match? <em>“Sorry, not tonight.”</em></p><pre><br>&lt;script&gt;alert(&quot;Hacked!&quot;);&lt;/script&gt; &lt;!-- Blocked! ❌ --&gt;  <br>&lt;script nonce=&quot;FAKE123&quot;&gt;alert(&quot;Hacked!&quot;);&lt;/script&gt; &lt;!-- Blocked! ❌ --&gt;  </pre><h3>4. How Nonces Work with CSP</h3><ul><li><strong>Step 1</strong>: Server generates a unique nonce (e.g., ABC123) for each HTTP response.</li><li><strong>Step 2</strong>: The server sends the nonce in two places:</li><li><strong>CSP Header</strong>: Content-Security-Policy: script-src &#39;nonce-ABC123&#39;;</li><li><strong>HTML Script Tags</strong>: &lt;script nonce=&quot;ABC123&quot;&gt;/* Trusted code */&lt;/script&gt;</li><li><strong>Step 3</strong>: Browser validates scripts by comparing the nonce in the script tag to the CSP header.</li><li><strong>Match</strong>: Script executes.</li><li><strong>No Match</strong>: Script blocked.</li></ul><h3>5. Visualizing the Process</h3><ul><li><strong>Concert Wristband Analogy</strong>:</li><li>Server = Event organizer issuing wristbands (nonces).</li><li>Browser = Security guard checking wristbands.</li><li>Scripts = Guests needing wristbands to enter.</li></ul><h3>6. Best Practices</h3><ul><li>✅ <strong>Always Use HTTPS</strong>: Nonces are useless without encryption.</li><li>✅ <strong>Generate Nonces Securely</strong>: Never reuse or predict nonces.</li><li>✅ <strong>Combine with </strong><strong>strict-dynamic</strong>: Restrict unauthorized dynamic scripts.</li><li>✅ <strong>Avoid </strong><strong>unsafe-inline</strong>: Nonces replace the need for it.</li></ul><h3>7. Common Pitfalls</h3><ul><li>❌ <strong>Reusing Nonces</strong>: Makes them guessable.</li><li>❌ <strong>Leaking Nonces</strong>: Exposing them in logs or client-side code.</li><li>❌ <strong>Mixed Content</strong>: HTTP resources on HTTPS pages weaken security.</li></ul><p><strong>Never rely on a single mechanism</strong> —<strong><em> security is about layers!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7637cdf294de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding SOP, CORS, and CSP: Vulnerabilities, Impact, and Misconfigurations]]></title>
            <link>https://medium.com/@youssefemira1/understanding-sop-cors-and-csp-vulnerabilities-impact-and-misconfigurations-43d428fab365?source=rss-eb200196c4fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/43d428fab365</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[secure-web-development]]></category>
            <dc:creator><![CDATA[Youssefemira]]></dc:creator>
            <pubDate>Fri, 04 Oct 2024 16:16:16 GMT</pubDate>
            <atom:updated>2024-10-04T16:16:16.311Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EOEWpHxHbVcKZRE8U1PXBQ.jpeg" /></figure><p>Web security often revolves around securing how web pages interact with each other and access data from different origins. Three critical security policies — <strong>Same-Origin Policy (SOP)</strong>, <strong>Cross-Origin Resource Sharing (CORS)</strong>, and <strong>Content Security Policy (CSP)</strong> — define how resources are accessed and shared. This blog explores their purpose, common misconfigurations, potential vulnerabilities, and how these can be exploited.</p><h3>Same-Origin Policy (SOP)</h3><p><strong>SOP</strong> is a fundamental security measure enforced by web browsers that prevents malicious scripts on one page from interacting with resources from another domain unless they share the same origin (scheme, host, and port). It restricts how documents and scripts loaded from one origin can interact with resources from another.</p><h3>Vulnerabilities and Misconfigurations in SOP</h3><ul><li><strong>Session Hijacking</strong>: If an attacker finds a way to bypass SOP (e.g., through a vulnerability in the browser or through insecure implementation), they could potentially hijack user sessions and gain access to sensitive data.</li><li><strong>Bypassing SOP</strong>: Through techniques like DNS rebinding, attackers can make cross-origin requests appear as though they are from the same origin.</li></ul><h3>Exploitation</h3><ul><li><strong>Cross-Site Scripting (XSS)</strong>: By bypassing SOP via XSS, an attacker could inject malicious scripts into web pages, allowing them to steal sensitive information from the same origin.</li><li><strong>Cookie Theft</strong>: Once SOP is bypassed, sensitive cookies could be accessed, leading to session hijacking.</li></ul><h3>Cross-Origin Resource Sharing (CORS)</h3><p><strong>CORS</strong> is a mechanism that allows servers to specify who can access their resources by setting specific headers. It essentially extends the SOP by allowing servers to define which external origins can access specific resources.</p><h3>Misconfigurations and Vulnerabilities in CORS</h3><ul><li><strong>Wildcard </strong><strong>* in </strong><strong>Access-Control-Allow-Origin</strong>: This allows any domain to access sensitive resources. Misconfiguring this header can open doors to attackers.</li><li><strong>Overly Permissive Access</strong>: Allowing credentials (Access-Control-Allow-Credentials: true) without restricting origins can lead to account takeover attacks.</li><li><strong>Preflight Request Misconfigurations</strong>: Some servers mismanage preflight requests, allowing unauthorized methods (like PUT or DELETE) to be executed.</li></ul><h3>Exploitation</h3><ul><li><strong>CSRF with CORS</strong>: If a server allows cross-origin requests without proper validation, an attacker could perform Cross-Site Request Forgery (CSRF) attacks by tricking users into making unwanted requests.</li><li><strong>Stealing Data</strong>: Attackers can use a vulnerable CORS setup to read sensitive information from APIs that should only be available to certain origins.</li></ul><h3>Content Security Policy (CSP)</h3><p><strong>CSP</strong> is a security measure designed to prevent various types of attacks, including Cross-Site Scripting (XSS) and data injection attacks, by specifying which resources are allowed to load on a page (such as scripts, images, styles, etc.).</p><h3>Misconfigurations and Vulnerabilities in CSP</h3><ul><li><strong>Overly Permissive Policies</strong>: Allowing unsafe-inline in scripts or styles can negate the protective benefits of CSP.</li><li><strong>Whitelisting Dangerous Origins</strong>: If CSP policies allow external domains that are not trustworthy, attackers may be able to inject malicious scripts or content from these domains.</li><li><strong>Missing Policies</strong>: Not having CSP configured at all exposes the application to XSS and other injection-based attacks.</li></ul><h3>Exploitation</h3><ul><li><strong>XSS with Misconfigured CSP</strong>: Even with CSP in place, if it is misconfigured (e.g., allowing inline scripts), attackers can execute scripts that steal data or perform unwanted actions on behalf of the user.</li><li><strong>Data Exfiltration</strong>: Malicious scripts from untrusted sources could be allowed to exfiltrate sensitive data from the web application.</li></ul><h3>Impact of SOP, CORS, and CSP Misconfigurations</h3><p>The misconfiguration of SOP, CORS, and CSP can have significant impacts on the security of web applications:</p><ul><li><strong>Data Breaches</strong>: Attackers can steal sensitive information such as login credentials, cookies, and personal information through improper access control.</li><li><strong>Account Takeover</strong>: Vulnerabilities in CORS and CSP can allow attackers to hijack user sessions or manipulate users into performing unwanted actions.</li><li><strong>Reputation Damage</strong>: Exploits that lead to data leakage or service disruption can damage the reputation of the company or service provider.</li><li><strong>Legal and Compliance Issues</strong>: Failure to protect user data can result in non-compliance with regulations like GDPR or CCPA, leading to fines.</li></ul><h3>Best Practices for Securing SOP, CORS, and CSP</h3><ol><li><strong>Enforce SOP Strictly</strong>: Ensure that browsers and servers follow SOP properly to avoid cross-origin vulnerabilities.</li><li><strong>Configure CORS Carefully</strong>:</li></ol><ul><li>Avoid using wildcard * in Access-Control-Allow-Origin for sensitive resources.</li><li>Ensure Access-Control-Allow-Credentials is only set for trusted origins.</li><li>Review preflight request handling to prevent unauthorized methods.</li></ul><p><strong>3. Implement a Strong CSP</strong>:</p><ul><li>Avoid unsafe-inline and unsafe-eval in your CSP configurations.</li><li>Whitelist only trusted sources for scripts, styles, and other resources.</li><li>Regularly review and update CSP policies to reduce the risk of XSS and other attacks.</li></ul><p>finally, By carefully configuring SOP, CORS, and CSP, you can protect your web applications from common vulnerabilities that lead to exploits and attacks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43d428fab365" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[File Upload Task (Lab: Web shell upload via obfuscated file extension)]]></title>
            <link>https://medium.com/@youssefemira1/file-upload-task-lab-web-shell-upload-via-obfuscated-file-extension-08a2edc50aba?source=rss-eb200196c4fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/08a2edc50aba</guid>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[file-upload-vulnerability]]></category>
            <dc:creator><![CDATA[Youssefemira]]></dc:creator>
            <pubDate>Sat, 31 Aug 2024 15:23:17 GMT</pubDate>
            <atom:updated>2024-10-04T16:36:02.739Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*ezHBm2e1L4jx46BKJOGSJg.png" /></figure><p><strong>main objective</strong> : trying to analyze the lab and how the validation process is implemented</p><h3>lets start :</h3><p>first we have a file upload function in our profile page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*jDKhb6IgfHXgq-RPp00j4A.png" /></figure><p>We simply have to upload a php code that allows us exfiltrate the contents of the file /home/carlos/secret so the php file <strong>test.php</strong> will be</p><pre>&lt;?php echo file_get_contents(&#39;/home/carlos/secret&#39;); ?&gt;</pre><p>uploading gives us a error message</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1qocCwoodmdraZqnO5M3pQ.png" /></figure><p>from that error message we come up with that the application uses a white list to validate for the extention of the uploaded file</p><p>i check if there is any client side validation for the uploaded file</p><p>by using BASH COMMAND to fetch all the JS codes in the website</p><pre>wget -r -l1 -A .js https://0ab5005303dce45c87fa70e900c70003.web-security-academy.net/</pre><p>after a quick reading for the js files i didn’t find any function envolved validating the file extention</p><p><strong>so the validation is implemented in the server side</strong></p><h3>trying to bypass the validation pattern</h3><p>First We check if He validate the extention or the word of any other extention</p><p>we renamed the file for `<strong>test.php.jpg` </strong>and the responce showed that “”<strong>the file wass successfully </strong>”” updated so there is no validation on the name of the file it onley checks for the extension</p><p>so here we can use the<strong> NULL BYTE %00 after the .php </strong>to make the backend language to terminate the rest of the file name while saving it</p><p>so the name of the file will be<strong> test.php%00.jpg</strong></p><p>and it gives us ``“<strong>The file avatars/test.php has been uploaded</strong>&quot;``</p><p>and tying to access the file it was excuted and gived us the flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*27TiYmr-Yg1Tnp1EYMhmaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*xCIVu9hGTEItFLk7T9jTzQ.png" /></figure><p>so what happend in the background in the server you may wonder</p><p>so here is the backend code behind this validation</p><pre>$filename = &quot;test.php%00.jpg&quot;;<br>$extension = substr($filename, -4);<br>// Validate the file extension<br>if ($extension === &quot;.jpg&quot;) <br>    // Path where the file will be saved<br>    $uploadDir = &#39;/files/avatars/&#39;;<br>    <br>    // Save the file to the server<br>    $destination = $uploadDir . $filename;<br><br>    //moving the uploaded file to the destination<br>    move_uploaded_file($_FILES[&#39;avatar&#39;][&#39;tmp_name&#39;], $destination);<br>    <br>    echo &quot;The file avatar/ s${destination} has been uploaded&quot;;<br>} else {<br>    echo &quot;<br>Sorry, only JPG &amp; PNG files are allowed<br>Sorry, there was an error uploading your file&quot;;<br>}</pre><p>You may ask why the NULLBYTE didn’t excute while validating for extention</p><p>that’s why this happend Here, substr() might only return the portion of the string before the null byte, which is &quot;test.php&quot;, leading to incorrect extension validation.</p><p>but when he get to handling saving the file in a directory</p><p>If the server or filesystem does not handle null bytes properly, it might save the file with a name that ignores the null byte, potentially leading to the file being saved with an unintended name like test.php .</p><h3>the metigation for this scenario</h3><pre>$filename = $_FILES[&#39;avatar&#39;][&#39;name&#39;];<br><br>// Sanitize the filename to prevent null byte injection and other issues<br>$filename = preg_replace(&#39;/[\x00-\x1F\x7F-\xFF]/&#39;, &#39;&#39;, $filename); // Remove control characters and non-ASCII characters<br><br>// Ensure the filename has a valid extension<br>$allowedExtensions = [&#39;jpg&#39;, &#39;jpeg&#39;, &#39;png&#39;];<br>$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));<br><br>if (in_array($extension, $allowedExtensions)) {<br>    // Define the upload directory and create a safe filename<br>    $uploadDir = &#39;/path/to/upload/directory/&#39;;<br>    $safeFilename = basename($filename); // Remove any directory paths from the filename<br>    $destination = $uploadDir . $safeFilename;<br><br>    // Move the uploaded file to the destination<br>    if (move_uploaded_file($_FILES[&#39;avatar&#39;][&#39;tmp_name&#39;], $destination)) {<br>        echo &quot;File saved as: &quot; . $destination;<br>    } else {<br>        echo &quot;File upload failed&quot;;<br>    }<br>} else {<br>    echo &quot;Invalid file type&quot;;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=08a2edc50aba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>