{"id":529,"date":"2019-03-05T12:13:46","date_gmt":"2019-03-05T12:13:46","guid":{"rendered":"https:\/\/int64software.com\/blog\/?p=529"},"modified":"2019-03-05T12:13:48","modified_gmt":"2019-03-05T12:13:48","slug":"http-security-headers-update","status":"publish","type":"post","link":"https:\/\/int64software.com\/blog\/2019\/03\/05\/http-security-headers-update\/","title":{"rendered":"HTTP Security Headers Update"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Back in November I posted a surprisingly popular first part in a series of articles on Hardening Website Security (<a rel=\"noreferrer noopener\" aria-label=\"link (opens in a new tab)\" href=\"https:\/\/int64software.com\/blog\/2018\/11\/05\/hardening-website-security-part-1-http-security-headers\/\" target=\"_blank\">link<\/a>). Since then I have been analysing Content Security Report (CSP) violation false-positives and expanding my knowledge on the subject, and thought an update was due.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you haven&#8217;t yet, I recommend reading the original article first <a href=\"https:\/\/int64software.com\/blog\/2018\/11\/05\/hardening-website-security-part-1-http-security-headers\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"here (opens in a new tab)\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Feature Policy<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before we get back into the Content Security Policy, I thought it would be worthwhile adding another header to the list: Feature-Policy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">About the Feature Policy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Feature Policy behaves much like a Content Security Policy, in that it is used for restricting or unrestricting functionality on a website. However, where a CSP is used to control security around resources, a feature policy is used to control\u2026 well\u2026 features.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basically, the Feature Policy is used to communicate with the client&#8217;s web browser to let it know what features the website is going to use (if any), and what sources are allowable for it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s take &#8220;camera&#8221; for example. If your website doesn&#8217;t have any need to access the client&#8217;s webcam then setting this to <em>&#8216;none<\/em>&#8216; is like telling the browser: &#8220;<em>We don&#8217;t want access to your camera, if you get a request then just block it.<\/em>&#8220;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alternatively, if you <em>do<\/em> use the camera, then setting it to &#8216;<em>self<\/em>&#8216; tells the browser to expect this request if it comes through. This has the added benefit of exerting extra control when using third party libraries so you are saying &#8220;<em>This website may need access to your camera, but if a request comes from anywhere else, block it.<\/em>&#8220;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can find the full list of features in Chromium&#8217;s <a href=\"https:\/\/cs.chromium.org\/chromium\/src\/third_party\/blink\/renderer\/platform\/feature_policy\/feature_policy.cc?l=138&amp;rcl=ab90b51c5b60de15054a32b0bd18e4839536a1c9\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"feature policy source code (opens in a new tab)\">feature policy source code<\/a>, but the main ones are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>accelerometer<\/li><li> autoplay<\/li><li> camera<\/li><li> encrypted-media<\/li><li> fullscreen<\/li><li> geolocation<\/li><li> gyroscope<\/li><li> magnetometer<\/li><li> microphone<\/li><li> midi<\/li><li> payment<\/li><li> speaker<\/li><li> vr<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You can find descriptions for each of these on the <a rel=\"noreferrer noopener\" aria-label=\"Mozilla Developer Network (opens in a new tab)\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Feature-Policy\" target=\"_blank\">Mozilla Developer Network<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All of these features are currently opt-in, so if you aren&#8217;t using any of them then you shouldn&#8217;t need to worry about setting a feature policy. However, for future-proofing sake, you may choose to explicitly define the policy anyway.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Content Security Policy<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most of the information from my original article still stands. However, I have tweaked my recommendations a little.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Referrer-Policy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Referrer Policy defines what information should be included in the &#8220;Referer&#8221; <em>(sic)<\/em> header when clicking internal and external links on your website. This is important for your users&#8217; security as they don&#8217;t necessarily want the next website they visit to know exactly what page they viewed on your website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The possible values for your Referrer-Policy are shown below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>no-referrer<\/strong><br>Stops the &#8220;Referer&#8221; header from being set at all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>no-referrer-when-downgrade <\/strong>(default)<br>If the security protocol remains the same between this request and the next (so the current site is served over HTTP and the next site or page is as well, or HTTPS to HTTPS), or if the request is upgraded (HTTP to HTTPS), then the current URL is sent as the &#8220;Referer&#8221;. Otherwise it is omitted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>origin<\/strong><br>Only send the root URL as the referrer (so &#8220;https:\/\/example.com\/page.html&#8221; will set &#8220;https:\/\/example.com&#8221; as the referrer).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>origin-when-cross-origin<\/strong><br>Sends the full URL as the referrer if the next request is to the same root URL (i.e. &#8220;https:\/\/example.com\/page1.html&#8221; to &#8220;https:\/\/example.com\/page2.html&#8221;), otherwise only the root URL is sent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>same-origin<\/strong><br>Sets the referrer to the full URL of the current request on same root URL requests only. Any non-root requests have no referrer sent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>strict-origin<\/strong><br>As with &#8220;origin&#8221;, except the security protocol must remain the same or upgraded between requests. If a request goes from, for example, &#8220;https:\/\/example.com&#8221; to &#8220;http:\/\/example.com&#8221; then no referrer will be set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>strict-origin-when-cross-origin<\/strong><br>As with &#8220;origin-when-cross-origin&#8221;, but again if the security protocol is is downgraded then no referrer will be sent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default the full URL is set as the referrer unless the security is being downgraded. As mentioned before, this could be considered a violation of your visitor&#8217;s trust, so I would recommend changing it. It&#8217;s a question of weighing up how valuable the referrer information is to you internally, and how much you respect your visitor&#8217;s right to not be tracked throughout the web.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Generally speaking, &#8220;strict-origin-when-cross-origin&#8221; is a good catch-all as that protects against leaking data when a connection requests get downgraded, only provides your base URL as the referrer when going to another URL, and still provides you with internal referral information for analytics.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Base-URI<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The HTML5 <em>&lt;base&gt;<\/em> head tag is used to specify the base URI for all subsequent relative URLS on the page. This can lead erroneous behaviour or niche attacks, and by not setting it at all any and all URLS are allows in the <em>&lt;base&gt;<\/em> tag. For example:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- https:\/\/example.com\/page.html -->\n&lt;html>\n&lt;head>\n  &lt;base href=\"https:\/\/example.com\/folder\/\" target=\"_self\">\n&lt;\/head>\n&lt;body>\n  &lt;!-- Will link to https:\/\/example.com\/folder\/page2.html -->\n  &lt;a href=\"page2.html\">Link&lt;\/a>\n&lt;\/body>\n&lt;\/html><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Setting the &#8220;<em>base-uri<\/em>&#8221; CSP directive to &#8220;<em>&#8216;self&#8217;<\/em>&#8221; limits its use to the current page&#8217;s URL only. Alternatively, and perhaps more preferably, setting it to &#8220;<em>&#8216;none&#8217;<\/em>&#8221; will disable the ability to use the  tag entirely.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An update on HTTP headers for website security, Content Security Policies (CSP) and best-practice for securing websites.<\/p>\n","protected":false},"author":1,"featured_media":533,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[50],"tags":[61,110,109,51,9],"class_list":["post-529","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","tag-content-security-policy","tag-csp","tag-html","tag-http","tag-security"],"_links":{"self":[{"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/posts\/529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/comments?post=529"}],"version-history":[{"count":4,"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/posts\/529\/revisions"}],"predecessor-version":[{"id":534,"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/posts\/529\/revisions\/534"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/media\/533"}],"wp:attachment":[{"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/media?parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/categories?post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/int64software.com\/blog\/wp-json\/wp\/v2\/tags?post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}