您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package httplib
  4. import (
  5. "net/url"
  6. "strings"
  7. "code.gitea.io/gitea/modules/setting"
  8. )
  9. // IsRiskyRedirectURL returns true if the URL is considered risky for redirects
  10. func IsRiskyRedirectURL(s string) bool {
  11. // Unfortunately browsers consider a redirect Location with preceding "//", "\\", "/\" and "\/" as meaning redirect to "http(s)://REST_OF_PATH"
  12. // Therefore we should ignore these redirect locations to prevent open redirects
  13. if len(s) > 1 && (s[0] == '/' || s[0] == '\\') && (s[1] == '/' || s[1] == '\\') {
  14. return true
  15. }
  16. u, err := url.Parse(s)
  17. if err != nil || ((u.Scheme != "" || u.Host != "") && !strings.HasPrefix(strings.ToLower(s), strings.ToLower(setting.AppURL))) {
  18. return true
  19. }
  20. return false
  21. }