diff --git a/docs/manual/src/docs/asciidoc/_includes/about/exploits/headers.adoc b/docs/manual/src/docs/asciidoc/_includes/about/exploits/headers.adoc new file mode 100644 index 0000000000..32abe9a31a --- /dev/null +++ b/docs/manual/src/docs/asciidoc/_includes/about/exploits/headers.adoc @@ -0,0 +1,369 @@ +[[headers]] += Security HTTP Response Headers + +[NOTE] +==== +This portion of the documentation discusses the general topic of Security HTTP Response Headers. +Refer to the relevant sections for specific information on Security HTTP Response Headers <> and <> based applications. +==== + +There are many https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#tab=Headers[HTTP response headers] that can be used to increase the security of web applications. +This section is dedicated to the various HTTP response headers that Spring Security provides explicit support for. +If necessary, Spring Security can also be configured to provide <>. + +[[headers-default]] +== Default Security Headers + +[NOTE] +==== +Refer to the relevant sections to see how to customize the defaults for both <> and <> based applications. +==== + +Spring Security provides a default set of security related HTTP response headers to provide secure defaults. + +The default for Spring Security is to include the following headers: + +.Default Security HTTP Response Headers +==== +[source,http] +---- +Cache-Control: no-cache, no-store, max-age=0, must-revalidate +Pragma: no-cache +Expires: 0 +X-Content-Type-Options: nosniff +Strict-Transport-Security: max-age=31536000 ; includeSubDomains +X-Frame-Options: DENY +X-XSS-Protection: 1; mode=block +---- +==== + +NOTE: Strict-Transport-Security is only added on HTTPS requests + +If the defaults do not meet your needs, you can easily remove, modify, or add headers from these defaults. +For additional details on each of these headers, refer to the corresponding sections: + +* <> +* <> +* <> +* <> +* <> + +[[headers-cache-control]] +== Cache Control + +[NOTE] +==== +Refer to the relevant sections to see how to customize the defaults for both <> and <> based applications. +==== + +Spring Security's default is to disable caching to protect user's content. + +If a user authenticates to view sensitive information and then logs out, we don't want a malicious user to be able to click the back button to view the sensitive information. +The cache control headers that are sent by default are: + +.Default Cache Control HTTP Response Headers +==== +[source] +---- +Cache-Control: no-cache, no-store, max-age=0, must-revalidate +Pragma: no-cache +Expires: 0 +---- +==== + +In order to be secure by default, Spring Security adds these headers by default. +However, if your application provides it's own cache control headers Spring Security will back out of the way. +This allows for applications to ensure that static resources like CSS and JavaScript can be cached. + + +[[headers-content-type-options]] +== Content Type Options + +[NOTE] +==== +Refer to the relevant sections to see how to customize the defaults for both <> and <> based applications. +==== + +Historically browsers, including Internet Explorer, would try to guess the content type of a request using https://en.wikipedia.org/wiki/Content_sniffing[content sniffing]. +This allowed browsers to improve the user experience by guessing the content type on resources that had not specified the content type. +For example, if a browser encountered a JavaScript file that did not have the content type specified, it would be able to guess the content type and then execute it. + +[NOTE] +==== +There are many additional things one should do (i.e. only display the document in a distinct domain, ensure Content-Type header is set, sanitize the document, etc) when allowing content to be uploaded. +However, these measures are out of the scope of what Spring Security provides. +It is also important to point out when disabling content sniffing, you must specify the content type in order for things to work properly. +==== + +The problem with content sniffing is that this allowed malicious users to use polyglots (i.e. a file that is valid as multiple content types) to execute XSS attacks. +For example, some sites may allow users to submit a valid postscript document to a website and view it. +A malicious user might create a http://webblaze.cs.berkeley.edu/papers/barth-caballero-song.pdf[postscript document that is also a valid JavaScript file] and execute a XSS attack with it. + +Spring Security disables content sniffing by default by adding the following header to HTTP responses: + +.nosniff HTTP Response Header +==== +[source,http] +---- +X-Content-Type-Options: nosniff +---- +==== + +[[headers-hsts]] +== HTTP Strict Transport Security (HSTS) + +[NOTE] +==== +Refer to the relevant sections to see how to customize the defaults for both <> and <> based applications. +==== + +When you type in your bank's website, do you enter mybank.example.com or do you enter https://mybank.example.com[]? +If you omit the https protocol, you are potentially vulnerable to https://en.wikipedia.org/wiki/Man-in-the-middle_attack[Man in the Middle attacks]. +Even if the website performs a redirect to https://mybank.example.com a malicious user could intercept the initial HTTP request and manipulate the response (i.e. redirect to https://mibank.example.com and steal their credentials). + +Many users omit the https protocol and this is why https://tools.ietf.org/html/rfc6797[HTTP Strict Transport Security (HSTS)] was created. +Once mybank.example.com is added as a https://tools.ietf.org/html/rfc6797#section-5.1[HSTS host], a browser can know ahead of time that any request to mybank.example.com should be interpreted as https://mybank.example.com. +This greatly reduces the possibility of a Man in the Middle attack occurring. + +[NOTE] +==== +In accordance with https://tools.ietf.org/html/rfc6797#section-7.2[RFC6797], the HSTS header is only injected into HTTPS responses. +In order for the browser to acknowledge the header, the browser must first trust the CA that signed the SSL certificate used to make the connection (not just the SSL certificate). +==== + +One way for a site to be marked as a HSTS host is to have the host preloaded into the browser. +Another is to add the `Strict-Transport-Security` header to the response. +For example, Spring Security's default behavior is to add the following header which instructs the browser to treat the domain as an HSTS host for a year (there are approximately 31536000 seconds in a year): + + +.Strict Transport Security HTTP Response Header +==== +[source] +---- +Strict-Transport-Security: max-age=31536000 ; includeSubDomains ; preload +---- +==== + +The optional `includeSubDomains` directive instructs the browser that subdomains (i.e. secure.mybank.example.com) should also be treated as an HSTS domain. + +The optional `preload` directive instructs the browser that domain should be preloaded in browser as HSTS domain. +For more details on HSTS preload please see https://hstspreload.org. + +[[headers-hpkp]] +== HTTP Public Key Pinning (HPKP) + +[NOTE] +==== +In order to remain passive Spring Security still provides <>, but for the reasons listed above HPKP is no longer recommended by the security team. +==== + +https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning[HTTP Public Key Pinning (HPKP)] specifies to a web client which public key to use with certain web server to prevent Man in the Middle (MITM) attacks with forged certificates. +When used correctly, HPKP could add additional layers of protection against compromised certificates. +However, due to the complexity of HPKP many experts no longer recommend using it and https://www.chromestatus.com/feature/5903385005916160[Chrome has even removed support] for it. + +[[headers-hpkp-deprecated]] +For additional details around why HPKP is no longer recommended read https://blog.qualys.com/ssllabs/2016/09/06/is-http-public-key-pinning-dead[ +Is HTTP Public Key Pinning Dead?] and https://scotthelme.co.uk/im-giving-up-on-hpkp/[I'm giving up on HPKP]. + +[[headers-frame-options]] +== X-Frame-Options + +[NOTE] +==== +Refer to the relevant sections to see how to customize the defaults for both <> and <> based applications. +==== + +Allowing your website to be added to a frame can be a security issue. +For example, using clever CSS styling users could be tricked into clicking on something that they were not intending (https://www.youtube.com/watch?v=3mk0RySeNsU[video demo]). +For example, a user that is logged into their bank might click a button that grants access to other users. +This sort of attack is known as https://en.wikipedia.org/wiki/Clickjacking[Clickjacking]. + +[NOTE] +==== +Another modern approach to dealing with clickjacking is to use <>. +==== + +There are a number ways to mitigate clickjacking attacks. +For example, to protect legacy browsers from clickjacking attacks you can use https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet#Best-for-now_Legacy_Browser_Frame_Breaking_Script[frame breaking code]. +While not perfect, the frame breaking code is the best you can do for the legacy browsers. + +A more modern approach to address clickjacking is to use https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options[X-Frame-Options] header. +By default Spring Security disables rendering pages within an iframe using with the following header: + +[source] +---- +X-Frame-Options: DENY +---- + +[[headers-xss-protection]] +== X-XSS-Protection + +[NOTE] +==== +Refer to the relevant sections to see how to customize the defaults for both <> and <> based applications. +==== + +Some browsers have built in support for filtering out https://www.owasp.org/index.php/Testing_for_Reflected_Cross_site_scripting_(OWASP-DV-001)[reflected XSS attacks]. +This is by no means foolproof, but does assist in XSS protection. + +The filtering is typically enabled by default, so adding the header typically just ensures it is enabled and instructs the browser what to do when a XSS attack is detected. +For example, the filter might try to change the content in the least invasive way to still render everything. +At times, this type of replacement can become a https://hackademix.net/2009/11/21/ies-xss-filter-creates-xss-vulnerabilities/[XSS vulnerability in itself]. +Instead, it is best to block the content rather than attempt to fix it. +By default Spring Security blocks the content using the following header: + +[source] +---- +X-XSS-Protection: 1; mode=block +---- + + +[[headers-csp]] +== Content Security Policy (CSP) + +[NOTE] +==== +Refer to the relevant sections to see how to configure both <> and <> based applications. +==== + +https://www.w3.org/TR/CSP2/[Content Security Policy (CSP)] is a mechanism that web applications can leverage to mitigate content injection vulnerabilities, such as cross-site scripting (XSS). +CSP is a declarative policy that provides a facility for web application authors to declare and ultimately inform the client (user-agent) about the sources from which the web application expects to load resources. + +[NOTE] +==== +Content Security Policy is not intended to solve all content injection vulnerabilities. +Instead, CSP can be leveraged to help reduce the harm caused by content injection attacks. +As a first line of defense, web application authors should validate their input and encode their output. +==== + +A web application may employ the use of CSP by including one of the following HTTP headers in the response: + +* `Content-Security-Policy` +* `Content-Security-Policy-Report-Only` + +Each of these headers are used as a mechanism to deliver a security policy to the client. +A security policy contains a set of security policy directives, each responsible for declaring the restrictions for a particular resource representation. + +For example, a web application can declare that it expects to load scripts from specific, trusted sources, by including the following header in the response: + +.Content Security Policy Example +==== +[source] +---- +Content-Security-Policy: script-src https://trustedscripts.example.com +---- +==== + +An attempt to load a script from another source other than what is declared in the `script-src` directive will be blocked by the user-agent. +Additionally, if the https://www.w3.org/TR/CSP2/#directive-report-uri[report-uri] directive is declared in the security policy, then the violation will be reported by the user-agent to the declared URL. + +For example, if a web application violates the declared security policy, the following response header will instruct the user-agent to send violation reports to the URL specified in the policy's `report-uri` directive. + +.Content Security Policy with report-uri +==== +[source] +---- +Content-Security-Policy: script-src https://trustedscripts.example.com; report-uri /csp-report-endpoint/ +---- +==== + +https://www.w3.org/TR/CSP2/#violation-reports[Violation reports] are standard JSON structures that can be captured either by the web application's own API or by a publicly hosted CSP violation reporting service, such as, https://report-uri.io/. + +The `Content-Security-Policy-Report-Only` header provides the capability for web application authors and administrators to monitor security policies, rather than enforce them. +This header is typically used when experimenting and/or developing security policies for a site. +When a policy is deemed effective, it can be enforced by using the `Content-Security-Policy` header field instead. + +Given the following response header, the policy declares that scripts may be loaded from one of two possible sources. + +.Content Security Policy Report Only +==== +[source] +---- +Content-Security-Policy-Report-Only: script-src 'self' https://trustedscripts.example.com; report-uri /csp-report-endpoint/ +---- +==== + +If the site violates this policy, by attempting to load a script from _evil.com_, the user-agent will send a violation report to the declared URL specified by the _report-uri_ directive, but still allow the violating resource to load nevertheless. + +Applying Content Security Policy to a web application is often a non-trivial undertaking. +The following resources may provide further assistance in developing effective security policies for your site. + +https://www.html5rocks.com/en/tutorials/security/content-security-policy/[An Introduction to Content Security Policy] + +https://developer.mozilla.org/en-US/docs/Web/Security/CSP[CSP Guide - Mozilla Developer Network] + +https://www.w3.org/TR/CSP2/[W3C Candidate Recommendation] + +[[headers-referrer]] +== Referrer Policy + +[NOTE] +==== +Refer to the relevant sections to see how to configure both <> and <> based applications. +==== + +https://www.w3.org/TR/referrer-policy[Referrer Policy] is a mechanism that web applications can leverage to manage the referrer field, which contains the last +page the user was on. + +Spring Security's approach is to use https://www.w3.org/TR/referrer-policy/[Referrer Policy] header, which provides different https://www.w3.org/TR/referrer-policy/#referrer-policies[policies]: + +.Referrer Policy Example +==== +[source] +---- +Referrer-Policy: same-origin +---- +==== + +The Referrer-Policy response header instructs the browser to let the destination knows the source where the user was previously. + +[[headers-feature]] +== Feature Policy + +[NOTE] +==== +Refer to the relevant sections to see how to configure both <> and <> based applications. +==== + +https://wicg.github.io/feature-policy/[Feature Policy] is a mechanism that allows web developers to selectively enable, disable, and modify the behavior of certain APIs and web features in the browser. + +.Feature Policy Example +==== +[source] +---- +Feature-Policy: geolocation 'self' +---- +==== + +With Feature Policy, developers can opt-in to a set of "policies" for the browser to enforce on specific features used throughout your site. +These policies restrict what APIs the site can access or modify the browser's default behavior for certain features. + + +[[headers-clear-site-data]] +== Clear Site Data + +[NOTE] +==== +Refer to the relevant sections to see how to configure both <> and <> based applications. +==== + +https://www.w3.org/TR/clear-site-data/[Clear Site Data] is a mechanism by which any browser-side data - cookies, local storage, and the like - can be removed when an HTTP response contains this header: + +[source] +---- +Clear-Site-Data: "cache", "cookies", "storage", "executionContexts" +---- + +This is a nice clean-up action to perform on logout. + + +[[headers-custom]] +== Custom Headers + +[NOTE] +==== +Refer to the relevant sections to see how to configure both <> based applications. +==== + +Spring Security has mechanisms to make it convenient to add the more common security headers to your application. +However, it also provides hooks to enable adding custom headers. diff --git a/docs/manual/src/docs/asciidoc/_includes/about/exploits/index.adoc b/docs/manual/src/docs/asciidoc/_includes/about/exploits/index.adoc index 59abee37db..bb42a5c6dc 100644 --- a/docs/manual/src/docs/asciidoc/_includes/about/exploits/index.adoc +++ b/docs/manual/src/docs/asciidoc/_includes/about/exploits/index.adoc @@ -6,3 +6,5 @@ Whenever possible, the protection is enabled by default. Below you will find high level description of the various exploits that Spring Security protects against. include::csrf.adoc[leveloffset=+1] + +include::headers.adoc[leveloffset=+1] diff --git a/docs/manual/src/docs/asciidoc/_includes/reactive/exploits/headers.adoc b/docs/manual/src/docs/asciidoc/_includes/reactive/exploits/headers.adoc index acea0e6982..6885ee193b 100644 --- a/docs/manual/src/docs/asciidoc/_includes/reactive/exploits/headers.adoc +++ b/docs/manual/src/docs/asciidoc/_includes/reactive/exploits/headers.adoc @@ -1,54 +1,22 @@ [[webflux-headers]] = Security HTTP Response Headers -This section discusses Spring Security's support for adding various security headers to the response of WebFlux. +<> can be used to increase the security of web applications. +This section is dedicated to WebFlux based support for Security HTTP Response Headers. + +[[webflux-headers-default]] == Default Security Headers -Spring Security allows users to easily inject the default security headers to assist in protecting their application. -The default for Spring Security is to include the following headers: - -[source,http] ----- -Cache-Control: no-cache, no-store, max-age=0, must-revalidate -Pragma: no-cache -Expires: 0 -X-Content-Type-Options: nosniff -Strict-Transport-Security: max-age=31536000 ; includeSubDomains -X-Frame-Options: DENY -X-XSS-Protection: 1; mode=block ----- - -NOTE: Strict-Transport-Security is only added on HTTPS requests - -For additional details on each of these headers, refer to the corresponding sections: - -* <> -* <> -* <> -* <> -* <> +Spring Security provides a <> to provide secure defaults. While each of these headers are considered best practice, it should be noted that not all clients utilize the headers, so additional testing is encouraged. You can customize specific headers. -For example, assume that want your HTTP response headers to look like the following: - -[source,http] ----- -Cache-Control: no-cache, no-store, max-age=0, must-revalidate -Pragma: no-cache -Expires: 0 -X-Content-Type-Options: nosniff -X-Frame-Options: SAMEORIGIN -X-XSS-Protection: 1; mode=block ----- - -Specifically, you want all of the default headers with the following customizations: - -* <> to allow any request from same domain -* <> will not be added to the response +For example, assume that you want the defaults except you wish to specify `SAMEORIGIN` for <>. You can easily do this with the following Java Configuration: +.Customize Default Security Headers with Java Configuration +==== [source,java] ---- @Bean @@ -57,10 +25,6 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { // ... .headers(headers -> headers - .hsts(hsts -> - hsts - .disable() - ) .frameOptions(frameOptions -> frameOptions .mode(Mode.SAMEORIGIN) @@ -69,13 +33,13 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- - +==== If you do not want the defaults to be added and want explicit control over what should be used, you can disable the defaults. -An example for both Java and XML based configuration is provided below: - -If necessary, you can disable all of the HTTP Security response headers with the following Java Configuration: +An example for both Java configuration is provided below: +.Disable HTTP Security Response Headers +==== [source,java] ---- @Bean @@ -89,27 +53,23 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- +==== [[webflux-headers-cache-control]] == Cache Control -In the past Spring Security required you to provide your own cache control for your web application. -This seemed reasonable at the time, but browser caches have evolved to include caches for secure connections as well. -This means that a user may view an authenticated page, log out, and then a malicious user can use the browser history to view the cached page. -To help mitigate this Spring Security has added cache control support which will insert the following headers into you response by default. -[source] ----- -Cache-Control: no-cache, no-store, max-age=0, must-revalidate -Pragma: no-cache -Expires: 0 ----- +Spring Security includes <> headers by default. - -If you actually want to cache specific responses, your application can selectively set the cache control headers to override the header set by Spring Security. +However, if you actually want to cache specific responses, your application can selectively add them to the https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/server/reactive/ServerHttpResponse.html[ServerHttpResponse] to override the header set by Spring Security. This is useful to ensure things like CSS, JavaScript, and images are properly cached. -You can also disable cache control using the following Java Configuration: +When using Spring WebFluxZz, this is typically done within your configuration. +Details on how to do this can be found in the https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/web-reactive.html#webflux-config-static-resources[Static Resources] portion of the Spring Reference documentation +If necessary, you can also disable Spring Security's cache control HTTP response headers. + +.Cache Control Disabled +==== [source,java] ---- @Bean @@ -123,34 +83,16 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- +==== + [[webflux-headers-content-type-options]] == Content Type Options -Historically browsers, including Internet Explorer, would try to guess the content type of a request using https://en.wikipedia.org/wiki/Content_sniffing[content sniffing]. -This allowed browsers to improve the user experience by guessing the content type on resources that had not specified the content type. -For example, if a browser encountered a JavaScript file that did not have the content type specified, it would be able to guess the content type and then execute it. - -[NOTE] -== -There are many additional things one should do (i.e. only display the document in a distinct domain, ensure Content-Type header is set, sanitize the document, etc) when allowing content to be uploaded. -However, these measures are out of the scope of what Spring Security provides. -It is also important to point out when disabling content sniffing, you must specify the content type in order for things to work properly. -== - -The problem with content sniffing is that this allowed malicious users to use polyglots (i.e. a file that is valid as multiple content types) to execute XSS attacks. -For example, some sites may allow users to submit a valid postscript document to a website and view it. -A malicious user might create a http://webblaze.cs.berkeley.edu/papers/barth-caballero-song.pdf[postscript document that is also a valid JavaScript file] and execute a XSS attack with it. - -Content sniffing can be disabled by adding the following header to our response: - -[source] ----- -X-Content-Type-Options: nosniff ----- - -Just as with the cache control element, the nosniff directive is added by default. -However, if need to disable the header, the following may be used: +Spring Security includes <> headers by default. +However, you can disable it in Java Configuration with: +.Content Type Options Disabled with Java Configuration +==== [source,java] ---- @Bean @@ -164,40 +106,16 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- +==== [[webflux-headers-hsts]] == HTTP Strict Transport Security (HSTS) -When you type in your bank's website, do you enter mybank.example.com or do you enter https://mybank.example.com[]? -If you omit the https protocol, you are potentially vulnerable to https://en.wikipedia.org/wiki/Man-in-the-middle_attack[Man in the Middle attacks]. -Even if the website performs a redirect to https://mybank.example.com a malicious user could intercept the initial HTTP request and manipulate the response (i.e. redirect to https://mibank.example.com and steal their credentials). - -Many users omit the https protocol and this is why https://tools.ietf.org/html/rfc6797[HTTP Strict Transport Security (HSTS)] was created. -Once mybank.example.com is added as a https://tools.ietf.org/html/rfc6797#section-5.1[HSTS host], a browser can know ahead of time that any request to mybank.example.com should be interpreted as https://mybank.example.com. -This greatly reduces the possibility of a Man in the Middle attack occurring. - -[NOTE] -== -In accordance with https://tools.ietf.org/html/rfc6797#section-7.2[RFC6797], the HSTS header is only injected into HTTPS responses. -In order for the browser to acknowledge the header, the browser must first trust the CA that signed the SSL certificate used to make the connection (not just the SSL certificate). -== - -One way for a site to be marked as a HSTS host is to have the host preloaded into the browser. -Another is to add the "Strict-Transport-Security" header to the response. -For example the following would instruct the browser to treat the domain as an HSTS host for a year (there are approximately 31536000 seconds in a year): - -[source] ----- -Strict-Transport-Security: max-age=31536000 ; includeSubDomains ; preload ----- - -The optional includeSubDomains directive instructs Spring Security that subdomains (i.e. secure.mybank.example.com) should also be treated as an HSTS domain. - -The optional preload directive instructs Spring Security that domain should be preloaded in browser as HSTS domain. For more details on HSTS preload please see -https://hstspreload.org. - -As with the other headers, Spring Security adds HSTS by default. -You can customize HSTS headers with Java Configuration: +Spring Security provides the <> header by default. +However, you can customize the results explicitly. +For example, the following is an example of explicitly providing HSTS with Java Configuration: +.Strict Transport Security with Java Configuration +==== [source,java] ---- @Bean @@ -216,36 +134,16 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- - +==== [[webflux-headers-frame-options]] == X-Frame-Options -Allowing your website to be added to a frame can be a security issue. -For example, using clever CSS styling users could be tricked into clicking on something that they were not intending (https://www.youtube.com/watch?v=3mk0RySeNsU[video demo]). -For example, a user that is logged into their bank might click a button that grants access to other users. -This sort of attack is known as https://en.wikipedia.org/wiki/Clickjacking[Clickjacking]. +By default, Spring Security disables rendering within an iframe using <>. -[NOTE] -== -Another modern approach to dealing with clickjacking is to use <>. -== - -There are a number ways to mitigate clickjacking attacks. -For example, to protect legacy browsers from clickjacking attacks you can use https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet#Best-for-now_Legacy_Browser_Frame_Breaking_Script[frame breaking code]. -While not perfect, the frame breaking code is the best you can do for the legacy browsers. - -A more modern approach to address clickjacking is to use https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options[X-Frame-Options] header: - -[source] ----- -X-Frame-Options: DENY ----- - -The X-Frame-Options response header instructs the browser to prevent any site with this header in the response from being rendered within a frame. -By default, Spring Security disables rendering within an iframe. - -You can customize X-Frame-Options with Java Configuration using the following: +You can customize frame options to use the same origin within Java Configuration using the following: +.X-Frame-Options: SAMEORIGIN +==== [source,java] ---- @Bean @@ -262,26 +160,15 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- +==== [[webflux-headers-xss-protection]] == X-XSS-Protection -Some browsers have built in support for filtering out https://www.owasp.org/index.php/Testing_for_Reflected_Cross_site_scripting_(OWASP-DV-001)[reflected XSS attacks]. -This is by no means foolproof, but does assist in XSS protection. - -The filtering is typically enabled by default, so adding the header typically just ensures it is enabled and instructs the browser what to do when a XSS attack is detected. -For example, the filter might try to change the content in the least invasive way to still render everything. -At times, this type of replacement can become a https://hackademix.net/2009/11/21/ies-xss-filter-creates-xss-vulnerabilities/[XSS vulnerability in itself]. -Instead, it is best to block the content rather than attempt to fix it. -To do this we can add the following header: - -[source] ----- -X-XSS-Protection: 1; mode=block ----- - -This header is included by default. -However, we can customize with Java Configuration with the following: +By default, Spring Security instructs browsers to block reflected XSS attacks using the <. +You can disable `X-XSS-Protection` with the following Java Configuration: +.X-XSS-Protection Customization +==== [source,java] ---- @Bean @@ -295,75 +182,27 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- +==== [[webflux-headers-csp]] == Content Security Policy (CSP) - -https://www.w3.org/TR/CSP2/[Content Security Policy (CSP)] is a mechanism that web applications can leverage to mitigate content injection vulnerabilities, such as cross-site scripting (XSS). -CSP is a declarative policy that provides a facility for web application authors to declare and ultimately inform the client (user-agent) about the sources from which the web application expects to load resources. - -[NOTE] -== -Content Security Policy is not intended to solve all content injection vulnerabilities. -Instead, CSP can be leveraged to help reduce the harm caused by content injection attacks. -As a first line of defense, web application authors should validate their input and encode their output. -== - -A web application may employ the use of CSP by including one of the following HTTP headers in the response: - -* *_Content-Security-Policy_* -* *_Content-Security-Policy-Report-Only_* - -Each of these headers are used as a mechanism to deliver a *_security policy_* to the client. -A security policy contains a set of *_security policy directives_* (for example, _script-src_ and _object-src_), each responsible for declaring the restrictions for a particular resource representation. - -For example, a web application can declare that it expects to load scripts from specific, trusted sources, by including the following header in the response: - -[source] ----- -Content-Security-Policy: script-src https://trustedscripts.example.com ----- - -An attempt to load a script from another source other than what is declared in the _script-src_ directive will be blocked by the user-agent. -Additionally, if the https://www.w3.org/TR/CSP2/#directive-report-uri[*_report-uri_*] directive is declared in the security policy, then the violation will be reported by the user-agent to the declared URL. - -For example, if a web application violates the declared security policy, the following response header will instruct the user-agent to send violation reports to the URL specified in the policy's _report-uri_ directive. - -[source] ----- -Content-Security-Policy: script-src https://trustedscripts.example.com; report-uri /csp-report-endpoint/ ----- - -https://www.w3.org/TR/CSP2/#violation-reports[*_Violation reports_*] are standard JSON structures that can be captured either by the web application's own API or by a publicly hosted CSP violation reporting service, such as, https://report-uri.io/[*_REPORT-URI_*]. - -The *_Content-Security-Policy-Report-Only_* header provides the capability for web application authors and administrators to monitor security policies, rather than enforce them. -This header is typically used when experimenting and/or developing security policies for a site. -When a policy is deemed effective, it can be enforced by using the _Content-Security-Policy_ header field instead. - -Given the following response header, the policy declares that scripts may be loaded from one of two possible sources. - -[source] ----- -Content-Security-Policy-Report-Only: script-src 'self' https://trustedscripts.example.com; report-uri /csp-report-endpoint/ ----- - -If the site violates this policy, by attempting to load a script from _evil.com_, the user-agent will send a violation report to the declared URL specified by the _report-uri_ directive, but still allow the violating resource to load nevertheless. - -[[webflux-headers-csp-configure]] -=== Configuring Content Security Policy - -It's important to note that Spring Security *_does not add_* Content Security Policy by default. +Spring Security does not add <> by default, because a reasonable default is impossible to know without context of the application. The web application author must declare the security policy(s) to enforce and/or monitor for the protected resources. For example, given the following security policy: -[source] +.Content Security Policy Example +==== +[source,http] ---- -script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/ +Content-Security-Policy: script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/ ---- +==== You can enable the CSP header using Java configuration as shown below: +.Content Security Policy +==== [source,java] ---- @Bean @@ -380,9 +219,12 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- +==== -To enable the CSP _'report-only'_ header, provide the following Java configuration: +To enable the CSP `report-only` header, provide the following Java configuration: +.Content Security Policy Report Only +==== [source,java] ---- @Bean @@ -400,40 +242,16 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- - -[[webflux-headers-csp-links]] -=== Additional Resources - -Applying Content Security Policy to a web application is often a non-trivial undertaking. -The following resources may provide further assistance in developing effective security policies for your site. - -https://www.html5rocks.com/en/tutorials/security/content-security-policy/[An Introduction to Content Security Policy] - -https://developer.mozilla.org/en-US/docs/Web/Security/CSP[CSP Guide - Mozilla Developer Network] - -https://www.w3.org/TR/CSP2/[W3C Candidate Recommendation] +==== [[webflux-headers-referrer]] == Referrer Policy -https://www.w3.org/TR/referrer-policy[Referrer Policy] is a mechanism that web applications can leverage to manage the referrer field, which contains the last page the user was on. - -Spring Security's approach is to use https://www.w3.org/TR/referrer-policy/[Referrer Policy] header, which provides different https://www.w3.org/TR/referrer-policy/#referrer-policies[policies]: - -[source] ----- -Referrer-Policy: same-origin ----- - -The Referrer-Policy response header instructs the browser to let the destination knows the source where the user was previously. - -[[webflux-headers-referrer-configure]] -=== Configuring Referrer Policy - -Spring Security *_doesn't add_* Referrer Policy header by default. - -You can enable the Referrer-Policy header using Java configuration as shown below: +Spring Security does not add <> headers by default. +You can enable the Referrer Policy header using Java configuration as shown below: +.Referrer Policy Java Configuration +==== [source,java] ---- @Bean @@ -450,28 +268,27 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- +==== [[webflux-headers-feature]] == Feature Policy -https://wicg.github.io/feature-policy/[Feature Policy] is a mechanism that allows web developers to selectively enable, disable, and modify the behavior of certain APIs and web features in the browser. +Spring Security does not add <> headers by default. +The following `Feature-Policy` header: +.Feature-Policy Example +==== [source] ---- Feature-Policy: geolocation 'self' ---- +==== -With Feature Policy, developers can opt-in to a set of "policies" for the browser to enforce on specific features used throughout your site. -These policies restrict what APIs the site can access or modify the browser's default behavior for certain features. - -[[webflux-headers-feature-configure]] -=== Configuring Feature Policy - -Spring Security *_doesn't add_* Feature Policy header by default. - -You can enable the Feature-Policy header using Java configuration as shown below: +can enable the Feature Policy header using Java configuration as shown below: +.Feature-Policy Java Configuration +==== [source,java] ---- @Bean @@ -485,43 +302,40 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http.build(); } ---- +==== -[[webflux-headers-clearsitedata]] +[[webflux-headers-clear-site-data]] == Clear Site Data -https://www.w3.org/TR/clear-site-data/[Clear Site Data] is a mechanism by which any browser-side data - cookies, local storage, and the like - can be removed when an HTTP response contains this header: +Spring Security does not add <> headers by default. +The following Clear-Site-Data header: -[source] +.Clear-Site-Data Example +==== ---- -Clear-Site-Data: "cache", "cookies", "storage", "executionContexts" +Clear-Site-Data: "cache", "cookies" ---- +==== -This is a nice clean-up action to perform on logout. - -[[webflux-headers-clearsitedata-configure]] -=== Configuring Clear Site Data - -Spring Security *_doesn't add_* the Clear Site Data header by default. - -You can configure your application to send down this header on logout like so: +can be sent on log out with the following configuration: +.Clear-Site-Data Java Configuration +==== [source,java] ---- @Bean SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { ServerLogoutHandler securityContext = new SecurityContextServerLogoutHandler(); - ServerLogoutHandler clearSiteData = new HeaderWriterServerLogoutHandler(new ClearSiteDataServerHttpHeadersWriter()); + ClearSiteDataServerHttpHeadersWriter writer = new ClearSiteDataServerHttpHeadersWriter(CACHE, COOKIES); + ServerLogoutHandler clearSiteData = new HeaderWriterServerLogoutHandler(writer); DelegatingServerLogoutHandler logoutHandler = new DelegatingServerLogoutHandler(securityContext, clearSiteData); http // ... .logout() - .logoutHandler(logoutHandler); + .logoutHandler(logoutHandler); return http.build(); } ---- - -[NOTE] -It's not recommended that you configure this header writer via the `headers()` directive. -The reason for this is that any session state, say the `JSESSIONID` cookie, would be removed, effectively logging the user out. +==== diff --git a/docs/manual/src/docs/asciidoc/_includes/servlet/exploits/headers.adoc b/docs/manual/src/docs/asciidoc/_includes/servlet/exploits/headers.adoc index 44f8db8018..9ae0a4afb2 100644 --- a/docs/manual/src/docs/asciidoc/_includes/servlet/exploits/headers.adoc +++ b/docs/manual/src/docs/asciidoc/_includes/servlet/exploits/headers.adoc @@ -1,55 +1,22 @@ -[[headers]] -[[ns-headers]] +[[servlet-headers]] = Security HTTP Response Headers -This section discusses Spring Security's support for adding various security headers to the response. +<> can be used to increase the security of web applications. +This section is dedicated to servlet based support for Security HTTP Response Headers. + +[[servlet-headers-default]] == Default Security Headers -Spring Security allows users to easily inject the default security headers to assist in protecting their application. -The default for Spring Security is to include the following headers: - -[source,http] ----- -Cache-Control: no-cache, no-store, max-age=0, must-revalidate -Pragma: no-cache -Expires: 0 -X-Content-Type-Options: nosniff -Strict-Transport-Security: max-age=31536000 ; includeSubDomains -X-Frame-Options: DENY -X-XSS-Protection: 1; mode=block ----- - -NOTE: Strict-Transport-Security is only added on HTTPS requests - -For additional details on each of these headers, refer to the corresponding sections: - -* <> -* <> -* <> -* <> -* <> +Spring Security provides a <> to provide secure defaults. While each of these headers are considered best practice, it should be noted that not all clients utilize the headers, so additional testing is encouraged. You can customize specific headers. -For example, assume that want your HTTP response headers to look like the following: - -[source,http] ----- -Cache-Control: no-cache, no-store, max-age=0, must-revalidate -Pragma: no-cache -Expires: 0 -X-Content-Type-Options: nosniff -X-Frame-Options: SAMEORIGIN -X-XSS-Protection: 1; mode=block ----- - -Specifically, you want all of the default headers with the following customizations: - -* <> to allow any request from same domain -* <> will not be addded to the response +For example, assume that you want the defaults except you wish to specify `SAMEORIGIN` for <>. You can easily do this with the following Java Configuration: +.Customize Default Security Headers with Java Configuration +==== [source,java] ---- @EnableWebSecurity @@ -57,24 +24,24 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override - protected void configure(HttpSecurity http) throws Exception { + protected void configure(HttpSecurity http) { http // ... .headers(headers -> - headers - .frameOptions(frameOptions -> - frameOptions.sameOrigin() - ) - .httpStrictTransportSecurity(hsts -> - hsts.disable() - ) + headers + .frameOptions(frameOptions -> + frameOptions.sameOrigin() + ) ); } } ---- +==== Alternatively, if you are using Spring Security XML Configuration, you can use the following: +.Customize Default Security Headers with XML Configuration +==== [source,xml] ---- @@ -82,10 +49,10 @@ Alternatively, if you are using Spring Security XML Configuration, you can use t - ---- +==== If you do not want the defaults to be added and want explicit control over what should be used, you can disable the defaults. An example for both Java and XML based configuration is provided below: @@ -98,17 +65,17 @@ If you are using Spring Security's Java Configuration the following will only ad public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - // do not use any default headers unless explicitly listed - .defaultsDisabled() - .cacheControl(withDefaults()) - ); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers + // do not use any default headers unless explicitly listed + .defaultsDisabled() + .cacheControl(withDefaults()) + ); + } } ---- @@ -134,14 +101,14 @@ If necessary, you can disable all of the HTTP Security response headers with the public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers.disable() - ); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers.disable() + ); + } } ---- @@ -156,261 +123,112 @@ If necessary, you can disable all of the HTTP Security response headers with the ---- -[[headers-cache-control]] +[[servlet-headers-cache-control]] == Cache Control -In the past Spring Security required you to provide your own cache control for your web application. -This seemed reasonable at the time, but browser caches have evolved to include caches for secure connections as well. -This means that a user may view an authenticated page, log out, and then a malicious user can use the browser history to view the cached page. -To help mitigate this Spring Security has added cache control support which will insert the following headers into you response. -[source] ----- -Cache-Control: no-cache, no-store, max-age=0, must-revalidate -Pragma: no-cache -Expires: 0 ----- +Spring Security includes <> headers by default. -Simply adding the <>> element with no child elements will automatically add Cache Control and quite a few other protections. -However, if you only want cache control, you can enable this feature using Spring Security's XML namespace with the <>> element and the <> attribute. - -[source,xml] ----- - - - - - - - ----- - -Similarly, you can enable only cache control within Java Configuration with the following: - -[source,java] ----- -@EnableWebSecurity -public class WebSecurityConfig extends -WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .defaultsDisabled() - .cacheControl(withDefaults()) - ); - } -} ----- - -If you actually want to cache specific responses, your application can selectively invoke https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html#setHeader(java.lang.String,java.lang.String)[HttpServletResponse.setHeader(String,String)] to override the header set by Spring Security. +However, if you actually want to cache specific responses, your application can selectively invoke https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html#setHeader(java.lang.String,java.lang.String)[HttpServletResponse.setHeader(String,String)] to override the header set by Spring Security. This is useful to ensure things like CSS, JavaScript, and images are properly cached. When using Spring Web MVC, this is typically done within your configuration. -For example, the following configuration will ensure that the cache headers are set for all of your resources: +Details on how to do this can be found in the https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/web.html#mvc-config-static-resources[Static Resources] portion of the Spring Reference documentation +If necessary, you can also disable Spring Security's cache control HTTP response headers. + +.Cache Control Disabled with Java Configuration +==== [source,java] ---- -@EnableWebMvc -public class WebMvcConfiguration implements WebMvcConfigurer { +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends +WebSecurityConfigurerAdapter { @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry - .addResourceHandler("/resources/**") - .addResourceLocations("/resources/") - .setCachePeriod(31556926); + protected void configure(HttpSecurity http) { + http + // ... + .headers(headers -> + headers.cacheControl(cache -> + cache.disabled() + ) + ); } - - // ... } ---- +==== -[[headers-content-type-options]] +Similarly, you can use the <>> element to disable it: + +.Cache Control Disabled with XML +==== +[source,xml] +---- + + + + + + + +---- +==== + +[[servlet-headers-content-type-options]] == Content Type Options -Historically browsers, including Internet Explorer, would try to guess the content type of a request using https://en.wikipedia.org/wiki/Content_sniffing[content sniffing]. -This allowed browsers to improve the user experience by guessing the content type on resources that had not specified the content type. -For example, if a browser encountered a JavaScript file that did not have the content type specified, it would be able to guess the content type and then execute it. -[NOTE] -=== -There are many additional things one should do (i.e. only display the document in a distinct domain, ensure Content-Type header is set, sanitize the document, etc) when allowing content to be uploaded. -However, these measures are out of the scope of what Spring Security provides. -It is also important to point out when disabling content sniffing, you must specify the content type in order for things to work properly. -=== +Spring Security includes <> headers by default. +However, you can disable it in Java Configuration with: -The problem with content sniffing is that this allowed malicious users to use polyglots (i.e. a file that is valid as multiple content types) to execute XSS attacks. -For example, some sites may allow users to submit a valid postscript document to a website and view it. -A malicious user might create a http://webblaze.cs.berkeley.edu/papers/barth-caballero-song.pdf[postscript document that is also a valid JavaScript file] and execute a XSS attack with it. - -Content sniffing can be disabled by adding the following header to our response: - -[source] +.Content Type Options Disabled with Java Configuration +==== +[source,java] ---- -X-Content-Type-Options: nosniff +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends + WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) { + http + // ... + .headers(headers -> + headers.contentTypeOptions(contentType -> + contentType.disabled() + ) + ); + } +} ---- +==== -Just as with the cache control element, the nosniff directive is added by default when using the element with no child elements. -However, if you want more control over which headers are added you can use the <>> element and the <> attribute as shown below: +Similarly, you can use the <>> element to disable it: +.Content Type Options Disabled with XML +==== [source,xml] ---- - - + + ---- +==== -The X-Content-Type-Options header is added by default with Spring Security Java configuration. -If you want more control over the headers, you can explicitly specify the content type options with the following: - -[source,java] ----- -@EnableWebSecurity -public class WebSecurityConfig extends -WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .defaultsDisabled() - .contentTypeOptions(withDefaults()) - ); - } -} ----- - -[[headers-hsts]] +[[servlet-headers-hsts]] == HTTP Strict Transport Security (HSTS) -When you type in your bank's website, do you enter mybank.example.com or do you enter https://mybank.example.com[]? If you omit the https protocol, you are potentially vulnerable to https://en.wikipedia.org/wiki/Man-in-the-middle_attack[Man in the Middle attacks]. -Even if the website performs a redirect to https://mybank.example.com a malicious user could intercept the initial HTTP request and manipulate the response (i.e. redirect to https://mibank.example.com and steal their credentials). -Many users omit the https protocol and this is why https://tools.ietf.org/html/rfc6797[HTTP Strict Transport Security (HSTS)] was created. -Once mybank.example.com is added as a https://tools.ietf.org/html/rfc6797#section-5.1[HSTS host], a browser can know ahead of time that any request to mybank.example.com should be interpreted as https://mybank.example.com. -This greatly reduces the possibility of a Man in the Middle attack occurring. - -[NOTE] -=== -In accordance with https://tools.ietf.org/html/rfc6797#section-7.2[RFC6797], the HSTS header is only injected into HTTPS responses. -In order for the browser to acknowledge the header, the browser must first trust the CA that signed the SSL certificate used to make the connection (not just the SSL certificate). -=== - -One way for a site to be marked as a HSTS host is to have the host preloaded into the browser. -Another is to add the "Strict-Transport-Security" header to the response. -For example the following would instruct the browser to treat the domain as an HSTS host for a year (there are approximately 31536000 seconds in a year): - -[source] ----- -Strict-Transport-Security: max-age=31536000 ; includeSubDomains ; preload ----- - -The optional includeSubDomains directive instructs Spring Security that subdomains (i.e. secure.mybank.example.com) should also be treated as an HSTS domain. - -The optional preload directive instructs Spring Security that domain should be preloaded in browser as HSTS domain. For more details on HSTS preload please see -https://hstspreload.org. - -As with the other headers, Spring Security adds HSTS by default. -You can customize HSTS headers with the <>> element as shown below: - -[source,xml] ----- - - - - - - - ----- - -Similarly, you can enable only HSTS headers with Java Configuration: - -[source,java] ----- -@EnableWebSecurity -public class WebSecurityConfig extends -WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .httpStrictTransportSecurity(hsts -> - hsts - .includeSubDomains(true) - .preload(true) - .maxAgeInSeconds(31536000) - ) - ); - } -} ----- - -[[headers-hpkp]] -== HTTP Public Key Pinning (HPKP) -HTTP Public Key Pinning (HPKP) is a security feature that tells a web client to associate a specific cryptographic public key with a certain web server to prevent Man in the Middle (MITM) attacks with forged certificates. - -To ensure the authenticity of a server's public key used in TLS sessions, this public key is wrapped into a X.509 certificate which is usually signed by a certificate authority (CA). -Web clients such as browsers trust a lot of these CAs, which can all create certificates for arbitrary domain names. -If an attacker is able to compromise a single CA, they can perform MITM attacks on various TLS connections. -HPKP can circumvent this threat for the HTTPS protocol by telling the client which public key belongs to a certain web server. -HPKP is a Trust on First Use (TOFU) technique. -The first time a web server tells a client via a special HTTP header which public keys belong to it, the client stores this information for a given period of time. -When the client visits the server again, it expects a certificate containing a public key whose fingerprint is already known via HPKP. -If the server delivers an unknown public key, the client should present a warning to the user. - -[NOTE] -=== -Because the user-agent needs to validate the pins against the SSL certificate chain, the HPKP header is only injected into HTTPS responses. -=== - -Enabling this feature for your site is as simple as returning the Public-Key-Pins HTTP header when your site is accessed over HTTPS. -For example, the following would instruct the user-agent to only report pin validation failures to a given URI (via the https://tools.ietf.org/html/rfc7469#section-2.1.4[*_report-uri_*] directive) for 2 pins: - -[source] ----- -Public-Key-Pins-Report-Only: max-age=5184000 ; pin-sha256="d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=" ; pin-sha256="E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=" ; report-uri="https://example.net/pkp-report" ; includeSubDomains ----- - -A https://tools.ietf.org/html/rfc7469#section-3[*_pin validation failure report_*] is a standard JSON structure that can be captured either by the web application's own API or by a publicly hosted HPKP reporting service, such as, https://report-uri.io/[*_REPORT-URI_*]. - -The optional includeSubDomains directive instructs the browser to also validate subdomains with the given pins. - -Opposed to the other headers, Spring Security does not add HPKP by default. -You can customize HPKP headers with the <>> element as shown below: - -[source,xml] ----- - - - - - - - d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM= - E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g= - - - - ----- - -Similarly, you can enable HPKP headers with Java Configuration: +Spring Security provides the <> header by default. +However, you can customize the results explicitly. +For example, the following is an example of explicitly providing HSTS with Java Configuration: +.Strict Transport Security with Java Configuration +==== [source,java] ---- @EnableWebSecurity @@ -422,47 +240,130 @@ WebSecurityConfigurerAdapter { http // ... .headers(headers -> - headers - .httpPublicKeyPinning(hpkp -> - hpkp + headers + .httpStrictTransportSecurity(hsts -> + hsts .includeSubDomains(true) - .reportUri("https://example.net/pkp-report") - .addSha256Pins("d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=", "E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=") - ) + .preload(true) + .maxAgeInSeconds(31536000) + ) ); } } ---- +==== -[[headers-frame-options]] +Similarly, you can explicitly provide HSTS with XML configuration using the <>> element as shown below: + + +.Strict Transport Security with XML Configuration +==== +[source,xml] +---- + + + + + + + +---- +==== + +[[servlet-headers-hpkp]] +== HTTP Public Key Pinning (HPKP) +For passivity reasons, Spring Security provides servlet support for <> but it is <>. + +You can enable HPKP headers with Java Configuration: + +.HTTP Public Key Pinning with Java Configuration +==== +[source,java] +---- +@EnableWebSecurity +public class WebSecurityConfig extends +WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers + .httpPublicKeyPinning(hpkp -> + hpkp + .includeSubDomains(true) + .reportUri("https://example.net/pkp-report") + .addSha256Pins("d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=", "E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=") + ) + ); + } +} +---- +==== + +Similarly you can enable HPKP headers using the <>> element as shown below: + +.HTTP Public Key Pinning with XML Configuration +==== +[source,xml] +---- + + + + + + + d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM= + E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g= + + + + +---- +==== + + +[[servlet-headers-frame-options]] == X-Frame-Options -Allowing your website to be added to a frame can be a security issue. -For example, using clever CSS styling users could be tricked into clicking on something that they were not intending (https://www.youtube.com/watch?v=3mk0RySeNsU[video demo]). -For example, a user that is logged into their bank might click a button that grants access to other users. -This sort of attack is known as https://en.wikipedia.org/wiki/Clickjacking[Clickjacking]. -[NOTE] -=== -Another modern approach to dealing with clickjacking is to use <>. -=== +By default, Spring Security disables rendering within an iframe using <>. -There are a number ways to mitigate clickjacking attacks. -For example, to protect legacy browsers from clickjacking attacks you can use https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet#Best-for-now_Legacy_Browser_Frame_Breaking_Script[frame breaking code]. -While not perfect, the frame breaking code is the best you can do for the legacy browsers. +You can customize frame options to use the same origin within Java Configuration using the following: -A more modern approach to address clickjacking is to use https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options[X-Frame-Options] header: - -[source] +.X-Frame-Options: SAMEORIGIN with Java Configuration +==== +[source,java] ---- -X-Frame-Options: DENY +@EnableWebSecurity +public class WebSecurityConfig extends +WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers + .frameOptions(frameOptions -> + frameOptions + .sameOrigin() + ) + ); + } +} ---- +==== -The X-Frame-Options response header instructs the browser to prevent any site with this header in the response from being rendered within a frame. -By default, Spring Security disables rendering within an iframe. - -You can customize X-Frame-Options with the <> element. -For example, the following will instruct Spring Security to use "X-Frame-Options: SAMEORIGIN" which allows iframes within the same domain: +Alternatively, you can use <> element within XML configuration: +.X-Frame-Options: SAMEORIGIN with XML Configuration +==== [source,xml] ---- @@ -474,50 +375,44 @@ For example, the following will instruct Spring Security to use "X-Frame-Options ---- +==== -Similarly, you can customize frame options to use the same origin within Java Configuration using the following: +[[servlet-headers-xss-protection]] +== X-XSS-Protection + +By default, Spring Security instructs browsers to block reflected XSS attacks using the <. +However, you can change this default. +For example, the following Java Configuration specifies that Spring Security should no longer instruct browsers to block the content: + +.X-XSS-Protection Customization with Java Configuration +==== [source,java] ---- @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .frameOptions(frameOptions -> - frameOptions - .sameOrigin() - ) - ); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers + .xssProtection(xssProtection -> + xssProtection + .block(false) + ) + ); + } } ---- +==== -[[headers-xss-protection]] -== X-XSS-Protection -Some browsers have built in support for filtering out https://www.owasp.org/index.php/Testing_for_Reflected_Cross_site_scripting_(OWASP-DV-001)[reflected XSS attacks]. -This is by no means foolproof, but does assist in XSS protection. - -The filtering is typically enabled by default, so adding the header typically just ensures it is enabled and instructs the browser what to do when a XSS attack is detected. -For example, the filter might try to change the content in the least invasive way to still render everything. -At times, this type of replacement can become a https://hackademix.net/2009/11/21/ies-xss-filter-creates-xss-vulnerabilities/[XSS vulnerability in itself]. -Instead, it is best to block the content rather than attempt to fix it. -To do this we can add the following header: - -[source] ----- -X-XSS-Protection: 1; mode=block ----- - -This header is included by default. -However, we can customize it if we wanted. -For example: +Similarly, the following XML configuration specifies that Spring Security should no longer instruct browsers to block the content: +.X-XSS-Protection Customization with XML Configuration +==== [source,xml] ---- @@ -528,98 +423,55 @@ For example: ---- +==== -Similarly, you can customize XSS protection within Java Configuration with the following: +[[servlet-headers-csp]] +== Content Security Policy (CSP) + +Spring Security does not add <> by default, because a reasonable default is impossible to know without context of the application. +The web application author must declare the security policy(s) to enforce and/or monitor for the protected resources. + +For example, given the following security policy: + +.Content Security Policy Example +==== +[source,http] +---- +Content-Security-Policy: script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/ +---- +==== + +You can enable the CSP header using Java configuration as shown below: + +.Content Security Policy Java Configuration +==== [source,java] ---- @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .xssProtection(xssProtection -> - xssProtection - .block(false) - ) - ); - } + @Override + protected void configure(HttpSecurity http) { + http + // ... + .headers(headers -> + headers + .contentSecurityPolicy(csp -> + csp + .policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/") + ) + ); + } } ---- +==== -[[headers-csp]] -== Content Security Policy (CSP) - -https://www.w3.org/TR/CSP2/[Content Security Policy (CSP)] is a mechanism that web applications can leverage to mitigate content injection vulnerabilities, such as cross-site scripting (XSS). -CSP is a declarative policy that provides a facility for web application authors to declare and ultimately inform the client (user-agent) about the sources from which the web application expects to load resources. - -[NOTE] -=== -Content Security Policy is not intended to solve all content injection vulnerabilities. -Instead, CSP can be leveraged to help reduce the harm caused by content injection attacks. -As a first line of defense, web application authors should validate their input and encode their output. -=== - -A web application may employ the use of CSP by including one of the following HTTP headers in the response: - -* *_Content-Security-Policy_* -* *_Content-Security-Policy-Report-Only_* - -Each of these headers are used as a mechanism to deliver a *_security policy_* to the client. -A security policy contains a set of *_security policy directives_* (for example, _script-src_ and _object-src_), each responsible for declaring the restrictions for a particular resource representation. - -For example, a web application can declare that it expects to load scripts from specific, trusted sources, by including the following header in the response: - -[source] ----- -Content-Security-Policy: script-src https://trustedscripts.example.com ----- - -An attempt to load a script from another source other than what is declared in the _script-src_ directive will be blocked by the user-agent. -Additionally, if the https://www.w3.org/TR/CSP2/#directive-report-uri[*_report-uri_*] directive is declared in the security policy, then the violation will be reported by the user-agent to the declared URL. - -For example, if a web application violates the declared security policy, the following response header will instruct the user-agent to send violation reports to the URL specified in the policy's _report-uri_ directive. - -[source] ----- -Content-Security-Policy: script-src https://trustedscripts.example.com; report-uri /csp-report-endpoint/ ----- - -https://www.w3.org/TR/CSP2/#violation-reports[*_Violation reports_*] are standard JSON structures that can be captured either by the web application's own API or by a publicly hosted CSP violation reporting service, such as, https://report-uri.io/[*_REPORT-URI_*]. - -The *_Content-Security-Policy-Report-Only_* header provides the capability for web application authors and administrators to monitor security policies, rather than enforce them. -This header is typically used when experimenting and/or developing security policies for a site. -When a policy is deemed effective, it can be enforced by using the _Content-Security-Policy_ header field instead. - -Given the following response header, the policy declares that scripts may be loaded from one of two possible sources. - -[source] ----- -Content-Security-Policy-Report-Only: script-src 'self' https://trustedscripts.example.com; report-uri /csp-report-endpoint/ ----- - -If the site violates this policy, by attempting to load a script from _evil.com_, the user-agent will send a violation report to the declared URL specified by the _report-uri_ directive, but still allow the violating resource to load nevertheless. - -[[headers-csp-configure]] -=== Configuring Content Security Policy - -It's important to note that Spring Security *_does not add_* Content Security Policy by default. -The web application author must declare the security policy(s) to enforce and/or monitor for the protected resources. - -For example, given the following security policy: - -[source] ----- -script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/ ----- - -You can enable the CSP header using XML configuration with the <>> element as shown below: +The same can be done using XML configuration with the <>> element as shown below: +.Content Security Policy Java Configuration +==== [source,xml] ---- @@ -631,9 +483,39 @@ You can enable the CSP header using XML configuration with the < ---- +==== -To enable the CSP _'report-only'_ header, configure the element as follows: +To enable the CSP `report-only` header, provide the following Java configuration: +.Content Security Policy Report Only Java Configuration +==== +[source,java] +---- +@EnableWebSecurity +public class WebSecurityConfig extends + WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers + .contentSecurityPolicy(csp -> + csp + .policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/") + .reportOnly() + ) + ); + } +} +---- +==== + +The same can be achieved with XML configuration using: + +.Content Security Policy XML Configuration +==== [source,xml] ---- @@ -646,88 +528,42 @@ To enable the CSP _'report-only'_ header, configure the element as follows: ---- +==== -Similarly, you can enable the CSP header using Java configuration as shown below: - -[source,java] ----- -@EnableWebSecurity -public class WebSecurityConfig extends -WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .contentSecurityPolicy(csp -> - csp - .policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/") - ) - ); - } -} ----- - -To enable the CSP _'report-only'_ header, provide the following Java configuration: - -[source,java] ----- -@EnableWebSecurity -public class WebSecurityConfig extends -WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .contentSecurityPolicy(csp -> - csp - .policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/") - .reportOnly() - ) - ); - } -} ----- - -[[headers-csp-links]] -=== Additional Resources - -Applying Content Security Policy to a web application is often a non-trivial undertaking. -The following resources may provide further assistance in developing effective security policies for your site. - -https://www.html5rocks.com/en/tutorials/security/content-security-policy/[An Introduction to Content Security Policy] - -https://developer.mozilla.org/en-US/docs/Web/Security/CSP[CSP Guide - Mozilla Developer Network] - -https://www.w3.org/TR/CSP2/[W3C Candidate Recommendation] - -[[headers-referrer]] +[[servlet-headers-referrer]] == Referrer Policy -https://www.w3.org/TR/referrer-policy[Referrer Policy] is a mechanism that web applications can leverage to manage the referrer field, which contains the last -page the user was on. +Spring Security does not add <> headers by default. +You can enable the Referrer Policy header using Java configuration as shown below: -Spring Security's approach is to use https://www.w3.org/TR/referrer-policy/[Referrer Policy] header, which provides different https://www.w3.org/TR/referrer-policy/#referrer-policies[policies]: - -[source] +.Referrer Policy Java Configuration +==== +[source,java] ---- -Referrer-Policy: same-origin +@EnableWebSecurity +public class WebSecurityConfig extends +WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) { + http + // ... + .headers(headers -> + headers + .referrerPolicy(referrerPolicy -> + referrerPolicy + .policy(ReferrerPolicy.SAME_ORIGIN) + ) + ); + } +} ---- - -The Referrer-Policy response header instructs the browser to let the destination knows the source where the user was previously. - -[[headers-referrer-configure]] -=== Configuring Referrer Policy - -Spring Security *_doesn't add_* Referrer Policy header by default. +==== You can enable the Referrer-Policy header using XML configuration with the <>> element as shown below: +.Referrer Policy XML Configuration +==== [source,xml] ---- @@ -738,51 +574,51 @@ You can enable the Referrer-Policy header using XML configuration with the < ---- +==== -Similarly, you can enable the Referrer Policy header using Java configuration as shown below: +[[servlet-headers-feature]] +== Feature Policy + +Spring Security does not add <> headers by default. +The following `Feature-Policy` header: + +.Feature-Policy Example +==== +[source] +---- +Feature-Policy: geolocation 'self' +---- +==== + +can enable the Feature Policy header using Java configuration as shown below: + +.Feature-Policy Java Configuration +==== [source,java] ---- @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .referrerPolicy(referrerPolicy -> - referrerPolicy - .policy(ReferrerPolicy.SAME_ORIGIN) - ) - ); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers + .featurePolicy("geolocation 'self'") + ); + } } ---- +==== -[[headers-feature]] -== Feature Policy - -https://wicg.github.io/feature-policy/[Feature Policy] is a mechanism that allows web developers to selectively enable, disable, and modify the behavior of certain APIs and web features in the browser. - -[source] ----- -Feature-Policy: geolocation 'self' ----- - -With Feature Policy, developers can opt-in to a set of "policies" for the browser to enforce on specific features used throughout your site. -These policies restrict what APIs the site can access or modify the browser's default behavior for certain features. - -[[headers-feature-configure]] -=== Configuring Feature Policy - -Spring Security *_doesn't add_* Feature Policy header by default. - -You can enable the Feature-Policy header using XML configuration with the <>> element as shown below: +Alternatively, you can enable the Feature-Policy header using XML configuration with the <>> element as shown below: +.Feature-Policy XML Configuration +==== [source,xml] ---- @@ -793,72 +629,48 @@ You can enable the Feature-Policy header using XML configuration with the < ---- +==== -Similarly, you can enable the Feature Policy header using Java configuration as shown below: - -[source,java] ----- -@EnableWebSecurity -public class WebSecurityConfig extends -WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .featurePolicy("geolocation 'self'") - ); - } -} ----- - -[[headers-clearsitedata]] +[[servlet-headers-clear-site-data]] == Clear Site Data -https://www.w3.org/TR/clear-site-data/[Clear Site Data] is a mechanism by which any browser-side data - cookies, local storage, and the like - can be removed when an HTTP response contains this header: +Spring Security does not add <> headers by default. +The following Clear-Site-Data header: -[source] +.Clear-Site-Data Example +==== ---- -Clear-Site-Data: "cache", "cookies", "storage", "executionContexts" +Clear-Site-Data: "cache", "cookies" ---- +==== -This is a nice clean-up action to perform on logout. - -[[headers-clearsitedata-configure]] -=== Configuring Clear Site Data - -Spring Security *_doesn't add_* the Clear Site Data header by default. - -You can configure your application to send down this header on logout like so: +can be sent on log out with the following configuration: +.Clear-Site-Data Java Configuration +==== [source,java] ---- @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .logout() - .addLogoutHandler(new HeaderWriterLogoutHandler(new ClearSiteDataHeaderWriter(CACHE, COOKIES))); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .logout() + .addLogoutHandler(new HeaderWriterLogoutHandler(new ClearSiteDataHeaderWriter(CACHE, COOKIES))); + } } ---- +==== -[NOTE] -It's not recommended that you configure this header writer via the `headers()` directive. -The reason for this is that any session state, say the `JSESSIONID` cookie, would be removed, effectively logging the user out. - -[[headers-custom]] +[[servlet-headers-custom]] == Custom Headers Spring Security has mechanisms to make it convenient to add the more common security headers to your application. However, it also provides hooks to enable adding custom headers. -[[headers-static]] +[[servlet-headers-static]] === Static Headers There may be times you wish to inject custom security headers into your application that are not supported out of the box. For example, given the following custom security header: @@ -868,8 +680,33 @@ For example, given the following custom security header: X-Custom-Security-Header: header-value ---- +The headers could be added to the response using Java Configuration as shown in the following: + +.StaticHeadersWriter Java Configuration +==== +[source,java] +---- +@EnableWebSecurity +public class WebSecurityConfig extends +WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers + .addHeaderWriter(new StaticHeadersWriter("X-Custom-Security-Header","header-value")) + ); + } +} +---- +==== + When using the XML namespace, these headers can be added to the response using the <>> element as shown below: +.StaticHeadersWriter XML Configuration +==== [source,xml] ---- @@ -880,35 +717,41 @@ When using the XML namespace, these headers can be added to the response using t ---- +==== -Similarly, the headers could be added to the response using Java Configuration as shown in the following: +[[servlet-headers-writer]] +=== Headers Writer +When the namespace or Java configuration does not support the headers you want, you can create a custom `HeadersWriter` instance or even provide a custom implementation of the `HeadersWriter`. + +Let's take a look at an example of using an custom instance of `XFrameOptionsHeaderWriter`. +If you wanted to explicitly configure <> it could be done with the following Java Configuration: + +.Headers Writer Java Configuration +==== [source,java] ---- @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .addHeaderWriter(new StaticHeadersWriter("X-Custom-Security-Header","header-value")) - ); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http + // ... + .headers(headers -> + headers + .addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.SAMEORIGIN)) + ); + } } ---- +==== -[[headers-writer]] -=== Headers Writer -When the namespace or Java configuration does not support the headers you want, you can create a custom `HeadersWriter` instance or even provide a custom implementation of the `HeadersWriter`. - -Let's take a look at an example of using an custom instance of `XFrameOptionsHeaderWriter`. -Perhaps you want to allow framing of content for the same origin. -This is easily supported by setting the <> attribute to "SAMEORIGIN", but let's take a look at a more explicit example using the <> attribute. +Alternatively, we could use the <> attribute for XML based configuration: +.Headers Writer XML Configuration +==== [source,xml] ---- @@ -925,39 +768,48 @@ See https://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsi class="org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter" c:frameOptionsMode="SAMEORIGIN"/> ---- +==== +[[headers-delegatingrequestmatcherheaderwriter]] +=== DelegatingRequestMatcherHeaderWriter -We could also restrict framing of content to the same origin with Java configuration: +At times you may want to only write a header for certain requests. +For example, perhaps you want to only protect your log in page from being framed. +You could use the `DelegatingRequestMatcherHeaderWriter` to do so. +An example of using `DelegatingRequestMatcherHeaderWriter` in Java Configuration can be seen below: +.DelegatingRequestMatcherHeaderWriter Java Configuration +==== [source,java] ---- @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... - .headers(headers -> - headers - .addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.SAMEORIGIN)) - ); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + RequestMatcher matcher = new AntPathRequestMatcher("/login"); + DelegatingRequestMatcherHeaderWriter headerWriter = + new DelegatingRequestMatcherHeaderWriter(matcher,new XFrameOptionsHeaderWriter()); + http + // ... + .headers(headers -> + headers + .frameOptions(frameOptions -> + frameOptions.disable() + ) + .addHeaderWriter(headerWriter) + ); + } } ---- +==== +The same can be achieved with XML based configuration: - -[[headers-delegatingrequestmatcherheaderwriter]] -=== DelegatingRequestMatcherHeaderWriter -At times you may want to only write a header for certain requests. -For example, perhaps you want to only protect your log in page from being framed. -You could use the `DelegatingRequestMatcherHeaderWriter` to do so. -When using the XML namespace configuration, this can be done with the following: - - +.DelegatingRequestMatcherHeaderWriter XML Configuration +==== [source,xml] ---- @@ -981,32 +833,5 @@ When using the XML namespace configuration, this can be done with the following: ---- - - -We could also prevent framing of content to the log in page using java configuration: - - -[source,java] ----- -@EnableWebSecurity -public class WebSecurityConfig extends -WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - RequestMatcher matcher = new AntPathRequestMatcher("/login"); - DelegatingRequestMatcherHeaderWriter headerWriter = - new DelegatingRequestMatcherHeaderWriter(matcher,new XFrameOptionsHeaderWriter()); - http - // ... - .headers(headers -> - headers - .frameOptions(frameOptions -> - frameOptions.disable() - ) - .addHeaderWriter(headerWriter) - ); - } -} ----- +====