Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: return safe copy of string slice in 'ParseStringSliceClaim'
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
  • Loading branch information
Emyrk committed Apr 17, 2025
commit 8494aa9c677e5d9f61a19cdf731793bd186c6adb
4 changes: 3 additions & 1 deletion coderd/idpsync/idpsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
11 changes: 11 additions & 0 deletions coderd/idpsync/idpsync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading