Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

improvements: address feedback

Scott Wilson0b58d8df2aaf
diff --git a/backend/src/ee/routes/v1/group-router.ts b/backend/src/ee/routes/v1/group-router.ts
index 03bdfea9d4..c8199d6ad2 100644
--- a/backend/src/ee/routes/v1/group-router.ts
+++ b/backend/src/ee/routes/v1/group-router.ts
@@ -31,6 +31,23 @@ const GroupWithRoleSchema = GroupsSchema.extend({
roleId: z.string().nullish()
});
+// Member/identity search matches free-form user names, emails, and machine-identity names, so allow
+// letters/digits (any script), spaces, and the punctuation those values commonly contain.
+const MEMBER_SEARCH_ALLOWED_CHARACTERS = [
+ CharacterType.UnicodeLettersAndDigits,
+ CharacterType.Spaces,
+ CharacterType.Hyphen,
+ CharacterType.Period,
+ CharacterType.Underscore,
+ CharacterType.At,
+ CharacterType.Plus,
+ CharacterType.SingleQuote,
+ CharacterType.ForwardSlash,
+ CharacterType.Colon
+];
+const MEMBER_SEARCH_INVALID_MESSAGE =
+ "Invalid search: only letters, numbers, spaces, and the characters - . _ @ + ' / : are allowed.";
+
export const registerGroupRouter = async (server: FastifyZodProvider) => {
server.route({
url: "/",
@@ -306,19 +323,9 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
search: z
.string()
.trim()
- .refine(
- (val) =>
- characterValidator([
- CharacterType.AlphaNumeric,
- CharacterType.Hyphen,
- CharacterType.Period,
- CharacterType.At,
- CharacterType.Spaces
- ])(val),
- {
- message: "Invalid pattern: only alphanumeric characters, -, ., @, and spaces are allowed."
- }
- )
+ .refine(characterValidator(MEMBER_SEARCH_ALLOWED_CHARACTERS), {
+ message: MEMBER_SEARCH_INVALID_MESSAGE
+ })
.optional()
.describe(GROUPS.LIST_USERS.search),
filter: z.nativeEnum(FilterReturnedUsers).optional().describe(GROUPS.LIST_USERS.filterUsers)
@@ -375,8 +382,8 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
search: z
.string()
.trim()
- .refine((val) => characterValidator([CharacterType.AlphaNumeric, CharacterType.Hyphen])(val), {
- message: "Invalid pattern: only alphanumeric characters, - are allowed."
+ .refine(characterValidator(MEMBER_SEARCH_ALLOWED_CHARACTERS), {
+ message: MEMBER_SEARCH_INVALID_MESSAGE
})
.optional()
.describe(GROUPS.LIST_MACHINE_IDENTITIES.search),
diff --git a/frontend/src/pages/organization/GroupDetailsByIDPage/components/AddGroupMemberModal.tsx b/frontend/src/pages/organization/GroupDetailsByIDPage/components/AddGroupMemberModal.tsx
index f4d743eff8..9375575fcf 100644
--- a/frontend/src/pages/organization/GroupDetailsByIDPage/components/AddGroupMemberModal.tsx
+++ b/frontend/src/pages/organization/GroupDetailsByIDPage/components/AddGroupMemberModal.tsx
@@ -41,13 +41,6 @@ enum AddMemberType {
const MEMBER_SEARCH_LIMIT = 100;
const MEMBER_PREVIEW_LIMIT = 10;
-// The two endpoints validate the `search` param against different character sets: users allow
-// alphanumeric + - . @ and spaces (spaces enable full-name search); machine identities allow only
-// alphanumeric + -. A single search box must respect both, so we skip a type's query (and hide its
-// options) when the query isn't valid for that type — otherwise it 400s.
-const USER_SEARCH_REGEX = /^[a-zA-Z0-9\-.@\s]+$/;
-const IDENTITY_SEARCH_REGEX = /^[a-zA-Z0-9-]+$/;
-
type MemberOption = {
type: AddMemberType;
// `id` is the mutation argument: username for users, identity id for machine identities.
@@ -116,12 +109,9 @@ export const AddGroupMembersModal = ({
// Trim so a whitespace-only query isn't sent (the endpoints reject an all-spaces search).
const trimmedSearch = debouncedSearch.trim();
- // Only send the query to an endpoint when it's valid for that endpoint's charset (and
- // only surface that type's options then) — otherwise skip it to avoid a 400 / stale rows.
- const isUserSearchValid = !trimmedSearch || USER_SEARCH_REGEX.test(trimmedSearch);
- const isIdentitySearchValid = !trimmedSearch || IDENTITY_SEARCH_REGEX.test(trimmedSearch);
- const showUsers = !isOidcManageGroupMembershipsEnabled && isUserSearchValid;
- const showIdentities = isIdentitySearchValid;
+ // Users can't be added when OIDC manages group membership, so skip that query entirely (an empty
+ // slug makes the hook's `enabled` guard false) instead of fetching and discarding the results.
+ const showUsers = !isOidcManageGroupMembershipsEnabled;
const listLimit = trimmedSearch ? MEMBER_SEARCH_LIMIT : MEMBER_PREVIEW_LIMIT;
@@ -130,10 +120,10 @@ export const AddGroupMembersModal = ({
const { data: usersData, isFetching: isUsersFetching } = useListGroupUsers({
id: groupId,
- groupSlug,
+ groupSlug: showUsers ? groupSlug : "",
offset: 0,
limit: listLimit,
- search: isUserSearchValid ? trimmedSearch : "",
+ search: trimmedSearch,
filter: FilterReturnedUsers.NON_MEMBERS
});
@@ -142,7 +132,7 @@ export const AddGroupMembersModal = ({
groupSlug,
offset: 0,
limit: listLimit,
- search: isIdentitySearchValid ? trimmedSearch : "",
+ search: trimmedSearch,
filter: FilterReturnedMachineIdentities.NON_ASSIGNED_MACHINE_IDENTITIES
});
@@ -160,16 +150,16 @@ export const AddGroupMembersModal = ({
})
: [];
- const identities: MemberOption[] = showIdentities
- ? (identitiesData?.machineIdentities ?? []).map((identity) => ({
- type: AddMemberType.MachineIdentities,
- id: identity.id,
- label: identity.name
- }))
- : [];
+ const identities: MemberOption[] = (identitiesData?.machineIdentities ?? []).map(
+ (identity) => ({
+ type: AddMemberType.MachineIdentities,
+ id: identity.id,
+ label: identity.name
+ })
+ );
return [...users, ...identities];
- }, [usersData, identitiesData, showUsers, showIdentities]);
+ }, [usersData, identitiesData, showUsers]);
const {
control,