Skip to content

Commit

Permalink
Merge branch 'release/v1.21' into lunny/backport_30577
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Apr 22, 2024
2 parents 470b526 + 0e20ccf commit 8a1c230
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ been added to each release, please refer to the [blog](https://blog.gitea.com).
* SECURITY
* Use go1.21.9 to include Golang security fix
* Fix possible renderer security problem (#30136) (#30315)
* Performance optimization for git push and check permissions for push options (#30104) (#30354)
* BUGFIXES
* Fix close file in the Upload func (#30262) (#30269)
* Fix inline math blocks can't be preceeded/followed by alphanumerical characters (#30175) (#30250)
Expand All @@ -18,12 +19,10 @@ been added to each release, please refer to the [blog](https://blog.gitea.com).
* Load attachments for code comments (#30124) (#30126)
* Fix gitea doctor will remove repo-avatar files when executing command storage-archives (#30094) (#30120)
* Fix possible data race on tests (#30093) (#30108)
* Performance optimization for git push (#30104)
* Fix duplicate migrated milestones (#30102) (#30105)
* Fix panic for fixBrokenRepoUnits16961 (#30068) (#30100)
* Fix incorrect SVGs (#30087)
* Fix incorrect SVGs (#30086) (#30087)
* Fix create commit status (#30225) (#30340)
* Performance optimization for git push (#30104) (#30354)
* Fix misuse of unsupported global variables (#30402)
* Fix to delete the cookie when AppSubURL is non-empty (#30375) (#30468)
* Avoid user does not exist error when detecting schedule actions when the commit author is an external user (#30357) (#30408)
Expand Down
2 changes: 1 addition & 1 deletion modules/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func parseCommitFileStatus(fileStatus *CommitFileStatus, stdout io.Reader) {
_, _ = rd.Discard(1)
}
for {
modifier, err := rd.ReadSlice('\x00')
modifier, err := rd.ReadString('\x00')
if err != nil {
if err != io.EOF {
log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
Expand Down
13 changes: 6 additions & 7 deletions modules/session/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ package session
import (
"net/http"

"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web/middleware"

"gitea.com/go-chi/session"
)

Expand All @@ -21,10 +18,12 @@ type Store interface {

// RegenerateSession regenerates the underlying session and returns the new store
func RegenerateSession(resp http.ResponseWriter, req *http.Request) (Store, error) {
// Ensure that a cookie with a trailing slash does not take precedence over
// the cookie written by the middleware.
middleware.DeleteLegacySiteCookie(resp, setting.SessionConfig.CookieName)

for _, f := range BeforeRegenerateSession {
f(resp, req)
}
s, err := session.RegenerateSession(resp, req)
return s, err
}

// BeforeRegenerateSession is a list of functions that are called before a session is regenerated.
var BeforeRegenerateSession []func(http.ResponseWriter, *http.Request)
15 changes: 12 additions & 3 deletions modules/web/middleware/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"strings"

"code.gitea.io/gitea/modules/session"
"code.gitea.io/gitea/modules/setting"
)

Expand Down Expand Up @@ -48,12 +49,12 @@ func SetSiteCookie(resp http.ResponseWriter, name, value string, maxAge int) {
// Previous versions would use a cookie path with a trailing /.
// These are more specific than cookies without a trailing /, so
// we need to delete these if they exist.
DeleteLegacySiteCookie(resp, name)
deleteLegacySiteCookie(resp, name)
}

// DeleteLegacySiteCookie deletes the cookie with the given name at the cookie
// deleteLegacySiteCookie deletes the cookie with the given name at the cookie
// path with a trailing /, which would unintentionally override the cookie.
func DeleteLegacySiteCookie(resp http.ResponseWriter, name string) {
func deleteLegacySiteCookie(resp http.ResponseWriter, name string) {
if setting.SessionConfig.CookiePath == "" || strings.HasSuffix(setting.SessionConfig.CookiePath, "/") {
// If the cookie path ends with /, no legacy cookies will take
// precedence, so do nothing. The exception is that cookies with no
Expand All @@ -74,3 +75,11 @@ func DeleteLegacySiteCookie(resp http.ResponseWriter, name string) {
}
resp.Header().Add("Set-Cookie", cookie.String())
}

func init() {
session.BeforeRegenerateSession = append(session.BeforeRegenerateSession, func(resp http.ResponseWriter, _ *http.Request) {
// Ensure that a cookie with a trailing slash does not take precedence over
// the cookie written by the middleware.
deleteLegacySiteCookie(resp, setting.SessionConfig.CookieName)
})
}
5 changes: 3 additions & 2 deletions routers/web/org/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
shared_user "code.gitea.io/gitea/routers/web/shared/user"
Expand Down Expand Up @@ -100,7 +101,7 @@ func Projects(ctx *context.Context) {
}

for _, project := range projects {
project.RenderedContent = project.Description
project.RenderedContent = string(templates.RenderMarkdownToHtml(ctx, project.Description))
}

err = shared_user.LoadHeaderCount(ctx)
Expand Down Expand Up @@ -391,7 +392,7 @@ func ViewProject(ctx *context.Context) {
}
}

project.RenderedContent = project.Description
project.RenderedContent = string(templates.RenderMarkdownToHtml(ctx, project.Description))
ctx.Data["LinkedPRs"] = linkedPrsMap
ctx.Data["PageIsViewProjects"] = true
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
Expand Down
2 changes: 1 addition & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func Routes() *web.Route {
routes.Get("/metrics", append(mid, Metrics)...)
}

routes.Get("/robots.txt", append(mid, misc.RobotsTxt)...)
routes.Methods("GET,HEAD", "/robots.txt", append(mid, misc.RobotsTxt)...)
routes.Get("/ssh_info", misc.SSHInfo)
routes.Get("/api/healthz", healthcheck.Check)

Expand Down
9 changes: 7 additions & 2 deletions services/actions/notifier_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func newNotifyInput(repo *repo_model.Repository, doer *user_model.User, event we
}
}

func newNotifyInputForSchedules(repo *repo_model.Repository) *notifyInput {
// the doer here will be ignored as we force using action user when handling schedules
return newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
}

func (input *notifyInput) WithDoer(doer *user_model.User) *notifyInput {
input.Doer = doer
return input
Expand Down Expand Up @@ -454,7 +459,7 @@ func handleSchedules(
RepoID: input.Repo.ID,
OwnerID: input.Repo.OwnerID,
WorkflowID: dwf.EntryName,
TriggerUserID: input.Doer.ID,
TriggerUserID: user_model.ActionsUserID,
Ref: ref,
CommitSHA: commit.ID.String(),
Event: input.Event,
Expand Down Expand Up @@ -496,7 +501,7 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
// We need a notifyInput to call handleSchedules
// if repo is a mirror, commit author maybe an external user,
// so we use action user as the Doer of the notifyInput
notifyInput := newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
notifyInput := newNotifyInputForSchedules(repo)

return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
}

0 comments on commit 8a1c230

Please sign in to comment.