fix: user resource names can be uuidv4 from idp sub claim (#5856)

This commit is contained in:
George Wu 2026-04-18 22:05:08 -07:00 committed by GitHub
parent f8a304bae3
commit bbded584ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 2 deletions

View file

@ -3,5 +3,5 @@ package base
import "regexp" import "regexp"
var ( var (
UIDMatcher = regexp.MustCompile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,30}[a-zA-Z0-9])?$") UIDMatcher = regexp.MustCompile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,34}[a-zA-Z0-9])?$")
) )

View file

@ -22,6 +22,8 @@ func TestUIDMatcher(t *testing.T) {
{"a1234567890123456789012345678901", true}, {"a1234567890123456789012345678901", true},
{"abc123", true}, {"abc123", true},
{"abc123-", false}, {"abc123-", false},
{"123e4567-e89b-12d3-a456-426614174000", true}, // UUID v4 from IDP
{"a123456789012345678901234567890123456", false}, // 37 characters (too long)
} }
for _, test := range tests { for _, test := range tests {

View file

@ -143,7 +143,7 @@ func ValidateAndGenerateUID(provided string) (string, error) {
return shortuuid.New(), nil return shortuuid.New(), nil
} }
if !base.UIDMatcher.MatchString(uid) { if !base.UIDMatcher.MatchString(uid) {
return "", status.Errorf(codes.InvalidArgument, "invalid ID format: must be 1-32 characters, alphanumeric and hyphens only, cannot start or end with hyphen") return "", status.Errorf(codes.InvalidArgument, "invalid ID format: must be 1-36 characters, alphanumeric and hyphens only, cannot start or end with hyphen")
} }
return uid, nil return uid, nil
} }