<?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 Shofa on Medium]]></title>
        <description><![CDATA[Stories by Shofa on Medium]]></description>
        <link>https://medium.com/@ahmed202123713?source=rss-cfbf13b05bbf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3li4o_jqUBRllbvOVPEpWA.png</url>
            <title>Stories by Shofa on Medium</title>
            <link>https://medium.com/@ahmed202123713?source=rss-cfbf13b05bbf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:31:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmed202123713/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Landed 3 Firefox DevTools Fixes (and the Workflow You Can Copy)]]></title>
            <link>https://medium.com/@ahmed202123713/how-i-landed-3-firefox-devtools-fixes-and-the-workflow-you-can-copy-69a290841e3d?source=rss-cfbf13b05bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/69a290841e3d</guid>
            <category><![CDATA[mozilla]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[open-source-contribution]]></category>
            <category><![CDATA[mozilla-firefox]]></category>
            <dc:creator><![CDATA[Shofa]]></dc:creator>
            <pubDate>Sat, 17 Oct 2026 19:01:27 GMT</pubDate>
            <atom:updated>2026-10-18T09:44:56.354Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KgF3gLW7eT4hUvtv3eM0iA.jpeg" /><figcaption>Night-time trail camera Fox</figcaption></figure><p>I have three patches in Firefox DevTools. I didn’t understand the codebase when I started, and I still don’t understand all of it. What I had was a repeatable way to attack one bug at a time.</p><p>My first patch went from “can I take this?” to merged in about three days. It landed for Firefox 160.</p><p>Here’s the workflow, then the three bugs it got me through.</p><p><strong>The short version</strong></p><ol><li>Reproduce the bug locally</li><li>Find a similar feature that already works (Searchfox)</li><li>Trace the logic until you know the root cause</li><li>Make the smallest change that fixes it</li><li>Run the relevant tests, then take review feedback seriously</li></ol><h3>Enhancement #1: grid-lanes badges (Bug 2076779)</h3><p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=2076779">2076779 — Add a `(inline-)grid-lanes` badge in the markup view for element with display: (inline-)grid-lanes</a></p><p>The Inspector shows badges next to elements with display: grid or flex. The maintainer’s bug description was one line: “We do it for (inline-)grid, so let’s do the same here.” The job was to add badges for grid-lanes and inline-grid-lanes.</p><p>Before writing code, I left a comment on the bug saying I was new and asking if anyone was already working on it. Do this every time. It’s polite, and it stops you from duplicating someone’s work.</p><p>I searched Searchfox for how the grid badge was defined, rendered, and tested, then followed the same pattern.</p><p>The source change was small: markup.js (2 lines) and views/element-editor.js (12 lines).</p><p>Everything else was tests: two browser_markup_display_node files, 65 lines each. About 90% of the patch was test code.</p><p><strong>What I took from it:</strong> in a mature codebase, the best patch looks like it was always there. Find the existing pattern, extend it, and write the tests.</p><p>Before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kL3TrmJFezUR-U7EbA5yRg.jpeg" /><figcaption>Issue: Markup-dom-tree doesn’t show badges for grid-lanes css new feature.</figcaption></figure><p>After:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KLaAsygGx2COb03e7lP7xA.jpeg" /><figcaption>Issue: Markup-dom-tree supports grid-lanes css new feature</figcaption></figure><h3>Enhancement #2: inactive CSS on grid-lanes (Bug 2076777)</h3><p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=2076777">2076777 — Fix inactive CSS for display grid-lanes / inline-grid-lanes</a></p><p>After my first patch landed, the maintainer asked if I wanted another grid-lanes bug. I said yes and had a patch up the same day it was assigned. It merged the next day.</p><p>The problem: properties like gap and grid-template* work on grid-lanes containers, but the Styles panel showed them greyed out with the “inactive CSS” icon. The panel’s rules said these properties only applied to grid containers, so it was telling developers something false.</p><p>The badge was fine. The rule data behind it was wrong. The whole fix was 12 lines in inactive-property-helper.js, the server-side helper that decides whether a property applies to an element. I backed it with 135 lines of tests: unit tests for gap, align-content, and the grid container properties, plus a rules-panel test (browser_rules_inactive_css_grid.js).</p><p><strong>What I took from it:</strong> when the UI shows something wrong, check the logic feeding it before you touch the component that renders it. A 12-line fix in the right file beats a big patch in the wrong one.</p><p>Before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*qawzMJgqpxPSAW9LpiVR7Q.jpeg" /><figcaption>Issue: Grid-lanes-rules wasn’t supported in mozilla firefox</figcaption></figure><p>After:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*K1IG2P5lUzM7KyAeNEQ7-A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*qSrRciPA0-2zaxqnfoxnWA.jpeg" /><figcaption>Fix: After working out to make grid-lanes, New CSS feature come out to mozilla firefox in the DevTool.</figcaption></figure><h3>Bug 1#: focus flying away on delete (Bug 1327787)</h3><p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1327787">1327787 — [a11y] Keyboard navigation in devtools: Focus flies away when I delete attribute</a></p><p>This one was filed in 2016. Focus an attribute in the markup view with the keyboard, press Delete, and focus disappears. A later comment on the bug explains why: focus lands on something hidden inside the row.</p><p>The expected behavior from the report is a clean fallback:</p><ul><li>Focus the next attribute if there is one</li><li>Otherwise the previous one</li><li>Otherwise the tag name</li></ul><p>The fix lives in views/element-container.js (33 lines), where the markup view handles attribute removal. I added browser_markup_keybindings_delete_attributes.js (22 lines) to check where focus ends up after a delete, starting from the repro in the report: data:text/html,&lt;body a b c&gt;&lt;/body&gt;, tab to b, press Delete.</p><p><strong>What I took from it:</strong> if a user can’t see where focus went, the fix isn’t done, even when the attribute disappears correctly.</p><p>Before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*LLeXCU52ZMqC3lW_q-Htag.gif" /><figcaption>Issue: Removing an attribute doesn’t focus to the existing previous attribute nor the element tag.</figcaption></figure><p>After:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QnaBNGfsPjt_kGfBBPX5Ow.gif" /><figcaption>Fix: Now removing an attribute can focus to the existing previous attribute or the element tag.</figcaption></figure><h3>The workflow, in full</h3><ol><li><strong>Pick one area.</strong> Firefox is huge. I only cared about the DevTools Inspector.</li><li><strong>Get a local build running.</strong> Follow the Firefox Source Docs. ./mach bootstrap sets up your environment, then:</li></ol><pre>   ./mach build<br>   ./mach run<br>   ./mach test &lt;test-path&gt;</pre><ol><li><strong>Read the bug.</strong> Know the current behavior, the expected behavior, and what’s already been discussed. Comment to claim it before you start.</li><li><strong>Reproduce it locally.</strong> This is the most important step. If you can’t reproduce it, you’re guessing.</li><li><strong>Search first.</strong> Use Searchfox to find similar features and follow the references to the end.</li><li><strong>No Shame…Use AI for gaps, not answers.</strong> I ask it why a function runs at a certain point or how two components talk. Then I check it against the code and the real behavior.</li><li><strong>Make a small, focused patch.</strong> No drive-by refactors.</li><li><strong>Test and lint.</strong> For DevTools UI, that means mochitests. Run ./mach lint on your changes too, so the reviewer doesn’t have to point out style issues.</li><li><strong>Submit to Phabricator and listen to the reviewer.</strong> The moz-phab tool submits your commit for review. Reviewers catch edge cases you didn’t think of, so read their comments as free teaching.</li></ol><p>One rule sits above all of it: <strong>never submit code you can’t explain.</strong></p><h3>Where your patch actually goes: Central, Beta, Release</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOhgRXwE-rH73l8cCBP2VA.png" /><figcaption>Firefox Release Calendar, For Features and upcoming features</figcaption></figure><p>I assumed “merged” meant “shipped.” It doesn’t, and it helps to know the path.</p><ul><li><strong>autoland, then mozilla-central (Central/Nightly).</strong> After review, my patch was pushed to autoland, where automation runs the tests. Once it’s stable, it gets merged into mozilla-central, and a bot marks the bug RESOLVED FIXED. That’s what you see in Bugzilla. Central is what ships as <strong>Firefox Nightly</strong>, so Nightly users get your change first.</li><li><strong>Beta.</strong> Every few weeks, Central is branched into Beta. Your patch rides along unless someone requests an <strong>uplift</strong> (a backport) to ship a fix sooner. That’s normally for serious bugs, not enhancements like a new badge.</li><li><strong>Release.</strong> Beta then becomes the stable Firefox most people use. There’s also ESR, a long-term channel that only gets selected fixes.</li></ul><p>Bugzilla tracks this with the <strong>Target Milestone</strong> and the per-version status flags. My bugs show firefox160: fixed and a 160 Branch milestone, which means they landed on Central during the 160 cycle.</p><p>The practical tip: to see your own fix in a normal browser, install <strong>Firefox Nightly</strong> instead of running your local build.</p><h3>If you’re about to start</h3><p>Pick one component. Pick one bug. Reproduce it. Let the bug tell you which files matter.</p><p>You don’t need to understand Firefox. You need a starting point and the patience to follow the code until it makes sense.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69a290841e3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Session Hijacking & Injection]]></title>
            <link>https://javascript.plainenglish.io/session-hijacking-injection-0d8f04df4b6f?source=rss-cfbf13b05bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d8f04df4b6f</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Shofa]]></dc:creator>
            <pubDate>Tue, 21 Jul 2026 04:12:55 GMT</pubDate>
            <atom:updated>2026-07-29T21:27:56.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QzlXJNb2DXWGn8-62bdFFQ.jpeg" /><figcaption>Close-up of a vaccination being administered.</figcaption></figure><p><strong><em>Not every security vulnerability requires advanced hacking skills.</em></strong></p><p><em>Sometimes, all it takes is an application that trusts user input more than it should.</em></p><p><em>That’s exactly why </em><strong><em>SQL Injection (SQLi)</em></strong><em> remains one of the most common and impactful web security vulnerabilities, even after decades.</em></p><p><em>In this article, I break down:</em></p><ul><li>Privilege Escalation</li><li>Session Hijacking</li><li>SQL Injections &amp; How to defend yourself</li><li>Parameter Injection &amp; How to defend yourself</li><li>Other types of Injections</li></ul><p><em>Whether you’re learning web security or building web applications, understanding SQL Injection is fundamental.</em></p><h3>Privilege Escalation</h3><blockquote><em>A Type of security Exploit where an attacker gains elevated access to resources that normally protected from an application or user.</em></blockquote><p>How Privilege Escalation it works.</p><ul><li><strong>Initial Access:</strong> The attacker gains limited access to the application or system.</li><li><strong>Discovering Weaknesses:</strong> The attacker identifies misconfigurations or vulnerabilities that can be exploited.</li><li><strong>Exploiting Vulnerabilities:</strong> They then use these weaknesses to gain higher privileges than originally intended.</li><li><strong>Gaining Control:</strong> With escalated privileges, they can access sensitive data or execute unauthorized actions.</li></ul><p>This is called a bug-bounty hunting</p><h3>Session Hijacking</h3><blockquote><em>Using a cookie value in an attempt to try to trick the server into thinking that you’re someone that you’re not.</em></blockquote><p><strong>Privilege Escalation is Broader Than You Think</strong></p><ul><li>Usually, people think privilege escalation only means a regular user magically turning themselves into a “Super Admin.” While that is true, it includes any unauthorized action.</li><li><strong>Vertical Escalation:</strong> Gaining higher privileges (e.g., User → Admin).</li><li><strong>Horizontal Escalation:</strong> Accessing resources belonging to another user with the same privilege level (e.g., User A accessing User B’s private account details).</li></ul><p><strong>Attackers “Feel Around” Before Striking</strong></p><ul><li>Security vulnerabilities are rarely exploited in a single, blind attempt. notes that attackers engage in reconnaissance:</li><li>They analyze API responses for telltale leaks or patterns.</li><li>They look for subtle misconfigurations.</li><li>niche example of using CSS injection rather than JavaScript. An attacker might inject CSS that requests a background image from their own server only if a specific element (like &lt;div id=&quot;administrator&quot;&gt;) exists on the page. If the attacker&#39;s server receives that image request, they successfully mapped out the page&#39;s structure and know an admin panel exists.</li></ul><p><strong>Session Hijacking vs. The Server’s Trust</strong></p><ul><li>If an attacker cannot guess a signed, random cookie through brute force, they will shift their strategy to stealing or tricking the system into giving them an existing valid cookie.</li><li>If they can steal your active cookie, they don’t need to break your password the server already trusts that cookie and will completely hand over control of your session to them.</li></ul><p><strong>Man-in-the-Middle (MitM) is Harder Now</strong></p><blockquote><em>A Man-in-the-Middle attack, where an attacker intercepts data moving over the network between the browser and the server.</em></blockquote><ul><li>because of modern HTTPS (SSL/TLS), network traffic is encrypted.</li><li>Even if someone intercepts the packet in transit, it just looks like gibberish unless the server is using a severely outdated, weak encryption algorithm that can be cracked. Because of this, attackers prefer targeting application-level flaws (like session hijacking) over network sniffing.</li></ul><h3>Injection Attacks</h3><h3>1) SQL Injection Attack</h3><h3>How it works</h3><p>The root cause is failing to separate <strong>data</strong> from <strong>code</strong>. When user input gets dropped straight into a query through string interpolation (e.g. SELECT * FROM users WHERE email = &quot;${input}&quot;), the database can&#39;t tell the difference between a legitimate value and an instruction.</p><h3>Bypassing login</h3><p>Submitting a password like &#39; OR 1=1-- turns the intended query:</p><pre>SELECT * FROM users WHERE email = &#39;someone@example.com&#39; AND password = &#39;&#39; OR 1=1--&#39;</pre><p>Since 1=1 is always true, the query succeeds and the attacker is logged in without ever knowing a real password and from there, gets a valid session token.</p><h3>Extracting data with UNION SELECT</h3><p>Once basic injection works, attackers escalate using UNION SELECT to pull columns from <em>other</em> tables through an endpoint that was only meant to return one type of data:</p><ul><li>Padding with NULL lets the attacker match column counts on tables like products.</li><li>This technique can expose plaintext passwords, credit card numbers, CVVs, and session IDs.</li></ul><h3>Stealing sessions</h3><p>A UNION SELECT sessionId FROM sessions style query can dump every active session ID in the system. An attacker can then literally swap their own cookie for someone else&#39;s session and impersonate that user directly no password needed.</p><h3>The fix: parameterized queries / prepared statements</h3><p>Replace string interpolation with placeholders (?). The database compiles the query structure <em>first</em>, with no data in it, then binds user input separately as a literal value never as executable code.</p><pre>app.get(&#39;/users&#39;, async (req, res) =&gt; {<br>  const name = req.query.name;<br>  try {<br>    const users = await db.all(`SELECT * FROM users WHERE name = ?`, [name]);<br>    res.json(users);<br>  } catch (err) {<br>    res.status(500).json({ error: err.message });<br>  }<br>});</pre><p>Going a step further with prepared statements:</p><pre>const usersQuery = await db.prepare(`SELECT * FROM users WHERE name = ?`);<br>const users = await usersQuery.all(name);</pre><p>Even if someone passes in DROP TABLE Students; as the parameter, the database just searches for a row whose name is literally that string it never executes it.</p><p><strong>Library safeguards:</strong> well-built DB drivers (e.g. sqlite3&#39;s db.all / db.get) often block multi-statement execution by design, which stops attackers from tacking destructive trailing commands onto an injected query.</p><h3>2. Privilege Escalation (Mass Assignment)</h3><h3>How it works</h3><p>This isn’t about breaking a database it’s about sneaking extra fields into a request that the backend blindly accepts.</p><p>Conceptually, it’s the dangerous version of an innocent JS pattern:</p><p>Parameter Injection</p><p>You can do this in mongodb, couchdb, any nosql db because it uses json under the hood</p><pre>const updated = {<br>  ...user,<br>  admin: true,<br>};</pre><p>In practice, an attacker can:</p><ul><li>Add a hidden form field: &lt;input type=&quot;hidden&quot; name=&quot;admin&quot; value=&quot;true&quot; /&gt;</li><li>Or just craft the request directly:</li></ul><pre>curl &#39;http://localhost:4007/profile&#39; \<br>  -X &#39;PATCH&#39; \<br>  -H &#39;Content-Type: application/json&#39; \<br>  -H &#39;Cookie: session=987292f04aaca60af0c3c56b93326da9&#39; \<br>  --data-raw &#39;{&quot;admin&quot;:true}&#39;</pre><p>If the server does something like db.update(req.body) without checking which fields it&#39;s actually allowed to update, it&#39;ll happily promote the attacker to admin.</p><h3>The fix</h3><p>Explicitly destructure and whitelist only the fields you intend to accept:</p><pre>const { name, email, password /* etc */ } = req.body;<br>const fields = toParamsAndValues({ name, email, password });</pre><h3>3. Information Disclosure</h3><p>Attackers rarely get an exploit right on the first attempt they spend most of their time mapping out the tech stack so they know what to target.</p><ul><li><strong>Stack traces:</strong> raw error pages that leak file paths, framework names, or database type (e.g. SQLite vs. MongoDB) hand attackers a free blueprint for their next move.</li><li><strong>Framework headers:</strong> headers like X-Powered-By: Express broadcast the stack to automated scanners hunting for known unpatched vulnerabilities in specific legacy versions (e.g. Rails 4.2).</li></ul><p><strong>The fix:</strong> disable or strip these identifying headers and generic error pages in production configs.</p><h3>4. Beyond SQL: Other Injection Variants</h3><p>The same core idea <em>sliding input into a place it doesn’t belong</em> shows up in a few other forms:</p><p>Variant Where the payload lands SQL Injection Database query engine Command Injection OS shell (e.g. Bash) Remote Code Execution (RCE) The application runtime itself (e.g. JavaScript, Ruby)</p><h3>5. Timing Attacks</h3><p>Security operations (hashing, signature verification) cost CPU cycles and that cost is measurable, which means it can leak information even when the actual error message is identical.</p><p><strong>Account enumeration example:</strong></p><ul><li>A fake/random username → instant “user not found,” ~5ms.</li><li>A real username → server fetches the user, then runs the password through a heavy de-hashing function before failing, ~25ms.</li><li>Even with an identical generic “Invalid credentials” message on both, that ~20ms gap reveals the account exists.</li></ul><p>This is why response timing needs to be considered a side channel, not just an implementation detail.</p><h3>6. Code Architecture as a Security Control</h3><p>Scattering raw database queries across dozens of files makes a codebase very hard to patch quickly during an active incident.</p><ul><li><strong>Abstraction as defense:</strong> centralizing data access into wrapper functions (e.g. getUserFromSessionId()) means a bad or insecure query written by one engineer can be fixed in one place instead of audited across the entire codebase.</li><li><strong>Why vulnerabilities really happen:</strong> rarely from negligence — usually from teams that are tired, multitasking, or rushing out an emergency fix at 2am.</li></ul><h3>7. Standing on the Shoulders of Giants</h3><p>Abstractions, ORMs, and managed services (e.g. Stripe for payments) can occasionally have their own vulnerabilities but relying on battle-tested, widely-used tools is still much safer than rolling a custom driver or auth system from scratch.</p><p>When a major library or cloud provider has a critical flaw, the entire industry mobilizes to patch it. A homemade vulnerability, by contrast, gets discovered and fixed by exactly one team, working alone.</p><p>For example: Making payment by taking segments of card numbers and storing it somewhere and responsible for encryption</p><p>ORRRR</p><p>just use stripe 🙂</p><h3>8. Logging and Alerting as a Primary Defense</h3><p>Logging should be treated as a core security control, not a “fast follow” nice-to-have.</p><ul><li><strong>Proactive value:</strong> logs capture failed attack attempts, revealing what attackers are probing for <em>before</em> they succeed.</li><li><strong>Reactive value:</strong> if a breach does happen, logs are the only reliable source of truth for figuring out exactly what was compromised and how to close the gap.</li></ul><h3>Other Types of Attacks And Injections</h3><h3>Command Injection</h3><p><strong>Vulnerability Overview:</strong></p><ul><li>A type of security vulnerability where an attacker can execute arbitrary commands on the host operating system via a vulnerable application.</li></ul><p><strong>How it works:</strong></p><ul><li><strong>Target:</strong> Applications that pass unsafe user inputs directly to system shell commands.</li><li><strong>User Input:</strong> The application receives structural input parameters from an external user.</li><li><strong>Unsanitized Input:</strong> The user input is concatenated with a system command string in an unsafe way that allows additional system commands to be executed concurrently.</li><li><strong>Shell Execution:</strong> The combined command string is processed directly inside the system command shell execution thread.</li><li><strong>Malicious Payload:</strong> Attackers inject malicious commands, effectively piggybacking on legitimate system execution pathways.</li><li><strong>Insecure Code Implementation Example:</strong></li><li>A somewhat silly example that fits on a slide:</li></ul><pre>import { exec } from &#39;child_process&#39;;</pre><pre>app.get(&#39;/files&#39;, (req, res) =&gt; {<br>  // Unsafe string interpolation mapping input data directly to a system shell call<br>  const command = `ls ${req.body}`;</pre><pre>  exec(command, (error, stdout, stderr) =&gt; {<br>    if (error) {<br>      return res.status(500).send(error.message);<br>    }<br>    if (stderr) {<br>      res.status(500).send(stderr);<br>    }<br>    res.send(stdout);<br>  });<br>});</pre><p><strong>The Destructive Payload Example:</strong> test.txt; rm -rf /</p><p><strong>Remediation &amp; Mitigation Strategy:</strong></p><ul><li><strong>First:</strong> Just don’t do it.</li><li><strong>Second:</strong> Use a language-native built-in Node module (e.g., fs) if you <em>really</em> need to perform file system operations.</li><li><strong>Third:</strong> Fall back on execFile if you <em>really</em> need to execute binary pathways with distinct parameter mapping.</li><li><strong>Fourth:</strong> Rigorously sanitize parameters, implement strict execution allowlists, and enforce the <strong>Principle of Least Privilege</strong> if system commands are absolutely necessary.</li></ul><h3>File Upload Vulnerabilities</h3><p><strong>Vulnerability Definition:</strong></p><ul><li>A class of security flaws that occur when a web application improperly or insecurely handles the uploading and storage of incoming user files.</li><li><em>PSA: If you are uploading an image, It might not be an image, you have to make sure that the file is Media you are uploading.</em></li><li><em>Make sure that payload not malicious, not contain malicious data pixels.</em></li></ul><h3>Remote Code Execution (RCE)</h3><ul><li><strong>Vulnerability Overview:</strong></li><li>This one kind of does what it says on the tin. <strong>Remote Code Execution (RCE)</strong> is a high-severity vulnerability that allows an attacker to execute arbitrary code blocks directly on a remote host system.</li></ul><p><strong>How it works:</strong></p><ul><li><strong>Injection:</strong> RCE typically occurs when the user input parameters are not properly sanitized or validated at the application boundary.</li><li><strong>Processing:</strong> The malicious input is parsed by the server through vulnerable pathways such as native eval() functions, un-sanitized inputs passed to shell commands, or unsafe object deserialization mechanisms.</li><li><strong>Execution:</strong> Malicious code executes inside the server environment context, providing the attacker with total runtime control over system resources.</li></ul><p><strong>Steps to Prevent Bad Things From Happening:</strong></p><ul><li><strong>Input Validation:</strong> Always validate and sanitize user inputs. Use strict data types and structural constraints.</li><li><strong>Don’t Do Dangerous Stuff:</strong> Avoid using eval(), Function(), exec(), and other potentially dangerous Node.js execution functions entirely.</li><li><strong>Use Security Libraries:</strong> Utilize proven mitigation libraries such as DOMPurify for sanitizing raw HTML content. Use sandboxed virtual environments (like VM2) for isolating untrusted code paths.</li><li><strong>Principle of Least Privilege:</strong> Run background services with minimal required system permissions. Never run your core application server as a root user.</li><li><strong>Update Your Stuff:</strong> Keep Node.js and all package dependencies up-to-date to quickly mitigate known zero-day vulnerabilities.</li></ul><h3>Further Reading</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/SQL_Injection">SQL injection — Glossary | MDN</a></li><li><a href="https://portswigger.net/web-security/sql-injection">What is SQL Injection? Tutorial &amp; Examples | Web Security Academy</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d8f04df4b6f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/session-hijacking-injection-0d8f04df4b6f">Session Hijacking &amp; Injection</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cookies, Same-Origin Policy, and CORS: The Web Security Basics Most Developers Skip]]></title>
            <link>https://javascript.plainenglish.io/cookies-same-origin-policy-and-cors-the-web-security-basics-most-developers-skip-58ad5830607f?source=rss-cfbf13b05bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/58ad5830607f</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Shofa]]></dc:creator>
            <pubDate>Wed, 15 Jul 2026 04:38:20 GMT</pubDate>
            <atom:updated>2026-07-15T07:38:59.330Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Kahk is an Arabian Cookies" src="https://cdn-images-1.medium.com/max/900/1*0ugumIuzS2vflCFSOkkUUA.jpeg" /><figcaption>Kahk is an Arabian Cookies</figcaption></figure><p>Most developers know cookies exist. Fewer know what happens when one is missing an attribute, or why a frontend on one port suddenly can’t talk to a backend on another. These aren’t edge cases. They show up in real apps, all the time, and they’re usually the reason a “simple” login flow breaks in production or, worse, gets exploited.</p><p>This is a practical walkthrough of three things that are easy to use wrong: cookies, the Same-Origin Policy, and CORS. The goal isn’t to memorize specs, it’s to build a mental model you can reason from the next time something doesn’t work, or works a little too well for an attacker’s taste.</p><h3>Why This Matters</h3><p>Security best practices are skipped constantly, and the gap has only widened as AI-assisted tools make it easier to ship code quickly without examining how it can be attacked. Even setting aside legal concerns, weak security has real costs: data leaks, account takeovers, and subtle advantages handed to competitors or attackers. That’s reason enough to slow down and get the fundamentals right.</p><h3>Part 1: Cookies</h3><h3>What Is a Cookie?</h3><p>A cookie is a small piece of data stored in the browser. It exists because HTTP is stateless: the server has no memory of you between requests. Cookies solve this by persisting small bits of data that the browser automatically resends on future matching requests.</p><p>Common uses for cookies include:</p><ul><li>Session IDs and authentication tokens</li><li>User preferences (theme, language)</li><li>“Remember me” functionality</li><li>Tracking identifiers</li></ul><p>Keep cookies small. The practical limit is about <strong>4 KB per cookie</strong>.</p><h3>The Three Attributes That Actually Matter</h3><p><strong>HttpOnly</strong> prevents JavaScript from reading the cookie through document.cookie. It reduces—but does not eliminate—the risk of cookie theft through XSS.</p><pre>Set-Cookie: sessionId=abc123; HttpOnly</pre><p><strong>Secure</strong> ensures the cookie is sent only over HTTPS.</p><pre>Set-Cookie: sessionId=abc123; Secure</pre><p><strong>SameSite</strong> controls whether the browser includes the cookie in cross-site requests, making it one of the primary defenses against CSRF.</p><pre>Set-Cookie: sessionId=abc123; SameSite=Lax</pre><h3>SameSite, Properly Explained</h3><p>Cookies are automatically attached by the browser to matching requests. That’s what makes them useful — and also what creates a security problem.</p><p>A malicious website can trigger a request to your application, and the browser may automatically attach the victim’s session cookie. If your server accepts that request without additional protection, it may treat it as legitimate. This attack is known as <strong>Cross-Site Request Forgery (CSRF)</strong>.</p><p>The important distinction is that <strong>SameSite cares about sites, not origins</strong>.</p><p>An <strong>origin</strong> consists of:</p><ul><li>Protocol</li><li>Host</li><li>Port</li></ul><p>For example:</p><ul><li><a href="https://app.example.com/">https://app.example.com</a></li><li><a href="https://api.example.com/">https://api.example.com</a></li></ul><p>These are different <strong>origins</strong> because their hosts differ.</p><p>A <strong>site</strong> is broader. Both of the examples above belong to example.com, so they are generally considered the <strong>same site</strong>.</p><p>This distinction is why subdomains can be cross-origin while still being same-site.</p><p>There are three SameSite values.</p><p><strong>Strict</strong></p><p>The cookie is sent only during same-site requests. Even clicking a link from another website into yours may not include the cookie. It provides the strongest protection but can break some authentication flows.</p><p><strong>Lax</strong></p><p>The practical default for most session cookies.</p><p>It blocks cookies for most cross-site subrequests while still allowing them during top-level navigations such as clicking a regular link. It offers a good balance between usability and CSRF protection.</p><p><strong>None</strong></p><p>Allows cookies in cross-site contexts.</p><p>It <strong>must</strong> be combined with Secure.</p><pre>Set-Cookie: sessionId=abc123; SameSite=None; Secure</pre><p>Valid.</p><pre>Set-Cookie: sessionId=abc123; SameSite=None</pre><p>Invalid.</p><p>SameSite=None is necessary for scenarios such as:</p><ul><li>Frontend and backend hosted on different sites</li><li>Third-party SSO providers</li><li>Embedded widgets</li><li>Iframes</li></ul><p>Remember that SameSite is <strong>not</strong> a complete CSRF defense. It should be combined with CSRF tokens, proper authorization, and careful validation of state-changing requests.</p><p>A solid default configuration for most authentication cookies is:</p><pre>Set-Cookie: sessionId=abc123; HttpOnly; Secure; SameSite=Lax</pre><h3>Signed Cookies</h3><p>A signed cookie contains a server-generated signature that lets the server detect whether the cookie has been modified.</p><p>Signing protects <strong>integrity</strong>.</p><p>Encryption protects <strong>confidentiality</strong>.</p><p>These are different security properties.</p><h3>Expiration</h3><p>Cookies without Expires or Max-Age are <strong>session cookies</strong> and disappear when the browser session ends.</p><p>Persistent cookies specify a lifetime.</p><pre>Set-Cookie: theme=dark; Max-Age=2592000</pre><p>To delete a cookie:</p><pre>Set-Cookie: sessionId=; Max-Age=0; Path=/</pre><h3>What Belongs in a Cookie?</h3><p>Good candidates:</p><ul><li>Session IDs</li><li>Remember-me tokens</li><li>Theme preferences</li><li>Language preferences</li></ul><p>Avoid storing:</p><ul><li>Passwords</li><li>Large objects</li><li>Sensitive data in plain text</li><li>Values the server blindly trusts</li></ul><p>Not every cookie needs HttpOnly.</p><p>For example, a theme preference may intentionally be readable by frontend JavaScript. Authentication cookies, however, should almost always include:</p><ul><li>HttpOnly</li><li>Secure</li><li>SameSite</li></ul><h3>The Shared Hosting Edge Case</h3><p>Browsers generally determine a site using the <strong>TLD+1</strong> rule.</p><p>For example:</p><ul><li>example.com</li><li>login.example.com</li></ul><p>Both belong to the same site.</p><p>However, this breaks down for shared hosting platforms like github.io.</p><p>Without special handling, user1.github.io and user2.github.io would incorrectly appear to belong to the same site.</p><p>To solve this, browsers rely on the <strong>Public Suffix List</strong>, which treats domains such as github.io as effective top-level domains.</p><p>As a result:</p><ul><li>user1.github.io</li><li>user2.github.io</li></ul><p>are treated as completely separate sites.</p><h3>Part 2: Same-Origin Policy (SOP)</h3><h3>What Is SOP?</h3><p>The Same-Origin Policy is a browser security mechanism that restricts how one origin can interact with another.</p><p>Its goal is simple:</p><p>One website should not be able to freely access another website’s sensitive data.</p><h3>What Counts as an Origin?</h3><p>An origin consists of:</p><ul><li>Protocol</li><li>Host</li><li>Port</li></ul><p>All three must match.</p><p>Examples:</p><p>✅ Same origin</p><ul><li><a href="http://localhost:3000/">http://localhost:3000</a></li><li><a href="http://localhost:3000/profile">http://localhost:3000/profile</a></li></ul><p>❌ Different origins</p><ul><li><a href="http://localhost:3000/">http://localhost:3000</a></li><li><a href="http://localhost:5173/">http://localhost:5173</a></li></ul><p>Different port.</p><ul><li><a href="http://example.com/">http://example.com</a></li><li><a href="https://example.com/">https://example.com</a></li></ul><p>Different protocol.</p><ul><li><a href="https://api.example.com/">https://api.example.com</a></li><li><a href="https://www.example.com/">https://www.example.com</a></li></ul><p>Different host.</p><h3>Why SOP Exists</h3><p>Without SOP, any website could read data from sites where you’re already logged in, including:</p><ul><li>Banking information</li><li>Emails</li><li>User profiles</li><li>Private dashboards</li></ul><p>SOP prevents this kind of cross-site data theft.</p><h3>A Common Misunderstanding</h3><p>SOP does <strong>not</strong> stop browsers from sending cross-origin requests.</p><p>It primarily prevents JavaScript from <strong>reading the response</strong>.</p><pre>fetch(&quot;http://localhost:8080/api/users&quot;)<br>  .then((res) =&gt; res.json())<br>  .then((data) =&gt; console.log(data));</pre><p>If your frontend runs on http://localhost:5173 and your backend runs on http://localhost:8080, the request is cross-origin because the ports differ.</p><p>Whether JavaScript can access the response depends on CORS.</p><h3>What SOP Actually Restricts</h3><p>SOP limits JavaScript’s ability to:</p><ul><li>Read responses from fetch, XHR, and AJAX across origins</li><li>Access the DOM of cross-origin iframes</li><li>Read browser storage belonging to another origin</li></ul><h3>Part 3: CORS</h3><h3>What Is CORS?</h3><p>Cross-Origin Resource Sharing (CORS) is the mechanism that allows a server to explicitly grant another origin permission to read its responses.</p><p>For example:</p><pre>Access-Control-Allow-Origin: http://localhost:5173</pre><p>This tells the browser that the specified frontend is allowed to access the response.</p><p>A minimal Express configuration looks like this:</p><pre>const cors = require(&quot;cors&quot;);<br>const express = require(&quot;express&quot;);</pre><pre>const app = express();</pre><pre>app.use(<br>  cors({<br>    origin: &quot;http://localhost:5173&quot;,<br>    credentials: true,<br>  })<br>);</pre><pre>app.get(&quot;/api/users&quot;, (req, res) =&gt; {<br>  res.json([{ id: 1, name: &quot;Ahmed&quot; }]);<br>});</pre><pre>app.listen(8080);</pre><h3>Other Ways to Work Across Origins</h3><p>CORS is the standard approach, but it isn’t the only one.</p><p><strong>Backend proxy</strong></p><p>Instead of calling an external API directly, the browser calls your backend.</p><pre>Browser → Your Backend → External API</pre><p>Server-to-server requests are not restricted by the browser’s Same-Origin Policy.</p><p><strong>postMessage</strong></p><p>Provides secure communication between:</p><ul><li>Parent windows and iframes</li><li>Popups and their opener</li></ul><p>without disabling SOP.</p><p><strong>JSONP</strong></p><p>A legacy workaround that relied on &lt;script&gt; tags to fetch GET-only data before CORS existed.</p><p>Today, CORS should almost always be preferred.</p><h3>How Cookies, SOP, and CORS Work Together</h3><p>These three concepts frequently intersect in real applications.</p><p>Imagine:</p><ul><li>Frontend: <a href="http://localhost:5173/">http://localhost:5173</a></li><li>Backend: <a href="http://localhost:8080/">http://localhost:8080</a></li></ul><p>The frontend must explicitly include credentials:</p><pre>fetch(&quot;http://localhost:8080/api/me&quot;, {<br>  credentials: &quot;include&quot;,<br>});</pre><p>The backend must allow both the origin and credentials:</p><pre>app.use(<br>  cors({<br>    origin: &quot;http://localhost:5173&quot;,<br>    credentials: true,<br>  })<br>);</pre><p>Finally, the authentication cookie itself must have the correct SameSite and Secure configuration.</p><p>Miss any one of these three pieces, and cookie-based authentication will silently fail across origins.</p><h3>Where Things Go Wrong: Common Cookie Vulnerabilities</h3><p>Understanding the mechanics makes it easier to recognize real-world attacks.</p><p><strong>XSS Cookie Theft</strong></p><p>Occurs when HttpOnly is missing, allowing injected JavaScript to read document.cookie.</p><p><strong>CSRF</strong></p><p>Occurs when cookies are automatically included in forged requests and there is insufficient protection through SameSite or CSRF tokens.</p><p><strong>Session Hijacking</strong></p><p>Happens when attackers obtain or predict a session ID, especially if cookies travel over plain HTTP because Secure is missing.</p><p><strong>Cookie Tampering</strong></p><p>Occurs when cookie values are not signed and the server trusts modified data.</p><p><strong>Sensitive Data Exposure</strong></p><p>Storing passwords or other confidential information directly inside cookies unnecessarily increases risk.</p><p><strong>Misconfigured Cookie Attributes</strong></p><p>Examples include:</p><ul><li>SameSite=None without Secure</li><li>Authentication cookies missing HttpOnly</li></ul><h3>The Takeaway</h3><p>Use the following defaults for session and authentication cookies unless you have a specific reason not to:</p><pre>HttpOnly; Secure; SameSite=Lax</pre><p>Treat CORS as an explicit allowlist — not a configuration you copy and paste to make browser errors disappear.</p><p>And whenever cookies need to cross origins, remember that three separate pieces must work together:</p><ol><li>The frontend request (credentials: &quot;include&quot;).</li><li>The backend CORS configuration.</li><li>The cookie attributes themselves.</li></ol><p>If any one of those is wrong, authentication won’t behave the way you expect.</p><h3>Before you go</h3><ul><li>Please take a moment to like the post and follow the writer!</li><li>Did you know that over 400,000 developers share what they’re building, learning, and discovering across our platforms every month? Learn how you can contribute <a href="https://plainenglish.io/write-for-us">here</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58ad5830607f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/cookies-same-origin-policy-and-cors-the-web-security-basics-most-developers-skip-58ad5830607f">Cookies, Same-Origin Policy, and CORS: The Web Security Basics Most Developers Skip</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>