【问题标题】:How to enable Content Security Policy in HTTP server如何在 HTTP 服务器中启用内容安全策略
【发布时间】:2021-09-01 13:51:25
【问题描述】:

我们在产品中使用 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

我在配置或其他方面有什么遗漏吗?

【问题讨论】:

  • 我试过用 = 登录Header set X-XSS-Protection="1; mode=block",但还是同样的错误。
  • 其实试试把Header set Content-Security-Policy="default-src 'self';"中的等号去掉。

标签: xss httpd.conf content-security-policy


【解决方案1】:

httpd.conf 的语法与 .htaccess 的语法相同:

<IfModule mod_headers.c>                                                
  Header set X-XSS-Protection "1; mode=block"                
  Header set Content-Security-Policy "default-src 'self';" 
</IfModule>

【讨论】:

    猜你喜欢
    • 2023-04-08
    • 2019-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 2016-06-22
    • 2020-01-25
    • 2015-04-27
    相关资源
    最近更新 更多