Skip to content

chore: return safe copy of string slice in 'ParseStringSliceClaim' #17439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2025
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