security_headers_xss

The `security_headers_xss` directive configures the X-XSS-Protection HTTP header to protect against cross-site scripting attacks.

Syntaxsecurity_headers_xss on | off | block;
Defaultoff
Contexthttp, server, location
Arguments1

Description

The security_headers_xss directive is part of the NGINX module for sending security headers. This directive allows you to set the value of the X-XSS-Protection HTTP header, which is used to enable or disable the built-in cross-site scripting (XSS) filter in browsers. With this directive, you can specify whether to turn on this protection, block the page if an attack is detected, or turn it off completely. The directive accepts three primary parameters: off, which disables the protection; on, which enables the filter and allows the browser to sanitize the page; and block, which tells the browser to block the page if an attack is detected. This level of configuration helps website administrators to prevent XSS attacks by providing an essential security layer directly within the HTTP response headers.

The behavior of this directive is contingent upon the capabilities of the client's browser, as not all browsers support the XSS filter in the same way. For instance, modern browsers may ignore the header if they have their own XSS protection mechanisms. It is also worth noting that while this header can help mitigate some XSS risks, it should not be relied upon as the sole security measure; comprehensive web application security practices are still necessary. Overall, the security_headers_xss directive contributes to the security posture of an NGINX-based application by adapting a key web security header into the server's response to requests.

Config Example

http {
    security_headers on;
    security_headers_xss on;
}

Remember to test the behavior of the XSS protection in various browsers, as they might handle this header differently.

Using off might expose your application to XSS attacks, so ensure you have other protections in place.

The block option may lead to users experiencing access issues if legitimate requests are mistakenly flagged as attacking. Always monitor the impact of this setting.

← Back to all directives