<?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 Jared Smith on Medium]]></title>
        <description><![CDATA[Stories by Jared Smith on Medium]]></description>
        <link>https://medium.com/@jaredthecoder?source=rss-b0851132850d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TDdOrx7JgzjnY-gSSLBk4w.jpeg</url>
            <title>Stories by Jared Smith on Medium</title>
            <link>https://medium.com/@jaredthecoder?source=rss-b0851132850d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:58:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaredthecoder/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[First Steps to a More Secure JavaScript App]]></title>
            <link>https://medium.com/jaredthecoder/first-steps-to-a-more-secure-javascript-app-c2c601f4363d?source=rss-b0851132850d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2c601f4363d</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[computer-security]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Jared Smith]]></dc:creator>
            <pubDate>Thu, 05 Jan 2017 14:02:00 GMT</pubDate>
            <atom:updated>2017-01-05T14:02:00.664Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*k2VXju5iBhO6lJLnyqEy2w.gif" /><figcaption><a href="https://en.wikipedia.org/wiki/Hackers_(film)">Hackers</a>, 1995</figcaption></figure><p>If you have some free time in the near future, I recommend you watch the movie <a href="https://en.wikipedia.org/wiki/Hackers_(film)"><em>Hackers</em></a>, a less-than-realistic picture of the public perception of computer hacking set in the mid-1990’s in the United States.</p><p>If you only have five minutes, then I’ve got a slightly less exciting set of tips for you to keep in mind when building your next <a href="https://facebook.github.io/react/">React</a>, <a href="https://angular.io/">Angular 2</a>, <a href="https://infernojs.org/">Inferno</a>, <a href="https://vuejs.org/">Vue</a>, <a href="https://preactjs.com/">Preact</a>, <em>choose your UI framework here</em> app backed by a <a href="https://expressjs.com/">Node.js webserver</a>.</p><h3>Sanitize and Validate All User Input</h3><p>When you accept input from the users of your web app, whether it’s through an input field, an API, or through some other means, you risk opening yourself up to malicious users that want to tamper with your app.</p><p>Look at the following code example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6299428eb39a3c16d546f61cdc62f471/href">https://medium.com/media/6299428eb39a3c16d546f61cdc62f471/href</a></iframe><p>In this example, we’re transferring money from one account to another, one of the most canonical examples used to illustrate sanitization flaws. If a malicious user finds a way to call the transferMoney function as another user (<a href="https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)">through something like XSS</a>), then the targeted user is out of whatever amount of money they specify (at least until their bank account dries up). This function could be hooked up to a button on your app, or be part of an input field in a transaction page; regardless, this is a serious problem and leads to many other issues.</p><p>You can fix issues like this by sanitizing and validating user input, to make sure it conforms to what your application expects. In this example, you may want to check that the User instance calling transferMoney has authorized transfers to the account specified by the accountID parameter.</p><p><em>For further exploration: </em><a href="https://www.owasp.org/index.php/Data_Validation">OWASP Article on Data Validation</a>, <a href="https://github.com/ctavan/express-validator">Express-Validator</a>, and <a href="https://github.com/chriso/validator.js">Node-Validator</a> (for server-side and <strong>client-side </strong>validation)</p><h3>Set Security Protections through HTTP Headers</h3><p>HTTP headers are bits of requests that are sent every time you call an API with an HTTP client, and they can actually provide extra security protections if applied correctly.</p><p>For this purpose, the <a href="https://helmetjs.github.io/">Helmet</a> library was built. You can apply protections against<a href="https://helmetjs.github.io/docs/csp/"> XSS</a>, information leakage (like leaking MIME types of your requests), and enforce <a href="https://helmetjs.github.io/docs/hpkp/">public key pinning</a> (which enhances the strength of your HTTPS websites).</p><h3>Use HTTPS in Production</h3><p>This is a no-brainer in 2017. Not only will Google now ranks sites higher if they’re secured with that lovely green lock in the upper left of your browser, and your users will generally trust you more. Most importantly, if you are ever handling sensitive user data or even logging someone into your service, you need HTTPS.</p><p>You can get free certificates from <a href="https://letsencrypt.org/">Let’s Encrypt</a> or just route your traffic through <a href="https://www.cloudflare.com/">CloudFlare</a>, and receive all the benefits of having your static files behind a CDN and their free HTTPS certificates applied to your site.</p><p><em>Side Note:</em> You may also see SSL or TLS mentioned when HTTPS is mentioned. SSL and TLS are the implementations of the protocol which provide data encryption and integrity on top of the HTTP protocol.</p><h3>Authenticate Users with Proper Mechanisms</h3><p>When doing authentication for your users, don’t roll your own authentication if you can help it. For 99% of cases, a library like <a href="http://passportjs.org/">PassportJS</a> will do the trick, which has over 300 ways to authenticate users, from Facebook authentication to pure <a href="https://oauth.net/2/">OAuth 2.0</a>.</p><h3>Handling Cookies</h3><p>If you store sensitive data in cookies, that which can be accessed by XSS attacks (which occur when you don’t sanitize user input), consider using setting the flags HttpOnly (doesn’t allow cookies to be accessed via client-side JavaScript) and secure (only send cookies over HTTPS) on your cookies. You can use the <a href="https://www.npmjs.com/package/cookie-session">cookie-session</a> library to do this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*cf9w0s7sMTGbPSdYVKnEKQ.gif" /><figcaption><a href="https://en.wikipedia.org/wiki/Hackers_%28film%29">Hackers</a>, 1995</figcaption></figure><h3>Security Doesn’t Have to be Hard</h3><p>Now that you know some useful tips to get started with securing your JavaScript apps, go implement some of them and let me know how it goes!</p><p>You can reach me anytime on <a href="https://twitter.com/jaredthecoder">Twitter</a> or <a href="mailto:jared@jaredsmith.io">email me</a> and I’d love to chat. If you want an even more in-depth presentation on security in JavaScript, <a href="https://www.youtube.com/watch?v=POmnL-PruAs">check out my presentation</a> at the popular JavaScript and Node.js conference, <a href="https://nodevember.org">Nodevember</a>.</p><p>Happy Hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2c601f4363d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jaredthecoder/first-steps-to-a-more-secure-javascript-app-c2c601f4363d">First Steps to a More Secure JavaScript App</a> was originally published in <a href="https://medium.com/jaredthecoder">jaredthecoder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>