<?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[cross-site-request-forgery-csrf - Medium]]></title>
        <description><![CDATA[CSRF is a common attack vector that tricks a user into executing an unwanted action in a web application. While dangerous, the attack is easily preventable. - Medium]]></description>
        <link>https://medium.com/cross-site-request-forgery-csrf?source=rss----4a2a6c27f2c0---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>cross-site-request-forgery-csrf - Medium</title>
            <link>https://medium.com/cross-site-request-forgery-csrf?source=rss----4a2a6c27f2c0---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 08:38:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/cross-site-request-forgery-csrf" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Double Submit Cookie Pattern]]></title>
            <link>https://medium.com/cross-site-request-forgery-csrf/double-submit-cookie-pattern-65bb71d80d9f?source=rss----4a2a6c27f2c0---4</link>
            <guid isPermaLink="false">https://medium.com/p/65bb71d80d9f</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[blogger]]></category>
            <dc:creator><![CDATA[Harsha kavinda]]></dc:creator>
            <pubDate>Thu, 04 Oct 2018 06:21:45 GMT</pubDate>
            <atom:updated>2018-10-25T10:15:04.907Z</atom:updated>
            <content:encoded><![CDATA[<p>Previously, I have discussed the <a href="https://medium.com/cross-site-request-forgery-csrf/synchronizer-token-pattern-63871b4c83ad">Synchronizer Tokens Pattern</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><p><strong>What does it mean?</strong></p><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><strong>How does it work?</strong></p><p>When a user authenticates to a site, the site should generate a session identifier and set a cookie in the browser. At the same time, it generates the cryptographically strong random value or the CSRF token for the session 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 sometimes also called Stateless CSRF Defense.</p><p>The site then requires that every request include this random value as a hidden form value (or another request parameter). A cross-origin attacker cannot read any data sent from the server or modify cookie values, per the same-origin policy.</p><p>In the case of this mitigation technique the job of the client is very simple; just retrieve the CSRF cookie from the response and add it into a special header to all the requests.</p><p>Let’s look a sample project,</p><p>This application is developed using PHP &amp; JS( <strong>Github link —</strong><a href="https://github.com/Harshakavin/double-submit-cookie-pattern-csrf"><strong> click here</strong></a>)</p><p>First, you need to login to the application by entering username and password. For the demo, I have hardcoded the credentials(username: admin, password: ssd2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uxzJbbc9yXB0RtlquFYKaQ.png" /><figcaption>Login Screen</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*qgc4Pc5SQeeQyy9mlveWaw.png" /><figcaption>Login html post req</figcaption></figure><p>This login form submits user credentials using a POST method. if the user is authenticated successfully, server-side will creates a unique Session-Id and the CSRF token but the server only stores the Session-Id. Importantly server doesn&#39;t store CSRF token in this scenario.</p><p>Then the server will response the corresponding CSRF token along with the response body. After that generated session id &amp; server respond CSRF token set as cookies in the browser.</p><p>In here we must set the httponly flag “false” because js should able to access the csrf token cookie to add to the hidden field in the post request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*29uAYTvumGMstkgTXzq_1w.png" /><figcaption>Cookie setup code segment</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjehKozUo8esRvDegE8Y7Q.png" /><figcaption>Stored CSRF token</figcaption></figure><p>Then after user will redirect to user status update page. In this page, I have implemented an AJAX call(self-call) to get the stored CSRF token from the browser cookies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*p6LV6eCgdKsrn7wtNKOlhw.png" /><figcaption>AJAx call</figcaption></figure><p>Then the corresponding CSRF token added to the hidden field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YlStlPCJqMidbm78jcwTfg.png" /><figcaption>AJAX call</figcaption></figure><p>I have implemented a POST request to update some user status. The post request contains this generated CSRF token and the session cookie.</p><p>When the user clicks “updatepost” btn the Post request send. Then the server validates the cookie header for session id and also server compares CSRF token from request body(hidden field value) against CSRF token from the header cookie. If these tokens matched then server accepts the request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*2sLybgYeZtHZXS71qRqILQ.png" /><figcaption>Accepted request</figcaption></figure><p>How we can say the method is safe?</p><p>Cookies are sent automatically with every request, regardless of whether the request was initiated by the original site or by a third party site. That’s why a cookie alone does not suffice as every request will contain it.</p><p>But by having the token also in the request itself, an attacking site cannot generate valid requests any more as they can’t get hold on the user’s token.</p><h3>Conclusion</h3><p>The Double Submit Cookie Pattern techniques described in this story are viable and worth a thought for any application that contains useful data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65bb71d80d9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cross-site-request-forgery-csrf/double-submit-cookie-pattern-65bb71d80d9f">Double Submit Cookie Pattern</a> was originally published in <a href="https://medium.com/cross-site-request-forgery-csrf">cross-site-request-forgery-csrf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Synchronizer Token Pattern]]></title>
            <link>https://medium.com/cross-site-request-forgery-csrf/synchronizer-token-pattern-63871b4c83ad?source=rss----4a2a6c27f2c0---4</link>
            <guid isPermaLink="false">https://medium.com/p/63871b4c83ad</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Harsha kavinda]]></dc:creator>
            <pubDate>Thu, 04 Oct 2018 05:56:33 GMT</pubDate>
            <atom:updated>2018-10-25T10:15:41.728Z</atom:updated>
            <content:encoded><![CDATA[<p>I explained what is <a href="https://medium.com/cross-site-request-forgery-csrf/cross-site-request-forgery-csrf-bc92886dc5b">CSRF</a> attack on Web Applications. Today I am going to explain the Synchronizer Token Pattern in this blog post as one of the identified solutions for this CSRF security attack.</p><h4><strong>What is Synchronizer token pattern</strong>?</h4><p><strong>Synchronizer token pattern</strong> (STP) is a technique where a <strong>token</strong>, secret and unique value for each request, is embedded by the web application in all HTML forms and verified on the server side. SPT is using to preventing CSRF attacks from the attackers. Cross-Site Request Forgery (<strong>CSRF</strong>) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. <strong>CSRF</strong> attacks specifically target state-changing requests, not theft of data since the attacker has no way to see the response to the forged request.</p><p><strong>How to prevent?</strong></p><p>To prevent CSRF attacks we can use a simple method such as generating a random string in server side and append it to the body of the front end and check both values when user submit web page. also, we can use methods such as Check standard headers to verify the request is the same origin.</p><p><strong>Synchronizer (CSRF) Tokens</strong></p><ul><li>Any state changing operation requires a secure random token (e.g., CSRF token) to prevent CSRF attacks</li><li>Characteristics of a CSRF Token</li><li>Unique per user session</li><li>Large random value</li><li>Generated by a cryptographically secure random number generator</li><li>Add token to the session and check it in the backend</li><li>The CSRF token is added as a hidden field for forms or within the URL if the state changing operation occurs via a GET</li><li>The server rejects the requested action if the CSRF token fails validation</li></ul><p>Let’s look a sample project,</p><p>This application is developed using PHP &amp; JS.( Github link - <a href="https://github.com/Harshakavin/synchronizer-token-pattern-csrf">click here</a>)</p><p>First, you need to login to the application by entering username and password. For the demo, I have hardcoded the credentials(username: admin, password: ssd1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1iZEqTzAxl_H-tVXtluqA.png" /><figcaption>Login page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*LzS8QPkpZjDq5DzxORRm7g.png" /></figure><p>This login form submits user credentials using a POST method. if the user is authenticated successfully, a unique Session-Id and the CSRF token will be created along with this session and at the same time generated session id set as a cookie in the browser.</p><p>CSRF token is stored against the session identifier at the server side. you can see the stored CSRF token in the project text file,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*TGP2380pJl7xUwGDm0TN4Q.png" /><figcaption>Tokens</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ts09DqMBQ1azVQdUIaW4Lw.png" /></figure><p>Here, after the user logged in, the browser will send an Ajax call to get the CSRF token to csrf_token_generator.php. This Ajax call contains the session id. Then the server will response the corresponding CSRF token along with the response body.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*xxvYSn_HPyTNshityc769w.png" /></figure><p>This is where token embeds into a hidden field on form submit.Used openssl_randon_pseudo_bytes() function in PHP to generate the 32bit long CSRF token.The generated value then converted into it’s base64 value using base64_encode() in order to make it more secure. User doesn’t see this is happening when page loads.</p><p>After page loaded,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*q8vAan8BwL--sZrm4870aQ.png" /></figure><p>I have implemented a POST request to update some user status. The post request contains this generated CSRF token and the session cookie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fdsWgLqZEwOBrEAKYmdDUA.png" /></figure><p>When the user clicks “updatepost” btn the Post request send. Then the server validates session id which came from request header and CSRF token in the body.</p><p>If the token is valid server accept the request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*uywA9fiGq2T_nlFtth9UfQ.png" /><figcaption>Valid Request</figcaption></figure><p>If the token is not valid server ignore the request,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*8oFc8aOU6SleDPPRyoYe5Q.png" /></figure><p>How we can say the method is safe?</p><p>Let’s says an attacker send us a link that contains post request hidden to update user status but attacker not able add the CSRF token to the attaker’s POST request. so the server will ignore the request.</p><p>The source link of the example: <a href="https://github.com/Harshakavin/synchronizer-token-pattern-csrf.git">https://github.com/Harshakavin/synchronizer-token-pattern-csrf.git</a></p><p>In my next blog post, I will be discussing how Double Submit Cookie pattern is used to prevent from the CSRF attack and you can find it from <a href="https://medium.com/cross-site-request-forgery-csrf/double-submit-cookie-pattern-65bb71d80d9f">here</a>.</p><h3>Conclusion</h3><p>The Synchronizer token pattern techniques described in this story are viable and worth a thought for any application that contains useful data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63871b4c83ad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cross-site-request-forgery-csrf/synchronizer-token-pattern-63871b4c83ad">Synchronizer Token Pattern</a> was originally published in <a href="https://medium.com/cross-site-request-forgery-csrf">cross-site-request-forgery-csrf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross-Site Request Forgery (CSRF)]]></title>
            <link>https://medium.com/cross-site-request-forgery-csrf/cross-site-request-forgery-csrf-bc92886dc5b?source=rss----4a2a6c27f2c0---4</link>
            <guid isPermaLink="false">https://medium.com/p/bc92886dc5b</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[blogger]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Harsha kavinda]]></dc:creator>
            <pubDate>Thu, 04 Oct 2018 05:39:14 GMT</pubDate>
            <atom:updated>2018-10-04T05:39:13.629Z</atom:updated>
            <content:encoded><![CDATA[<p>Cross-Site Request Forgery (CSRF) is also known as “Session Riding” or “One-Click Attack”. This attack is a Malicious Exploit type of attack against web application users. This attack has been listed as 7th most exploitable among 10 top Web Attacks. CSRF is an attack which allows an attacker to perform unauthorized POST/GET arbitrary HTTP requests on behalf of the victim that is currently authenticated to the website.</p><p>we can prevent from this attack in web applications. In addition to that, I will be discussing two major security patterns, which we can implement for preventing CSRF attack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHTTs8jKSnUbyy9-1d4y9g.png" /></figure><p><strong>A quick example</strong></p><p>Before executing an assault, a perpetrator typically studies an application in order to make a forged request appear as legitimate as possible.</p><p>Let’s see a Facebook example,</p><p>In Facebook, used a session-id to identify the intended user. Let’s think about the normal Facebook users unfriend scenario.</p><p>what use does is simply enters his Username and Password to get in on Facebook. After entering his credentials on Facebook, it will authenticate the user and create a Session-Id. Later on, this session Id will be used to identify the user uniquely. And the important thing is the session Id will go along with the session cookie which is stored at the browser’s cookie storage.</p><p>In the Facebook was designed to use GET request to unfriend a friend, suppose URL looks like this,</p><pre><a href="http://m.facebook.com/users/unfriend?id=MyFriendID">http://m.facebook.com/users/unfriend?id=MyFriendID</a></pre><p>In Facebook, UI user simply selects the user and click unfriend button on the page, then this URL will trigger and unfried his friend. But imagine an attacker prepares that URL (shorten the URL using a URL shorter into <a href="https://goo.gl/124qa)">https://sllit.girls.com/seehotgirls)</a> to unfriend a user from the account and send that link to users to via chat or post.</p><p>The user does not know about that URL and he clicks on it. The browser is making this request unintentionally and friends will be removed from the Facebook account. This is how an attacker tricks a user to into execute an unwanted action and this problem is known as the Cross Site Request Forgery.</p><h3>The assumptions of CSRF</h3><p>In order to prevent from CSRF attack, some assumptions have to be verified:</p><ul><li>the attacked website <strong>does not check the Referer</strong> HTTP header, so that it accepts requests originating from external pages.</li><li>The website <strong>accepts data modification via form submissions or URLs</strong> that have side effects which the attacker can exploit.</li><li>The attacker can <strong>determine all the values for the request inputs</strong>. In the simplest case, authentication is done exclusively via a session cookie and so the attacker just has to fill non-sensitive fields.</li><li>The user must <strong>load a malicious page</strong> containing the attacker’s code. Judging by the amount of Facebook Likejacking, clicking on everything that moves is a pretty common behavior.</li></ul><p>So, to prevent from this CSRF attack security problem there are two major security patterns that we can implement. <br> <br> 1. Synchronizer Token Pattern<br> 2. Double Submit Cookie Pattern</p><p>I will be discussing these security patterns in my next blog posts</p><h3>Conclusion</h3><p>The techniques described in this story are viable and worth a thought for any application that contains useful data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc92886dc5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cross-site-request-forgery-csrf/cross-site-request-forgery-csrf-bc92886dc5b">Cross-Site Request Forgery (CSRF)</a> was originally published in <a href="https://medium.com/cross-site-request-forgery-csrf">cross-site-request-forgery-csrf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>