Skip to content

Commit abad3bb

Browse files
authored
repo: prevent preview and delete files in .git directories (gogs#7870)
## Describe the pull request Fixes GHSA-ccqv-43vm-4f3w
1 parent 858fc74 commit abad3bb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

internal/database/repo_editor.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
220220

221221
// GetDiffPreview produces and returns diff result of a file which is not yet committed.
222222
func (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *gitutil.Diff, err error) {
223+
// 🚨 SECURITY: Prevent uploading files into the ".git" directory
224+
if isRepositoryGitPath(treePath) {
225+
return nil, errors.Errorf("bad tree path %q", treePath)
226+
}
227+
223228
repoWorkingPool.CheckIn(com.ToStr(repo.ID))
224229
defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
225230

@@ -283,6 +288,11 @@ type DeleteRepoFileOptions struct {
283288
}
284289

285290
func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (err error) {
291+
// 🚨 SECURITY: Prevent uploading files into the ".git" directory
292+
if isRepositoryGitPath(opts.TreePath) {
293+
return errors.Errorf("bad tree path %q", opts.TreePath)
294+
}
295+
286296
repoWorkingPool.CheckIn(com.ToStr(repo.ID))
287297
defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
288298

0 commit comments

Comments
 (0)