@@ -119,7 +119,7 @@ type UpdateRepoFileOptions struct {
119
119
120
120
// UpdateRepoFile adds or updates a file in repository.
121
121
func (repo * Repository ) UpdateRepoFile (doer * User , opts UpdateRepoFileOptions ) (err error ) {
122
- // 🚨 SECURITY: Prevent uploading files into the ".git" directory
122
+ // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
123
123
if isRepositoryGitPath (opts .NewTreeName ) {
124
124
return errors .Errorf ("bad tree path %q" , opts .NewTreeName )
125
125
}
@@ -220,7 +220,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
220
220
221
221
// GetDiffPreview produces and returns diff result of a file which is not yet committed.
222
222
func (repo * Repository ) GetDiffPreview (branch , treePath , content string ) (diff * gitutil.Diff , err error ) {
223
- // 🚨 SECURITY: Prevent uploading files into the ".git" directory
223
+ // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
224
224
if isRepositoryGitPath (treePath ) {
225
225
return nil , errors .Errorf ("bad tree path %q" , treePath )
226
226
}
@@ -243,7 +243,8 @@ func (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *
243
243
return nil , fmt .Errorf ("write file: %v" , err )
244
244
}
245
245
246
- cmd := exec .Command ("git" , "diff" , treePath )
246
+ // 🚨 SECURITY: Prevent including unintended options in the path to the git command.
247
+ cmd := exec .Command ("git" , "diff" , "--end-of-options" , treePath )
247
248
cmd .Dir = localPath
248
249
cmd .Stderr = os .Stderr
249
250
@@ -288,7 +289,7 @@ type DeleteRepoFileOptions struct {
288
289
}
289
290
290
291
func (repo * Repository ) DeleteRepoFile (doer * User , opts DeleteRepoFileOptions ) (err error ) {
291
- // 🚨 SECURITY: Prevent uploading files into the ".git" directory
292
+ // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
292
293
if isRepositoryGitPath (opts .TreePath ) {
293
294
return errors .Errorf ("bad tree path %q" , opts .TreePath )
294
295
}
@@ -513,7 +514,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
513
514
return nil
514
515
}
515
516
516
- // 🚨 SECURITY: Prevent uploading files into the ".git" directory
517
+ // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
517
518
if isRepositoryGitPath (opts .TreePath ) {
518
519
return errors .Errorf ("bad tree path %q" , opts .TreePath )
519
520
}
@@ -554,7 +555,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
554
555
// 🚨 SECURITY: Prevent path traversal.
555
556
upload .Name = pathutil .Clean (upload .Name )
556
557
557
- // 🚨 SECURITY: Prevent uploading files into the ".git" directory
558
+ // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
558
559
if isRepositoryGitPath (upload .Name ) {
559
560
continue
560
561
}
0 commit comments