• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

lighttpd http响应报文Response增加安全头Referrer-Policy和X-Permitted-Cross-Domain-Policies方法

武飞扬头像
wellnw
帮助1

X-Permitted-Cross-Domain-Policies和Referrer-Policy说明

X-Permitted-Cross-Domain-Policies

       X-Permitted-Cross-Domain-Policies 浏览器提供了许多可选的安全相关功能与特性,这些功能与特性通常可以通过 HTTP 响应头来控制,使用这些功能,可以避免受到浏览器端的用户受到类似CSRF、XSS、Click Hijacking 等前端黑客攻击的影响。Web 服务器对于 HTTP 请 求的响应头中缺少 X-Permitted-Cross-Domain-Policies,这将导致浏览器提供的安全特性失效。 当一些在线的 Web Flash 需要加载其他域的内容时,很多 Web 会通 过设置一个 crossdomain.xml 文件的方式来控制其跨域方式。很有可能有些开发者 并没有修改 crossdomain.xml 文件的权限,但是又有和跨域的 Flash 共享数据的需求,这时候可以通过设置 X-Permitted-Cross-Domain-Policies 头的方式来替代 crossdomain.xml 文件

语法:

X-Permitted-Cross-Domain-Policies: master-only

说明:

  1.  
    none
  2.  
    不允许使用loadPolicyFile方法加载任何策略文件,包括此主策略文件。
  3.  
     
  4.  
    master-only:
  5.  
    只允许使用主策略文件[默认值]。
  6.  
     
  7.  
    by-content-type:
  8.  
    只允许使用loadPolicyFile方法加载HTTP/HTTPS协议下Content-Type 为text/x-cross-domain-policy的文件作为跨域策略文件。
  9.  
     
  10.  
    by-ftp-filename:
  11.  
    只允许使用loadPolicyFile方法加载FTP协议下文件名为 crossdomain.xml的文件作为跨域策略文件。
  12.  
     
  13.  
    all:
  14.  
    可使用loadPolicyFile方法加载目标域上的任何文件作为跨域策略文件,甚至是一 个JPG也可被加载为策略文件

Referrer-Policy

Referrer-Policy 首部用来监管哪些访问来源信息——会在 Referer 中发送——应该被包含在生成的请求当中

语法:

  1.  
    Referrer-Policy: no-referrer
  2.  
    Referrer-Policy: no-referrer-when-downgrade
  3.  
    Referrer-Policy: origin
  4.  
    Referrer-Policy: origin-when-cross-origin
  5.  
    Referrer-Policy: same-origin
  6.  
    Referrer-Policy: strict-origin
  7.  
    Referrer-Policy: strict-origin-when-cross-origin
  8.  
    Referrer-Policy: unsafe-url

说明:

  1.  
    no-referrer
  2.  
    整个 Referer 首部会被移除。访问来源信息不随着请求一起发送。
  3.  
     
  4.  
    no-referrer-when-downgrade (默认值) 在没有指定任何策略的情况下用户代理的默认行为。在同等安全级别的情况下(HTTPS->HTTPS),引用页面的地址会被发送,但是在降级的情况下 (HTTPS->HTTP)不会被发送。
  5.  
     
  6.  
    origin
  7.  
    在任何情况下,仅发送文件的源作为引用地址。例如 https://example.com/page.html 会将 https://example.com/ 作为引用地址。
  8.  
     
  9.  
    origin-when-cross-origin
  10.  
    对于同源的请求,会发送完整的URL作为引用地址,但是对于非同源请求仅发送文件的源。
  11.  
     
  12.  
    same-origin
  13.  
    对于同源的请求会发送引用地址,但是对于非同源请求则不发送引用地址信息。
  14.  
     
  15.  
    strict-origin
  16.  
    在同等安全级别的情况下(HTTPS->HTTPS),发送文件的源作为引用地址,但是在降级的情况下(HTTPS->HTTP)不会发送 。
  17.  
     
  18.  
    strict-origin-when-cross-origin
  19.  
    对于同源的请求,会发送完整的URL作为引用地址;对于非同源,在同等安全级别的情况下(HTTPS->HTTPS),发送文件的源作为引用地址;在降级的情况下(HTTPS->HTTP)不发送此首部。
  20.  
     
  21.  
    unsafe-url
  22.  
    无论是同源请求还是非同源请求,都发送完整的 URL(移除参数信息之后)作为引用地址。 这项设置会将受 TLS 安全协议保

lighttpd修改方法

 在lighttpd.conf文件中增加以下配置

  1.  
     
  2.  
    setenv.add-response-header = (
  3.  
    "X-Permitted-Cross-Domain-Policies" => "master-only"
  4.  
    )
  5.  
    setenv.add-response-header = (
  6.  
    "Referrer-Policy" => "no-referrer-when-downgrade"
  7.  
    )

测试

修改之后重启

lighttpd  /lighttpd -f /etc/lighttpd.conf

修改前响应头

  1.  
    Content-Length: 191
  2.  
    content-security-policy: default-src http:
  3.  
    Content-Type: application/json;charset=UTF-8
  4.  
    Date: Fri, 28 Oct 2022 09:31:15 GMT
  5.  
    permissions-policy: interest-cohort=()
  6.  
    strict-transport-security: max-age=300; includeSubDomains
  7.  
    x-content-type-options: nosniff
  8.  
    x-frame-options: SAMEORIGIN
  9.  
    x-xss-protection: 1; mode=block

 修改后响应头

  1.  
    Content-Length: 224
  2.  
    content-security-policy: default-src http:
  3.  
    Content-Type: application/json;charset=UTF-8
  4.  
    Date: Fri, 28 Oct 2022 10:01:49 GMT
  5.  
    permissions-policy: interest-cohort=()
  6.  
    Referrer-Policy: no-referrer-when-downgrade
  7.  
    strict-transport-security: max-age=300; includeSubDomains
  8.  
    x-content-type-options: nosniff
  9.  
    x-frame-options: SAMEORIGIN
  10.  
    X-Permitted-Cross-Domain-Policies: master-only
  11.  
    x-xss-protection: 1; mode=block

从测试响应可以看到修改之后,响应头增加了以下部分

  1.  
    Referrer-Policy: no-referrer-when-downgrade
  2.  
    X-Permitted-Cross-Domain-Policies: master-only

参考链接

响应头缺失、禁用Options方法、解决跨域-pudn.com

Add HTTP Response Headers in lighttpd • Computer Science and Machine Learning (xarg.org)

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgaagcg
系列文章
更多 icon
同类精品
更多 icon
继续加载