Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/yurthub/storage/disk/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func (ds *diskStorage) KeyFunc(info storage.KeyBuildInfo) (storage.Key, error) {
if info.Resources == "" {
return nil, storage.ErrEmptyResource
}
// Component comes from the client User-Agent and the other fields come from
// the request path, so "." or ".." must not be allowed to move the key out
// of its component dir or out of the cache dir.
for _, s := range []string{info.Component, info.Resources, info.Namespace, info.Name} {
for _, elem := range strings.Split(s, "/") {
if elem == "." || elem == ".." {
return nil, storage.ErrUnrecognizedKey
}
}
}
if info.Name == "" {
isRoot = true
}
Expand Down
55 changes: 55 additions & 0 deletions pkg/yurthub/storage/disk/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,61 @@ func TestKeyFunc(t *testing.T) {
key: "cilium-agent/partialobjectmetadata/customresourcedefinitions.v1.apiextensions.k8s.io",
isRoot: true,
},
"component is parent dir": {
info: storage.KeyBuildInfo{
Component: "..",
Resources: "configmaps",
Version: "v1",
Namespace: "default",
Name: "foo",
},
err: storage.ErrUnrecognizedKey,
},
"component is current dir": {
info: storage.KeyBuildInfo{
Component: ".",
Resources: "configmaps",
Version: "v1",
Namespace: "default",
},
err: storage.ErrUnrecognizedKey,
},
"partial object metadata of parent dir component": {
info: storage.KeyBuildInfo{
Component: "../partialobjectmetadatas.v1.meta.k8s.io",
Resources: "configmaps",
Version: "v1",
},
err: storage.ErrUnrecognizedKey,
},
"resource is parent dir": {
info: storage.KeyBuildInfo{
Component: "kubelet",
Resources: "..",
Version: "v1",
Name: "foo",
},
err: storage.ErrUnrecognizedKey,
},
"namespace is parent dir": {
info: storage.KeyBuildInfo{
Component: "kubelet",
Resources: "configmaps",
Version: "v1",
Namespace: "..",
Name: "foo",
},
err: storage.ErrUnrecognizedKey,
},
"name is parent dir": {
info: storage.KeyBuildInfo{
Component: "kubelet",
Resources: "nodes",
Version: "v1",
Name: "..",
},
err: storage.ErrUnrecognizedKey,
},
}

disk, err := NewDiskStorage(keyFuncTestDir)
Expand Down