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
This commit is contained in:
Steven Masley
2025-04-28 12:18:02 -05:00
committed by GitHub
parent 9167cbfe4c
commit 37c5e7c440
2 changed files with 14 additions and 1 deletions
+3 -1
View File
@@ -186,7 +186,9 @@ func ParseStringSliceClaim(claim interface{}) ([]string, error) {
// The simple case is the type is exactly what we expected
asStringArray, ok := claim.([]string)
if ok {
return asStringArray, nil
cpy := make([]string, len(asStringArray))
copy(cpy, asStringArray)
return cpy, nil
}
asArray, ok := claim.([]interface{})
+11
View File
@@ -136,6 +136,17 @@ func TestParseStringSliceClaim(t *testing.T) {
}
}
func TestParseStringSliceClaimReference(t *testing.T) {
t.Parallel()
var val any = []string{"a", "b", "c"}
parsed, err := idpsync.ParseStringSliceClaim(val)
require.NoError(t, err)
parsed[0] = ""
require.Equal(t, "a", val.([]string)[0], "should not modify original value")
}
func TestIsHTTPError(t *testing.T) {
t.Parallel()