Skip to content

Commit 2c64b8f

Browse files
authored
fix(vex): reject non-local VEX repository names (aquasecurity#10987)
1 parent e73c76d commit 2c64b8f

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

pkg/vex/repo/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ func (m *Manager) Config(ctx context.Context) (Config, error) {
104104
}
105105

106106
for i, repo := range conf.Repositories {
107+
// The repository name is joined onto the cache directory, so reject names that are not
108+
// local relative paths to prevent path traversal (e.g., "../foo", "/foo", or "C:\foo" on Windows).
109+
if !filepath.IsLocal(repo.Name) {
110+
return Config{}, xerrors.Errorf("invalid repository name %q: must be a local relative path", repo.Name)
111+
}
107112
conf.Repositories[i].dir = filepath.Join(m.cacheDir, repoDir, repo.Name)
108113
}
109114

pkg/vex/repo/manager_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)