<?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 Zeyad Naguib on Medium]]></title>
        <description><![CDATA[Stories by Zeyad Naguib on Medium]]></description>
        <link>https://medium.com/@zeyadnaguib1?source=rss-2faf8ac563a0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*bEUI4T1BV4jiVP-j</url>
            <title>Stories by Zeyad Naguib on Medium</title>
            <link>https://medium.com/@zeyadnaguib1?source=rss-2faf8ac563a0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 15:11:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zeyadnaguib1/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[Lab 3 : Source code disclosure via backup files]]></title>
            <link>https://infosecwriteups.com/lab-3-source-code-disclosure-via-backup-files-54b056ee6d36?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/54b056ee6d36</guid>
            <category><![CDATA[information-disclosure]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Fri, 17 Jul 2026 07:05:37 GMT</pubDate>
            <atom:updated>2026-07-17T07:05:37.196Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lab Objective</h3><p>The goal of this lab is to locate leaked backup files and extract a hard-coded database password from the disclosed source code.</p><h3>Step-by-Step Solution</h3><h3>1. Check robots.txt for hidden paths</h3><p>robots.txt is designed to tell search engine crawlers which paths <em>not</em> to index :</p><pre>/robots.txt</pre><p>revealed a disallowed /backup directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*immgMfnDuweHpMSvq1MSKg.png" /></figure><h3>2. Enumerate the backup directory</h3><p>Browsing directly to /backup surfaced a file named:</p><pre>ProductTemplate.java.bak</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SWdXYo2qj8lWL7McnE3Rfw.png" /></figure><h3>3. Retrieve and read the leaked source file</h3><p>Navigating to:</p><pre>/backup/ProductTemplate.java.bak</pre><h3>4. Extract the hard-coded credential</h3><p>Reading through the disclosed source, the database connection logic contained a hard-coded password used to authenticate against a Postgres database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ALxf9SLF4iQJ2ez87_TlEA.png" /></figure><h3>5. Submit the solution</h3><p>I copied the password value, returned to the lab, clicked <strong>Submit solution</strong>, and entered it. The lab was marked as solved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ihofmuPt9xxS9TAlUQA-tQ.png" /></figure><h3>Written by Zeyad Naguib,<br>🔗 <a href="https://www.linkedin.com/in/zeyadnageeb">https://www.linkedin.com/in/zeyadnageeb</a><br>✍️ <a href="https://medium.com/@zeyadnaguib1">https://medium.com/@zeyadnaguib1</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54b056ee6d36" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/lab-3-source-code-disclosure-via-backup-files-54b056ee6d36">Lab 3 : Source code disclosure via backup files</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>
        <item>
            <title><![CDATA[Lab 2 : Information Disclosure on a Debug Page]]></title>
            <link>https://infosecwriteups.com/lab-2-information-disclosure-on-a-debug-page-5c0295cfbc12?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c0295cfbc12</guid>
            <category><![CDATA[information-disclosure]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Fri, 17 Jul 2026 07:04:02 GMT</pubDate>
            <atom:updated>2026-07-17T07:04:02.368Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Vulnerability</h3><p>Debug pages are a common byproduct of development. Tools like phpinfo() are incredibly useful while building and troubleshooting an application, since they dump detailed information about the server environment: PHP configuration, loaded modules, environment variables, file paths, and more.</p><p>The problem is that this same information is a goldmine for an attacker if the page is ever left accessible in production. Environment variables in particular often hold:</p><ul><li>API keys and secrets</li><li>Database credentials</li><li>Session signing keys (like SECRET_KEY)</li><li>Internal service URLs</li></ul><h3>Step-by-Step Solution</h3><h3>1. Browse the application with Burp running</h3><p>With Burp Suite intercepting traffic, I loaded the lab’s home page as a normal user would. This populates Burp’s site map with the page and its underlying requests.</p><h3>2. Search for clues in HTML comments</h3><p>Rather than guessing at hidden paths, I used Burp’s built-in comment finder. In <strong>Target &gt; Site Map</strong>, I right-clicked the top-level entry for the lab and selected <strong>Engagement tools &gt; Find comments</strong>.</p><p>This surfaced an HTML comment on the home page referencing a link labeled “Debug,” pointing to:</p><pre>/cgi-bin/phpinfo.php</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsXjEDebrrxUk6tWbqsgZw.png" /></figure><h3>3. Send the debug page to Repeater</h3><p>In the site map, I right-clicked the /cgi-bin/phpinfo.php entry and selected <strong>Send to Repeater</strong> to inspect the response more closely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tyi8cr4GBJ8Nanc0_hwyvQ.png" /></figure><h3>4. Retrieve the debug output</h3><p>Sending the request in Repeater returned the full output of a phpinfo() call. This page is normally used to help developers verify their PHP configuration, but here it exposed the server&#39;s environment variables in full — including:</p><pre>SECRET_KEY = zz296qa73qpb5t6k6yddcb5pj0fxr387</pre><p>No authentication, no obfuscation — the value was returned directly in the HTTP response body.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7r9Tsfy3wILx5EbUfIr67Q.png" /></figure><h3>5. Submit the solution</h3><p>I copied the SECRET_KEY value, returned to the lab, clicked <strong>Submit solution</strong>, and entered it. The lab was marked as solved.gets exposed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9llcUgaLJTNEcZn_y5iew.png" /></figure><p>Written by Zeyad Naguib,<br>🔗 <a href="https://www.linkedin.com/in/zeyadnageeb">https://www.linkedin.com/in/zeyadnageeb</a><br>✍️ <a href="https://medium.com/@zeyadnaguib1">https://medium.com/@zeyadnaguib1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c0295cfbc12" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/lab-2-information-disclosure-on-a-debug-page-5c0295cfbc12">Lab 2 : Information Disclosure on a Debug Page</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>
        <item>
            <title><![CDATA[Information Disclosure in Version Control History]]></title>
            <link>https://cybersecuritywriteups.com/information-disclosure-in-version-control-history-1159413ea8aa?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1159413ea8aa</guid>
            <category><![CDATA[information-disclosure]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Tue, 07 Jul 2026 13:52:01 GMT</pubDate>
            <atom:updated>2026-07-07T13:52:01.043Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Vulnerability</h3><p>When a .git directory is accidentally deployed alongside a web application and left publicly accessible, an attacker can download the entire repository — not just the current state of the code, but every commit ever made. This means:</p><ul><li>Deleted files can be recovered from earlier commits</li><li>“Fixed” secrets can be found in the diffs that removed them</li><li>Commit messages and authorship can reveal internal processes, naming conventions, or even personal information</li><li>Branches and tags that were never merged into production may still contain sensitive changes</li></ul><h3>Step-by-Step Solution</h3><h3>1. Discover the exposed .git directory</h3><p>Browsing to:</p><pre>/.git</pre><p>confirmed that the application’s Git repository data was directly accessible over HTTP — a strong indicator that the .git folder had been deployed alongside the application&#39;s public-facing files instead of being excluded.</p><h3>2. Download the entire repository</h3><p>Having confirmed the directory was accessible, the next step was to pull down a full local copy for analysis. On Linux, this can be done with:</p><pre>wget -r https://YOUR-LAB-ID.web-security-academy.net/.git/</pre><p>The -r flag recursively downloads the entire directory structure, reconstructing the repository&#39;s .git folder locally. Windows users would need an equivalent tool, or a Unix-like environment such as Cygwin, to run the same command.</p><h3>3. Explore the commit history locally</h3><p>With the .git directory downloaded, I opened the folder using a local Git installation and inspected the commit log. One commit stood out immediately due to its message:</p><pre>&quot;Remove admin password from config&quot;</pre><p>A commit message like this is effectively a neon sign pointing at exactly where the sensitive data used to live — and, more importantly, where it still lives in history.</p><h3>4. Inspect the diff for the leaked credential</h3><p>Looking closely at the diff for that commit, I found that it modified a file called admin.conf. The change replaced a hard-coded password with a reference to an environment variable, ADMIN_PASSWORD — a legitimate security improvement for the <em>current</em> state of the code.</p><p>However, a diff by nature shows both the old and new versions of the changed lines. The previous, hard-coded password was still clearly visible in the removed line of the diff, fully readable despite having been “deleted” in the newer commit.</p><h3>5. Log in as the administrator</h3><p>Using the recovered password, I returned to the lab and logged into the administrator account.</p><h3>6. Delete carlos</h3><p>With administrator access secured, I navigated to the admin interface and deleted the user carlos, solving the lab.</p><h3>Written by Zeyad Naguib,<br>🔗 <a href="https://www.linkedin.com/in/zeyadnageeb">https://www.linkedin.com/in/zeyadnageeb</a><br>✍️ <a href="https://medium.com/@zeyadnaguib1">https://medium.com/@zeyadnaguib1</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1159413ea8aa" width="1" height="1" alt=""><hr><p><a href="https://cybersecuritywriteups.com/information-disclosure-in-version-control-history-1159413ea8aa">Information Disclosure in Version Control History</a> was originally published in <a href="https://cybersecuritywriteups.com/">Cyber Security Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unprotected admin functionality with unpredictable URL — PortSwigger Access Control Lab 2]]></title>
            <link>https://infosecwriteups.com/unprotected-admin-functionality-with-unpredictable-url-portswigger-access-control-lab-2-63dd82874875?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/63dd82874875</guid>
            <category><![CDATA[access-control]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[broken-access-control]]></category>
            <category><![CDATA[role-based-access-control]]></category>
            <category><![CDATA[authorization]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Tue, 30 Dec 2025 11:30:33 GMT</pubDate>
            <atom:updated>2026-07-27T09:36:24.124Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unprotected admin functionality with unpredictable URL — PortSwigger Access Control Lab 2</h3><p><strong>Finding ID: BAC-Portswigger-002</strong></p><p><strong>Title: Unprotected admin functionality with unpredictable URL</strong></p><p><strong>Risk (Severity): High</strong></p><h3><strong>Rationale:</strong></h3><p>The application exposes an administrative interface that is accessible without authentication. Although the admin panel is located at a non-obvious (unpredictable) URL, the location is disclosed within client-side JavaScript on the home page. Any attacker who inspects the page source can discover the admin endpoint and access sensitive administrative functionality without authorization. This allows full compromise of the application, including deleting user accounts.</p><h3><strong>Affected asset / Location:</strong></h3><p>Unprotected admin panel endpoint disclosed via client-side JavaScript</p><h3><strong>Root cause:</strong></h3><ul><li>Missing authentication and authorization checks on administrative functionality</li><li>Disclosure of sensitive endpoints in client-side JavaScript</li><li>Reliance on security through obscurity instead of proper access control</li></ul><p><strong>Discovery date: 2025–12–30</strong></p><h3>Executive Summary :</h3><p>The application contains an unprotected admin panel located at an unpredictable URL. However, this URL is disclosed in the JavaScript code of the home page. An attacker can easily identify the admin endpoint by inspecting the page source and directly access the admin panel without authentication. This results in a Broken Access Control vulnerability that allows attackers to perform privileged actions such as deleting users, leading to complete application takeover.</p><h3><strong>Reproducible Steps (PoC — Lab Only) :</strong></h3><ol><li>First, open the target lab in a browser, read lab description carefully.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*B1gJiQUVrJyQ3zzwdFCwiQ.png" /></figure><p>2. Next, access the lab …</p><p>3. Try to append /robots.txt to the lab URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLYmPuJqYLfTVLcZEzmDnQ.png" /></figure><p>4. On the lab home page, right click and view the page source:</p><p>5. Identify a script that reveals the admin panel URL, for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25-YKdtL_VgtqAE2ZsTk8w.png" /></figure><p>5. I found a disclosed admin path</p><pre>/admin-xyz123</pre><p>6. Copy the disclosed admin path and append it to the lab base URL:</p><pre>https://LAB-ID.web-security-academy.net/admin-xyz123</pre><p>7. Load the URL and confirm that the admin panel is accessible without authentication and locate the list of users in the admin interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_v3L3J8tgtJPXDJZuz9xIg.png" /></figure><p>8. Click <strong>Delete</strong> next to the user <strong>carlos</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdUcZUvEvy_nJyGvzrrLBQ.png" /></figure><p>9. The user is successfully deleted, and the lab is solved.</p><h3>Impact :</h3><ul><li>Unauthorized access to administrative functionality</li><li>Ability to delete or modify user accounts</li><li>Full compromise of application security</li><li>Clear exploitation of Broken Access Control (OWASP A01)</li></ul><h3><strong>Remediation (Recommended) :</strong></h3><ol><li><strong>Enforce Authentication</strong><br>Require login before accessing any admin endpoints.</li><li><strong>Implement Authorization Checks</strong><br>Ensure only privileged users can perform administrative actions.</li></ol><p><strong>3. Avoid Security Through Obscurity</strong><br> Unpredictable URLs must not be used as a security control.</p><p><strong>4. Do Not Expose Sensitive Endpoints in Client-Side Code</strong><br> Never disclose admin paths in JavaScript, HTML, or comments.</p><p><strong>5. Do Not Rely on robots.txt</strong><br>robots.txt must never be used to protect sensitive paths.</p><p><strong>6. Apply Role-Based Access Control (RBAC)</strong><br>Validate permissions on every sensitive request.</p><p><strong>7. Regular Security Testing</strong><br>Include access control testing in security assessments.</p><h3>References :</h3><ul><li>OWASP Top 10 — A01: Broken Access Control<br> <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">https://owasp.org/Top10/A01_2021-Broken_Access_Control/</a></li><li>PortSwigger — Access Control Vulnerabilities<br> <a href="https://portswigger.net/web-security/access-control">https://portswigger.net/web-security/access-control</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63dd82874875" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/unprotected-admin-functionality-with-unpredictable-url-portswigger-access-control-lab-2-63dd82874875">Unprotected admin functionality with unpredictable URL — PortSwigger Access Control Lab 2</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>
        <item>
            <title><![CDATA[Unprotected admin functionality — PortSwigger Access control vulnerabilities Lab 1]]></title>
            <link>https://infosecwriteups.com/unprotected-admin-functionality-portswigger-access-control-vulnerabilities-lab-1-6f20abccfe14?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f20abccfe14</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[access-control]]></category>
            <category><![CDATA[broken-access-control]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[role-based-access-control]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Tue, 30 Dec 2025 10:38:27 GMT</pubDate>
            <atom:updated>2026-07-28T07:43:05.326Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unprotected admin functionality — PortSwigger Access control vulnerabilities Lab 1</h3><p><strong>Finding ID:</strong> BAC-Portswigger-001</p><p><strong>Title:</strong> Unprotected Admin Functionality</p><p><strong>Risk (Severity):</strong> High</p><p><strong>Rationale:</strong></p><p>The application exposes an administrative interface that is accessible without authentication. The admin panel path is disclosed through the robots.txt file and is not protected by any server-side authorization checks. An attacker can directly access the admin panel and perform sensitive actions such as deleting user accounts, leading to full compromise of the application.</p><p><strong>Affected asset / Location:</strong><br>/administrator-panel (Admin panel endpoint)</p><p><strong>Root cause:</strong><br>Missing authentication and authorization checks on administrative functionality. The application relies on obscurity instead of enforcing proper access control.</p><p><strong>Discovery date:</strong> 2025–12–30</p><p>Executive Summary :</p><p>The application contains an unprotected admin panel that can be discovered by viewing the robots.txt file. Any unauthenticated user can access the admin interface and execute privileged actions, including deleting users. This represents a clear case of Broken Access Control and allows complete administrative takeover of the application.Press enter or click to view image in full size</p><h3>Reproducible Steps (PoC — Lab Only) :</h3><ol><li>First, open the target lab in a browser, read lab description carefully.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*x3xxLl2oUguugktq3d4gWA.png" /></figure><p>2. Next, access the lab …</p><p>3. Append /robots.txt to the lab URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9yfsFTwmM6IgdRDZy0Tww.png" /></figure><p>4. Observe that the file reveals a hidden admin path:</p><pre>Disallow: /administrator-panel</pre><p>5. Replace /robots.txt with the disclosed path:</p><pre>https://LAB-ID.web-security-academy.net/administrator-panel</pre><p>6. Confirm that the admin panel loads without authentication and locate the user list.</p><p>7. Click <strong>Delete</strong> next to the user <strong>carlos</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bmsnGEOwiO5a7jeHiqFQcQ.png" /></figure><p>8. The user is successfully deleted, solving the lab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7KVV3j7oTgqgjG9FAs9VwQ.png" /></figure><h3>Impact :</h3><ul><li>Unauthorized access to administrative functionality</li><li>Ability to delete or modify user accounts</li><li>Full compromise of application security</li><li>Clear exploitation of Broken Access Control</li></ul><h3>Remediation (Recommended) :</h3><ol><li><strong>Enforce Authentication</strong><br> Require login before accessing any admin endpoints.</li><li><strong>Implement Authorization Checks</strong><br> Ensure only privileged users can perform administrative actions.</li><li><strong>Do Not Rely on robots.txt</strong><br> robots.txt must never be used to protect sensitive paths.</li><li><strong>Apply Role-Based Access Control (RBAC)</strong><br> Validate permissions on every sensitive request.</li><li><strong>Regular Security Testing</strong><br> Include access control testing in security assessments.</li></ol><h3>References :</h3><ul><li>OWASP Top 10 — A01: Broken Access Control</li><li><a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">https://owasp.org/Top10/A01_2021-Broken_Access_Control/</a></li><li><a href="https://portswigger.net/web-security/access-control">https://portswigger.net/web-security/access-control</a></li></ul><h4><strong>Written by Zeyad Naguib,<br></strong>🔗 https://www.linkedin.com/in/zeyadnageeb<br>✍️ https://medium.com/@zeyadnaguib1</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f20abccfe14" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/unprotected-admin-functionality-portswigger-access-control-vulnerabilities-lab-1-6f20abccfe14">Unprotected admin functionality — PortSwigger Access control vulnerabilities Lab 1</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>
        <item>
            <title><![CDATA[DOM XSS in document.write sink inside a select element — Cross-site Scripting Lab 10]]></title>
            <link>https://cybersecuritywriteups.com/dom-xss-in-document-write-sink-inside-a-select-element-cross-site-scripting-lab-10-b83de89b0cf5?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b83de89b0cf5</guid>
            <category><![CDATA[cross-site-scripting]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[dom-xss]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Tue, 11 Nov 2025 17:39:17 GMT</pubDate>
            <atom:updated>2025-11-11T17:39:17.159Z</atom:updated>
            <content:encoded><![CDATA[<h3>DOM XSS in document.write sink using location.search inside a select element — Cross-site Scripting Lab 10</h3><p><strong>Finding ID:</strong> PT-Portswigger-010</p><p><strong>Title:</strong> DOM XSS — document.write with location.search inside a &lt;select&gt; element (stock checker)</p><p><strong>Risk (Severity):</strong> High</p><p><strong>Rationale:</strong> The client-side code reads a storeId value from the URL (location.search) and writes it into the page via document.write() as part of an &lt;option&gt; inside a &lt;select&gt;. Because the value is not escaped or validated, an attacker can break out of the &lt;select&gt; / &lt;option&gt; context and inject HTML with event handlers (for example &lt;img onerror=...&gt;), leading to execution of arbitrary JavaScript in any victim’s browser that loads the manipulated URL. This DOM-based XSS is exploitable from the client-side (via crafted links or an exploit page).</p><p><strong>Affected asset / Location:</strong><br> Product page stock-checker client code that extracts storeId from location.search and uses document.write() to add options to a &lt;select&gt;.</p><p>Example vulnerable behavior:</p><pre>document.write(&#39;&lt;option value=&quot;&#39; + storeId + &#39;&quot;&gt;&#39; + storeId + &#39;&lt;/option&gt;&#39;);</pre><p><strong>Root cause:</strong><br> Untrusted input from location.search is passed to document.write() without any encoding/validation and is output inside HTML element context (&lt;select&gt;/&lt;option&gt;). document.write() will insert the raw string into the DOM, allowing the attacker to inject tags/attributes that break out of the option/select context and run script via event attributes.</p><p><strong>Discovery date:</strong> 2025–11–11</p><h3>Executive Summary</h3><p>The product page’s stock-checker feature uses document.write() to insert a storeId option taken directly from the URL fragment/query. Because the input is neither validated nor escaped, a crafted storeId can close the &lt;select&gt;/&lt;option&gt; context and inject an element with an event handler (e.g., &lt;img onerror=alert(1)&gt;) that executes in the victim’s browser. This is a reliable DOM XSS vector in the client and can be triggered by sending victims a malicious product URL.</p><h3>Reproducible Steps (PoC — Lab Only)</h3><p>⚠️ <strong>Lab-only payloads. Do not use on unauthorized systems.</strong></p><ol><li>Open a product page (example):</li></ol><p>2. There is no any input field , just drop list so inspect/ view page source to look for the place of vulnerability or useful thing for us.</p><p>3. I found the following code show how the web app work and i found out that there is a hidden parameter called “storeId”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*85FhP9w88RxoncLiGJBI-Q.png" /></figure><p>4. Now, add a storeId parameter with a random value in url to confirm reflection:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GmxSIm-W9Wxdl-HEncGl5g.png" /></figure><ul><li>OK, now we sure that what we input to this parameter will created as a new option in the list .</li></ul><p>5. Replace storeId value with the XSS payload that breaks out of the option/select and injects an element with an onerror handler:</p><pre>&amp;storeId=&quot;&gt;&lt;/select&gt;&lt;img src=0 onerror=alert(&quot;Hacked By Zeyad&quot;)&gt;</pre><p>note : we have to close &lt;/select&gt; before our payload .</p><p>The injected &lt;img&gt; will attempt to load src=0 (404), triggering onerror and causing alert() to run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NL1GK-87wvo7jscoPdA94w.png" /></figure><p>R<strong>esult : </strong>The injected img onerror runs, demonstrating that document.write() allowed HTML injection from location.search.</p><h3>Impact</h3><ul><li>Arbitrary JavaScript execution in the context of the vulnerable origin (DOM XSS).</li><li>Possible theft of session tokens (if not HttpOnly), DOM manipulation, unauthorized actions, or data exfiltration.</li><li>Because the payload is placed via URL, this can be delivered via phishing links or exploit pages; severity is high.</li></ul><h3>Remediation (Recommended)</h3><ol><li><strong>Stop using </strong><strong>document.write() with untrusted input :</strong></li></ol><p>remove document.write() calls that output user-controlled values. document.write() writes raw HTML and should never be used with unescaped input.</p><p><strong>3. Use safe DOM APIs and treat user input as text</strong></p><ul><li>Create options using DOM methods and set values via textContent/value rather than inserting HTML:</li></ul><pre>// Safe example: create option node and assign safe text/value<br>const select = document.querySelector(&#39;#storeSelect&#39;);<br>const option = document.createElement(&#39;option&#39;);<br>option.value = storeId;                // ensure storeId is validated<br>option.textContent = storeId;          // inserts as text, not HTML<br>select.appendChild(option);</pre><p><strong>3. Validate and canonicalize </strong><strong>storeId</strong></p><ul><li>Accept only expected formats (e.g., numeric IDs or restricted slug pattern /^[A-Za-z0-9_-]+$/). Reject or sanitize anything outside the whitelist.</li></ul><p><strong>4. Encode when HTML output is unavoidable</strong></p><ul><li>If server/client must output HTML, use context-appropriate encoding/escaping to neutralize &lt;, &gt;, quotes, and attributes, or use libraries that perform context-aware sanitization.</li></ul><p><strong>5. Defense in depth</strong></p><ul><li>Apply CSP to limit script sources and disable inline script execution where feasible (CSP reduces impact but is not a substitute for fixes).</li><li>Ensure session cookies are HttpOnly, Secure, and have appropriate SameSite.</li><li>Log suspicious query parameters and monitor for repeated exploitation attempts.</li></ul><h3>References</h3><ul><li>OWASP DOM-based XSS Prevention Cheat Sheet</li><li>OWASP XSS Prevention Cheat Sheet — output encoding for HTML contexts</li><li>MDN: Element.textContent and DOM creation APIs</li></ul><p>Written by Zeyad Naguib, <br>🔗 <a href="https://www.linkedin.com/in/zeyadnageeb">https://www.linkedin.com/in/zeyadnageeb</a><br>✍️ <a href="https://medium.com/@zeyadnaguib1">https://medium.com/@zeyadnaguib1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b83de89b0cf5" width="1" height="1" alt=""><hr><p><a href="https://cybersecuritywriteups.com/dom-xss-in-document-write-sink-inside-a-select-element-cross-site-scripting-lab-10-b83de89b0cf5">DOM XSS in document.write sink inside a select element — Cross-site Scripting Lab 10</a> was originally published in <a href="https://cybersecuritywriteups.com/">Cyber Security Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reflected XSS inside a JavaScript string (angle brackets HTML-encoded) — Cross-site Scripting Lab 9]]></title>
            <link>https://cybersecuritywriteups.com/reflected-xss-inside-a-javascript-string-angle-brackets-html-encoded-cross-site-scripting-lab-9-fa99886fb1ab?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa99886fb1ab</guid>
            <category><![CDATA[cross-site-scripting]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[reflected-xss]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Tue, 11 Nov 2025 14:36:58 GMT</pubDate>
            <atom:updated>2025-11-11T14:36:58.950Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reflected XSS inside a JavaScript string (angle brackets HTML-encoded) — Cross-site Scripting Lab 9</h3><p><strong>Finding ID:</strong> PT-Portswigger-009</p><p><strong>Title:</strong> Reflected XSS — break out of JavaScript string where angle brackets are HTML-encoded</p><p><strong>Risk (Severity):</strong> High</p><p><strong>Rationale:</strong> User input from the search parameter is reflected inside a JavaScript <strong>string</strong> literal on the results page. Angle brackets (&lt; / &gt;) are HTML-encoded, but the application does not properly escape or sanitize quotes or string-context characters. An attacker can break out of the string literal (by injecting a quote/terminator) and append JavaScript code such as alert(1). This results in reflected XSS (client-side script execution) exploitable via a crafted URL.</p><p><strong>Affected asset / Location:</strong><br> Search query tracking / results page — the q (search) parameter value is echoed into an inline &lt;script&gt; as part of a JavaScript string (e.g., var searchTerms= &#39;...USER INPUT...&#39;;), with angle brackets encoded but string delimiters not safely handled.</p><p><strong>Root cause:</strong><br> Improper context-aware output encoding: user input is inserted into JavaScript string context without escaping quotes, backslashes, or other characters significant to JS string syntax. Encoding &lt;/&gt; alone is insufficient to prevent injection into JavaScript contexts.</p><p><strong>Discovery date:</strong> 2025–11–11</p><h3>Executive Summary</h3><p>The search query is written into a JavaScript string on the page (e.g., var searchTerms= &#39;USER_INPUT&#39;;). Although the app encodes &lt; and &gt;, it fails to escape or validate quote characters and other string delimiters. By submitting a payload that closes the string and appends JavaScript (for example &#39;+alert()+&#39;), an attacker can force the page to execute alert() when the crafted URL is visited. This reflected XSS can be delivered via phishing links and abused to steal data or perform actions in the victim’s browser.</p><h3>Reproducible Steps (PoC — Lab Only)</h3><p>⚠️ <strong>Lab-only payloads. Do not use on unauthorized systems.</strong></p><ol><li>Open the search page and submit a simple test string (e.g., hello”&gt;).</li><li>inspect to see where your input entered</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4aXXFlx1IYaEiRwJ8HOuGg.png" /></figure><pre>var searchTerms = &#39;&#39;;</pre><p>this is where our input will be</p><p>so, we have 2 ways to solve it :</p><ol><li>input==&gt; ‘ + alert(“Hacked By Zeyad”) + ‘</li></ol><pre>var searchTerms = &#39;&#39; + alert(&quot;Hacked By Zeyad&quot;) + &#39;&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r8oMMtPV_-j1L_Ca5iS0LA.png" /></figure><p>2. input==&gt; ‘; alert(“Hacked By Zeyad”); //</p><pre>var searchTerms = &#39;&#39; ; alert(&quot;Hacked By Zeyad&quot;); //&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BSWU9dWCMaFaYQAIRmn5Ig.png" /></figure><p><strong>Result:</strong> alert() executes (alert dialog appears), confirming reflected XSS via JavaScript string break-out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNjPrZPqUowHozV29QjpmQ.png" /></figure><h3>Impact</h3><ul><li>Execution of arbitrary JavaScript in the victim’s browser (reflected XSS).</li><li>Possible theft of non-HttpOnly cookies, tokens, or data accessible via DOM/JavaScript.</li><li>The vulnerability can be delivered via crafted links (phishing) and may lead to account takeover, UI manipulation, or data exfiltration.</li></ul><h3>Remediation (Recommended)</h3><ol><li><strong>Apply context-aware encoding for JavaScript strings</strong></li></ol><ul><li>When inserting untrusted data into JS string literals, escape characters like \, &#39;, &quot;, newline, and control characters using a library or built-in framework function. Example encoding replacements for single-quoted string:</li><li>\ → \\</li><li>&#39; → \&#39;</li><li>newline → \n</li><li>Better: use server/templates that provide JavaScript string encoding helpers.</li></ul><p><strong>2. Prefer safe patterns</strong></p><ul><li>Avoid embedding raw user input in inline scripts. Pass data via data- attributes or JSON safely encoded and then read with textContent / JSON.parse in a controlled way.</li></ul><p><strong>3. Validate and canonicalize input</strong></p><p>Restrict search query characters where feasible (allow letters, digits, whitespace, safe punctuation), and normalize input server-side.</p><p><strong>4. Avoid inline scripts or use safer serialization</strong></p><ul><li>If embedding JSON, use JSON.stringify on the server to produce a safe JavaScript value, or render the JSON into a &lt;script type=&quot;application/json&quot;&gt; block and parse it client-side.</li></ul><p><strong>5. Defense in depth</strong></p><ul><li>Deploy a strict Content Security Policy (CSP) to limit script sources. CSP helps mitigate exploitation but does not replace proper encoding.</li><li>Ensure cookies are HttpOnly and Secure to limit theft via XSS.</li></ul><h3>References</h3><ul><li>OWASP XSS (Cross Site Scripting) Prevention Cheat Sheet — JavaScript context encoding</li><li>OWASP Secure Coding Practices — Output Encoding &amp; Data Serialization</li><li>MDN: safely embedding JSON in HTML</li></ul><p><strong>Written by Zeyad Naguib</strong><br>🔗 <a href="https://www.linkedin.com/in/zeyadnageeb">https://www.linkedin.com/in/zeyadnageeb</a><br>✍️ <a href="https://medium.com/@zeyadnaguib1">https://medium.com/@zeyadnaguib1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa99886fb1ab" width="1" height="1" alt=""><hr><p><a href="https://cybersecuritywriteups.com/reflected-xss-inside-a-javascript-string-angle-brackets-html-encoded-cross-site-scripting-lab-9-fa99886fb1ab">Reflected XSS inside a JavaScript string (angle brackets HTML-encoded) — Cross-site Scripting Lab 9</a> was originally published in <a href="https://cybersecuritywriteups.com/">Cyber Security Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stored XSS into anchor href attribute with double quotes HTML-encoded — Cross-site scripting Lab 8]]></title>
            <link>https://medium.com/@zeyadnaguib1/stored-xss-into-anchor-href-attribute-with-double-quotes-html-encoded-cross-site-scripting-lab-8-25bc419b611d?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/25bc419b611d</guid>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[cross-site-scripting]]></category>
            <category><![CDATA[stored-xss]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Tue, 11 Nov 2025 12:01:10 GMT</pubDate>
            <atom:updated>2025-11-11T12:01:10.073Z</atom:updated>
            <content:encoded><![CDATA[<h3>Stored XSS into anchor href attribute with double quotes HTML-encoded — PortSwigger Cross-site Scripting Lab 8</h3><p><strong>Finding ID:</strong> PT-Portswigger-008</p><p><strong>Title:</strong> Stored XSS into anchor href attribute with double quotes HTML-encoded</p><p><strong>Risk (Severity):</strong> High</p><p><strong>Rationale:</strong> A user-controlled value from the comment form (Website field) is stored on the server and later reflected into an anchor element’s href attribute on the post page. Double quotes are HTML-encoded, but the application does not validate or restrict URL schemes and allows javascript: URIs. An attacker can therefore store a javascript: URL that executes when another user clicks the author name link. This is a persistent (stored) XSS with reliable client-side execution when the link is followed.</p><p><strong>Affected asset / Location:</strong><br> Comment submission / display functionality — the Website input from the comment form is saved and rendered inside an anchor link’s href attribute on the post view page .</p><p><strong>Root cause:</strong><br> Improper handling of persisted user-supplied URLs: the server persists raw user input into an attribute context without canonicalization/validation and does not block dangerous schemes (javascript:). Encoding of angle brackets or double quotes alone is insufficient for attribute context protection if URLs (or schemes) are not validated.</p><p><strong>Discovery date:</strong> 2025–11–09</p><h3>Executive Summary</h3><p>The comment form’s Website field is stored and later used as the href target of the comment author’s name. Although certain characters (like &quot;/&lt;/&gt;) may be encoded in output, the application allows dangerous URL schemes such as javascript:. By submitting a comment where the Website value is javascript:alert(), the author link becomes an executable JavaScript URI — clicking the name triggers alert(). This is a stored XSS that affects any user viewing the post.</p><h3>Reproducible Steps (PoC — Lab Only)</h3><p>⚠️ <strong>Lab-only payloads. Do not use on unauthorized systems.</strong></p><ol><li>Open any blog post page and locate the comment form (fields typically: Comment, Name, Email, Website).</li><li>First, try to fill the fields with simple inputs</li></ol><p>3. when you mouseover the name of the author you will find that is clickable link direct you to the author website</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0Rcx5WNIF7uDXGI8BdC9w.png" /></figure><p>4. inspect to see href attibute and your input</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZHg30gykWCs2LobIH8IbgQ.png" /></figure><p>5. Now, if you input an payload in the website field =&gt; it turned to an executable JavaScript URI</p><pre>javascript:alert(&quot;Hacked By Zeyad&quot;)</pre><p>6. View the post page and locate your comment. Right-click the author name, choose <strong>Copy link address</strong>, and paste the URL into the browser address bar — or simply click the author name.<br> <strong>Result:</strong> The browser executes javascript:alert(“Hacked By Zeyad”) and shows an alert dialog, confirming stored XSS via an executable href.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etVW1EA-Dpdq6cGtWLZLqg.png" /></figure><p><strong>Result:</strong> The browser executes javascript:alert(1) and shows an alert dialog, confirming stored XSS via an executable href.</p><p>It Is Workinggg !!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PXNrxzG_PJBZi305TqXqNw.png" /></figure><h3>Impact</h3><ul><li>Persistent client-side script execution whenever a user views and clicks the malicious author link.</li><li>Allows attackers to run arbitrary JavaScript in victims’ browsers — possible session token theft (if cookies are not HttpOnly), UI manipulation, data exfiltration, or further chained attacks.</li><li>High real-world severity because the payload is stored and affects all viewers of the comment</li></ul><h3>Remediation (Recommended)</h3><p>1. Validate and canonicalize stored URL input (primary fix)</p><ul><li>On the server, parse and validate the Website input as a URL. Accept only safe, expected schemes such as http: and https: and optionally relative paths. Reject or normalize anything else (including javascript:, data:, vbscript:). Example (pseudo):</li></ul><p>2. Do not allow user-controlled javascript: URIs</p><ul><li>Explicitly block javascript: and other dangerous URI schemes server-side before persisting any user value.</li></ul><p><strong>3. Encode for the attribute context</strong></p><ul><li>When writing into an attribute, perform proper attribute encoding (escape &amp;, &quot;, &#39;, &lt;, &gt;). Use your templating/encoding library’s context-aware escaping functions rather than ad-hoc replacements.</li></ul><p><strong>4. Prefer using a server-side mapping or white-list approach</strong></p><ul><li>If the Website field is intended to be a link to an external site, consider storing only validated hostnames or tokenized IDs and resolving them server-side when rendering. Or append rel=&quot;nofollow noopener noreferrer&quot; and require http(s) only.</li></ul><p><strong>5. Use safe rendering patterns</strong></p><ul><li>When generating anchor tags, ensure href is set to a sanitized/validated URL.</li></ul><p><strong>6. Defense-in-depth</strong></p><ul><li>Content Security Policy (CSP): serve a strict CSP (e.g., disallow unsafe-inline and restrict script sources). CSP helps limit impact but does not replace validation.</li><li>Secure cookies: set session cookies HttpOnly, Secure, SameSite to reduce theft risk.</li><li>Input length checks, rate limiting, and moderation workflows for user-supplied links.</li></ul><h3>References</h3><ul><li>OWASP XSS (Cross Site Scripting) Prevention Cheat Sheet — attribute &amp; URL context guidance</li><li>OWASP Secure Coding Practices — Input &amp; Output Validation</li><li>RFC 3986 — URI Generic Syntax (for parsing/validating URLs)</li></ul><h4><strong>Written by Zeyad Naguib</strong><br>🔗 <a href="https://www.linkedin.com/in/zeyadnageeb">https://www.linkedin.com/in/zeyadnageeb</a><br>✍️ <a href="https://medium.com/@zeyadnaguib1">https://medium.com/@zeyadnaguib1</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25bc419b611d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reflected XSS into attribute with angle brackets HTML-encoded— Cross-site Scripting Lab 7]]></title>
            <link>https://medium.com/@zeyadnaguib1/reflected-xss-into-attribute-with-angle-brackets-html-encoded-portswigger-cross-site-scripting-29903bb632e4?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/29903bb632e4</guid>
            <category><![CDATA[reflected-xss]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[cross-site-scripting]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Sun, 09 Nov 2025 09:11:22 GMT</pubDate>
            <atom:updated>2025-11-11T11:37:27.727Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reflected XSS into attribute with angle brackets HTML-encoded — PortSwigger Cross-site Scripting Lab 7</h3><p><strong>Finding ID:</strong> PT-Portswigger-007</p><p><strong>Title:</strong> Reflected XSS into attribute with angle brackets HTML-encoded</p><p><strong>Risk (Severity):</strong> High</p><p><strong>Rationale:</strong> User input from the search parameter is reflected into an HTML attribute on the results page. The application HTML‑encodes angle brackets (&lt; / &gt;) but does <strong>not</strong> properly handle quotes or attribute context, which allows an attacker to break out of the attribute value and inject a new attribute with an event handler (for example onmouseover or onerror) that calls alert(). This results in reflected XSS even though &lt; and &gt; are encoded. Such injection can be used for session theft, UI manipulation, phishing, or further client‑side attacks.</p><p><strong>Affected asset / Location:</strong> Search functionality — the value of the search query parameter is reflected into an HTML attribute (e.g., inside title=&quot;...&quot;, <strong>value=&quot;...&quot;</strong>, href=&quot;...&quot;, or similar).</p><p><strong>Root cause:</strong> Improper output encoding: the application encodes &lt; and &gt; but treats user input as plain text inside an attribute without escaping or handling attribute delimiters (single/double quotes). This permits breaking out of the attribute value and injecting an event handler attribute.</p><p><strong>Discovery date:</strong> 2025–11–09</p><h3>Executive Summary</h3><p>The search parameter is echoed into an HTML attribute on the results page. Although &lt; and &gt; are HTML‑encoded, the application fails to escape or validate quotation marks and attribute context. By injecting a quote to break out of the attribute and adding an event handler (for example onmouseover=alert(1)), an attacker can trigger JavaScript execution in the victim’s browser. This is a reflected XSS vulnerability exploitable via a crafted search URL.Reproducible Steps (PoC — Lab Only)</p><h3>Reproducible Steps (PoC — Lab Only)</h3><p>⚠️ <strong>Lab-only payloads. Do not use on unauthorized systems.</strong></p><ol><li>Open the lab page and read description of the lab carefully…</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*RD4mSHuzqQULIH6i4oPVig.png" /></figure><p>2. Access the lab and start with a simple test to check for encoding or filtering</p><pre>hello&quot;&gt;</pre><p>3. Inspect to show page source, you will notice some things :</p><p><strong>&gt;</strong> was <strong>encoded </strong>and your inputs enter between <strong>double quotes</strong> ”” of the <strong>value</strong> attribute so you don’t need a full payload just event handler can do it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*yDsTOZ1Z4k0rJU1_fCbqDg.png" /></figure><p>4. I tried some event handlers and onmouseover was working and the lab was solved</p><pre>&quot;onmouseover=&quot;alert(&#39;Hacked By Zeyad&#39;)</pre><p>important note : notice double quotes !!!!</p><ul><li>first one is for closing the value attribute</li><li>second one before alert but why i didn’t close it ??! ==&gt; because there was a double quote belong to value attribute was still exist at the end.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XHIxwiyfcwJLzKP6_iiWsA.png" /></figure><p>It is Working !</p><h3>Impact</h3><ul><li>Reflected JavaScript execution in a victim’s browser (client-side XSS).</li><li>Potential cookie/token theft (if cookies are not HttpOnly), CSRF-like actions performed via DOM, UI/UX manipulation, and data exfiltration.</li><li>Attack can be delivered via a crafted link (phishing) or injected into third-party content that reflects the query.</li></ul><h3>Remediation (Recommended)</h3><ol><li><strong>Encode for the correct context (attribute)</strong></li></ol><ul><li>When reflecting data into an attribute, perform attribute‑context encoding. Escape at least: &amp; → &amp;amp;, &quot; → &amp;quot;, &#39; → &amp;#x27;, &lt; → &amp;lt;, &gt; → &amp;gt;.</li><li>Use framework/template functions that perform context‑aware escaping rather than ad‑hoc replacements.</li></ul><p><strong>2. Prefer output in safe contexts</strong></p><ul><li>If the user input is purely textual, place it into the DOM using textContent (or jQuery .text()) rather than inside attributes or innerHTML.</li></ul><p><strong>3. Validate and canonicalize input</strong></p><ul><li>Validate allowable characters for the search parameter (e.g., restrict to letters, digits, common punctuation) and normalize input before rendering.</li></ul><p><strong>4. Use server‑side sanitization libraries for attribute data</strong></p><ul><li>Use vetted libraries or templating systems that provide attribute encoding.</li></ul><p><strong>5. Defense‑in‑depth</strong></p><ul><li>Apply a strict Content Security Policy (CSP) that restricts script sources and disallows unsafe inline scripts (note: CSP mitigates impact but does not replace correct encoding).</li><li>Ensure session cookies are HttpOnly, Secure, and have appropriate SameSite settings.</li></ul><h3>References</h3><ul><li>OWASP XSS (Cross Site Scripting) Prevention Cheat Sheet — attribute encoding guidance</li><li>OWASP Secure Coding Practices — Output Encoding</li><li>MDN: HTML escaping and DOM APIs</li></ul><p><strong>Written by Zeyad Naguib</strong><br>🔗 <a href="https://www.linkedin.com/in/zeyadnageeb">https://www.linkedin.com/in/zeyadnageeb</a><br>✍️ <a href="https://medium.com/@zeyadnaguib1">https://medium.com/@zeyadnaguib1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29903bb632e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DOM XSS in jQuery selector sink using a hashchange event — PortSwigger Cross-site Scripting Lab 6]]></title>
            <link>https://medium.com/@zeyadnaguib1/dom-xss-in-jquery-selector-sink-using-a-hashchange-event-portswigger-cross-site-scripting-lab-6-427a6d91ea7a?source=rss-2faf8ac563a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/427a6d91ea7a</guid>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[dom-xss]]></category>
            <dc:creator><![CDATA[Zeyad Naguib]]></dc:creator>
            <pubDate>Sat, 08 Nov 2025 10:55:31 GMT</pubDate>
            <atom:updated>2025-11-08T10:55:31.280Z</atom:updated>
            <content:encoded><![CDATA[<h3>DOM XSS in jQuery selector sink using a hashchange event — PortSwigger Cross-site Scripting Lab 6</h3><p><strong>Finding ID:</strong> PT-Portswigger-006</p><p><strong>Title:</strong> DOM XSS in jQuery selector sink using location.hash (hashchange event)</p><p><strong>Risk (Severity):</strong> High</p><p><strong>Rationale:</strong> Untrusted data from the URL fragment (location.hash) is used directly inside a jQuery selector expression ($(&#39;:contains(...)&#39;)) without escaping or validation. An attacker can supply HTML with event handlers (e.g., &lt;img onerror=...&gt;, &lt;svg onload=...&gt;) or break out of selector quoting to execute arbitrary JavaScript when the page processes the hash. In this lab the exploit triggers print() in the victim’s browser. This allows client-side code execution, which can be abused for session theft, UI manipulation, data exfiltration, or targeted phishing.</p><p><strong>Affected asset / Location:</strong><br> Client-side code on the home page that listens for hashchange and builds a jQuery selector using the decoded fragment.</p><p><strong>Root cause:</strong><br> Unsafe concatenation of untrusted input (location.hash) into a selector string passed to jQuery. The code neither escapes special characters nor validates the fragment, allowing HTML parsing/selector injection and execution of injected event handlers.</p><p><strong>Discovery date:</strong> 2025–11–08</p><h3>Executive Summary</h3><p>The application reads the URL fragment and places it directly in a jQuery :contains() selector. Because the fragment is not escaped or validated, a crafted hash can create HTML elements with event handlers or break selector context, enabling DOM-based XSS. In this training lab a crafted exploit causes the victim’s browser to call print() when the hash is processed. This vulnerability is exploitable entirely from the client side (via a malicious link or an exploit page/iframe).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*hrQL1UsGWxyBUryEAAeVIQ.png" /></figure><h3>Reproducible Steps (PoC — Lab Only)</h3><p>⚠️ <strong>Lab-only payloads. Do not use on real/production systems.</strong></p><ol><li>Open the lab banner → <strong>Go to exploit server</strong>.</li><li>In the exploit server <strong>Body</strong> field, store this HTML (replace YOUR-LAB-ID with the lab host if needed):</li></ol><pre>&lt;iframe src=&quot;https://YOUR-LAB-ID.web-security-academy.net/#&quot; onload=&quot;this.src += &#39;&lt;img src=x onerror=print()&gt;&#39;&quot;&gt;&lt;/iframe&gt;</pre><p>3. Click <strong>Store</strong>, then <strong>View exploit</strong> to verify the exploit triggers print() locally.</p><p>4. Click <strong>Deliver exploit to victim</strong>. The victim’s browser will load the exploit page; the iframe will set the fragment inside the target origin, firing the page’s hashchange handler and causing print() to execute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*-vRi-y1JYtf6UfjS0NCSEA.png" /></figure><p><strong>Result:</strong> The page executes print() when processing the crafted fragment.</p><p><strong>Notes:</strong></p><p>If &lt;script&gt; tags are filtered, event attributes on elements (e.g., onerror, onload) are commonly used as bypasses; svg or img payloads are effective alternatives.</p><h3>Impact</h3><ul><li>Execution of arbitrary JavaScript in victims’ browsers (DOM XSS).</li><li>Potential theft of non-HttpOnly cookies or tokens accessible in the DOM.</li><li>Ability to modify page content, perform actions on behalf of users, or exfiltrate data.</li><li>Can be weaponized for targeted phishing or chained with other weaknesses to escalate impact.</li></ul><h3>Remediation (Recommended) :</h3><p><strong>1. Stop building selectors from raw user input</strong><br> Avoid concatenating untrusted fragments into selector strings.</p><p><strong>Preferred safe approach (compare textContent):</strong></p><pre>$(window).on(&#39;hashchange&#39;, function(){<br>    var raw = decodeURIComponent(window.location.hash.slice(1));<br>    var posts = $(&#39;section.blog-list h2&#39;).filter(function(){<br>        return $(this).text() === raw;<br>    });<br>    if (posts.length) posts.get(0).scrollIntoView();<br>});</pre><p>This treats user data as plain text and does not create selectors or parse HTML.</p><p><strong>2. Escape if you must use selectors</strong><br> If building a selector is necessary, escape the value with CSS.escape() or $.escapeSelector():</p><pre>var raw = decodeURIComponent(window.location.hash.slice(1));<br>var safe = (typeof CSS !== &#39;undefined&#39; &amp;&amp; CSS.escape) ? CSS.escape(raw) : $.escapeSelector(raw);<br>var post = $(&#39;section.blog-list h2:contains(&quot;&#39; + safe + &#39;&quot;)&#39;);</pre><p><strong>3. Validate and restrict fragment format</strong><br> Only accept a limited, known format for fragments (e.g., numeric IDs, slugs matching /^[A-Za-z0-9_-]+$/). Reject or canonicalize unexpected values.</p><p><strong>4. Avoid HTML parsing / creating elements from untrusted strings</strong><br> Do not pass user-supplied strings to APIs that will treat them as HTML fragments. Use .text() / .textContent for inserting untrusted text into the DOM.</p><p><strong>5. Defense in depth</strong></p><ul><li>Implement a strict Content Security Policy (CSP) to reduce impact (note: CSP is not a substitute for fixing the vulnerability).</li><li>Ensure cookies are HttpOnly, Secure, and have appropriate SameSite values.</li><li>Add logging/monitoring to detect suspicious hash payloads.</li></ul><h3><strong>References</strong></h3><ul><li>OWASP DOM-based XSS Prevention Cheat Sheet</li><li>OWASP XSS (Cross Site Scripting) Prevention Cheat Sheet</li><li>MDN: CSS.escape() — <a href="https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape">https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape</a></li></ul><p><strong>Written by Zeyad Naguib</strong><br> 🔗 <a href="https://www.linkedin.com/in/zeyadnageeb">https://www.linkedin.com/in/zeyadnageeb</a><br> ✍️ <a href="https://medium.com/@zeyadnaguib1">https://medium.com/@zeyadnaguib1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=427a6d91ea7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>