gitRepo volume: directory must be max 1 level deep

More details on Hackerone #2266560
This commit is contained in:
Imre Rad 2024-04-25 14:21:51 +00:00
parent 8a9031f9c9
commit c7846fd24c
2 changed files with 20 additions and 0 deletions

View File

@ -261,6 +261,12 @@ func validateVolume(src *v1.GitRepoVolumeSource) error {
if err := validateNonFlagArgument(src.Directory, "directory"); err != nil {
return err
}
if (src.Revision != "") && (src.Directory != "") {
cleanedDir := filepath.Clean(src.Directory)
if strings.Contains(cleanedDir, "/") || (strings.Contains(cleanedDir, "\\")) {
return fmt.Errorf("%q is not a valid directory, it must not contain a directory separator", src.Directory)
}
}
return nil
}

View File

@ -267,6 +267,20 @@ func TestPlugin(t *testing.T) {
},
isExpectedFailure: true,
},
{
name: "invalid-revision-directory-combo",
vol: &v1.Volume{
Name: "vol1",
VolumeSource: v1.VolumeSource{
GitRepo: &v1.GitRepoVolumeSource{
Repository: gitURL,
Revision: "main",
Directory: "foo/bar",
},
},
},
isExpectedFailure: true,
},
}
for _, scenario := range scenarios {