--- url: "https://owasp.org/www-project-secure-headers/best-practices/" titulek: "Best Practices | OWASP Secure Headers Project" h1: "Best Practices" popis: "Provides technical information about HTTP security headers." jazyk: "en-US" kanonicka: "https://owasp.github.io/www-project-secure-headers/best-practices/" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 22:14:07" znaku: 39885 slov: 4297 kodovani: "utf-8" sha256: "4e68da1fc807d156ce13a51e8d4a3c752c719f5b2d49cecb16a5103c4e709cd0" --- # Best Practices - Configuration proposal - Prevent information disclosure via HTTP headers - Prevent exposure to cross-site scripting when hosting uploaded files - Prevent CORS misconfiguration issues - Prevent information disclosure via the browser local cached files - Prevent CSP bypasses - Support for a large CSP policy ## Configuration proposal Please note the best practices below suggest methods to change web server configuration to add headers. Security headers can also be successfully added to your application at the software level as well in almost every web language. Many web frameworks add some of these headers automatically. The following section proposes a configuration for the [actively supported and working draft security headers](/www-project-secure-headers/response-headers/#response-headers). πŸ’‘ Additional information about HTTP security headers on [OpenCRE](https://opencre.org/cre/636-347?name=OWASP+Secure+Headers+Project§ion=configuration&link=https%3A%2F%2Fgithub.com%2FOWASP%2Fwww-project-secure-headers%2Fblob%2Fmaster%2Fmainsite%2F03_best_practices.md%23configuration-proposal). πŸ“– The headers proposed below can be applied both in the context of a *classic web application* and in that of a *web API*: - This [demonstration video](/www-project-secure-headers/mainsite/assets/misc/demo_csp_usefulness_in_api_context.mp4) as well as this [blog post](https://treblle.com/blog/api-escaping-output-importance) show how HTTP response security headers, like the `Content-Security-Policy` one, can be useful in the context of a web API. 🚩 Regarding the header `Content-Security-Policy`, keep in mind that the policy applicability depends on the execution context. Technical details are available [here](https://www.w3.org/TR/CSP2/#which-policy-applies). Therefore, CSP usage in a web API application implies **defining the CSP in the document consuming the content of the web API**. 🚩 The header `Clear-Site-Data` will cause the browser to take additional processing time for the HTTP response, so, set it to the logout function when possible. Additional information about the support for experimental values: - Experimental value `"executionContexts"` is not supported by Chromium version `140.0.7292.0` . - Experimental values `"executionContexts"` , `"prefetchCache"` , `"prerenderCache"` and `"clientHints"` are not supported by Firefox version `141.0.3` . 🚩 The header `X-DNS-Prefetch-Control` seems currently only supported by [Chromium based browsers](https://github.com/OWASP/www-project-secure-headers/issues/201#issuecomment-3190756900) and more precisely Chrome for the `off` instruction. Therefore, as Chrome is highly used ([source](https://gs.statcounter.com/browser-market-share)), the proposal is to add the header on HTTP response which either: - Return sensitive or private content (commonly called [PII](https://en.wikipedia.org/wiki/Personal_data) ). - Prone to HTML injection where an attacker can inject a tag `` to exfiltrate data quietly via DNS or be notified via DNS when the victim rendered the response in a browser. 🚩 Regarding the header `Integrity-Policy`, it was not added to the list of headers to add as it requires that all the *scripts* and/or *styles* of the application specify the [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Subresource_Integrity) information. Therefore, adding this header will break the correct execution in the browser if the mentioned condition is not fulfilled. πŸ”¬ For the header `Permissions-Policy`, as it is currently only supported by [Chromium based browsers](https://caniuse.com/permissions-policy), the proposed value was generated with this [site](https://www.permissionspolicy.com/) and tested against the version `140.0.7292.0` of [Chromium](https://chromium.woolyss.com/download/en/) to only specify supported features. πŸ’‘ Content of the table below is also provided, as JSON, via this [file](https://github.com/OWASP/www-project-secure-headers/blob/master/ci/headers_add.json) (automatically updated). | Header name | Proposed value | | --- | --- | | Strict-Transport-Security | `max-age=63072000; includeSubDomains` | | X-Frame-Options | `deny` | | X-Content-Type-Options | `nosniff` | | Content-Security-Policy | `default-src 'self'; form-action 'self'; base-uri 'self'; object-src 'none'; frame-ancestors 'none'; upgrade-insecure-requests` | | X-Permitted-Cross-Domain-Policies | `none` | | Referrer-Policy | `no-referrer` | | Clear-Site-Data | `"cache","cookies","storage"` | | Cross-Origin-Embedder-Policy | `require-corp` | | Cross-Origin-Opener-Policy | `same-origin` | | Cross-Origin-Resource-Policy | `same-origin` | | Permissions-Policy | `accelerometer=(), autoplay=(), camera=(), cross-origin-isolated=(), display-capture=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(self), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), unload=()` | | Cache-Control | `no-store, max-age=0` | | X-DNS-Prefetch-Control | `off` | ## Prevent information disclosure via HTTP headers This section provides a collection of HTTP response headers to remove, when possible, from any HTTP response to prevent any [disclosure of technical information](https://cwe.mitre.org/data/definitions/200.html) about environment. The following list of headers can be used to configure a [reverse proxy](https://www.nginx.com/resources/glossary/reverse-proxy-server/) or a [web application firewall](https://en.wikipedia.org/wiki/Web_application_firewall) to handle removal operation of the mentioned headers. πŸ’‘ Additional information about technical information disclosure in HTTP header on [OpenCRE](https://www.opencre.org/cre/233-748?name=OWASP+Secure+Headers+Project§ion=Prevent+information+disclosure+via+HTTP+headers&link=https%3A%2F%2Fgithub.com%2FOWASP%2Fwww-project-secure-headers%2Fblob%2Fmaster%2Fmainsite%2F03_best_practices.md%23prevent-information-disclosure-via-http-headers). πŸ“– When possible, a reference link about the documentation of the header is provided. 🚩 The response header [Content-Type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Type) can sometimes disclose the web framework used. It is the case for the following ones: - [Spring Boot Actuator REST API](https://docs.spring.io/spring-boot/api/rest/actuator/auditevents.html) : `Content-Type: application/vnd.spring-boot.actuator.v3+json` . - For the Spring Boot case above, ensure to update the response header `Content-Type` with the value `application/json` . 🚩 The response header [WWW-Authenticate](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/WWW-Authenticate) can sometimes disclose the software requiring authentication: - Example of value for the response header `WWW-Authenticate` disclosing the software requiring authentication: - `Basic realm="rocketmq"` - `Basic realm="Prometheus Access"` - `Basic realm="Karma Alertmanager UI"` - `Basic realm="NETGEAR D7800` - Ensure to update the value of the attribute **[realm](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/WWW-Authenticate#realm)** to something generic like `RestrictedArea` . πŸ’‘ Content of the table below is also provided, as JSON, via this [file](https://github.com/OWASP/www-project-secure-headers/blob/master/ci/headers_remove.json) (automatically updated). | Header name | Header value example | Description | | --- | --- | --- | | Server | `Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips` | Contain information about the server handling the request. | | Liferay-Portal | `Liferay Digital Experience Platform 7.2.10 GA1` | Contain the version of the [Liferay](https://www.liferay.com) software in use. | | X-Turbo-Charged-By | `LiteSpeed/5.4.12 Enterprise` | Contain information about the server handling the request. | | [X-Powered-By](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Powered-By) | `PHP/5.3.3` | Contain information about hosting environments or other frameworks in use. | | X-Server-Powered-By | `Engintron` | Contain information about hosting environments or other frameworks in use. | | X-Powered-CMS | `Bitrix Site Manager (DEMO)` | Contain the information about the [CMS](https://en.wikipedia.org/wiki/Content_management_system) that generated the HTTP response. | | [SourceMap](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/SourceMap) | `https://mysite.com/js/mylib.js.map` | Links generated code to a [source map](https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map) file, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger. | | [X-SourceMap](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/SourceMap) | `https://mysite.com/js/mylib.js.map` | Links generated code to a [source map](https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map) file, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger. | | X-AspNetMvc-Version | `5.2` | Contain the version of the ASP .Net MVC framework in use. | | X-AspNet-Version | `4.0.30319` | Contain the version of the ASP .Net framework Common Language Runtime (CLR) in use (see [here](https://github.com/OWASP/www-project-secure-headers/issues/215) for more details). | | X-SourceFiles | `=?UTF-8?B?QzpcVXNlcnN?=` | Contain information needed by the .Net SDK debugger during debugging operation on a project. | | X-Redirect-By | `TYPO3 Shortcut/Mountpoint` | Specifies the component that is responsible for a particular redirect (source [Wikipedia](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields)). | | X-Generator | `Drupal 8` | Contain the information about the [CMS](https://en.wikipedia.org/wiki/Content_management_system) that generated the HTTP response. | | X-Generated-By | `Smartsite version 7.11.1.3` | Contain the information about the [CMS](https://en.wikipedia.org/wiki/Content_management_system) that generated the HTTP response. | | X-CMS | `Thinq CMS 1.7.0.0` | Contain the information about the [CMS](https://en.wikipedia.org/wiki/Content_management_system) that generated the HTTP response. | | X-Powered-By-Plesk | `PleskLin` or `PleskWin` | Indicate that the platform is based on the [Plesk](https://www.plesk.com) software in addition to the underlying operating system. | | X-Php-Version | `7.4` | Indicate the version of [PHP](https://www.php.net) technology used. | | Powered-By | `PrestaShop` | Indicate the name of the framework or platform used. | | X-Content-Encoded-By | `Joomla! 2.5` | Indicate the name of the framework or platform used. | | Product | `Z-BlogPHP 1.7.2` | Indicate the name of the framework or platform used. | | X-CF-Powered-By | `CF-Joomla 0.1.5` | Indicate the name of the framework or platform used. | | X-Framework | `JP/4.01` | Indicate the name of the framework or platform used. | | Host-Header | `owasp.org` | Indicate which virtual host of the web server the response is coming from. | | Pega-Host | `srv-pega11` | Indicate the internal host name of the server that handled the request in the context of usage of a software from the [PEGA](https://www.pega.com/) company. | | [X-Atmosphere-first-request](https://github.com/Atmosphere/atmosphere) | `true` | Indicate that the java framework [Atmosphere](https://github.com/Atmosphere/atmosphere) is used. | | [X-Atmosphere-tracking-id](https://github.com/Atmosphere/atmosphere) | `7852fcbf-f8a9-4667-9dcc-a0b5b162499c` | Indicate that the java framework [Atmosphere](https://github.com/Atmosphere/atmosphere) is used. | | [X-Atmosphere-error](https://github.com/Atmosphere/atmosphere) | `Websocket protocol not supported` | Indicate that the java framework [Atmosphere](https://github.com/Atmosphere/atmosphere) is used. | | [X-Mod-Pagespeed](https://www.modpagespeed.com/doc/configuration) | `1.13.35.2-0` | Indicate the presence of the Apache module [mod_pagespeed](https://github.com/apache/incubator-pagespeed-mod) in the call flow. | | [X-Page-Speed](https://www.modpagespeed.com/doc/configuration) | `1.13.35.2-0` | Indicate the presence of the Nginx module [mod_pagespeed](https://github.com/apache/incubator-pagespeed-ngx) in the call flow. | | X-Varnish-Backend | `pb01` | Indicate the name of the backend server from which the [Varnish](https://varnish-cache.org) instance will accelerate the content. | | X-Varnish-Server | `proxy01` | Indicate the name of the [Varnish](https://varnish-cache.org) server instance that provided the accelerated content. | | [X-Envoy-Upstream-Service-Time](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter) | `42` | Indicate the presence of the proxy software [Envoy](https://www.envoyproxy.io) in the call flow. | | [X-Envoy-Attempt-Count](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter) | `1` | Indicate the presence of the proxy software [Envoy](https://www.envoyproxy.io) in the call flow. | | [X-Envoy-External-Address](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers) | `124.128.159.165` | Indicate the presence of the proxy software [Envoy](https://www.envoyproxy.io) in the call flow. | | [X-Envoy-Internal](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers) | `true` | Indicate the presence of the proxy software [Envoy](https://www.envoyproxy.io) in the call flow. | | [X-Envoy-Original-Dst-Host](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers) | `10.195.16.237:8888` | Indicate the presence of the proxy software [Envoy](https://www.envoyproxy.io) in the call flow. | | [X-B3-ParentSpanId](https://github.com/openzipkin/b3-propagation) | `dea3f6d0324583db` | Indicate the presence of the software [Zipkin](https://zipkin.io/) that is a distributed tracing system. | | [X-B3-Sampled](https://github.com/openzipkin/b3-propagation) | `0` | Indicate the presence of the software [Zipkin](https://zipkin.io/) that is a distributed tracing system. | | [X-B3-SpanId](https://github.com/openzipkin/b3-propagation) | `244753d494e83353` | Indicate the presence of the software [Zipkin](https://zipkin.io/) that is a distributed tracing system. | | [X-B3-TraceId](https://github.com/openzipkin/b3-propagation) | `11bef07b0f5c0468` | Indicate the presence of the software [Zipkin](https://zipkin.io/) that is a distributed tracing system. | | [K-Proxy-Request](https://knative.dev/docs/serving/istio-authorization/) | `activator` | Indicate the presence of the software [Knative](https://knative.dev) that is an Open-Source Enterprise-level solution to build Serverless and Event Driven Applications in Kubernetes environments. | | X-Old-Content-Length | `135` | Indicate the presence of the software [WebSEAL](https://www.ibm.com/docs/en/samfm/8.0.1.2?topic=overview-webseal-introduction) that is a high performance, multithreaded web server by IBM. | | [$wsep](https://www.ibm.com/docs/en/was/8.5.5?topic=SSEQTP_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/rweb_custom_props.htm) | `empty value` | Indicate the presence of the software [WebSphere Application Server](https://www.ibm.com/products/websphere-application-server) that is a JavaEE application server by IBM. | | X-Nextjs-Matched-Path | `/blog` | Indicate that the web framework [Next.js](https://nextjs.org/) is used. | | X-Nextjs-Page | `/articles` | Indicate that the web framework [Next.js](https://nextjs.org/) is used. | | X-Nextjs-Cache | `REVALIDATED` | Indicate that the web framework [Next.js](https://nextjs.org/) is used. | | [X-Nextjs-Redirect](https://github.com/search?q=repo%3Avercel%2Fnext.js%20X-Nextjs-Redirect&type=code) | `/home` | Indicate that the web framework [Next.js](https://nextjs.org/) is used. | | X-OneAgent-JS-Injection | `true` | Indicate that the [Dynatrace](https://www.dynatrace.com) analytics and automation platform is used. | | X-ruxit-JS-Agent | `true` | Indicate that the [Dynatrace](https://www.dynatrace.com) analytics and automation platform is used. | | [X-dtHealthCheck](https://www.dynatrace.com/support/help/platform-modules/digital-experience/web-applications/initial-setup/firewall-constraints-for-rum) | `Technical diagnostic data` | Indicate that the [Dynatrace](https://www.dynatrace.com) analytics and automation platform is used. | | [X-dtAgentId](https://www.dynatrace.com/support/help/platform-modules/digital-experience/web-applications/initial-setup/firewall-constraints-for-rum) | `95b3121c36` | Indicate that the [Dynatrace](https://www.dynatrace.com) analytics and automation platform is used. | | [X-dtInjectedServlet](https://www.dynatrace.com/support/help/platform-modules/digital-experience/web-applications/initial-setup/firewall-constraints-for-rum) | `com.company.ReportServlet` | Indicate that the [Dynatrace](https://www.dynatrace.com) analytics and automation platform is used. | | [X-Litespeed-Cache-Control](https://docs.litespeedtech.com/lscache/devguide/controls/) | `no-cache` | Indicate the presence of the [LiteSpeed](https://litespeedtech.com/) web server. | | [X-LiteSpeed-Purge](https://docs.litespeedtech.com/lscache/devguide/controls/) | `/phpinfo.php` | Indicate the presence of the [LiteSpeed](https://litespeedtech.com/) web server. | | [X-LiteSpeed-Tag](https://docs.litespeedtech.com/lscache/devguide/controls/) | `pubtag1,pubtag2` | Indicate the presence of the [LiteSpeed](https://litespeedtech.com/) web server. | | [X-LiteSpeed-Vary](https://docs.litespeedtech.com/lscache/devguide/controls/) | `value=ismobile` | Indicate the presence of the [LiteSpeed](https://litespeedtech.com/) web server. | | [X-LiteSpeed-Cache](https://docs.litespeedtech.com/lscache/devguide/controls/) | `hit,litemage` | Indicate the presence of the [LiteSpeed](https://litespeedtech.com/) web server. | | X-Umbraco-Version | `4.7` | Indicate the usage of the [Umbraco CMS](https://umbraco.com/products/umbraco-cms/) software as well as its version. | | OracleCommerceCloud-Version | `23.08.01` | Indicate the usage of the [Oracle Commerce](https://www.oracle.com/cx/ecommerce/) software as well as its version. | | [X-BEServer](https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-ashttp/e11c906e-0a38-41e8-8b6d-571a4e84164f) | `EXSRV01` | Indicate the internal host name of the server that handled the request in the context of usage of the [Microsoft Exchange](https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-ashttp/08ad30b6-5b73-41bc-890b-1cab2cf49827) software. | | [X-DiagInfo](https://learn.microsoft.com/en-us/exchange/management/health/troubleshooting-autodiscover-health-set) | `EXSRV01` | Indicate the internal host name of the server that handled the request in the context of usage of the [Microsoft Exchange](https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-ashttp/08ad30b6-5b73-41bc-890b-1cab2cf49827) software. | | [X-FEServer](https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-ashttp/ea0b90c5-710a-4b23-823b-ddb86342b5ac) | `EXSRV01` | Indicate the internal host name of the server that handled the request in the context of usage of the [Microsoft Exchange](https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-ashttp/08ad30b6-5b73-41bc-890b-1cab2cf49827) software. | | [X-CalculatedBETarget](https://learn.microsoft.com/en-us/exchange/management/health/troubleshooting-autodiscover-health-set) | `exsrv01.mydomain.com` | Indicate the internal host name of the server that handled the request in the context of usage of the [Microsoft Exchange](https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-ashttp/08ad30b6-5b73-41bc-890b-1cab2cf49827) software. | | X-OWA-Version | `15.2.1258.27` | Indicate the version of the Microsoft Exchange software in use. | | X-Cocoon-Version | `2.1.13` | Indicate that the web framework [Apache Cocoon](https://cocoon.apache.org/) is used as well as the version used. | | [X-Kubernetes-PF-FlowSchema-UI](https://kubernetes.io/docs/reference/debug-cluster/flow-control) | `cf931e2d-5a5e-4c12-892c-9bafa71f30dc` | Indicate that the web application issuing the HTTP response is deployed on a [Kubernetes](https://kubernetes.io/) cluster. | | [X-Kubernetes-PF-PriorityLevel-UID](https://kubernetes.io/docs/reference/debug-cluster/flow-control) | `78b3face-e1cf-4fc6-a27e-08eb7f0f5b23` | Indicate that the web application issuing the HTTP response is deployed on a [Kubernetes](https://kubernetes.io/) cluster. | | X-Jitsi-Release | `5082` | Indicate the version of [Jitsi](https://github.com/jitsi/jitsi) software in use. | | X-Joomla-Version | `3.9.25` | Indicate that the CMS [Joomla](https://www.joomla.org/) is used as well as the version used. | | X-Backside-Transport | `OK OK` | Indicate the presence of the products [IBM WebSphere DataPower](https://www.ibm.com/products/datapower-gateway) in the call flow. | | [X-Woodpecker-Version](https://github.com/woodpecker-ci/woodpecker/blob/main/server/router/middleware/version.go) | `2.7.0` | Indicate the version of the products [Woodpecker CI](https://woodpecker-ci.org/) used. | | X-Gitlab-Meta | `{"correlation_id":"01KR...","version":"1"}` | Indicate that the flow has involved an instance of the [GitLab](https://gitlab.com/) source code management software. | | [X-Kong-Proxy-Latency](https://developer.konghq.com/gateway/logs/) | `4` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | [X-Kong-Upstream-Latency](https://developer.konghq.com/gateway/logs/) | `12` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | [X-Kong-Response-Latency](https://developer.konghq.com/gateway/logs/) | `8` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | [X-Kong-Admin-Latency](https://developer.konghq.com/gateway/logs/) | `9` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | [X-Kong-Upstream-Status](https://developer.konghq.com/gateway/logs/) | `200` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | [X-Kong-Request-Id](https://developer.konghq.com/gateway/logs/) | `125cc1e1-c72a-4ea0-b9ff-93849847e40c` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | [X-Kong-Total-Latency](https://developer.konghq.com/gateway/logs/) | `100` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | [X-Kong-Third-Party-Latency](https://developer.konghq.com/gateway/logs/) | `46` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | [X-Kong-Client-Latency](https://developer.konghq.com/gateway/logs/) | `50` | Indicate that the flow has involved an instance of the API gateway software from the company named [Kong](https://konghq.com/products/kong-gateway). | | X-Tyk-Trace-Id | `ba31c85da42c43d28fe00c6f780c7151` | Indicate that the flow has involved an instance of the API gateway software from the company named [Tyk](https://tyk.io/api-gateway/). | | [X-Datadog-Origin](https://docs.datadoghq.com/tracing/trace_collection/trace_context_propagation/?tab=java#custom-header-formats) | `rum` | Indicate that the flow has involved an instance of the observability software from the company named [Datadog](https://www.datadoghq.com/). | | [X-Datadog-Parent-Id](https://docs.datadoghq.com/tracing/trace_collection/trace_context_propagation/?tab=java#custom-header-formats) | `856398187332022578` | Indicate that the flow has involved an instance of the observability software from the company named [Datadog](https://www.datadoghq.com/). | | [X-Datadog-Trace-Id](https://docs.datadoghq.com/tracing/trace_collection/trace_context_propagation/?tab=java#custom-header-formats) | `987298187332022483` | Indicate that the flow has involved an instance of the observability software from the company named [Datadog](https://www.datadoghq.com/). | | [X-Datadog-Sampling-Priority](https://docs.datadoghq.com/tracing/trace_collection/trace_context_propagation/?tab=java#custom-header-formats) | `1` | Indicate that the flow has involved an instance of the observability software from the company named [Datadog](https://www.datadoghq.com/). | | [X-Datadog-Tags](https://docs.datadoghq.com/tracing/trace_collection/trace_context_propagation/?tab=java#custom-header-formats) | `_dd.p.tid=6593c2f700000000` | Indicate that the flow has involved an instance of the observability software from the company named [Datadog](https://www.datadoghq.com/). | | TeamCity-Node-Id | `MAIN_SERVER` | Indicate the presence of the [JetBrains TeamCity](https://www.jetbrains.com/teamcity/) CI/CD platform instance. | ## Prevent exposure to cross-site scripting when hosting uploaded files This section describes, how the HTTP response header named [Content-Disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition), can be used to prevent exposure to cross-site scripting when hosting uploaded files and opening them in the same web browsing context as the application. There can be a case in which an application allows a user to upload a file and then allows this file to be accessed by other users. If such a feature allows uploading of HTML files (also applies for [SVG files](https://hackerone.com/reports/1276742)) then it can be used, as a vector, to store an HTML file containing JavaScript code. Therefore, the feature become prone to [stored cross-site scripting](https://portswigger.net/web-security/cross-site-scripting/stored) vulnerability. To prevent this exposure, the HTTP response header named [Content-Disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition), can be used with the following value to instruct browsers to download the file instead of open it in the same web browsing context as the application: ``` Content-Disposition: attachment; filename="myfile.html" ``` ## Prevent CORS misconfiguration issues > πŸ“– An excellent tutorial about [Cross-Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) (called **CORS**) is provided on the [Mozilla MDN](https://developer.mozilla.org/en-US/). In addition, [Julien Cretel](https://jub0bs.com/about/) provided a great [blog post](https://jub0bs.com/posts/2023-02-08-fearless-cors/) about CORS pitfalls. This section proposes an approach to help preventing [CORS misconfiguration issues](https://portswigger.net/research/exploiting-cors-misconfigurations-for-bitcoins-and-bounties) using a simple idea: *Provide the collection of [CORS related HTTP response headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#the_http_response_headers) to use according to different contexts.* ### Key points to consider - πŸ’‘ If the web framework/web server you are using provides CORS features then always leverage them instead of implementing it manually: - [List of web framework/web server](https://enable-cors.org/server.html) supporting CORS. - [CORS middleware for Go](https://pkg.go.dev/github.com/jub0bs/cors) by Julien Cretel. - 🚩 Whatever the context, when the request is a **HTTP OPTIONS** ([preflight request](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests)) then the value provided by the following headers must be validated against expected values. If the validation failed then return an HTTP 403 **without any [CORS related HTTP response headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#the_http_response_headers)**: - [Origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#origin) - [Access-Control-Request-Method](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#access-control-request-method) - [Access-Control-Request-Headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#access-control-request-headers) - 🚩 Validation of the `Origin` / `Access-Control-Request-Method` / `Access-Control-Request-Headers` request header value, against a list of allowed ones, must be performed using [strict case sensitive string comparison](https://jub0bs.com/posts/2023-02-08-fearless-cors/#violation-of-the-case-sensitivity-of-method-names) to prevent, as much as possible, the [presence of bypasses into the validation logic](https://portswigger.net/web-security/cors#errors-parsing-origin-headers). If possible, do not use regular expressions for the implementation of the validation, see [here](https://jub0bs.com/posts/2023-02-08-fearless-cors/#disallow-dangerous-origin-patterns) for an explanation of the source of this recommendation. - 🚩 CORS scope is the access control aspect, from a browser perspective (client side), regarding [cross origins](https://developer.mozilla.org/en-US/docs/Glossary/Origin) access to a resource. Thus, it **does NOT replace** the requirement to implement access control on the server side too. CORS and server-side access controls are complementary. - 🚩 Never take the value of the request header [Origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#origin) to add it into the response header [Access-Control-Allow-Origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#access-control-allow-origin) (mirroring), see [here](https://portswigger.net/web-security/cors#server-generated-acao-header-from-client-specified-origin-header) for an explanation of the source of this recommendation. Indeed, always use a list of allowed origins when only a restricted collection of origins is expected to call your endpoints. ### Contexts #### Public without authentication πŸ’¬ Context: Your endpoints are expected to be consumed, by a browser, from any origins without any authentication. πŸ’» Configuration proposal: ``` Access-Control-Allow-Origin: * Access-Control-Max-Age: 3600 Access-Control-Allow-Credentials: false ``` #### Public with authentication πŸ’¬ Context: Your endpoints are expected to be consumed, by a browser, from any origins with authentication. 🚩 The value `*`, for the response header `Access-Control-Allow-Origin`, cannot be used when the response header `Access-Control-Allow-Credentials` is allowed (`true`). Indeed, the browser raises the following error (tested on Chrome 118.x): ``` The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. ``` πŸ“– It is explicitly mentioned, into the [Mozilla MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests) documentation, as the following: ``` When responding to a "credentialed request" request, the server must specify an origin in the value of the Access-Control-Allow-Origin header, instead of specifying the "*" wildcard. ``` Therefore, refer to the restricted with authentication case for the configuration to use. #### Restricted without authentication πŸ’¬ Context: Your endpoints are expected to be consumed, by a browser, from a specific collection of origins without any authentication. πŸ’» Configuration proposal: - If the value of the request header [Origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#origin) is present into the **list of allowed Origins** then: ``` Access-Control-Allow-Origin: [Value_Taken_From_The_List_Of_Allowed_Origins] Access-Control-Max-Age: 10 Access-Control-Allow-Credentials: false ``` - Otherwise return an HTTP 403 **without any [CORS related HTTP response headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#the_http_response_headers)** . #### Restricted with authentication πŸ’¬ Context: Your endpoints are expected to be consumed, by a browser, from a specific collection of origins with authentication. πŸ’» Configuration proposal: - If the value of the request header [Origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#origin) is present into the **list of allowed Origins** then: ``` Access-Control-Allow-Origin: [Value_Taken_From_The_List_Of_Allowed_Origins] Access-Control-Max-Age: 10 Access-Control-Allow-Credentials: true ``` - Otherwise return an HTTP 403 **without any [CORS related HTTP response headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#the_http_response_headers)** . ### Test CORS configuration The tool [nuclei](https://github.com/projectdiscovery/nuclei) can be used, via the template named [cors-misconfig](https://github.com/projectdiscovery/nuclei-templates/blob/main/http/vulnerabilities/generic/cors-misconfig.yaml), to test a CORS configuration. πŸ’» Command to use: ``` $ nuclei -silent -template-id cors-misconfig -u https://domain.com [cors-misconfig:arbitrary-origin] [http] [info] https://domain.com [...] ``` ### References - [https://portswigger.net/web-security/cors](https://portswigger.net/web-security/cors) - [https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) - [https://jub0bs.com/posts/2023-02-08-fearless-cors/](https://jub0bs.com/posts/2023-02-08-fearless-cors/) - [https://enable-cors.org/](https://enable-cors.org/) - [https://developer.mozilla.org/en-US/docs/Glossary/Origin](https://developer.mozilla.org/en-US/docs/Glossary/Origin) - [https://cwe.mitre.org/data/definitions/942.html](https://cwe.mitre.org/data/definitions/942.html) - [https://cwe.mitre.org/data/definitions/346.html](https://cwe.mitre.org/data/definitions/346.html) - [OWASP WSTG - Testing Cross Origin Resource Sharing](https://owasp.org/www-project-web-security-testing-guide/stable/4-Web_Application_Security_Testing/11-Client-side_Testing/07-Testing_Cross_Origin_Resource_Sharing) - [https://pkg.go.dev/github.com/jub0bs/cors](https://pkg.go.dev/github.com/jub0bs/cors) ## Prevent information disclosure via the browser local cached files This section describes why it is important to specify a **caching policy**, via the [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) HTTP response header, when sensitive information is managed by a web-based application. ### Context πŸ’¬ The application allows a user to access to documents containing information, considered sensitive, from a confidentiality perspective. Let’s assume that the application returns the following HTTP response to a request, in which, no caching policy is defined: ``` HTTP/1.1 200 OK accept-ranges: bytes content-length: 433994 content-type: application/pdf date: Sat, 30 Mar 2024 10:06:34 GMT server: LiteSpeed ``` So, the browser will store a copy of the file (here a PDF one) into its cache storage for a certain amount of time. 🚩 **Consequence:** Any application running on the user’s computer, will be able to access to the file (at least if executed as the user identity or an administrator one) causing an exposure of the resource to non-expected entities. πŸ“Ί This [demonstration video](/www-project-secure-headers/mainsite/assets/misc/demo_information_disclosure_via_browser_file_caching.mp4) shows an example, of such information disclosure, via a file cached by the browser. ### Configuration proposal πŸ’» To prevent such issue, the following **caching policy** can be specified: ``` Cache-Control: no-store, max-age=0 ``` πŸ‘€ Where: - `no-store` : Is used to indicate that the response may not be stored in any cache. - `max-age=0` : Is used to force the expiration of any cached version of the resources associated with the response. πŸ’‘ The HTTP response header [Clear-Site-Data](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data) can also be leveraged, in addition, to instruct the browser to remove any cached data related to the application. πŸ“– An excellent research and course content, about [web cache poisoning](https://portswigger.net/web-security/web-cache-poisoning), is provided by the [PortSwigger team](https://portswigger.net/). ### References - [https://redbot.org](https://redbot.org) - [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) - [https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching) - [https://caniuse.com/mdn-http_headers_cache-control](https://caniuse.com/mdn-http_headers_cache-control) - [https://cwe.mitre.org/data/definitions/525.html](https://cwe.mitre.org/data/definitions/525.html) - [https://cwe.mitre.org/data/definitions/524.html](https://cwe.mitre.org/data/definitions/524.html) - [OWASP WSTG - Testing for Browser Cache Weaknesses](https://owasp.org/www-project-web-security-testing-guide/stable/4-Web_Application_Security_Testing/04-Authentication_Testing/06-Testing_for_Browser_Cache_Weaknesses) - [https://portswigger.net/kb/issues/00700100_cacheable-https-response](https://portswigger.net/kb/issues/00700100_cacheable-https-response) - [https://portswigger.net/web-security/web-cache-poisoning](https://portswigger.net/web-security/web-cache-poisoning) - [https://portswigger.net/web-security/web-cache-deception](https://portswigger.net/web-security/web-cache-deception) - [https://portswigger.net/research/gotta-cache-em-all](https://portswigger.net/research/gotta-cache-em-all) ## Prevent CSP bypasses > πŸ’‘ This [online tool](https://cspbypass.com/) can be used to identify existing bypasses for a CSP policy. This section describes some points, to keep in mind, during the creation of a [Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) (called **CSP**) policy to prevent introducing bypasses. 🚩 Not every **[directive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#directives)** falls back to the **[default-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src)** directive when it is not specified in the CSP policy. ### Directive form-action πŸ‘€ It is the case for the **[form-action](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/form-action)** directive. Therefore, an html form can be used to bypass the CSP in place when the `form-action` is not defined. πŸ“Ί This [demonstration video](/www-project-secure-headers/mainsite/assets/misc/demo_csp_bypass_due_to_no_form_action_directive.mp4) shows an example. πŸ’‘ Therefore, ensure to always specify the `form-action` directive in a CSP policy to at least, the `'self'` value, to allow forms only on the current domain. ### Directive frame-ancestors πŸ‘€ It is the case for the **[frame-ancestors](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors)** directive. Therefore, IF it is not defined **AND** IF the header [X-Frame-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options) is not/incorrectly specified then the current domain can be embedded into a frame. πŸ“Ί This [demonstration video](/www-project-secure-headers/mainsite/assets/misc/demo_csp_bypass_due_to_no_frame_ancestors_directive.mp4) shows an example. πŸ’‘ Therefore, ensure to always specify the `frame-ancestors` directive in a CSP policy to at least, the `'none'` value, to deny the current domain to be β€œframed”. ### Directive base-uri πŸ‘€ It is the case for the **[base-uri](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/base-uri)** directive. πŸ“Ί This [demonstration video](/www-project-secure-headers/mainsite/assets/misc/demo_csp_bypass_due_to_no_base_uri_directive.mp4) show an example. πŸ’‘ Therefore, ensure to always specify the `base-uri` directive in a CSP policy to at least, the `'self'` value, to only allow the current domain to be specified as the document’s base URI via a `` html tag. ## Support for a large CSP policy Tests were performed to identify if any limitation was in place, regarding the definition and usage of a large CSP policy. Tests were performed against the following browsers: - Firefox `132.0.2` . - Chromium `131.0.6755.0` . - Edge `131.0.2903.51` . πŸ’‘ Based on tests performed, modern browsers support a sufficient size to specify a large CSP policy in case of need. πŸ“Š Technical details can be found [here](https://github.com/oshp/oshp-tracking/discussions/29) ([backup copy](/www-project-secure-headers/mainsite/assets/misc/backup_discussions_29.pdf)).