@@ -59,6 +59,58 @@ func TestManager_Config(t *testing.T) {
5959 },
6060 },
6161 },
62+ {
63+ name : "repository name with path traversal" ,
64+ setup : func (t * testing.T , dir string ) {
65+ config := repo.Config {
66+ Repositories : []repo.Repository {
67+ {
68+ Name : filepath .Join (".." , ".." , "outside-target" ),
69+ URL : "https://example.com/repo" ,
70+ Enabled : true ,
71+ },
72+ },
73+ }
74+ configPath := filepath .Join (dir , ".trivy" , "vex" , "repository.yaml" )
75+ testutil .MustWriteYAML (t , configPath , config )
76+ },
77+ wantErr : "invalid repository name" ,
78+ },
79+ {
80+ name : "repository name with absolute path" ,
81+ setup : func (t * testing.T , dir string ) {
82+ config := repo.Config {
83+ Repositories : []repo.Repository {
84+ {
85+ // dir is t.TempDir(), i.e. an absolute path, so this yields an absolute repository name.
86+ Name : filepath .Join (dir , "outside-target" ),
87+ URL : "https://example.com/repo" ,
88+ Enabled : true ,
89+ },
90+ },
91+ }
92+ configPath := filepath .Join (dir , ".trivy" , "vex" , "repository.yaml" )
93+ testutil .MustWriteYAML (t , configPath , config )
94+ },
95+ wantErr : "invalid repository name" ,
96+ },
97+ {
98+ name : "empty repository name" ,
99+ setup : func (t * testing.T , dir string ) {
100+ config := repo.Config {
101+ Repositories : []repo.Repository {
102+ {
103+ Name : "" ,
104+ URL : "https://example.com/repo" ,
105+ Enabled : true ,
106+ },
107+ },
108+ }
109+ configPath := filepath .Join (dir , ".trivy" , "vex" , "repository.yaml" )
110+ testutil .MustWriteYAML (t , configPath , config )
111+ },
112+ wantErr : "invalid repository name" ,
113+ },
62114 }
63115
64116 for _ , tt := range tests {
0 commit comments