如何添加 X-XSS-Protection: 1;模式=块HTML

How to add X-XSS-Protection: 1; mode=block HTML

我不知道如何将这部分代码添加到我的代码中。 它应该在 header 部分吗?

<head>
<meta content="text/html; charset=UTF-8; X-Content-Type-Options=nosniff" http-equiv="Content-Type" />
<title>TestWebsite</title>
</head>

问题是我必须将它添加到我的代码中,因为我进行了安全扫描,发现缺少 X-XSS 保护。

  1. 无法在 HTML 页面上添加。
  2. 它必须作为响应添加到您的服务器页面。

例如您可以根据需要添加以下任何选项。

PHP

header("X-XSS-Protection: 0");

.htaccess

Header set x-xss-protection "1; mode=block"

Apache 配置文件:

<IfModule mod_headers.c>
    Header set X-XSS-Protection: "1; mode=block"
</IfModule>