【已解决】“Content-Security-Policy”头缺失

简介: 【已解决】“Content-Security-Policy”头缺失

1、作用

简称CSP,意为内容安全策略,通过设置约束指定可信的内容来源,降低异源文件攻击,例如:js/css/image等

2、相关设置值

指令名

demo

说明

default-src

'self' cdn.example.com

默认策略,可以应用于js文件/图片/css/ajax请求等所有访问

script-src

'self' js.example.com

定义js文件的过滤策略

style-src

'self' css.example.com

定义css文件的过滤策略

img-src

'self' img.example.com

定义图片文件的过滤策略

connect-src

'self'

定义请求连接文件的过滤策略

font-src

font.example.com

定义字体文件的过滤策略

object-src

'self'

定义页面插件的过滤策略,如 <object>, <embed> 或者<applet>等元素

media-src

media.example.com

定义媒体的过滤策略,如 HTML6的 <audio>, <video>等元素

frame-src

'self'

定义加载子frmae的策略

sandbox

allow-forms allow-scripts

沙盒模式,会阻止页面弹窗/js执行等,你可以通过添加allow-forms allow-same-origin allow-scripts allow-popups, allow-modals, allow-orientation-lock, allow-pointer-lock, allow-presentation, allow-popups-to-escape-sandbox, and allow-top-navigation 策略来放开相应的操作

report-uri

/some-report-uri

3、示例:

default-src 'self';只允许同源下的资源

script-src 'self';只允许同源下的js

script-src 'self' www.google-analytics.com ajax.googleapis.com;允许同源以及两个地址下的js加载

default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self';多个资源时,后面的会覆盖前面的

4、在nginx配置文件中添加,例如:

add_header Content-Security-Policy "default-src 'self'";只允许同源下的资源

add_header Content-Security-Policy "upgrade-insecure-requests;content *";将本站内部http链接自动改为https,并不限制内容加载来源。

相关文章
|
8天前
|
存储 缓存 API
HTTP 请求的响应头部字段 Cache-Control 的值为 no-store 是什么意思
HTTP 请求的响应头部字段 Cache-Control 的值为 no-store 是什么意思
84 0
|
6月前
|
前端开发 应用服务中间件
SpringMVC 文件上传 消息 Required request part ‘file‘ is not present描述 由于被认为是客户端对错误(例如:畸形的请求语法、无效的请求信息帧或者
SpringMVC 文件上传 消息 Required request part ‘file‘ is not present描述 由于被认为是客户端对错误(例如:畸形的请求语法、无效的请求信息帧或者
458 0
|
8天前
|
安全 前端开发 Go
Content Security Policy (CSP) 中的 frame-ancestors ‘self‘ 指令介绍
Content Security Policy (CSP) 中的 frame-ancestors ‘self‘ 指令介绍
206 0
JavaWeb - Request 之 Header Key 大小写是否敏感?
JavaWeb - Request 之 Header Key 大小写是否敏感?
656 0
|
8天前
|
安全 JavaScript 前端开发
CSP(Content Security Policy)可以解决什么问题?
CSP(Content Security Policy)可以解决什么问题?
32 0
|
6月前
|
API
什么是 HTTP 响应字段里的 Referrer Policy
什么是 HTTP 响应字段里的 Referrer Policy
28 0
|
7月前
Android-async-http 添加token get方法报错 No valid URI scheme was provided
Android-async-http 添加token get方法报错 No valid URI scheme was provided
|
7月前
|
Web App开发 安全 JavaScript
Content Security Policy 学习笔记之一:定义 script-src 策略
Content Security Policy 学习笔记之一:定义 script-src 策略
95 0
|
8月前
|
安全 JavaScript Java
Content Security Policy 学习笔记之三:CSP 指令的使用方式
Content Security Policy 学习笔记之三:CSP 指令的使用方式
79 0
|
8月前
|
安全 JavaScript 前端开发
关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
39 0

热门文章

最新文章