@@ -121,6 +121,11 @@ type UpdateRepoFileOptions struct {
121
121
122
122
// UpdateRepoFile adds or updates a file in repository.
123
123
func (repo * Repository ) UpdateRepoFile (doer * User , opts UpdateRepoFileOptions ) (err error ) {
124
+ // 🚨 SECURITY: Prevent uploading files into the ".git" directory
125
+ if isRepositoryGitPath (opts .NewTreeName ) {
126
+ return errors .Errorf ("bad tree path %q" , opts .NewTreeName )
127
+ }
128
+
124
129
repoWorkingPool .CheckIn (com .ToStr (repo .ID ))
125
130
defer repoWorkingPool .CheckOut (com .ToStr (repo .ID ))
126
131
@@ -458,7 +463,8 @@ type UploadRepoFileOptions struct {
458
463
Files []string // In UUID format
459
464
}
460
465
461
- // isRepositoryGitPath returns true if given path is or resides inside ".git" path of the repository.
466
+ // isRepositoryGitPath returns true if given path is or resides inside ".git"
467
+ // path of the repository.
462
468
func isRepositoryGitPath (path string ) bool {
463
469
return strings .HasSuffix (path , ".git" ) ||
464
470
strings .Contains (path , ".git" + string (os .PathSeparator )) ||
@@ -472,7 +478,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
472
478
return nil
473
479
}
474
480
475
- // Prevent uploading files into the ".git" directory
481
+ // 🚨 SECURITY: Prevent uploading files into the ".git" directory
476
482
if isRepositoryGitPath (opts .TreePath ) {
477
483
return errors .Errorf ("bad tree path %q" , opts .TreePath )
478
484
}
@@ -512,7 +518,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
512
518
513
519
upload .Name = pathutil .Clean (upload .Name )
514
520
515
- // Prevent uploading files into the ".git" directory
521
+ // 🚨 SECURITY: Prevent uploading files into the ".git" directory
516
522
if isRepositoryGitPath (upload .Name ) {
517
523
continue
518
524
}
0 commit comments