URL跳转时检查前后跳转的URL是否一致,防止无限跳转

This commit is contained in:
GoEdgeLab
2021-12-02 10:35:51 +08:00
parent 00fcd53ffb
commit dab6efb424

View File

@@ -27,6 +27,12 @@ func (this *HTTPRequest) doHostRedirect() (blocked bool) {
if u.KeepRequestURI { if u.KeepRequestURI {
afterURL += this.RawReq.URL.RequestURI() afterURL += this.RawReq.URL.RequestURI()
} }
// 前后是否一致
if fullURL == afterURL {
return false
}
if u.Status <= 0 { if u.Status <= 0 {
http.Redirect(this.RawWriter, this.RawReq, afterURL, http.StatusTemporaryRedirect) http.Redirect(this.RawWriter, this.RawReq, afterURL, http.StatusTemporaryRedirect)
} else { } else {
@@ -60,6 +66,11 @@ func (this *HTTPRequest) doHostRedirect() (blocked bool) {
} }
} }
// 前后是否一致
if fullURL == afterURL {
return false
}
if u.Status <= 0 { if u.Status <= 0 {
http.Redirect(this.RawWriter, this.RawReq, afterURL, http.StatusTemporaryRedirect) http.Redirect(this.RawWriter, this.RawReq, afterURL, http.StatusTemporaryRedirect)
} else { } else {
@@ -68,6 +79,11 @@ func (this *HTTPRequest) doHostRedirect() (blocked bool) {
return true return true
} else { // 精准匹配 } else { // 精准匹配
if fullURL == u.RealBeforeURL() { if fullURL == u.RealBeforeURL() {
// 前后是否一致
if fullURL == u.AfterURL {
return false
}
if u.Status <= 0 { if u.Status <= 0 {
http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, http.StatusTemporaryRedirect) http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, http.StatusTemporaryRedirect)
} else { } else {