Address some CodeQL security concerns (#35572)
Although there is no real security problem
This commit is contained in:
@@ -169,7 +169,7 @@ func MoveIssuePin(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
err = issues_model.MovePin(ctx, issue, int(ctx.PathParamInt64("position")))
|
||||
err = issues_model.MovePin(ctx, issue, ctx.PathParamInt("position"))
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
|
||||
@@ -35,7 +35,7 @@ type RepoSearchOptions struct {
|
||||
// This function is also used to render the Admin Repository Management page.
|
||||
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||
// Sitemap index for sitemap paths
|
||||
page := int(ctx.PathParamInt64("idx"))
|
||||
page := ctx.PathParamInt("idx")
|
||||
isSitemap := ctx.PathParam("idx") != ""
|
||||
if page <= 1 {
|
||||
page = ctx.FormInt("page")
|
||||
|
||||
@@ -34,7 +34,7 @@ func isKeywordValid(keyword string) bool {
|
||||
// RenderUserSearch render user search page
|
||||
func RenderUserSearch(ctx *context.Context, opts user_model.SearchUserOptions, tplName templates.TplName) {
|
||||
// Sitemap index for sitemap paths
|
||||
opts.Page = int(ctx.PathParamInt64("idx"))
|
||||
opts.Page = ctx.PathParamInt("idx")
|
||||
isSitemap := ctx.PathParam("idx") != ""
|
||||
if opts.Page <= 1 {
|
||||
opts.Page = ctx.FormInt("page")
|
||||
|
||||
@@ -25,33 +25,28 @@ func Activity(ctx *context.Context) {
|
||||
|
||||
ctx.Data["PageIsPulse"] = true
|
||||
|
||||
ctx.Data["Period"] = ctx.PathParam("period")
|
||||
|
||||
timeUntil := time.Now()
|
||||
var timeFrom time.Time
|
||||
|
||||
switch ctx.Data["Period"] {
|
||||
period, timeFrom := "weekly", timeUntil.Add(-time.Hour*168)
|
||||
switch ctx.PathParam("period") {
|
||||
case "daily":
|
||||
timeFrom = timeUntil.Add(-time.Hour * 24)
|
||||
period, timeFrom = "daily", timeUntil.Add(-time.Hour*24)
|
||||
case "halfweekly":
|
||||
timeFrom = timeUntil.Add(-time.Hour * 72)
|
||||
period, timeFrom = "halfweekly", timeUntil.Add(-time.Hour*72)
|
||||
case "weekly":
|
||||
timeFrom = timeUntil.Add(-time.Hour * 168)
|
||||
period, timeFrom = "weekly", timeUntil.Add(-time.Hour*168)
|
||||
case "monthly":
|
||||
timeFrom = timeUntil.AddDate(0, -1, 0)
|
||||
period, timeFrom = "monthly", timeUntil.AddDate(0, -1, 0)
|
||||
case "quarterly":
|
||||
timeFrom = timeUntil.AddDate(0, -3, 0)
|
||||
period, timeFrom = "quarterly", timeUntil.AddDate(0, -3, 0)
|
||||
case "semiyearly":
|
||||
timeFrom = timeUntil.AddDate(0, -6, 0)
|
||||
period, timeFrom = "semiyearly", timeUntil.AddDate(0, -6, 0)
|
||||
case "yearly":
|
||||
timeFrom = timeUntil.AddDate(-1, 0, 0)
|
||||
default:
|
||||
ctx.Data["Period"] = "weekly"
|
||||
timeFrom = timeUntil.Add(-time.Hour * 168)
|
||||
period, timeFrom = "yearly", timeUntil.AddDate(-1, 0, 0)
|
||||
}
|
||||
ctx.Data["DateFrom"] = timeFrom
|
||||
ctx.Data["DateUntil"] = timeUntil
|
||||
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
|
||||
ctx.Data["Period"] = period
|
||||
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + period)
|
||||
|
||||
canReadCode := ctx.Repo.CanRead(unit.TypeCode)
|
||||
if canReadCode {
|
||||
|
||||
+18
-12
@@ -376,7 +376,7 @@ func (h *serviceHandler) sendFile(ctx *context.Context, contentType, file string
|
||||
ctx.Resp.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
reqFile := filepath.Join(h.getRepoDir(), file)
|
||||
reqFile := filepath.Join(h.getRepoDir(), filepath.Clean(file))
|
||||
|
||||
fi, err := os.Stat(reqFile)
|
||||
if os.IsNotExist(err) {
|
||||
@@ -395,13 +395,12 @@ func (h *serviceHandler) sendFile(ctx *context.Context, contentType, file string
|
||||
var safeGitProtocolHeader = regexp.MustCompile(`^[0-9a-zA-Z]+=[0-9a-zA-Z]+(:[0-9a-zA-Z]+=[0-9a-zA-Z]+)*$`)
|
||||
|
||||
func prepareGitCmdWithAllowedService(service string) (*gitcmd.Command, error) {
|
||||
if service == "receive-pack" {
|
||||
return gitcmd.NewCommand("receive-pack"), nil
|
||||
if service == ServiceTypeReceivePack {
|
||||
return gitcmd.NewCommand(ServiceTypeReceivePack), nil
|
||||
}
|
||||
if service == "upload-pack" {
|
||||
return gitcmd.NewCommand("upload-pack"), nil
|
||||
if service == ServiceTypeUploadPack {
|
||||
return gitcmd.NewCommand(ServiceTypeUploadPack), nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("service %q is not allowed", service)
|
||||
}
|
||||
|
||||
@@ -464,11 +463,16 @@ func serviceRPC(ctx *context.Context, h *serviceHandler, service string) {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
ServiceTypeUploadPack = "upload-pack"
|
||||
ServiceTypeReceivePack = "receive-pack"
|
||||
)
|
||||
|
||||
// ServiceUploadPack implements Git Smart HTTP protocol
|
||||
func ServiceUploadPack(ctx *context.Context) {
|
||||
h := httpBase(ctx)
|
||||
if h != nil {
|
||||
serviceRPC(ctx, h, "upload-pack")
|
||||
serviceRPC(ctx, h, ServiceTypeUploadPack)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,16 +480,18 @@ func ServiceUploadPack(ctx *context.Context) {
|
||||
func ServiceReceivePack(ctx *context.Context) {
|
||||
h := httpBase(ctx)
|
||||
if h != nil {
|
||||
serviceRPC(ctx, h, "receive-pack")
|
||||
serviceRPC(ctx, h, ServiceTypeReceivePack)
|
||||
}
|
||||
}
|
||||
|
||||
func getServiceType(ctx *context.Context) string {
|
||||
serviceType := ctx.Req.FormValue("service")
|
||||
if !strings.HasPrefix(serviceType, "git-") {
|
||||
return ""
|
||||
switch ctx.Req.FormValue("service") {
|
||||
case "git-" + ServiceTypeUploadPack:
|
||||
return ServiceTypeUploadPack
|
||||
case "git-" + ServiceTypeReceivePack:
|
||||
return ServiceTypeReceivePack
|
||||
}
|
||||
return strings.TrimPrefix(serviceType, "git-")
|
||||
return ""
|
||||
}
|
||||
|
||||
func updateServerInfo(ctx gocontext.Context, dir string) []byte {
|
||||
|
||||
@@ -279,7 +279,7 @@ func handleRepoViewSubmodule(ctx *context.Context, commitSubmoduleFile *git.Comm
|
||||
ctx.Data["NotFoundPrompt"] = redirectLink
|
||||
ctx.NotFound(nil)
|
||||
} else {
|
||||
ctx.Redirect(submoduleWebLink.CommitWebLink)
|
||||
ctx.RedirectToCurrentSite(redirectLink)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ func AvatarByUsernameSize(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
cacheableRedirect(ctx, user.AvatarLinkWithSize(ctx, int(ctx.PathParamInt64("size"))))
|
||||
cacheableRedirect(ctx, user.AvatarLinkWithSize(ctx, ctx.PathParamInt("size")))
|
||||
}
|
||||
|
||||
// AvatarByEmailHash redirects the browser to the email avatar link
|
||||
|
||||
Reference in New Issue
Block a user