Skip to content

Commit 37c5e7c

Browse files
authored
chore: return safe copy of string slice in 'ParseStringSliceClaim' (#17439)
Claims parsed should be safe to mutate and filter. This was likely not causing any bugs or issues, and just doing this out of precaution
1 parent 9167cbf commit 37c5e7c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

coderd/idpsync/idpsync.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ func ParseStringSliceClaim(claim interface{}) ([]string, error) {
186186
// The simple case is the type is exactly what we expected
187187
asStringArray, ok := claim.([]string)
188188
if ok {
189-
return asStringArray, nil
189+
cpy := make([]string, len(asStringArray))
190+
copy(cpy, asStringArray)
191+
return cpy, nil
190192
}
191193

192194
asArray, ok := claim.([]interface{})

coderd/idpsync/idpsync_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ func TestParseStringSliceClaim(t *testing.T) {
136136
}
137137
}
138138

139+
func TestParseStringSliceClaimReference(t *testing.T) {
140+
t.Parallel()
141+
142+
var val any = []string{"a", "b", "c"}
143+
parsed, err := idpsync.ParseStringSliceClaim(val)
144+
require.NoError(t, err)
145+
146+
parsed[0] = ""
147+
require.Equal(t, "a", val.([]string)[0], "should not modify original value")
148+
}
149+
139150
func TestIsHTTPError(t *testing.T) {
140151
t.Parallel()
141152

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy