Skip to content
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

SECURITY: prevent DeleteFilePost doing arbitrary deletion #5631

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
SECURITY: protect DeleteFilePost et al with cleanUploadFileName
    This commit wraps more of the TreePaths with cleanUploadFileName

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Jan 4, 2019
commit d87fcfca1143cb3f1967ddaf1998a6b50dcb4a0f
20 changes: 18 additions & 2 deletions routers/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
branchName = form.NewBranchName
}

form.TreePath = strings.Trim(path.Clean("/"+form.TreePath), " /")
form.TreePath = cleanUploadFileName(form.TreePath)
if len(form.TreePath) == 0 {
ctx.Error(500, "Upload file name is invalid")
zeripath marked this conversation as resolved.
Show resolved Hide resolved
return
}
treeNames, treePaths := getParentTreeFields(form.TreePath)

ctx.Data["TreePath"] = form.TreePath
Expand Down Expand Up @@ -373,6 +377,13 @@ func DeleteFile(ctx *context.Context) {
func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
ctx.Data["PageIsDelete"] = true
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()

ctx.Repo.TreePath = cleanUploadFileName(ctx.Repo.TreePath)
if len(ctx.Repo.TreePath) == 0 {
ctx.Error(500, "Delete file name is invalid")
return
}

ctx.Data["TreePath"] = ctx.Repo.TreePath
canCommit := renderCommitRights(ctx)

Expand Down Expand Up @@ -477,7 +488,12 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
branchName = form.NewBranchName
}

form.TreePath = strings.Trim(path.Clean("/"+form.TreePath), " /")
form.TreePath = cleanUploadFileName(form.TreePath)
if len(form.TreePath) == 0 {
ctx.Error(500, "Upload file name is invalid")
return
}

treeNames, treePaths := getParentTreeFields(form.TreePath)
if len(treeNames) == 0 {
// We must at least have one element for user to input.
Expand Down