防盗链增加”同时检查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

@@ -15,6 +15,13 @@ func (this *HTTPRequest) doCheckReferers() (shouldStop bool) {
const cacheSeconds = "3600" // 时间不能过长,防止修改设置后长期无法生效 const cacheSeconds = "3600" // 时间不能过长,防止修改设置后长期无法生效
var refererURL = this.RawReq.Header.Get("Referer") var refererURL = this.RawReq.Header.Get("Referer")
if len(refererURL) == 0 && this.web.Referers.CheckOrigin {
var origin = this.RawReq.Header.Get("Origin")
if len(origin) > 0 && origin != "null" {
refererURL = "https://" + origin // 因为Origin都只有域名部分所以为了下面的URL 分析需要加上https://
}
}
if len(refererURL) == 0 { if len(refererURL) == 0 {
if this.web.Referers.MatchDomain(this.ReqHost, "") { if this.web.Referers.MatchDomain(this.ReqHost, "") {
return return

View File

@@ -18,7 +18,14 @@ type RequestRefererBlockCheckpoint struct {
// RequestValue 计算checkpoint值 // RequestValue 计算checkpoint值
// 选项allowEmpty, allowSameDomain, allowDomains // 选项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) { 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() 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 len(referer) == 0 {
if options.GetBool("allowEmpty") { if options.GetBool("allowEmpty") {