成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Web安全之Content Security Policy(CSP 內容安全策略)詳解

安全 應用安全
CSP對于保護Web應用程序的安全非常重要,可以幫助減少很多XSS類攻擊。需要注意的是,CSP只是一種安全策略,不能完全保證網站的安全性。因此,在使用CSP時,還需要結合其他安全措施,如使用HTTPS、防火墻等,進一步提高網站的安全性。

什么是Content Security Policy(CSP)

Content Security Policy是一種網頁安全策略,現代瀏覽器使用它來增強網頁的安全性。可以通過Content Security Policy來限制哪些資源(如JavaScript、CSS、圖像等)可以被加載,從哪些url加載。

CSP 本質上是白名單機制,開發者明確告訴瀏覽器哪些外部資源可以加載和執行,可以從哪些url加載資源。

CSP最初被設計用來減少跨站點腳本攻擊(XSS),該規范的后續版本還可以防止其他形式的攻擊,如點擊劫持。

啟用CSP的兩種方法

啟用CSP的方法有兩種,第一種是通過設置一個HTTP響應頭(HTTP response header) “Content-Security-Policy”,第二種是通過HTML標簽<meta>設置,例如:

<meta http-equiv="Content-Security-Policy" content="script-src 'self'; object-src 'none'">

除了Content-Security-Policy外,還有一個Content-Security-Policy-Report-Only字段,表示不執行限制選項,只是記錄違反限制的行為,必須與report-uri值選項配合使用,例如:

Content-Security-Policy-Report-Only: default-src 'self'; report-uri /some-report-uri;

CSP指令介紹

Content-Security-Policy值由一個或多個指令組成,多個指令用分號分隔。

csp資源加載項限制指令如下:

script-src:外部腳本
style-src:樣式文件
img-src:圖片文件
media-src:媒體文件(音頻和視頻)
font-src:字體文件
object-src:插件(比如 Flash)
child-src:框架
frame-ancestors:嵌入的外部資源(比如<frame><iframe><embed><applet>
connect-src:HTTP 連接(通過 XHR、WebSockets、EventSource等)
worker-src:worker腳本
manifest-src:manifest 文件
default-src:用來設置上面各個選項的默認值。

上述指令對應的值如下:

Source Value

Example

Description

*

img-src *

Wildcard, allows any URL except data: blob: filesystem: schemes.

'none'

object-src 'none'

Prevents loading resources from any source.

'self'

script-src 'self'

Allows loading resources from the same origin (same scheme, host and port).

data:

img-src 'self' data:

Allows loading resources via the data scheme (eg Base64 encoded images).

domain.example.com

img-src domain.example.com

Allows loading resources from the specified domain name.

*.example.com

img-src *.example.com

Allows loading resources from any subdomain under example.com.

??https://cdn.com??

img-src https://cdn.com

Allows loading resources only over HTTPS matching the given domain.

https:

img-src https:

Allows loading resources only over HTTPS on any domain.

'unsafe-inline'

script-src 'unsafe-inline'

Allows use of inline source elements such as style attribute, onclick, or script tag bodies (depends on the context of the source it is applied to) and javascript: URIs

'unsafe-eval'

script-src 'unsafe-eval'

Allows unsafe dynamic code evaluation such as JavaScript eval()

'sha256-'

script-src 'sha256-xyz...'

Allows an inline script or CSS to execute if its hash matches the specified hash in the header. Currently supports SHA256, SHA384 or SHA512. CSP Level 2

'nonce-'

script-src 'nonce-rAnd0m'

Allows an inline script or CSS to execute if the script (eg: <script nonce="rAnd0m">) tag contains a nonce attribute matching the nonce specifed in the CSP header. The nonce should be a secure random string, and should not be reused. CSP Level 2

'strict-dynamic'

script-src 'strict-dynamic'

Enables an allowed script to load additional scripts via non-"parser-inserted" script elements (for example document.createElement('script'); is allowed). CSP Level 3

'unsafe-hashes'

script-src 'unsafe-hashes' 'sha256-abc...'

Allows you to enable scripts in event handlers (eg onclick). Does not apply to javascript: or inline <script> CSP Level 3

CSP URL限制指令如下:

frame-ancestors:限制嵌入框架的網頁
base-uri:限制<base#href>
form-action:限制<form#action>

CSP其它限制指令如下:

block-all-mixed-content:HTTPS 網頁不得加載HTTP鏈接的資源
upgrade-insecure-requests:自動將網頁加載的外部資源的鏈接由HTTP改為HTTPS
plugin-types:限制可以使用的插件格式
sandbox:瀏覽器行為的限制,比如不能有彈出窗口等。

小結

CSP對于保護Web應用程序的安全非常重要,可以幫助減少很多XSS類攻擊。需要注意的是,CSP只是一種安全策略,不能完全保證網站的安全性。因此,在使用CSP時,還需要結合其他安全措施,如使用HTTPS、防火墻等,進一步提高網站的安全性。

責任編輯:姜華 來源: 今日頭條
相關推薦

2014-04-21 10:24:06

2024-07-30 14:31:01

2012-11-14 17:18:58

2011-06-20 13:29:44

2015-09-02 10:21:55

2020-02-02 09:23:44

軟件安全滲透測試信息安全

2010-09-17 14:50:06

2024-01-10 08:03:50

數據安全網絡安全

2011-03-23 10:58:52

2009-08-05 10:49:50

信息安全策略安全管理

2013-02-20 10:33:28

Windows安全策略

2015-01-13 09:08:54

內容安全策略CSP

2017-02-07 09:28:29

云安全策略云計算

2022-02-13 00:13:26

云安全數據安全

2011-08-19 14:29:52

2010-05-05 15:38:31

Oracle安全策略

2010-06-03 17:02:49

2017-03-31 09:27:05

2010-01-05 11:00:54

2012-11-09 10:55:44

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 观看av| 91av导航 | 国产精品区二区三区日本 | av黄色在线| 久久久久久美女 | 日韩网站免费观看 | 免费精品国产 | 久久精品国产一区二区三区不卡 | 成人h动漫精品一区二区器材 | 午夜精品一区二区三区免费视频 | 久久在线精品 | 成人精品视频在线观看 | 日韩一区二区三区在线 | 亚洲看片网站 | 国产精品不卡视频 | 久久精品视频在线播放 | 狠狠爱免费视频 | 国产日韩精品在线 | 高清国产午夜精品久久久久久 | 成人免费在线小视频 | 网络毛片| 成人免费看 | 欧美三级在线 | 福利成人 | 欧美日韩国产中文 | 一级黄色片网址 | 天天插天天干 | 久久婷婷av| 亚洲一二三在线观看 | 日本精品一区二区在线观看 | 欧产日产国产精品国产 | www.日本在线| 天天操天天干天天爽 | 青草视频在线 | 人人看人人草 | 久久中文字幕视频 | 欧美日韩中文在线观看 | 日韩欧美精品在线 | 亚洲国产精品成人综合久久久 | 久久精品一区二区三区四区 | 亚洲一区久久 |