<?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 Dilmi Sashmitha on Medium]]></title>
        <description><![CDATA[Stories by Dilmi Sashmitha on Medium]]></description>
        <link>https://medium.com/@dsashmitha?source=rss-5e46fe84ffe5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*-dCGHwqbyF6PlJrbnuo_aA.jpeg</url>
            <title>Stories by Dilmi Sashmitha on Medium</title>
            <link>https://medium.com/@dsashmitha?source=rss-5e46fe84ffe5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:43:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dsashmitha/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[CSRF Mitigation — Synchronizer  Token Pattern]]></title>
            <link>https://medium.com/@dsashmitha/csrf-mitigation-synchronizer-token-pattern-524059703046?source=rss-5e46fe84ffe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/524059703046</guid>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[synchronizertokenpattern]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Dilmi Sashmitha]]></dc:creator>
            <pubDate>Sat, 12 Oct 2019 06:07:11 GMT</pubDate>
            <atom:updated>2019-10-12T06:07:11.732Z</atom:updated>
            <content:encoded><![CDATA[<h3>CSRF Mitigation — Synchronizer Token Pattern</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QLJPykCtpFg2pf_61ITtKQ.jpeg" /></figure><h4><strong>What is CSRF..?</strong></h4><p>Cross-site request forgery (also known as CSRF) is a web security vulnerability that allows an attacker to induce users to perform actions that they do not intend to perform. It allows an attacker to partly circumvent the same origin policy, which is designed to prevent different websites from interfering with each other.</p><h4>What is happening in CSRF.?</h4><p>CSRF attack surfaces are often HTTP requests that cause a victim-related change, for example: name, email address, website, and even password. Sometimes it is also used to change the authentication status. (login CSRF , logout CSRF) that is less severe but in some cases can be problematic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*M3WCG-nEfQSG2QWB1klBPQ.png" /></figure><h4>Methods of mitigationg CSRF…</h4><p>The most common method to prevent Cross-Site Request Forgery (CSRF) attacks is to append CSRF tokens to each request and associate them with the user’s session. Such tokens should at a minimum be unique per user session, but can also be unique per request.</p><p>There are two main security implementations to prevent this prevention. they are Synchronize token pattern &amp; Double submit cookie.</p><h4>Synchronize token pattern</h4><p>Synchronizer Token Pattern is a approach where a unique token or a value is generated for every session. It is Embedded as a hidden area in HTML types which will be validated with the aid of the server and authorize the request that should be completed. An attacker cannot read or regulate cookie values due to the fact of the same-origin requirement which will prevent CSRF.</p><p>This is a very simple concept to mitigate the risk of being attacked through CSRF. In most web applications, servers are using HTTP session objects to identify the logged in users. In this case, session is generated in the server side and pass the session ID to the client. This session ID is most of the time is saved in a client side cookie file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*rnmFfsMqNndjExE7u6wpxw.png" /></figure><p>As above figure, first client browser request login page and log in to the system. same time server generates CSRF token and store it on server side. next time user interact with the server, user ask server to send CSRF token with AJAX and user submit data along with CSRF token. So server can verify this request came from legitimate user by comparing CSRF token received and own.</p><h4>Implementation</h4><p>This sample project developed using PHP and JavaScript. to get the source code Click here.</p><p>First, you have to log into the application providing the hard-coded username and password. The credentials as,</p><p>username: hello,</p><p>password: 1234</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*yvAJv63CPjCgoV3XSiTguQ.png" /><figcaption>login.php</figcaption></figure><p>There is a function generate token, it will be a create a random number (it can be anything unique) and it will be saved in the session variable call token. that will be save in the server side. that token will generate for only that person who logged in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*8BKXTgTi5yllMKKgR5aDiw.png" /><figcaption>login.php(GenerateToken)</figcaption></figure><p>If the user is authenticated, the user will redirect to <strong><em>syncronizer_csrf_token.php</em></strong><em> </em>where you can add transaction details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHh9fiSrMNRQYi13LtLsnA.png" /><figcaption>synchronizer_csrf_token.php</figcaption></figure><p>AJAX call should be executed to retrieve the CSRF token. The retrieved CSRF token will be stored in a hidden field in application from which is in <strong><em>syncronizer_csrf_token.php</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*zSbW9husV_aOmlfiG1X3mw.png" /><figcaption>AJAXcall</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*V4UVUI8ieVwwcUg0c5qU3w.png" /><figcaption>Hidden field to store the CSRF Token</figcaption></figure><p>When a user add the account number, name and amount to the application, the CSRF token will be validated by the function called <strong><em>validateToken (). </em></strong>Then the server validates session-id which is in the request header using the one that is stored in the server-side, and it compares the CSRF token in the body with the token in the request header.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*sQ2mbG-54oeXclALD6k7zg.png" /><figcaption>Valid Function</figcaption></figure><p>If the POST request has the valid CSRF token the server will give a successful message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PU-0sCpIZN6hvKzupa5wLA.png" /></figure><p>else it will show a invalid message.</p><p>I have developed a sample project on Synchronizer Token Pattern. You can check the source code<a href="https://github.com/DilmiSashmitha/Synchronizer-Token-Pattern"> <strong><em>in here.</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=524059703046" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSRF Mitigation — Double Submit Cookies Pattern]]></title>
            <link>https://medium.com/@dsashmitha/csrf-mitigation-double-submit-cookies-pattern-f782f22b50e2?source=rss-5e46fe84ffe5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f782f22b50e2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[double-submit-cookie]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Dilmi Sashmitha]]></dc:creator>
            <pubDate>Sat, 12 Oct 2019 05:51:48 GMT</pubDate>
            <atom:updated>2019-10-12T05:51:48.085Z</atom:updated>
            <content:encoded><![CDATA[<h3>CSRF Mitigation — Double Submit Cookies Pattern</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*msaGuG8XrPePOwiHl2HFvg.png" /></figure><p>Previously, I have discussed the <a href="https://medium.com/p/524059703046/"><strong><em>Synchronizer Tokens Pattern and Cross-Site Request Forgery</em></strong></a> as one of the solutions for the Cross Site Request Forgery attack on Web Applications.</p><p>This blog post will discuss Double Submit Cookie Pattern to prevent from CSRF attack.</p><h4>Double Submit Cookie Pattern</h4><p>Double submitting cookies is defined as sending a random value in both a cookie and as a request parameter, with the server verifying if the cookie value and request value are equal.</p><p>When a user authenticates to a site, the site should generate a (cryptographically strong) pseudo-random value and set it as a cookie on the user’s machine separate from the session ID. The server does not have to save this value in any way, that’s why this pattern is also called Stateless CSRF Defense.</p><h4>Implementation</h4><p>First, you have to log into the application providing the hard-coded username and password. The credentials as,</p><p>username: hello,</p><p>password: 1234</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cVwt5dWxQQykMudsJtPWhw.png" /><figcaption>login.php</figcaption></figure><p>Using a POST method, this login form sends user credentials. If the client is successfully authenticated, the server side creates a unique Session-Id and CSRF token, but only the Session-Id is saved by the server. Importantly, in this situation, server does not store CSRF token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*-O3AKB_LLAPgrW0mr5m9FA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*mjhZhhU0H889Zdd5zN3P1Q.png" /><figcaption>Generate CSRF Token</figcaption></figure><p>After setting the CSRF token to a cookie, the stored CSRF token will assign the hidden field value using JavaScript below (AJAX call) when loading the transaction tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twgKoWd8zODdvV-Rzj_3ag.png" /><figcaption>Double_submit_csrf_token.php</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*TJoYVF9m6b1dLg9E9AN4vA.png" /><figcaption>AJAX call</figcaption></figure><p>Illustrate the value after the hidden field has been set by the token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*P2FwHz6-f7fXlTV2M0jWyQ.png" /><figcaption>Hidden filed to store the CSRF token</figcaption></figure><p>The application will be issued by the client when the form is sent with the details back end. The server then validates the detailsof the form and validates the CSRF cookie token with the client’s CSRF cookie token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*-5levA043fIG_MWF11jAZQ.png" /></figure><p>Finally, the message of success will be shown if the cookie is validated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PU-0sCpIZN6hvKzupa5wLA.png" /></figure><p>else this shows invalid message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bPTl8UuxpgTEibPDEMBRJw.jpeg" /></figure><p>The techniques of the Double Submit Cookie Pattern outlined in this story are worth thinking about any application containing useful data.</p><p>I have developed a sample project on Double submit cookie. You can check the source code<a href="https://github.com/DilmiSashmitha/Double-Submit-Cookies-Pattern"> <strong><em>in here.</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f782f22b50e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>