martini框架中为什么向http头添加一个header就能防范xss攻击?

正在用Golang写一个简单的web框架,于是读了一下martini的源码,关于安全部分仔细看了看。martini框架有一个中间件用来提供安全防护,其中关于xss防御的部分只有一个函数,函数内容如下:

Golangfunc applyXSS(opt Options, res http.ResponseWriter, req *http.Request) {
    if opt.BrowserXssFilter {
        res.Header().Add(xssProtectionHeader, xssProtectionValue)
    }
}

两个参数定义如下:

Golang    xssProtectionHeader = "X-XSS-Protection"
    xssProtectionValue  = "1; mode=block"

这是什么意思?为什么添加这个头就可以防御xss攻击了?

阅读 6.7k
1 个回答
推荐问题