{"id":1784,"date":"2017-01-30T08:13:16","date_gmt":"2017-01-30T08:13:16","guid":{"rendered":"https:\/\/lineo.es\/guia-hsts-seguridad-web\/"},"modified":"2026-04-01T07:15:38","modified_gmt":"2026-04-01T07:15:38","slug":"hsts","status":"publish","type":"post","link":"https:\/\/lineo.es\/en\/hsts\/","title":{"rendered":"HTTP Strict Transport Security (HSTS)"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1784\" class=\"elementor elementor-1784\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-c791692 e-flex e-con-boxed e-con e-parent\" data-id=\"c791692\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t<div class=\"elementor-element elementor-element-5728d5b e-con-full e-flex e-con e-child\" data-id=\"5728d5b\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-d2b3118 elementor-widget elementor-widget-theme-post-title elementor-page-title elementor-widget-heading\" data-id=\"d2b3118\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"theme-post-title.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">HTTP Strict Transport Security (HSTS)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-ec015ca e-con-full e-flex e-con e-child\" data-id=\"ec015ca\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-ebbca20 elementor-widget elementor-widget-text-editor\" data-id=\"ebbca20\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Just learned about HSTS and started using it. First let me explain HSTS with my own words.<\/p><h4>Scenario without hsts:<\/h4><ol><li>The user types the domain name in the URL bar without the protocol, such as \u201c<em>example.com\u201d<\/em>, and the browser automatically adds the \u201c<em>http:\/\/<\/em>\u201d prefix. This first request is vulnerable to Man In The Middle (MITM) attacks.<\/li><li>The server replies with a redirection to the secure \u201c<em>https:\/\/example.com\u201d<\/em>. From the rest of the interaction communication is secure.<\/li><li>The next day the user types again \u201cexample.com\u201d in the URL bar. The browser sends again an\u00a0<strong>insecure<\/strong>\u00a0HTTP request.<\/li><\/ol><h4>Scenario with hsts:<\/h4><ol><li>The user types the domain name in the URL bar without the protocol, such as \u201c<em>example.com\u201d<\/em>, and the browser automatically adds the \u201c<em>http:\/\/<\/em>\u201d prefix. This first request is vulnerable to Man In The Middle (MITM) attacks.<\/li><li>The server replies with a redirection to the secure \u201c<em>https:\/\/example.com\u201d<\/em>. From the rest of the interaction communication is secure.\u00a0<strong>And<\/strong>, the server adds the response header:<pre>Strict-Transport-Security: max-age=31536000<\/pre><p>This response header instructs the browser to use HTTPS, and asks him to do so for the next 31.536.000 seconds (1 year).<\/p><\/li><li>The next day, the user types again \u201cexample.com\u201d in the URL bar. But, the browser remembers, and it uses HTTPS instead of HTTP. And will do so even if the user includes explicitly the prefix \u201chttp:\/\/example.com\u201d.<\/li><\/ol><h4>Closing<\/h4><p>So with HSTS the user will only be vulnerable the first time, and not every time she starts a session.<\/p><p>After learning this I have added support for HSTS to my Ansible role for Django deployment. See\u00a0<a href=\"https:\/\/github.com\/jdavid\/django\/commit\/ec0c2ff4816df4d35b0db8861dd95bfcbfad0ea6\">commit<\/a>, and I encourage you to start using HSTS too.<\/p><p>Links:<\/p><ul><li><a href=\"https:\/\/www.nginx.com\/blog\/http-strict-transport-security-hsts-and-nginx\/\">Details on HSTS and Nginx<\/a>\u00a0(must read if using Nginx)<\/li><li><a href=\"https:\/\/news.netcraft.com\/archives\/2016\/03\/17\/95-of-https-servers-vulnerable-to-trivial-mitm-attacks.html\">Report on HSTS by Netcraft<\/a><\/li><\/ul><p>Have a nice secure day!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Just learned about HSTS and started using it. First let me explain HSTS with my own words. Scenario without hsts: The user types the domain name in the URL bar without the protocol, such as \u201cexample.com\u201d, and the browser automatically adds the \u201chttp:\/\/\u201d prefix. This first request is vulnerable to Man In The Middle (MITM) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"elementor_header_footer","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1784","post","type-post","status-publish","format-standard","hentry","category-sin-categoria"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/posts\/1784","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/comments?post=1784"}],"version-history":[{"count":4,"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/posts\/1784\/revisions"}],"predecessor-version":[{"id":2138,"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/posts\/1784\/revisions\/2138"}],"wp:attachment":[{"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/media?parent=1784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/categories?post=1784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lineo.es\/en\/wp-json\/wp\/v2\/tags?post=1784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}