<?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 Ivan Zhang on Medium]]></title>
        <description><![CDATA[Stories by Ivan Zhang on Medium]]></description>
        <link>https://medium.com/@ivnzhng?source=rss-d38c134fe3bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AaIUvNtoDbUdxs8gs-wQug.png</url>
            <title>Stories by Ivan Zhang on Medium</title>
            <link>https://medium.com/@ivnzhng?source=rss-d38c134fe3bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 07:31:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ivnzhng/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[Amateur Infosec Hour with Ivan Zhang]]></title>
            <link>https://medium.com/@ivnzhng/amateur-infosec-hour-with-ivan-zhang-186a2218dc84?source=rss-d38c134fe3bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/186a2218dc84</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Ivan Zhang]]></dc:creator>
            <pubDate>Thu, 10 Dec 2015 05:04:14 GMT</pubDate>
            <atom:updated>2015-12-10T18:32:24.322Z</atom:updated>
            <content:encoded><![CDATA[<p>At my new day job, I build web systems which handle lots of important and sensitive data. I am by no means a cyber security specialist, but I do believe that due to the nature of my work I need to do due diligence to avoid getting “pwned”. This meant I had to do a lot of catching up, and so I started a new routine of reading articles in the cyber security realm.</p><blockquote>Have you ever read about a cyber attack strategy the night before you caught yourself writing a vulnerability for one?</blockquote><p>Last night, I became intrigued with the <a href="https://en.wikipedia.org/wiki/Timing_attack">timing attack</a>. For my friends reading who aren’t as paranoid as me, it is, in a broad sense, a strategy in penetrating security in cyber systems where you analyze the amount of time it takes for a response to derive something about the system. For example, you can analyze the time it takes for a system to respond to a erroneous login attempt to derive up to which bit in your password string was <strong>correct </strong>(assuming you know your target’s username). I won’t delve too deeply into the implementations of a script to execute this attack, so like many teachers I’ve had before me I will leave it as an exercise for the reader.</p><p>Today, I almost left myself wide open for a less severe and more naive version of the attack than in the given example. Let’s say in the system I’m building I need to validate objects called “requests”. Today I tasked myself with the need to validate these “requests”, so I wrote a block of code represented by this pseudocode in my “request” controller:</p><pre>if request doesn&#39;t exist {<br>   return request_error<br>}</pre><pre>if request is invalid {<br>   return request_error<br>}</pre><p>Looks simple enough. If a “request” sent by a user doesn’t exist in our system, we return a <em>request_error. </em>Afterwards, we check if the request is invalid by our internal definition, and also return a <em>request_error. </em>By returning the same error for both cases, a clever attacker will not be able to tell which case failed!</p><p>Good shit, Ivan. You’ve built yourself a secure routine. Give yourself a pat on the back and commit your changes.</p><p>Oh but wait, what about that timing attack you read about last night?</p><p>Quite honestly I would’ve never thought twice about this block of code if not for reading about timing attacks last night. It dawned on me that someone could easily analyze the time it takes for the <em>request_error</em> to be returned, which they then would be able to derive whether the failed report existed or if it was invalid.</p><p>Although knowing whether a request failed because of its absence from our system or if its invalid may not seem like a severe vulnerability, a clever attacker may gain more fruitful insights and derive further vulnerabilities about the system.</p><p>Although it was frightening to know that I would’ve never noticed this vulnerability had I not read up about it the night before, I was relieved to have come up with a solution. A viable strategy to protect yourself from these kinds of attacks is to implement a constant time response system. Like so:</p><pre>bool bad = false<br>Timer t = Timer()<br>int CHECK_UPPER_BOUND = 100 //assumption</pre><pre>t.start()</pre><pre>if request doesn&#39;t exist {<br>    bad = true<br>} else if request is invalid {<br>    bad = true<br>}</pre><pre>t.end()</pre><pre>//Pad the return<br>if t.timePassed &lt; CHECK_UPPER_BOUND{<br>    wait(CHECK_UPPER_BOUND - t.timePassed)<br>}</pre><pre>if bad {<br>   return request_error<br>}</pre><p>With the addition and modification of a few lines, I would be safe until a clever reader points out another vulnerability which I would be very grateful for. Using a flag, in this case <em>bad, </em>to check through the error conditions, then checking for whether the flag had identified an error after both conditions. I’ve also added the use of timers to make sure the checks return as if they ran in the worst case.*</p><p>I hope you enjoyed my write up of a problem I found interesting today. Please feel free to leave comments on any thoughts or complaints you have about this post, my ignorance about cyber security, my grammatical error(s), or my overall story telling abilities.</p><p><em>*my dear friend </em><a href="https://github.com/colinchartier"><em>Colin Chartier</em></a><em> graciously pointed out that my previous general solution would fail in the case of the checks being not constant time checks. This meant that an attacker would still receive different timings on requests that fail only either of the cases. A solution he suggested for this case was to “pad” the check to return at a certain time.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=186a2218dc84" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>