-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Fix bug when push to prs with allow edits from maintainers and lfs usage #36376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
services/lfs/server.go
Outdated
| func normalizeLFSRefName(raw string) string { | ||
| ref := strings.TrimSpace(raw) | ||
| if ref == "" { | ||
| return "" | ||
| } | ||
| prefixes := []string{"refs/heads/", "refs/remotes/", "refs/"} | ||
| for _, prefix := range prefixes { | ||
| if trimmed, ok := strings.CutPrefix(ref, prefix); ok { | ||
| ref = trimmed | ||
| break | ||
| } | ||
| } | ||
| return ref | ||
| } | ||
|
|
||
| func refNameFromBatchRequest(br *lfs_module.BatchRequest) string { | ||
| if br == nil || br.Ref == nil { | ||
| return "" | ||
| } | ||
| return normalizeLFSRefName(br.Ref.Name) | ||
| } | ||
|
|
||
| func setLFSRefInContext(ctx *context.Context, ref string) { | ||
| ref = normalizeLFSRefName(ref) | ||
| if ref == "" { | ||
| return | ||
| } | ||
| if ctx.Data == nil { | ||
| ctx.Data = make(map[string]any) | ||
| } | ||
| ctx.Data[lfsRefContextKey] = ref | ||
| } | ||
|
|
||
| func getLFSRefFromContext(ctx *context.Context) string { | ||
| if ctx.Data == nil { | ||
| return "" | ||
| } | ||
| if ref, ok := ctx.Data[lfsRefContextKey].(string); ok { | ||
| return ref | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func setLFSRefFromQuery(ctx *context.Context) { | ||
| ref := ctx.Req.URL.Query().Get(lfsRefQueryKey) | ||
| setLFSRefInContext(ctx, ref) | ||
| } | ||
|
|
||
| func appendRefQuery(baseURL, ref string) string { | ||
| if ref == "" { | ||
| return baseURL | ||
| } | ||
| return baseURL + "?" + lfsRefQueryKey + "=" + url.QueryEscape(ref) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't understand why these newly added function can be right or necessary.
|
I really don't understand what you are doing. You always have the |
| if ref == "" { | ||
| return baseURL | ||
| } | ||
| return baseURL + "?" + lfsRefQueryKey + "=" + url.QueryEscape(ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if baseURL contains ?
|
|
||
| branchName := refName.BranchName() | ||
| if branchName == "" { | ||
| if strings.HasPrefix(ref, "refs/") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
| } | ||
| } | ||
|
|
||
| func canMaintainerWriteLFS(ctx *context.Context, perm access_model.Permission, user *user_model.User, ref string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to clearly document and test this behavior:
refcan be anything passed by the user, it is not fully trusted- if a PR branch is set "allow maintainer edit", a maintainer can pass that branch name and fully write all the LFS objects in the head repo, there is no check / no relation between the branch and LFS objects.
Fix #35226