{"id":11687,"date":"2023-03-04T20:21:41","date_gmt":"2023-03-04T20:21:41","guid":{"rendered":"https:\/\/www.icdsoft.com\/blog\/?p=11687"},"modified":"2023-03-08T05:29:10","modified_gmt":"2023-03-08T05:29:10","slug":"how-to-use-hsts-and-protect-your-website","status":"publish","type":"post","link":"https:\/\/www.icdsoft.com\/blog\/how-to-use-hsts-and-protect-your-website\/","title":{"rendered":"How To Use HSTS and Protect Your Website"},"content":{"rendered":"\n<p>If you are concerned about the security of your website, you would want your visitors to always visit it via HTTPS. Although simple HTTP to HTTPS redirects do work most of the time, there are certain type of cyberattacks which may be able to bypass such redirects and trick your visitors into willingly giving away sensitive information, like credit card numbers, personal names and addresses, etc.<\/p>\n\n\n\n<ul class=\"wp-block-advgb-summary advgb-toc alignnone\"><li class=\"toc-level-1\"><a href=\"#against-what-types-of-attacks-does-hsts-protect-my-website-3265b8f6-bccd-4389-bbff-1e295010a274\">Against what types of attacks does HSTS protect my website?<\/a><\/li><li class=\"toc-level-1\"><a href=\"#can-i-protect-the-visitors-of-my-website-dc58ad64-2484-4b54-9ae3-b9db2ee07834\">How can I protect my website visitors?<\/a><\/li><li class=\"toc-level-1\"><a href=\"#limitations-of-hsts-e1aa5041-ccc7-40c4-8816-ee8ca40b7d3e\">Limitations of HSTS<\/a><\/li><li class=\"toc-level-1\"><a href=\"#a-way-around-the-limitations-the-hsts-preload-list-942b4b18-2e08-4b05-9b87-b7e635fc9023\">A way around the limitations (the HSTS Preload list)<\/a><\/li><li class=\"toc-level-1\"><a href=\"#in-conclusion-2ec9db75-c641-41e6-b809-a4fecc2b3699\">In conclusion<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"against-what-types-of-attacks-does-hsts-protect-my-website-3265b8f6-bccd-4389-bbff-1e295010a274\">Against what types of attacks does HSTS protect my website?<\/h2>\n\n\n\n<p><strong>HTTP Strict Transport Security (HSTS)<\/strong> mainly protects your website against man-in-the-middle (MiTM) attacks, cookie hijacking (also called session hijacking), and protocol downgrade attacks.  <\/p>\n\n\n\n<p><strong>Man-in-the-middle attacks<\/strong>, or MiTM attacks for short, is a general term for when an unauthorized&nbsp;actor positions himself\/herself in a conversation between a user and an application. These attacks allow perpetrators to intercept confidential data and insert malicious data and links in a way indistinguishable from legitimate data. <br><br>Let's imagine you are in a restaurant, and you connect to one of the available Wi-Fi hotspots listed on your laptop or smartphone. You decide to check a bank statement, so you visit your online banking page. Little do you know that the access point to which you are connected is a hacker\u2019s device. They are intercepting your initial HTTP request and then redirecting you to a clone login page which looks exactly like the real login page of your bank. This is known as <strong>an SSL stripping attack<\/strong>. The hacker establishes their own HTTPS connection to the bank's website (posing as the user) and maintains the HTTP connection with the user (posing as the bank's website). When you attempt to log in with your real username and password, your private data is exposed to the hacker and captured. Before entering any sensitive data on a website, we would highly recommend that you make sure that there's a padlock in the URL bar, showing that the connection is indeed secure. At this point, using <a href=\"https:\/\/www.icdsoft.com\/blog\/a-short-guide-to-2-factor-authentication\/\" data-type=\"URL\" data-id=\"https:\/\/www.icdsoft.com\/blog\/a-short-guide-to-2-factor-authentication\/\" target=\"_blank\" rel=\"noreferrer noopener\">Two-Factor Authentication (2FA) <\/a>for your Internet banking may seem like a very important thing. <\/p>\n\n\n\n<p><br>There are different types of <strong>session hijacking<\/strong>, &nbsp;but they all generally involve guessing or intercepting an existing session cookie, or tricking the user into signing in with a session ID created by the attacker. If you are connected to an unsecured Wi-Fi, a criminal could utilize a \"packet sniffing\" tool to monitor your network traffic and steal your session.<br><br>Another example would be for you to receive an email with a link to a login form for the website the attacker wants to access. The email looks similar to legitimate ones you have received in the past, so you log in with the phony session ID, giving the attacker a way in the door. Usually, such scam emails have a tell - the layout of the message could be a bit disrupted and there could be serious spelling or grammar errors. Also, the headers of the email can usually reveal whether the message was sent from an unauthorized outgoing mail server.<br><br>There are many other similar examples, so you should definitely be vigilant when entering any sensitive data on websites, even trusted ones.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"683\" data-src=\"https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/secure-with-locks-1024x683.jpg\" alt=\"The HTTP Strict-Transport-Security (HSTS)\" class=\"wp-image-11700 lazyload\" data-srcset=\"https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/secure-with-locks-1024x683.jpg 1024w, https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/secure-with-locks-300x200.jpg 300w, https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/secure-with-locks-1536x1025.jpg 1536w, https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/secure-with-locks-600x400.jpg 600w, https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/secure-with-locks-270x180.jpg 270w, https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/secure-with-locks-770x515.jpg 770w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/683;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"can-i-protect-the-visitors-of-my-website-dc58ad64-2484-4b54-9ae3-b9db2ee07834\">How can I protect my website visitors?<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.icdsoft.com\/en\/kb\/view\/1202_how_to_use_htaccess_files#enable_hsts\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/www.icdsoft.com\/en\/kb\/view\/1202_how_to_use_htaccess_files#enable_hsts\" rel=\"noreferrer noopener\">Enabling <strong>HTTP Strict Transport Security (HSTS)<\/strong><\/a> is a simple way to add another security layer to your website, especially if it is one which somehow collects sensitive information. Of course, you need to issue and install an <a href=\"https:\/\/www.icdsoft.com\/blog\/should-you-get-an-ssl-certificate\/\" data-type=\"URL\" data-id=\"https:\/\/www.icdsoft.com\/blog\/should-you-get-an-ssl-certificate\/\" target=\"_blank\" rel=\"noreferrer noopener\">SSL certificate<\/a> for your domain name first. Then you just need to add a few lines to the .htaccess file located in your website's document root. <\/p>\n\n\n\n<p>To summarize, the main requirements of HSTS are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Redirect from HTTP to HTTPS on the same host. i.e. http:\/\/example.com to https:\/\/example.com and http:\/\/www.example.com to https:\/\/www.example.com;<\/li>\n\n\n\n<li>Redirect to the canonical hostname (www or non-www) on HTTPS only. (i.e. after #1 above);<\/li>\n\n\n\n<li>Send the Strict-Transport-Security (STS) HTTP response header when on HTTPS only, including on the canonical redirect (#2 above).<\/li>\n<\/ul>\n\n\n\n<p>To enable HSTS for your website and set up a redirect from non-www to www at the same time, add the following lines to your .htaccess file (the order of the lines is important):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\n\n# Set HSTS env var only if HTTPS\nRewriteCond %{HTTPS} on\nRewriteRule ^ - &#91;E=HSTS:1]\n\n# Redirect HTTP to HTTPS on the same host\nRewriteCond %{HTTPS} !=on\nRewriteRule ^ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;R=301,L]\n\n# Redirect non-www to www (HTTPS only)\nRewriteCond %{HTTP_HOST} !^www\\.\nRewriteRule ^ https:\/\/www.%{HTTP_HOST}%{REQUEST_URI} &#91;R=301,L]\n\n# Set HSTS header for 365 days including subdomains conditionally if request is over HTTPS only (based on HSTS env var)\nHeader always set Strict-Transport-Security \"max-age=31536000; includeSubDomains; preload\" env=HSTS<\/code><\/pre>\n\n\n\n<p>If you prefer using non-www URLs instead of www, you can add the following lines instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\n\n# Set HSTS env var only if HTTPS\nRewriteCond %{HTTPS} on\nRewriteRule ^ - &#91;E=HSTS:1]\n\n# Redirect HTTP to HTTPS on the same host\nRewriteCond %{HTTPS} !=on\nRewriteRule ^ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;R=301,L]\n\n# Redirect www to non-www (HTTPS only)\nRewriteCond %{HTTP_HOST} ^www\\.\nRewriteRule ^ https:\/\/your-domain-name.com%{REQUEST_URI} &#91;R=301,L]\n\n# Set HSTS header for 365 days including subdomains conditionally if request is over HTTPS only (based on HSTS env var)\nHeader always set Strict-Transport-Security \"max-age=31536000; includeSubDomains; preload\" env=HSTS<\/code><\/pre>\n\n\n\n<p>When redirecting from www to non-www URLs, make sure to replace&nbsp;<strong>your-domain-name.com&nbsp;<\/strong>with your actual domain name.<br><br>Detailed instructions for setting this up on the ICDSoft servers can be found in the \"<a href=\"https:\/\/www.icdsoft.com\/en\/kb\/view\/1202_how_to_use_htaccess_files#enable_hsts\" data-type=\"URL\" data-id=\"https:\/\/www.icdsoft.com\/en\/kb\/view\/1202_how_to_use_htaccess_files#enable_hsts\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>How to enable HSTS?<\/strong><\/a>\" knowledge base article, where additional information about avoiding certain configuration conflicts is also available.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"limitations-of-hsts-e1aa5041-ccc7-40c4-8816-ee8ca40b7d3e\">Limitations of HSTS<\/h2>\n\n\n\n<p>A key downside of using HSTS is that a visitor who cannot connect through HTTPS will be unable to view and use the website. Additionally, as \"HTTP Strict-Transport-Security\" is a response header, it requires the user agent to first visit the website to learn that it uses HSTS.\u00a0This means that the initial request remains unprotected from attacks if it uses an unsecure protocol such as plain HTTP, or if the URI for the initial request is obtained over an unencrypted channel. \u00a0Also, the HSTS header is ignored by the browser if the page is served over HTTP, which is why it is important to automatically redirect every HTTP request to HTTPS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-way-around-the-limitations-the-hsts-preload-list-942b4b18-2e08-4b05-9b87-b7e635fc9023\">A way around the limitations (the HSTS Preload list)<\/h2>\n\n\n\n<p>The solution to the unprotected initial request is Chrome's&nbsp;<a href=\"https:\/\/hstspreload.org\/\" data-type=\"URL\" data-id=\"https:\/\/hstspreload.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">HTTP Strict Transport Security (HSTS)&nbsp;Preload list<\/a>. All major browsers enforce secure connections to domains included in the preload list, leaving HTTP requests a relic of the past. This list is&nbsp;managed by Google. If you want to add your website to the HSTS preload list, you can do so via the&nbsp;<a href=\"https:\/\/hstspreload.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">hstspreload.org<\/a>&nbsp;website. As described there, you should keep in mind that there are certain submission requirements, and your website should continue to satisfy them at all times.&nbsp;Otherwise, your website may be removed automatically from the list for failing to meet the requirements.<\/p>\n\n\n\n<p>Don't request inclusion unless you're sure that you can support HTTPS for&nbsp;<strong>your entire site and all its subdomains<\/strong>&nbsp;in the long term. If you cannot have all applications on your primary domain and its subdomains working fully over HTTPS, then you should not submit your domain name to the HSTS Preload list, and you should <strong>not include the preload directive by default<\/strong> in your .htaccess file, as this could in time automatically add your website to the HSTS Preload list.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Header always set Strict-Transport-Security \"max-age=31536000; includeSubDomains; <s>preload<\/s>\" env=HSTS<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"in-conclusion-2ec9db75-c641-41e6-b809-a4fecc2b3699\">In conclusion<\/h2>\n\n\n\n<p>The security of your website should be of utmost importance to you, because you must protect your visitors and users and not put their data at risk. In addition to HTTPS and HSTS, there are additional headers you could add to your setup, and certain methods you could remove from the configuration of the web server, so a higher level of security is in place. We will write about this in one of our next posts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are concerned about the security of your website, you would want your visitors to always visit it via HTTPS. Although simple HTTP to HTTPS redirects do work most of the time, there are certain type of cyberattacks which may be able to bypass such redirects and trick your visitors into willingly giving away<\/p>\n","protected":false},"author":1,"featured_media":11708,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","footnotes":""},"categories":[6],"tags":[],"class_list":{"0":"post-11687","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-security"},"author_meta":{"display_name":"ICDSoft","author_link":"https:\/\/www.icdsoft.com\/blog\/author\/icdsoft\/"},"featured_img":"https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/HTTP-Strict-Transport-Security-HSTS-300x150.webp","featured_image_src":"https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/HTTP-Strict-Transport-Security-HSTS.webp","featured_image_src_square":"https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2023\/03\/HTTP-Strict-Transport-Security-HSTS.webp","author_info":{"display_name":"ICDSoft","author_link":"https:\/\/www.icdsoft.com\/blog\/author\/icdsoft\/"},"coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/www.icdsoft.com\/blog\/category\/security\/\" class=\"advgb-post-tax-term\">Security<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">Security<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 3 years ago","modified":"Updated 3 years ago"},"absolute_dates":{"created":"Posted on March 4, 2023","modified":"Updated on March 8, 2023"},"absolute_dates_time":{"created":"Posted on March 4, 2023 8:21 pm","modified":"Updated on March 8, 2023 5:29 am"},"featured_img_caption":"","series_order":"","_links":{"self":[{"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/posts\/11687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/comments?post=11687"}],"version-history":[{"count":17,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/posts\/11687\/revisions"}],"predecessor-version":[{"id":11720,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/posts\/11687\/revisions\/11720"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/media\/11708"}],"wp:attachment":[{"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/media?parent=11687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/categories?post=11687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/tags?post=11687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}