# 在Nginx上面 防範XSS攻擊 [參考網站](https://learnku.com/articles/9485/the-best-nginx-configuration-for-improving-security) ![](https://i.imgur.com/cj1k50D.jpg) ### X-XSS-Protection ```nginx add_header X-XSS-Protection "1; mode=block"; ``` 這是用來防範及過濾 XSS 的。指令如下: ```nginx X-XSS-Protection: 0 X-XSS-Protection: 1 X-XSS-Protection: 1; mode=block X-XSS-Protection: 1; report= ``` ### 說明 0,禁用 XSS 過濾 1,開啟 XSS 過濾 1; mode=block,開啟 XSS 過濾,若檢查到 XSS 攻擊,停止渲染網頁 X-XSS-Protection: 1; report=<reporting-uri>,開啟 XSS 過濾,若檢查到 XSS 攻擊,使用指定的 url 來傳送報告。 ![](https://i.imgur.com/F3KEpdn.jpg) ###### tags: `XSS`