服務端設置CSP(Content Security Policy,即內(nèi)容安全策略)
通過設置 HTTP 響應頭來聲明 CSP 和X-Frame-Options,例如:
# 不允許被嵌入,包括<frame>, <iframe>, <object>, <embed> 和 <applet> Content-Security-Policy: frame-ancestors 'none' # 只允許被同源的頁面嵌入 Content-Security-Policy: frame-ancestors 'self' # 只允許被白名單內(nèi)的頁面嵌入 Content-Security-Policy: frame-ancestors www.example.com # 不允許被嵌入,包括<frame>, <iframe>, <embed> 和 <object> X-Frame-Options: deny # 只允許被同源的頁面嵌入 X-Frame-Options: sameorigin # (已廢棄)只允許被白名單內(nèi)的頁面嵌入 X-Frame-Options: allow-from www.example.com
相關文章