<?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 Ameen Khan on Medium]]></title>
        <description><![CDATA[Stories by Ameen Khan on Medium]]></description>
        <link>https://medium.com/@ameen-khan.?source=rss-1b508b024fed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2lyM7McLocn4ICEk</url>
            <title>Stories by Ameen Khan on Medium</title>
            <link>https://medium.com/@ameen-khan.?source=rss-1b508b024fed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 06:12:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ameen-khan./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[Inactive. Not Gone.]]></title>
            <link>https://medium.com/@ameen-khan./inactive-not-gone-16ad17a4ef18?source=rss-1b508b024fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/16ad17a4ef18</guid>
            <category><![CDATA[production-bug]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[bugs]]></category>
            <dc:creator><![CDATA[Ameen Khan]]></dc:creator>
            <pubDate>Sat, 19 Sep 2026 16:09:18 GMT</pubDate>
            <atom:updated>2026-10-26T17:16:05.955Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0L-I33e2S4CyMfBoZKpK1w.png" /></figure><p>What if a deactivated user never really left?</p><p>That is not a hypothetical. That is a bug I found sitting quietly inside a production system that had been running for years.</p><h3>The Expected Behaviour</h3><p>When a user is deactivated in a system, they are soft deleted — not removed from the database, but marked as inactive. The record stays. The access goes. That is the contract.</p><p>The expectation is simple: an inactive user should not be able to log in. They should not be able to access the system. They should not be able to place orders. If a user is deactivated, the system should treat them as if they do not exist — at least as far as authentication is concerned.</p><p>That is what the code was supposed to do. But that was not happening.</p><h3>What Was Actually Happening</h3><p>I was not looking for this bug. I was working through a couple of tickets, exploring parts of the system I had not touched before, getting familiar with some flows I had not worked on directly. Routine work. Nothing unusual.</p><p>At some point, almost out of curiosity, I tested logging in as a deactivated user. Just to see what the system would do.</p><p>It let them in.</p><p>Not limited access. Not a read-only session with a warning message. A fully authenticated session. The user could access most features and, more critically, could place orders — the single most important flow in the entire platform. Wide open, for a user that the system had marked as inactive.</p><p>A bug this significant had been sitting in production for years. Nobody had caught it because nobody had gone looking. The happy path always worked. Active users logged in fine. It took someone wandering into the wrong corner of the system to find it.</p><h3>Why It Happened</h3><p>The login page accepted a username and password. For most users in this system, their username is their email address — so the form looks and feels like a standard email login. Nothing unusual about that.</p><p>Under the hood though, the SessionsController was looking up users by their email field specifically. Not by username. By email.</p><p>Here is the problem. The sign-in form only ever submitted the username. It never submitted an email value. Not sometimes — never. On every single login attempt, the email field arriving at the controller was blank.</p><p>So when the controller searched for a user by email and found nothing — because the email was always blank — the inactive check never ran. There was no user found by email, so there was no status to check. The system then fell back, found the user by username, skipped the inactive verification entirely, and opened the session.</p><p>One field. Always blank. Inactive check never triggered.</p><p>It was not a sophisticated flaw. It was likely a mistake made during development — the controller written to look up by email, the form wired to submit by username, and the two never properly reconciled. The inactive check sat on top of that mismatch, quietly failing every time without anyone realising.</p><h3>The Fix</h3><p>Once the root cause was clear, the fix had two parts.</p><p>First, the lookup. The controller was corrected to find the user by username, which is what the form actually submits. No more searching by a field that was always blank, no more silent fallback that bypassed the status check.</p><p>Second, a small but important tightening — the inactive check was extended to cover API calls as well. Because if an inactive user could walk in through the front door, the API was another door worth closing. Both gaps, sealed.</p><h3>What This Left Me Thinking</h3><p>This bug was not dramatic in its code. There was no complex logic, no clever exploit, no obscure edge case buried deep in a library. Just a mismatch between what the form submitted and what the controller expected — and an entire security assumption quietly depending on that gap without anyone knowing.</p><p>The system had been in production for years. The bug had been there just as long.</p><p>It is easy to assume that a system old enough and used enough has had its critical paths tested thoroughly. But assumptions are exactly where gaps like this live. The inactive check was there. The logic existed. It just never actually ran.</p><p>Sometimes the most critical issues are not hiding in complex code. They are sitting in the gap between what you assumed was being checked and what was actually being checked.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16ad17a4ef18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When a Space Is Not a Space]]></title>
            <link>https://medium.com/@ameen-khan./when-a-space-is-not-a-space-813403832131?source=rss-1b508b024fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/813403832131</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Ameen Khan]]></dc:creator>
            <pubDate>Wed, 26 Aug 2026 17:15:54 GMT</pubDate>
            <atom:updated>2026-08-26T17:15:54.017Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VG5Fktd7WqDMVfzshpesWQ.png" /></figure><p>A few weeks ago, a ticket came in reporting that some users were unable to log in and were not receiving emails. The description mentioned that whitespace trimming had already been handled — spaces were being stripped from email inputs before saving to the database.</p><p>I checked the code. The trimming was there. I tested it manually — added a space before and after an email address. It worked correctly.</p><p>And yet, users were still affected.</p><h3>Finding the Actual Cause</h3><p>After some investigation and reading, I came across something I genuinely had not known before — not all whitespace characters are the same.</p><p>The space your keyboard produces is U+0020. There is an entire family of other whitespace characters that look completely identical on screen but are different underneath. One of the most common is the <strong>non-breaking space</strong> — written as &amp;nbsp; in HTML, and represented as U+00A0 in Unicode.</p><p>Where does it come from? Most commonly, copy-paste. When someone copies an email address from a webpage, an Excel sheet, a CSV file, or a PDF, the text sometimes carries invisible formatting characters along with it. On screen, the input looks perfectly clean. In the database, it is not.</p><p>I added a non-breaking space before and after a test email address and attempted to log in.</p><p>It failed immediately.</p><p>The trimming logic was working exactly as written — it just had never been written to handle anything beyond the standard ASCII space. This was the gap.</p><h3>The Fix</h3><p>Rather than patching just the non-breaking space, I wanted to handle the broader problem — because if one invisible character had slipped through, others could too. Zero-width spaces, invisible formatting characters, and various UTF encoding artifacts all share the same trait: they are invisible in a text field, and a basic trim will not catch them.</p><p>Here is what I added in Rails:</p><pre>before_validation :normalize_login_attributes</pre><pre>def normalize_login_value(value)<br>  value.to_s<br>       .unicode_normalize(:nfkc)<br>       .gsub(/\p{Cf}/, &#39;&#39;)<br>       .gsub(/\p{Space}/, &#39;&#39;)<br>       .gsub(/[\u0000\uFFFD\uFFFC]/, &#39;&#39;)<br>end</pre><p>This runs automatically before every save, and does four things in order:</p><ul><li><strong>NFKC normalization</strong> — converts visually similar Unicode characters to their standard form. For example, full-width letters used in some languages get converted to their regular equivalents before anything else runs.</li><li><strong>Remove invisible formatting characters (</strong><strong>\p{Cf})</strong> — this covers zero-width spaces, soft hyphens, directional marks, and other characters that exist purely for formatting purposes and have no place in an email address or username.</li><li><strong>Remove all Unicode whitespace (</strong><strong>\p{Space})</strong> — unlike a basic trim, this catches the entire family: non-breaking spaces, thin spaces, em spaces, and regular spaces alike.</li><li><strong>Remove null and replacement characters</strong> — a final sweep for a few specific Unicode characters that occasionally appear due to encoding issues.</li></ul><p>One thing worth noting: this also removes spaces from the middle of values, not just the edges. So a username like &quot;john smith&quot; would become &quot;johnsmith&quot;. Whether that is acceptable depends on your application&#39;s rules — for this case, it was fine.</p><h3>Handling Existing Users</h3><p>The validation hook takes care of anyone signing up or updating their details going forward. But there were already users in the database whose emails and usernames had been stored with this invisible whitespace.</p><p>For those, I wrote a Rake task — a script that runs directly against the database. I tested it on a staging environment first with a dry run, which showed exactly what would change without actually changing anything. After reviewing the output and confirming it looked correct, I ran it on production.</p><p>Existing affected users were able to log in again. Email delivery resumed.</p><h3>What This Is Really About</h3><p>The core issue here is something easy to overlook: a standard .strip or .trim — in Ruby, JavaScript, or most other languages — only removes ASCII whitespace. It does not know that U+00A0 exists. So if your application accepts text that users might copy-paste from external sources, a basic trim gives you a false sense of clean data.</p><p>Unicode-aware whitespace handling is not complicated to add, but it does need to be intentional. The standard trim is simply not enough.</p><p>It took one bug report about users who could not log in to make that very clear.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=813403832131" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>