Skip to content

Commit 05fdf4d

Browse files
authored
Added anchors to cluster asset regex for security (#190)
1 parent f83b056 commit 05fdf4d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

internal/gke/discovery.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func filterMapSeachResults(results []*assetpb.ResourceSearchResult) []string {
162162

163163
// getIDFromName returns cluster identifier from full cluster asset name.
164164
func getIDFromName(name string) (string, error) {
165-
r := regexp.MustCompile(`//container\.googleapis\.com/(projects/.+/(locations|zones)/.+/clusters/.+)`)
165+
r := regexp.MustCompile(`^//container\.googleapis\.com/(projects/.+/(locations|zones)/.+/clusters/.+$)`)
166166
if !r.MatchString(name) {
167167
return "", fmt.Errorf("given name %q does not match GKE cluster name pattern", name)
168168
}

internal/gke/discovery_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func TestGetIDFromName_negative(t *testing.T) {
199199
inputs := []string{
200200
"projects/my-project/locations/europe-west2/clusters/my-cluster",
201201
"//container.googleapis.com/project/test/locations/europe/my-cluster",
202+
"malicious//container.googleapis.com/projects/my-project/locations/europe-west2/clusters/other-cluster/code",
202203
}
203204
for _, input := range inputs {
204205
if _, err := getIDFromName(input); err == nil {

0 commit comments

Comments
 (0)