<?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 Hasala Thenuwara on Medium]]></title>
        <description><![CDATA[Stories by Hasala Thenuwara on Medium]]></description>
        <link>https://medium.com/@hasalasandaru00?source=rss-18e70667f605------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GeA3JnVl7PBhXM6B.jpg</url>
            <title>Stories by Hasala Thenuwara on Medium</title>
            <link>https://medium.com/@hasalasandaru00?source=rss-18e70667f605------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 03:39:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hasalasandaru00/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[Double Submit Cookie Pattern]]></title>
            <link>https://medium.com/@hasalasandaru00/double-submit-cookie-pattern-72b88f5f4bb0?source=rss-18e70667f605------2</link>
            <guid isPermaLink="false">https://medium.com/p/72b88f5f4bb0</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[csrf-protection]]></category>
            <category><![CDATA[double-submit-cookie]]></category>
            <dc:creator><![CDATA[Hasala Thenuwara]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 09:13:56 GMT</pubDate>
            <atom:updated>2019-10-16T09:13:56.781Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Double Submit Cookie Pattern</strong></p><p>Today I am going to discuss about another <strong>CSRF </strong>protection method.</p><p>It is Double Submit Cookie Pattern method.</p><p><strong>What is Double Submit Cookie Pattern?</strong></p><p>Double submitting cookies is sending a random value in both a cookie and as a request parameter, so the server verifying if the cookie value and request value are same.</p><p><strong>How does it work?</strong></p><p>When a user authenticates to a website, 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 <strong>Stateless CSRF Defense.</strong></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 here to protect, the work 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>I have created a sample project check it out.</p><p><strong>Git-hub link — </strong><a href="https://github.com/HasalaS/Double-Submit-Cookie-Pattern"><strong>click here</strong></a></p><p>First, you need to login to the application by entering username and password. Here, I have hardcoded the credentials (username: hasala, password: 12345)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*QFg3E6yjvv6Shi5O.png" /></figure><p><strong>Login html post request</strong></p><p>This login form submits user credentials using a POST method. If the user is authenticated successfully, server will create a unique Session-Id and the CSRF token but the server only stores the Session-Id. (Importantly server doesn’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 http only flag “false” because JS should able to access the CSRF token cookie to add to the hidden field in the post request.(In real ones this is true)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*QORPiKkkekFzykwD.png" /></figure><p><strong>Stored CSRF token</strong></p><p>After that 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. 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/320/0*WouvpGUqH--3fMRk.png" /></figure><p>Then the relevant CSRF token added to the hidden field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*Ht5UNhq7uiZi34os.png" /></figure><p>When the user clicks “Update Idea” button the POST request sent. Then the server validates the cookie header for session-id and also server compares CSRF token from request is hidden field value against CSRF token from the header cookie. If these tokens matched then the server accepts the request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*UROEVsRSYvV-TYsR.png" /></figure><p><strong>How we can say the method is safe?</strong></p><p>Cookies are sent automatically with each request, no matter whether or not the request was initiated by the initial website} or by a 3rd party site. That’s why a cookie alone doesn’t fulfill 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><p><strong>Conclusion</strong></p><p>This Double Submit Cookie Pattern method is good for the applications which contain sensitive and useful data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72b88f5f4bb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manually Accessing Facebook API through OAuth 2.0]]></title>
            <link>https://medium.com/@hasalasandaru00/manually-accessing-facebook-api-through-oauth-2-0-5ee4ca929717?source=rss-18e70667f605------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ee4ca929717</guid>
            <category><![CDATA[facebook-api]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[facebook-developer]]></category>
            <dc:creator><![CDATA[Hasala Thenuwara]]></dc:creator>
            <pubDate>Mon, 16 Sep 2019 06:05:53 GMT</pubDate>
            <atom:updated>2019-09-16T06:05:53.168Z</atom:updated>
            <content:encoded><![CDATA[<p>1. First, create an account on Facebook for the Developers platform.</p><p>Here is the link <a href="https://developers.facebook.com/">https://developers.facebook.com/</a></p><p>2. Then after logging to your account select My App tab and create a new app.</p><p>3. In the new app in the products tab selects the Facebook login.</p><p>4. After that select Web as the platform to the app.</p><p>5. After that type your Redirect URI in the space given and save changes.</p><p>6. Then click settings and go to Basic and copy the App ID and app secret to another document.</p><p>7. Then without keeping any spaces put App ID and App secret together</p><p>&lt;App ID&gt;:&lt;App Secret&gt;</p><p>8. Then encode the above code in base 64 encoder keeps the encoded key with you.</p><p>9. As well as encode your redirect URI using URL encoder and keep it also.</p><p>10. Then type the following link (authorization grant link) on your address bar with filling the respective fields.</p><p>https://www.facebook.com/dialog/oauth?response_type=code&amp;client_id=&lt;appID&gt;&amp;redirect_uri=&lt;encoded format of the redirect URL&gt;&amp;scope=email%20user_posts&amp;state=123</p><p>11. Then if it is working it will ask for the Facebook confirmation.</p><p>12. After that you will have another link in your browser address bar. Copy it and save it in another document. In that link, you will have a code. Copy that.</p><p>13. Then go to RESTClient(An extension in web stores, if you do not have that please add that extension to your web browser) and select the method as POST and give the following URL.</p><p><a href="https://graph.facebook.com/oauth/access_token">https://graph.facebook.com/oauth/access_token</a></p><p>14. In the RESTClient go to the Headers tab and go to Custom Headers and type the following attributes and click Okay.</p><p>Name — Authorization</p><p>Basic&lt;space&gt;&lt;encoded base64 value&gt;</p><p>15. Then in the body part type the following code.</p><p>grant_type=authorization_code&amp;client_id=&lt;appID&gt;&amp;redirect_uri=&lt;encoded format of the redirect URL&gt;&amp;code=&lt;copied code from the link&gt;</p><p>16. Then click SEND.</p><p>17. So you will get the access token. Copy it and save it in another document.</p><p>18. Then reopen RESTClient and select the method as GET and type the URL as follows.</p><p><a href="https://graph.facebook.com/v4.0/me/feed?limit=25">https://graph.facebook.com/v4.0/me/feed?limit=25</a></p><p>19. Then go to Headers &gt; Custom Headers and change the attributes as follow.</p><p>Name — Authorization</p><p>Bearer&lt;space&gt;&lt;token value&gt;</p><p>20. Then click SEND and you will have the post feeds.</p><p>21. Then reopen the RESTClient and take another token to access the photos.</p><p>22. In there the authorization grant type URL is as follows.</p><p>https://www.facebook.com/dialog/oauth?response_type=code&amp;client_id=&lt;appID&gt;&amp;redirect_uri=&lt;encoded format of the redirect URL&gt;&amp;scope=email%20user_photos&amp;state=123</p><p>23. From there also you will have to confirm the access and you will get a code in the address bar. Copy it and save it.</p><p>24. And then open the RESTClient and change the method into GET and type the link as follows.</p><p><a href="https://graph.facebook.com/v4.0/me/albums">https://graph.facebook.com/v4.0/me/albums</a></p><p>25. Then as earlier Go to Headers tab and fill the attributes with the token value.</p><p>26. Then click SEND and you will get the albums of the authorized account.</p><p>27. Then with the same token value with GET method, we can get the photos of the album and finally photos.</p><p>To get album use the link https://graph.facebook.com/v4.0/&lt;album id&gt;/photos</p><p>To get the photos use the link https://graph.facebook.com/v4.0/&lt;photo id&gt;picture</p><p>28. And also you can preview the photos also.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ee4ca929717" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>