<?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"><channel><title><![CDATA[IRFAN ALI KHAN's blog]]></title><description><![CDATA[IRFAN ALI KHAN's blog]]></description><link>https://irfanalikhan.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 23:55:43 GMT</lastBuildDate><atom:link href="https://irfanalikhan.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Preventing Balance Transfer Exploits: Resolving a Case-Insensitive Username Comparison After a Hacker Attempt]]></title><description><![CDATA[Introduction
In web development, ensuring that users cannot perform unintended actions is crucial for maintaining the integrity and security of an application. Recently, I encountered a situation where users were able to transfer balance to their own...]]></description><link>https://irfanalikhan.hashnode.dev/preventing-balance-transfer-exploits-resolving-a-case-insensitive-username-comparison-after-a-hacker-attempt</link><guid isPermaLink="true">https://irfanalikhan.hashnode.dev/preventing-balance-transfer-exploits-resolving-a-case-insensitive-username-comparison-after-a-hacker-attempt</guid><category><![CDATA[#ServerSideValidation]]></category><category><![CDATA[#CaseSensitivity]]></category><category><![CDATA[webdevelopment]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Security]]></category><category><![CDATA[websecurity]]></category><category><![CDATA[CodingBestPractices]]></category><category><![CDATA[PHP]]></category><category><![CDATA[coding]]></category><category><![CDATA[Hackers]]></category><category><![CDATA[bugfix]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[techtips]]></category><category><![CDATA[development]]></category><category><![CDATA[General Programming]]></category><dc:creator><![CDATA[IRFAN ALI KHAN]]></dc:creator><pubDate>Mon, 22 Jul 2024 21:14:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721681816486/ba786aae-4692-453e-84ff-1d3afc8b4ef1.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>In web development, ensuring that users cannot perform unintended actions is crucial for maintaining the integrity and security of an application. Recently, I encountered a situation where users were able to transfer balance to their own accounts despite having validation in place. In this article, I’ll share my experience and the solution I implemented to resolve the issue.</p>
<h4 id="heading-the-problem"><strong>The Problem</strong></h4>
<p>I had implemented a feature to prevent users from transferring balance to their own account with the following validation:</p>
<pre><code class="lang-php">$sender = auth()-&gt;user();
<span class="hljs-keyword">if</span> ($sender-&gt;username === $receiver-&gt;username) {
    $notify[] = [<span class="hljs-string">'error'</span>, <span class="hljs-string">'You cannot transfer balance to your own account'</span>];
    <span class="hljs-keyword">return</span> back()-&gt;withNotify($notify);
}
</code></pre>
<p>Despite this validation, a user was able to transfer balance to themselves. This led me to investigate further and identify the root cause of the issue.</p>
<h4 id="heading-investigation"><strong>Investigation</strong></h4>
<p>After reviewing the code and considering various scenarios, I found that the issue was due to case-sensitive comparison of usernames. The original validation failed to account for different cases <strong>(e.g.,</strong> <code>UserName</code> <strong>vs</strong> <code>username</code><strong>).</strong> Additionally, it turned out that a user, aware of bypass techniques via client-side manipulation, attempted to exploit this oversight.</p>
<h4 id="heading-the-solution-case-insensitive-comparison"><strong>The Solution: Case-Insensitive Comparison</strong></h4>
<p>To resolve this, I updated the validation to perform a case-insensitive comparison using <code>strcasecmp</code> in PHP. Here’s the updated code:</p>
<pre><code class="lang-php">$sender = auth()-&gt;user();
<span class="hljs-keyword">if</span> (strcasecmp($sender-&gt;username, $receiver-&gt;username) == <span class="hljs-number">0</span>) {
    $notify[] = [<span class="hljs-string">'error'</span>, <span class="hljs-string">'You cannot transfer balance to your own account'</span>];
    <span class="hljs-keyword">return</span> back()-&gt;withNotify($notify);
}
</code></pre>
<h4 id="heading-why-case-insensitive-comparison"><strong>Why Case-Insensitive Comparison?</strong></h4>
<p>Case-insensitive comparison ensures that usernames are compared without considering their case, which eliminates the possibility of bypassing validation by changing the case of the username.</p>
<h4 id="heading-client-side-and-server-side-validation"><strong>Client-Side and Server-Side Validation</strong></h4>
<p>While client-side validation is useful for providing immediate feedback to users, it is not sufficient on its own. Critical validations must be performed on the server side to prevent bypasses via client-side manipulation. In this case, despite having client-side validation tested and in place, the server-side validation needed to be robust to prevent such exploits.</p>
<h4 id="heading-lessons-learned"><strong>Lessons Learned</strong></h4>
<ul>
<li><p><strong>Server-Side Validation</strong>: Always perform critical validations on the server side.</p>
</li>
<li><p><strong>Case Sensitivity</strong>: Be aware of case sensitivity in comparisons and ensure that validations account for different cases.</p>
</li>
<li><p><strong>Robust Security Measures</strong>: Implement comprehensive security measures to prevent exploits.</p>
</li>
</ul>
<h4 id="heading-conclusion"><strong>Conclusion</strong></h4>
<p>By updating the validation to use case-insensitive comparison, I was able to prevent users from transferring balance to their own accounts. It’s a small but important change that enhances the security and reliability of the application. I hope this article helps other developers facing similar issues.</p>
<h4 id="heading-your-thoughts"><strong>Your Thoughts</strong></h4>
<p>Have you encountered similar issues in your projects? How did you resolve them? Share your experiences and solutions in the comments below!</p>
]]></content:encoded></item></channel></rss>