{"id":1943,"date":"2022-06-17T13:37:34","date_gmt":"2022-06-17T11:37:34","guid":{"rendered":"https:\/\/www.dsecbypass.com\/?p=1943"},"modified":"2024-05-17T10:34:55","modified_gmt":"2024-05-17T08:34:55","slug":"http-headers-security","status":"publish","type":"post","link":"https:\/\/www.dsecbypass.com\/en\/http-headers-security\/","title":{"rendered":"HTTP header security"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; custom_padding=&#8221;0px||||false|false&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_image src=&#8221;https:\/\/www.dsecbypass.com\/wp-content\/uploads\/2022\/06\/entete_http-300&#215;195.png&#8221; alt=&#8221;HTTP headers&#8221; title_text=&#8221;entete_http&#8221; _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; width=&#8221;50%&#8221; module_alignment=&#8221;center&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<p style=\"text-align: justify;\">HTTP headers are sent to browsers by web servers in their responses to users&#8217; HTTP requests. They are not directly visible in the browser but they are essential: they define cookies, govern the interpretation of content and cache settings, but also the security of the browser.<\/p>\n<p style=\"text-align: justify;\">Certain HTTP headers are to be included in order to follow good security practices: they make it possible to reinforce the security of the web browsers of the users of your websites. Moreover, in the event of absence, the security auditors and vulnerability scanners will almost systematically raise it as a weakness.<\/p>\n<p style=\"text-align: justify;\">HTTP headers can be viewed in the browser inspector (F12), <em>network <\/em>tab, or with the following Linux <em>curl<\/em> command:<\/p>\n<blockquote>\n<p style=\"text-align: justify;\">curl -I https:\/\/www.dsecbypass.com\/<\/p>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p>[\/et_pb_text][et_pb_text module_id=&#8221;wpscan&#8221; _builder_version=&#8221;4.24.3&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<h2 class=\"part\" data-startline=\"14\" data-endline=\"14\">2. HTTP security headers<\/h2>\n<p data-pm-slice=\"1 1 []\" style=\"text-align: justify;\">Here is the list of security HTTP headers along with their description as <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\" target=\"_blank\" rel=\"noopener\" title=\"Documentation of HTTP headers by Mozilla\">documented by Mozilla<\/a>.<\/p>\n<p data-pm-slice=\"1 1 []\"><strong>The X-Content-Type-Options header:<\/strong><\/p>\n<p data-placeholder=\"Traduction\" id=\"tw-target-text\" dir=\"ltr\" style=\"text-align: justify;\"><span lang=\"fr\">The &#8220;<em>X-Content-Type-Options<\/em>&#8221; response HTTP header is a marker used by the server to indicate that MIME types advertised in <em>Content-Type<\/em> headers should be tracked and not changed.<\/span><\/p>\n<p><strong>The X-XSS-Protection header:<\/strong><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\" style=\"text-align: justify;\"><span lang=\"fr\">The &#8220;<em>X-XSS-Protection<\/em>&#8221; HTTP response header is a feature of Internet Explorer, Chrome, and Safari that prevents pages from loading when they detect Cross-Site Scripting (XSS) attacks. These protections are largely useless in modern browsers when sites implement a strong content security policy (CSP) that disables the use of inline (&#8220;unsafe-inline&#8221;) JavaScript. <\/span>Valid parameters for this header are:<\/p>\n<ul>\n<li data-placeholder=\"Traduction\" dir=\"ltr\">\u00ab 0 \u00bb to disable protection ;<\/li>\n<li data-placeholder=\"Traduction\" dir=\"ltr\">\u00ab 1 \u00bb to enable protection ;<\/li>\n<li data-placeholder=\"Traduction\" dir=\"ltr\">and \u00ab 1; mode=block \u00bb to tell the browser to block the response if it detects the attack rather than hiding it from the user.<span lang=\"fr\"><\/span><\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\">Note:<\/span> even though this feature can protect users of older web browsers that don&#8217;t yet support CSP, in some cases, XSS protection can create XSS vulnerabilities in otherwise safe websites. Set it to 0 or remove it.<\/p>\n<p><strong>The X-Frame-Options header:<\/strong><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\" style=\"text-align: justify;\"><span lang=\"fr\">The HTTP response header &#8220;<em>X-Frame-Options&#8221;<\/em> can be used to indicate whether or not a browser should be allowed to render a page into an HTML &lt;frame&gt;,  &lt;iframe&gt;,  &lt;embed&gt; or &lt;object&gt;. Sites can use it to prevent <em>clickjacking<\/em>attacks, by ensuring that their content is not embedded in other sites. <\/span>Valid values \u200b\u200bfor this header are:<\/p>\n<ul>\n<li data-placeholder=\"Traduction\" dir=\"ltr\">DENY (the site cannot be found in iframe) ;<\/li>\n<li data-placeholder=\"Traduction\" dir=\"ltr\">SAMEORIGIN (can be used in iframe only on own domain) ;<\/li>\n<li data-placeholder=\"Traduction\" dir=\"ltr\">and ALLOW-FROM (user specifies allowed sites as whitelist).<\/li>\n<\/ul>\n<p>Be careful, this header can block features of your site if misconfigured.<\/p>\n<p data-pm-slice=\"1 1 []\"><strong>The HTTP Strict Transport Security (HSTS) header:<\/strong><\/p>\n<p data-placeholder=\"Traduction\" id=\"tw-target-text\" dir=\"ltr\" style=\"text-align: justify;\"><span lang=\"fr\">The &#8220;<em>Strict-Transport-Security<\/em>&#8221; HTTP response header (often abbreviated as HSTS) informs browsers that the site should only be accessed using HTTPS and that any future attempts to access it using HTTP should be automatically converted to HTTPS. When implemented well, it makes Man-in-The-Middle attacks more difficult to perform. The parameters of this header are:<br \/><\/span><\/p>\n<ul>\n<li data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\"><span lang=\"fr\"><em>max-age=&lt;expire-time&gt;<\/em>, the<\/span><\/span><span lang=\"fr\"> time, in seconds, during which the browser must remember that a site should only be accessed using HTTPS ;<\/span><span lang=\"fr\"><span lang=\"fr\"><\/span><\/span><span lang=\"fr\"><span lang=\"fr\"><\/span><\/span><span lang=\"fr\"><span lang=\"fr\"><\/span><\/span><span lang=\"fr\"><span lang=\"fr\"><\/span><\/span><span lang=\"fr\"><span lang=\"fr\"><\/span><\/span><span lang=\"fr\"><span lang=\"fr\"><\/span><\/span><\/li>\n<li data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\"><span lang=\"fr\"><em>includeSubdomains<\/em>,<\/span><\/span><span lang=\"fr\">if this optional parameter is specified, this rule also applies to all subdomains of the site;<\/span><span lang=\"fr\"><span lang=\"fr\"><\/span><\/span><\/li>\n<li data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\"><em>preload<\/em>, asks browsers to be hard-coded into their <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Strict-Transport-Security#preloading_strict_transport_security\" target=\"_blank\" rel=\"noopener\" title=\"The advantages and consequences of HSTS preloading\">HTTP preload lists<\/a><\/span><\/li>\n<\/ul>\n<p><span lang=\"fr\">Please note, this header must be configured if the <a href=\"https:\/\/www.dsecbypass.com\/en\/improve-your-tls-encryption\/\" target=\"_blank\" rel=\"noopener\" title=\"Improve HTTPS security\">HTTPS<\/a> version of the website is accessible.<br \/><\/span><\/p>\n<p data-placeholder=\"Traduction\" id=\"tw-target-text\" dir=\"ltr\"><span lang=\"fr\"><strong>The Content-Security-Policy (CSP) header:<\/strong><br \/><\/span><\/p>\n<p data-placeholder=\"Traduction\" id=\"tw-target-text\" dir=\"ltr\" style=\"text-align: justify;\"><span lang=\"fr\">The &#8220;<em>Content-Security-Policy<\/em>&#8221; HTTP response header allows website administrators to control what resources the browser is allowed to load for a given page. With few exceptions, policies mostly involve specifying server origins and script endpoints. This helps guard against cross-site scripting (XSS) attacks. The &#8220;<em>Content-Security-Policy<\/em>&#8221; header should replace in the future part of the security HTTP headers mentioned above since it allows a very granular control of the accessible resources. <\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\" style=\"text-align: justify;\"><span lang=\"fr\">The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Content-Security-Policy\" title=\"Mozilla's content-security-policy header specification\" target=\"_blank\" rel=\"noopener\">values<\/a> \u200b\u200bof this header are multiple and more complex to configure: they are defined in the next chapter of this article.<br \/><\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.23.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h2>2. Implementing the CSP header<\/h2>\n<p style=\"text-align: justify;\"><em>Content-security-policy<\/em> can be used to block, for example, all scripts that are not called from a specific domain name.<\/p>\n<p style=\"text-align: justify;\">The list of parameters and their values is available in the <a href=\"https:\/\/developer.mozilla.org\/fr\/docs\/Web\/HTTP\/Headers\/Content-Security-Policy\" title=\"Documentation Mozilla CSP header\" target=\"_blank\" rel=\"noopener\">Mozilla documentation<\/a>.<\/p>\n<p style=\"text-align: justify;\">By default, this header risks breaking certain functionalities of your websites: it is not uncommon to include scripts from certain CDNs or to have script blocks written directly in the HTML page (&#8220;<em>inline<\/em>&#8220;).<\/p>\n<p style=\"text-align: justify;\">The benefit\/effort ratio of implementing the CSP header is <a href=\"https:\/\/csp.withgoogle.com\/docs\/why-csp.html\" target=\"_blank\" rel=\"noopener\" title=\"why and when to implement CSP header\">not high enough<\/a> in the following cases (other security measures will have more impact):<\/p>\n<div class=\"QmZWSe\">\n<div class=\"DHcWmd\">\n<div id=\"tw-target\">\n<div id=\"kAz1tf\">\n<div id=\"tw-target-text-container\" tabindex=\"0\">\n<ul>\n<li data-placeholder=\"Traduction\" id=\"tw-target-text\" dir=\"ltr\" style=\"text-align: justify;\"><span lang=\"fr\"><em>Static applications without login functionality or cookies<\/em>, which are hosted in their own (sub)domains. In such cases, XSS attacks are a minor concern.<\/span><\/li>\n<li data-placeholder=\"Traduction\" dir=\"ltr\">\n<p data-placeholder=\"Traduction\" id=\"tw-target-text\" dir=\"ltr\" style=\"text-align: justify;\"><span lang=\"fr\">Complex applications with a history of XSS vulnerabilities, which use <em>languages and frameworks without sufficient protections<\/em> against XSS. CSP is an additional security mechanism, <em>not a substitute for secure, well-designed source code<\/em>. In such cases, spending time improving the security posture of the application (adopting more secure <em>frameworks<\/em>, reviewing critical parts of the code) is the best approach.<\/span><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"text-align: justify;\">For other cases where implementing CSP is an effective security improvement, a good practice is to rewrite the web application code to make it easier to migrate to a strict CSP header: <a href=\"https:\/\/csp.withgoogle.com\/docs\/adopting-csp.html\" title=\"Rules for rewriting code to implement the CSP header\" target=\"_blank\" rel=\"noopener\">Google offers<\/a> some rules to follow to make it easier to transition.<\/p>\n<p style=\"text-align: justify;\">If the application code is not mastered or its change is too expensive, it is possible to configure the CSP header in a more flexible but less secure way by using tools: the <a href=\"https:\/\/addons.mozilla.org\/fr\/firefox\/addon\/laboratory-by-mozilla\/\" target=\"_blank\" rel=\"noopener\" title=\"Firefox extension to implement content-security-policy http header\">Firefox Laboratory<\/a> extension allows you to generate a CSP header compatible with your website. You must visit all the pages of your website to ensure that no resource is forgotten.<\/p>\n<p style=\"text-align: justify;\">Once configured, it is possible to test the security of the <em>content-security-polic<\/em>y HTTP header using Google&#8217;s online evaluator:<a href=\"https:\/\/csp-evaluator.withgoogle.com\/\" target=\"_blank\" rel=\"noopener\">https:\/\/csp-evaluator.withgoogle.com\/<\/a>. If the header has been built according to the content of the website, it is very likely that the security is not optimal: to improve security, the web applications must be adapted.<\/p>\n<p style=\"text-align: justify;\">Finally, the <em>report-to<\/em>\/<em>report-uri<\/em> parameters can be configured in such a way as to detect breaches of the security policy dictated by the CSP header: whether accidental, following an oversight, or voluntary when of an XSS type attack for example.<\/p>\n<p>[\/et_pb_text][et_pb_text module_id=&#8221;virus&#8221; _builder_version=&#8221;4.24.3&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<h2>3. Webservers configuration<\/h2>\n<p style=\"text-align: justify;\"><span style=\"text-decoration: underline;\">Note<\/span>: the configurations below add the <em>X-Content-Type-Options, X-Xss-Protection, X-Frame-Options<\/em> and <em>Strict-Transport-Security<\/em> headers. The <em>Content-Security-Policy<\/em> header should be added on a case-by-case basis after considering its deployment.<\/p>\n<p><strong>Apache<\/strong><\/p>\n<p>In the Apache VHOST of the website add the following HTTP headers (<em>mod_headers<\/em> enabled):<\/p>\n<blockquote>\n<p>Header always set X-Content-Type-Options: &#8220;nosniff&#8221;<\/p>\n<p>Header always set X-XSS-Protection: &#8220;0&#8221;<\/p>\n<p>Header always set X-Frame-Options: &#8220;sameorigin&#8221;<\/p>\n<p data-pm-slice=\"1 1 []\">Header always set Strict-Transport-Security: &#8220;max-age=31536000; includeSubDomains&#8221;<\/p>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p><strong>Nginx<\/strong><\/p>\n<p>In the nginx VHOST of the website add the following HTTP headers:<\/p>\n<blockquote>\n<p>add_header X-Content-Type-Options &#8220;nosniff&#8221; always;<\/p>\n<p>add_header X-Xss-Protection &#8220;0&#8221; always;<\/p>\n<p>add_header X-Frame-Options &#8220;SAMEORIGIN&#8221; always;<\/p>\n<p>add_header Strict-Transport-Security &#8220;max-age=31536000; includeSubDomains&#8221; always;<\/p>\n<\/blockquote>\n<p><strong>IIS<\/strong><\/p>\n<p data-placeholder=\"Traduction\" id=\"tw-target-text\" dir=\"ltr\"><span lang=\"fr\">Add to the <em>web.config<\/em> file under the IIS installation root directory: <\/span><\/p>\n<blockquote>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">&lt;system.webServer&gt;<\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">     &lt;httpProtocole&gt; <\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">        &lt;customHeaders&gt; <\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">            &lt;add name=&#8221;Strict-Transport-Security&#8221; value=&#8221;max-age=31536000&#8243;\/&gt; <\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">            &lt;add name=&#8221;X-Content-Type-Options&#8221; value=&#8221;nosniff&#8221;\/&gt;<\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">            &lt;add name=&#8221;X-Xss-Protection&#8221; value=&#8221;0&#8243;\/&gt;<\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">            &lt;add name=&#8221;X-Frame-Options&#8221; value=&#8221;SAMEORIGIN&#8221;\/&gt;<\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">        &lt;\/customHeaders&gt; <\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">    &lt;\/httpProtocole&gt; <\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">&lt;\/system.webServer&gt; <\/span><\/p>\n<\/blockquote>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\"> <\/span><\/p>\n<p data-placeholder=\"Traduction\" dir=\"ltr\"><span lang=\"fr\">In any case, restart the web servers for the new configuration to take effect.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text _builder_version=&#8221;4.23.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<p style=\"text-align: justify;\"><span>\ud83d\udee1\ufe0f DSecBypass accompanies you on <a href=\"https:\/\/www.dsecbypass.com\/en\/website-pentest\/\" title=\"Website pentest and WordPress pentest\">the security audits of your websites<\/a>, HTTP header configuration faults are among the problems reported. Do not hesitate to <a href=\"https:\/\/www.dsecbypass.com\/en\/contact\/\">contact <\/a>us for additional information and\/or a personalized quote \ud83d\udcdd.<\/span><\/p>\n<p style=\"text-align: left;\">[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.17.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_button button_url=&#8221;https:\/\/www.dsecbypass.com\/en\/contact\/&#8221; button_text=&#8221;CONTACT US&#8221; button_alignment=&#8221;center&#8221; _builder_version=&#8221;4.17.4&#8243; _module_preset=&#8221;default&#8221; custom_button=&#8221;on&#8221; button_text_size=&#8221;13px&#8221; button_bg_color=&#8221;#4328b7&#8243; button_border_width=&#8221;10px&#8221; button_border_color=&#8221;#4328b7&#8243; button_border_radius=&#8221;0px&#8221; button_letter_spacing=&#8221;2px&#8221; button_font=&#8221;Titillium Web|700||on|||||&#8221; background_layout=&#8221;dark&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_button][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTTP headers are sent to browsers by web servers in their responses to users&#8217; HTTP requests. They are not directly visible in the browser but they are essential: they define cookies, govern the interpretation of content and cache settings, but also the security of the browser.<br \/>\nCertain HTTP headers must be included in order to follow good security practices: they make it possible to reinforce the security of the web browsers of the users of your websites. Moreover, in the event of absence, the security auditors and vulnerability scanners will almost systematically raise it as a weakness.<\/p>\n","protected":false},"author":4,"featured_media":1929,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-1943","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en"],"_links":{"self":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/1943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/comments?post=1943"}],"version-history":[{"count":19,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/1943\/revisions"}],"predecessor-version":[{"id":3469,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/posts\/1943\/revisions\/3469"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/media\/1929"}],"wp:attachment":[{"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/media?parent=1943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/categories?post=1943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dsecbypass.com\/en\/wp-json\/wp\/v2\/tags?post=1943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}