如何在 HTTP 服务器中启用内容安全策略
How to enable Content Security Policy in HTTP server
我们在产品中使用 Apache HTTPS 服务器。作为 XSS(跨站点脚本)的修复程序,我尝试在 httpd.conf 文件中添加 Content-Security-Policy。但它不工作,服务器在这个更改后不启动。
目前我收到来自服务器的响应:
curl -k -I https://IP:Port
HTTP/1.1 200 OK
Date: Wed, 16 Jun 2021 16:53:12 GMT
Set-Cookie: JSESSIONID=xxxxxx; Path=/; Secure
X-Frame-Options: SAMEORIGIN
Cache-Control: no-cache
Content-Length: 1234
Content-Type: text/html;charset=UTF-8
作为在 HTTP 响应中包含 CSP 的修复,我已将 httpd.conf 更新为
Content-Security-Policy: script-src 'self'
在使用“httpd -t”验证语法时出现以下错误:
Invalid command 'Content-Security-Policy:', perhaps misspelled or defined by a module not included in the server configu
ration
还尝试了这些更改:
<IfModule mod_headers.c>
Header set X-XSS-Protection"1; mode=block"
Header set Content-Security-Policy="default-src 'self';"
</IfModule>
现在的语法错误是:
Header requires three arguments
我在配置或其他方面是否遗漏了什么?
httpd.conf
的语法与 .htaccess 的语法相同:
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
Header set Content-Security-Policy "default-src 'self';"
</IfModule>
我们在产品中使用 Apache HTTPS 服务器。作为 XSS(跨站点脚本)的修复程序,我尝试在 httpd.conf 文件中添加 Content-Security-Policy。但它不工作,服务器在这个更改后不启动。
目前我收到来自服务器的响应:
curl -k -I https://IP:Port
HTTP/1.1 200 OK
Date: Wed, 16 Jun 2021 16:53:12 GMT
Set-Cookie: JSESSIONID=xxxxxx; Path=/; Secure
X-Frame-Options: SAMEORIGIN
Cache-Control: no-cache
Content-Length: 1234
Content-Type: text/html;charset=UTF-8
作为在 HTTP 响应中包含 CSP 的修复,我已将 httpd.conf 更新为
Content-Security-Policy: script-src 'self'
在使用“httpd -t”验证语法时出现以下错误:
Invalid command 'Content-Security-Policy:', perhaps misspelled or defined by a module not included in the server configu
ration
还尝试了这些更改:
<IfModule mod_headers.c>
Header set X-XSS-Protection"1; mode=block"
Header set Content-Security-Policy="default-src 'self';"
</IfModule>
现在的语法错误是:
Header requires three arguments
我在配置或其他方面是否遗漏了什么?
httpd.conf
的语法与 .htaccess 的语法相同:
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
Header set Content-Security-Policy "default-src 'self';"
</IfModule>