--- url: "https://owasp.org/www-project-secure-headers/response-headers/" titulek: "Response Headers | OWASP Secure Headers Project" h1: "Response Headers" popis: "Provides technical information about HTTP security headers." jazyk: "en-US" kanonicka: "https://owasp.github.io/www-project-secure-headers/response-headers/" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 22:14:05" znaku: 59504 slov: 6449 kodovani: "utf-8" sha256: "1f2fa38e498a149553041f3a21c0ec35f3b2832e83acfb81249e9841e9d551cf" --- # Response Headers 💡 The collection of HTTP response security headers mentioned in this section is applicable when the [user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) processing the HTTP response is a browser. The support for these headers by non-browser API clients (user agent), like for example an HTTP client in a programming language, **is not standardized**. So, it requires specific testing to identify if an HTTP response security header is supported or not by such HTTP client. 🚦 Header lifecycle flow: 📐 **Working draft** - Permissions-Policy ✅ **Active** - Strict-Transport-Security - X-Frame-Options - X-Content-Type-Options - Content-Security-Policy - X-Permitted-Cross-Domain-Policies - Referrer-Policy - Clear-Site-Data - Cross-Origin-Embedder-Policy - Cross-Origin-Opener-Policy - Cross-Origin-Resource-Policy - Cache-Control - X-DNS-Prefetch-Control - Integrity-Policy ⏰ **Almost deprecated** None ❌ **Deprecated** - Feature-Policy - Expect-CT - Public-Key-Pins - X-XSS-Protection - Pragma ## Strict-Transport-Security HTTP Strict Transport Security (also named *HSTS*) is a browser security policy mechanism which helps to protect websites against protocol downgrade attacks and cookie hijacking. It allows web servers to declare that web browsers (or other complying user agents) should only interact with it using secure HTTPS connections, and within a defined timespan (max-age) not via the clear text HTTP protocol. HSTS is an IETF standard track protocol and is specified in [RFC 6797](https://www.rfc-editor.org/rfc/rfc6797). A server implements an HSTS policy by supplying a header (`Strict-Transport-Security`) over an HTTPS connection (HSTS headers over HTTP are ignored). 📍 Important note about the behavior of the header over a **HTTP connection** (source [Mozilla MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security#description)): - The `Strict-Transport-Security` header **is ignored by the browser when your site has only been accessed using HTTP** . - Once your site is accessed over HTTPS **with no certificate errors** , the browser knows your site is HTTPS capable and will honor the `Strict-Transport-Security` header. 💡 More information about *Preloading Strict Transport Security* can be found [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Strict-Transport-Security#preloading_strict_transport_security). 💡 The `preload` directive is not part of the RFC and its support/evolution is managed at browsers level. We explicitly decided to keep this directive out of the configuration proposed to be aligned with the advice specified by the `hstspreload.org` team ([source](https://hstspreload.org/#opt-in)): ``` If you maintain a project that provides HTTPS configuration advice or provides an option to enable HSTS, do not include the preload directive by default. We get regular emails from site operators who tried out HSTS this way, only to find themselves on the preload list without realizing that some subdomains cannot support HTTPS. Removal tends to be slow and painful for those sites. ``` ### Values | Value | Description | | --- | --- | | `max-age=SECONDS` | The time, in seconds, that the browser should remember that this site is only to be accessed using HTTPS. | | `includeSubDomains` | If this optional parameter is specified, this rule applies to all of the site’s subdomains as well. | | `preload` | If this optional parameter is specified, it instructs the browser to always access the site using HTTPS because the site is included into `Strict-Transport-Security` [preload list](https://www.chromium.org/hsts/). | ### Example ``` Strict-Transport-Security: max-age=63072000 ``` ``` Strict-Transport-Security: max-age=63072000 ; includeSubDomains ``` ``` Strict-Transport-Security: max-age=63072000 ; includeSubDomains ; preload ``` ### References - [https://tools.ietf.org/html/rfc6797](https://tools.ietf.org/html/rfc6797) - [https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Strict_Transport_Security_Cheat_Sheet.html](https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Strict_Transport_Security_Cheat_Sheet.html) - [https://owasp.org/www-project-web-security-testing-guide/stable/4-Web_Application_Security_Testing/02-Configuration_and_Deployment_Management_Testing/07-Test_HTTP_Strict_Transport_Security.html](https://owasp.org/www-project-web-security-testing-guide/stable/4-Web_Application_Security_Testing/02-Configuration_and_Deployment_Management_Testing/07-Test_HTTP_Strict_Transport_Security.html) - [https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security) - [https://www.chromium.org/hsts](https://www.chromium.org/hsts) - [https://hstspreload.org/](https://hstspreload.org/) - [https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security](https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security) - [https://raymii.org/s/tutorials/HTTP_Strict_Transport_Security_for_Apache_NGINX_and_Lighttpd.html](https://raymii.org/s/tutorials/HTTP_Strict_Transport_Security_for_Apache_NGINX_and_Lighttpd.html) - [https://blogs.windows.com/msedgedev/2015/06/09/http-strict-transport-security-comes-to-internet-explorer-11-on-windows-8-1-and-windows-7/](https://blogs.windows.com/msedgedev/2015/06/09/http-strict-transport-security-comes-to-internet-explorer-11-on-windows-8-1-and-windows-7/) ## X-Frame-Options The `X-Frame-Options` response header (also named **XFO**) improves the protection of web applications against [clickjacking](https://portswigger.net/web-security/clickjacking). It instructs the browser whether the content can be displayed within frames. The Content-Security-Policy (CSP) [frame-ancestors](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors) directive obsoletes the X-Frame-Options header. If a resource has both policies, the CSP frame-ancestors policy will be enforced and the X-Frame-Options policy will be ignored. ### Values | Value | Description | | --- | --- | | `deny` | No rendering within a frame. | | `sameorigin` | No rendering if origin mismatch. | | `allow-from: DOMAIN` | Allows rendering if framed by frame loaded from *DOMAIN* (**not supported by modern browsers**). | ### Example ``` X-Frame-Options: deny ``` ### References - [https://tools.ietf.org/html/rfc7034](https://tools.ietf.org/html/rfc7034) - [https://tools.ietf.org/html/draft-ietf-websec-x-frame-options-01](https://tools.ietf.org/html/draft-ietf-websec-x-frame-options-01) - [https://tools.ietf.org/html/draft-ietf-websec-frame-options-00](https://tools.ietf.org/html/draft-ietf-websec-frame-options-00) - [https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options) - [https://portswigger.net/web-security/clickjacking](https://portswigger.net/web-security/clickjacking) - [https://blogs.msdn.microsoft.com/ieinternals/2010/03/30/combating-clickjacking-with-x-frame-options/](https://blogs.msdn.microsoft.com/ieinternals/2010/03/30/combating-clickjacking-with-x-frame-options/) - [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors) ## X-Content-Type-Options Setting this header will prevent the browser from interpreting files as a different MIME type to what is specified in the `Content-Type` HTTP header (e.g. treating `text/plain` as `text/css`). ### Values | Value | Description | | --- | --- | | `nosniff` | Will prevent the browser from MIME-sniffing a response away from the declared content-type. | ### Example ``` X-Content-Type-Options: nosniff ``` ### References - [https://msdn.microsoft.com/en-us/library/gg622941%28v=vs.85%29.aspx](https://msdn.microsoft.com/en-us/library/gg622941%28v=vs.85%29.aspx) - [https://blogs.msdn.microsoft.com/ie/2008/09/02/ie8-security-part-vi-beta-2-update/](https://blogs.msdn.microsoft.com/ie/2008/09/02/ie8-security-part-vi-beta-2-update/) - [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options) ## Content-Security-Policy A Content Security Policy (also named CSP) requires careful tuning and testing after definition of the policy. A content security policy can have a significant impact on the way browsers render pages (e.g., inline JavaScript or CSS can be disabled). A proper CSP can prevent a wide range of attacks, including cross-site scripting, other cross-site injections and clickjacking. ### Values 💡 Source used was [Mozilla MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy#directives). The values below are an overview of available directives, for an exhaustive list please consult the dedicated [Mozilla MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy#directives) section. | Directive | Description | | --- | --- | | `base-uri` | Define the base URI for relative URIs. | | `default-src` | Define loading policy for all resources type in case a resource type’s dedicated directive is not defined (fallback). | | `script-src` | Define which scripts the protected resource can execute. | | `object-src` | Define from where the protected resource can load plugins. | | `style-src` | Define which styles (CSS) can be applied to the protected resource. | | `img-src` | Define from where the protected resource can load images. | | `media-src` | Define from where the protected resource can load video and audio. | | `frame-src` | *(Deprecated and replaced by `child-src`)* Define from where the protected resource can embed frames. | | `child-src` | Define from where the protected resource can embed frames. | | `frame-ancestors` | Define from where the protected resource can be embedded in frames. Useful against [clickjacking](https://portswigger.net/web-security/clickjacking) | | `font-src` | Define from where the protected resource can load fonts. | | `connect-src` | Define which URIs the protected resource can load using script interfaces. | | `manifest-src` | Define from where the protected resource can load manifests. | | `form-action` | Define which URIs can be used as the action of HTML form elements. | | `sandbox` | Specifies an HTML sandbox policy that the user agent applies to the protected resource. | | `block-all-mixed-content` | *(Deprecated)* Prevent the user agent from loading mixed content. | | `upgrade-insecure-requests` | Instruct the user agent to use HTTPS when trying to download insecure HTTP resources. | | `referrer` | *(Deprecated)* Define information the user agent can send in the `Referer` header. | | `report-uri` | *(Deprecated and replaced by `report-to`)* Specifies a URI to which the user agent sends reports about policy violation. | | `report-to` | Specifies a group (defined in the `Report-To` header) to which the user agent sends reports about policy violation. | | `require-trusted-types-for` | Instructs user agents to control the data passed to [DOM XSS](https://portswigger.net/web-security/cross-site-scripting/dom-based) **sink** functions. | | `trusted-types` | Specify an allowlist of [Trusted Type policy names](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) that a website can create using `trustedTypes.createPolicy()`. | ### Example ``` Content-Security-Policy: script-src 'self' ``` ### Trusted Types feature [Trusted Types](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) is a security feature in the [Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/Security/CSP) header that stops the browser from accepting plain strings in *dangerous functions* (called **sinks**) like `.innerHTML` or `eval()`. Instead, it forces usage of **Trusted Type** objects that have been vetted by a defined policy. Browsers support level ([source](https://caniuse.com/trusted-types)): - Supported by default in Chromium based browsers. - Supported by default in Safari. - Supported by Firefox in its *Nightly* version. Below is an example of definition of a **default Trusted Types policy** leveraging [DOMPurify](https://github.com/cure53/DOMPurify) for the sanitization processing: 📋 `Content-Security-Policy` policy specifying **Trusted Types** via `require-trusted-types-for` and `trusted-types` directives. ``` default-src 'self'; form-action 'self'; base-uri 'self'; object-src 'none'; frame-ancestors 'none'; require-trusted-types-for 'script'; trusted-types default dompurify; ``` 🔒 Script defining the **Trusted Types policy** (file named `defineDefaultTrustedTypesPolicy.js`): ``` if (window.trustedTypes && window.trustedTypes.createPolicy) { // Create the default policy and leverage DOMPurify to sanitize any HTML content created trustedTypes.createPolicy("default", { createHTML: (unsafeValue) => { console.info("Default trusted types policy used."); return DOMPurify.sanitize(unsafeValue); } // Functions createScript() and createScriptURL() implementation are missing here as it is a simple example // See https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicyFactory/createPolicy }); } else { console.warn("Trusted types not supported!"); } ``` 🐞 Script defining the dangerous behavior (file named `dangerousCode.js`): ``` const input = document.getElementById("userInput"); const display = document.getElementById("display"); const button = document.getElementById("renderBtn"); button.addEventListener("click", () => { const rawValue = input.value; try { display.innerHTML = rawValue; } catch (e) { display.innerText = "Blocked by Trusted Types! Check the console."; console.error(e); } }); ``` 📜 Test HTML page using elements above: ```