From 9b37b1569c2d466dc8293ed482c1549aa9a6d4a9 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 25 Dec 2018 10:01:52 -0500 Subject: models/repo_editor: add isRepositoryGitPath to detect invalid file path (#5558) --- models/repo_editor.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'models/repo_editor.go') diff --git a/models/repo_editor.go b/models/repo_editor.go index 62914c6d..bb4b6300 100644 --- a/models/repo_editor.go +++ b/models/repo_editor.go @@ -443,6 +443,11 @@ type UploadRepoFileOptions struct { Files []string // In UUID format } +// isRepositoryGitPath returns true if given path is or resides inside ".git" path of the repository. +func isRepositoryGitPath(path string) bool { + return strings.HasSuffix(path, ".git") || strings.Contains(path, ".git"+string(os.PathSeparator)) +} + func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) (err error) { if len(opts.Files) == 0 { return nil @@ -480,7 +485,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) } // Prevent copying files into .git directory, see https://github.com/gogs/gogs/issues/5558. - if strings.HasPrefix(upload.Name, ".git/") { + if isRepositoryGitPath(upload.Name) { continue } -- cgit v1.2.3