新聞中心
什么是Content Security Policy(CSP)
Content Security Policy是一種網(wǎng)頁安全策略,現(xiàn)代瀏覽器使用它來增強(qiáng)網(wǎng)頁的安全性??梢酝ㄟ^Content Security Policy來限制哪些資源(如JavaScript、CSS、圖像等)可以被加載,從哪些url加載。

站在用戶的角度思考問題,與客戶深入溝通,找到天壇街道網(wǎng)站設(shè)計(jì)與天壇街道網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、主機(jī)域名、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋天壇街道地區(qū)。
CSP 本質(zhì)上是白名單機(jī)制,開發(fā)者明確告訴瀏覽器哪些外部資源可以加載和執(zhí)行,可以從哪些url加載資源。
CSP最初被設(shè)計(jì)用來減少跨站點(diǎn)腳本攻擊(XSS),該規(guī)范的后續(xù)版本還可以防止其他形式的攻擊,如點(diǎn)擊劫持。
啟用CSP的兩種方法
啟用CSP的方法有兩種,第一種是通過設(shè)置一個(gè)HTTP響應(yīng)頭(HTTP response header) “Content-Security-Policy”,第二種是通過HTML標(biāo)簽設(shè)置,例如:
除了Content-Security-Policy外,還有一個(gè)Content-Security-Policy-Report-Only字段,表示不執(zhí)行限制選項(xiàng),只是記錄違反限制的行為,必須與report-uri值選項(xiàng)配合使用,例如:
Content-Security-Policy-Report-Only: default-src 'self'; report-uri /some-report-uri;
CSP指令介紹
Content-Security-Policy值由一個(gè)或多個(gè)指令組成,多個(gè)指令用分號(hào)分隔。
csp資源加載項(xiàng)限制指令如下:
script-src:外部腳本
style-src:樣式文件
img-src:圖片文件
media-src:媒體文件(音頻和視頻)
font-src:字體文件
object-src:插件(比如 Flash)
child-src:框架
frame-ancestors:嵌入的外部資源(比如、
上述指令對(duì)應(yīng)的值如下:
|
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.cdxwcx.com |
img-src domain.cdxwcx.com |
Allows loading resources from the specified domain name. |
|
*.cdxwcx.com |
img-src *.cdxwcx.com |
Allows loading resources from any subdomain under cdxwcx.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: |


咨詢
建站咨詢