Refactor URL detection (#29960)

"Redirect" functions should only redirect if the target is for current Gitea site.
This commit is contained in:
wxiaoguang authored and GitHub committed 2024-03-21 12:02:34 +00:00
1 parent 0b4ff15356
commit 01500957c2
9 files changed
+96 -43

No files matched your search

+3 -3
View File
@@ -44,14 +44,14 @@ func RedirectToUser(ctx *Base, userName string, redirectUserID int64) {
ctx.Redirect(path.Join(setting.AppSubURL, redirectPath), http.StatusTemporaryRedirect)
}
// RedirectToFirst redirects to first not empty URL
func (ctx *Context) RedirectToFirst(location ...string) {
// RedirectToCurrentSite redirects to first not empty URL which belongs to current site
func (ctx *Context) RedirectToCurrentSite(location ...string) {
for _, loc := range location {
if len(loc) == 0 {
continue
}
if httplib.IsRiskyRedirectURL(loc) {
if !httplib.IsCurrentGiteaSiteURL(loc) {
continue
}