<?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 Salman Shan on Medium]]></title>
        <description><![CDATA[Stories by Salman Shan on Medium]]></description>
        <link>https://medium.com/@salmanshan?source=rss-4a0d4e06f42------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Quj6kduG-gEEzZf6</url>
            <title>Stories by Salman Shan on Medium</title>
            <link>https://medium.com/@salmanshan?source=rss-4a0d4e06f42------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 13:06:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@salmanshan/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[Cross-Site Request Forgery (CSRF) Prevention]]></title>
            <link>https://medium.com/shansalman/cross-site-request-forgery-csrf-prevention-38decb21302f?source=rss-4a0d4e06f42------2</link>
            <guid isPermaLink="false">https://medium.com/p/38decb21302f</guid>
            <category><![CDATA[what-is-csrf]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[csrf-protection]]></category>
            <category><![CDATA[ajax-call]]></category>
            <category><![CDATA[csrf-token]]></category>
            <dc:creator><![CDATA[Salman Shan]]></dc:creator>
            <pubDate>Thu, 30 Apr 2020 08:18:28 GMT</pubDate>
            <atom:updated>2020-04-30T08:18:28.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*uo5FkLng3Ycl2UmshOCQiA.jpeg" /></figure><p>In this post let’s discuss about using a synchronize token pattern to prevent CSRF (CSRF meaning Cross-site request forgery.). Synchronize token pattern (STP) is a technique where a token, secret and unique value for each request, is embedded by the web application in all HTML forms and verified on the server side.</p><p>Then the token is generated by the server with ensuring the uniqueness. In here server generates token per every session. In that case the attacker is unable to place a correct token in their requests to authenticate them.</p><h3><strong>Why STP?</strong></h3><p>A third party attacker cannot perform a CSRF attack, because cross domain AJAX calls are not possible. This means, the victim is in banker.com, and attacker.com cannot request the CSRF token from the server via an ajax, because the domain doesn’t match each other, and cross domain ajax calls are not possible as I mentioned before.</p><p>Let’s understand STP with a flow diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*wmnna674hoEfUf7URZ965g.png" /></figure><ol><li>User sends GET request to a server.</li><li>Server sets the cookie with session_id, and saving session data with the token.</li><li>Server returns HTML with a form containing token in a hidden field.</li><li>User submits form, along with a hidden field.</li><li>Server compares token from the submitted form (hidden field) with the token saved in the session storage. If they match, it means that form is submitted by a user.</li></ol><p><strong>Advantages:</strong></p><ul><li>Simple to implement.</li><li>Works with AJAX.</li><li>Works with forms.</li><li>Cookie can actually be HTTP Only.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>All forms must output the hidden field in HTML.</li><li>Any AJAX POSTs must also include the value.</li><li>The page must know in advance that it requires the CSRF token so it can include it in the page content so all pages must contain the token value somewhere, which could make it time consuming to implement for a large site.</li></ul><h3><strong>What is the impact of a CSRF attack?</strong></h3><p>In a successful CSRF attack, the attacker causes the victim user to carry out an action unintentionally. For example, this might be to change the email address on their account, to change their password, or to make a funds transfer. Depending on the nature of the action, the attacker might be able to gain full control over the user’s account. If the compromised user has a privileged role within the application, then the attacker might be able to take full control of all the application’s data and functionality.</p><h3><strong>explain with my sample web page</strong></h3><p>I have implemented a website using basic HTML and PHP. Here credential is hard coded. First we need to type user name and password.</p><p><strong>username = shan </strong>and <strong>password = 12345</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*ya00h_Zvu8Op6icrVp8iTQ.png" /><figcaption>hard coded credential</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*D8U-sZsyY9UnkDmhwS8eqw.png" /><figcaption>index.php</figcaption></figure><p>You can only login using this user name and password. if the credential is invalid then we can see the invalid massage in my login page.</p><p>After the user giving the right credentials he will be redirected to page called welcome.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*fzjA-32dGTJGpnxkzQAGLg.png" /><figcaption>welcome.php</figcaption></figure><p>it will look like this in front end. It will welcome the user from a simple php line of code and start a session. calling about sessions, when the user type the right credentials and log in, immediately a session starts and a cookie generates.</p><h3>Sessions and Cookies</h3><p>Talking about sessions and cookies, when the page page load a session will start as well as a cookie will set for a time period of 7 days. in name of shan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*IwwPd3oeJt4ZN5NnYdFA5g.png" /><figcaption>session</figcaption></figure><p>Then the given credentials are correct and they are matched with what are hard corded, cookies will be generated on session id and token.</p><h3>Ajax Call</h3><p>An Ajax call is a non-concurrent request started by the browser that does not straightforwardly result in a page transition. A servlet request could be a Java-specif term (servlets are a Java determination) for adjusting an HTTP request that may get a basic GET or POST (etc) or an Ajax request.</p><p>An Ajax (‘Asynchronous JavaScript and XML’) request is often named a XHR request (‘XmlHttpRequest’), which is the name most browsers assign to the entity used to submit an Ajax request, since at least initially Ajax calls included sending and receiving XML, but now it’s just as usual to submit or receive JSON, plain text or HTML.</p><p>A good example of an Ajax request is the Stack-overflow comment system. Instead the browser will send probably a POST request via XHR to the server and be notified of the response (hence “asynchronous”). But the server typically can’t distinguish between an Ajax request or a page transition because both simply come down to HTTP requests.</p><p>Instead, the client would possibly submit a POST request to the server via XHR and will be informed of the response (“asynchronous” therefore).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38decb21302f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/shansalman/cross-site-request-forgery-csrf-prevention-38decb21302f">Cross-Site Request Forgery (CSRF) Prevention</a> was originally published in <a href="https://medium.com/shansalman">shansalman</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Synchronized Token Pattern Works?]]></title>
            <link>https://medium.com/shansalman/how-synchronized-token-pattern-works-cdc91e82525b?source=rss-4a0d4e06f42------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdc91e82525b</guid>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[security-token]]></category>
            <category><![CDATA[synchronizer-token]]></category>
            <category><![CDATA[ajax-call]]></category>
            <category><![CDATA[vulnerability]]></category>
            <dc:creator><![CDATA[Salman Shan]]></dc:creator>
            <pubDate>Wed, 29 Apr 2020 19:36:55 GMT</pubDate>
            <atom:updated>2020-04-29T19:36:55.700Z</atom:updated>
            <content:encoded><![CDATA[<img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdc91e82525b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/shansalman/how-synchronized-token-pattern-works-cdc91e82525b">How Synchronized Token Pattern Works?</a> was originally published in <a href="https://medium.com/shansalman">shansalman</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>