防盗链增加”同时检查Origin选项“

This commit is contained in:
刘祥超
2023-05-02 17:06:24 +08:00
parent b3857adc0f
commit 1beafc9976
2 changed files with 14 additions and 0 deletions

View File

@@ -18,7 +18,14 @@ type RequestRefererBlockCheckpoint struct {
// RequestValue 计算checkpoint值
// 选项allowEmpty, allowSameDomain, allowDomains
func (this *RequestRefererBlockCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
var checkOrigin = options.GetBool("checkOrigin")
var referer = req.WAFRaw().Referer()
if len(referer) == 0 && checkOrigin {
var origin = req.WAFRaw().Header.Get("Origin")
if len(origin) > 0 && origin != "null" {
referer = "https://" + origin // 因为Origin都只有域名部分所以为了下面的URL 分析需要加上https://
}
}
if len(referer) == 0 {
if options.GetBool("allowEmpty") {