Skip to content

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

improvements: address feedback

Scott Wilsonc6a7daffe774
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/AddOrgMemberModal.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/AddOrgMemberModal.tsx
index 1d48325f21..49dfc7b99b 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/AddOrgMemberModal.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/AddOrgMemberModal.tsx
@@ -89,9 +89,7 @@ const PRODUCT_DEFINITIONS: ProductDefinition[] = [
type: ProjectType.SecretScanning,
name: getProjectTitle(ProjectType.SecretScanning),
isSingleton: false
- },
- { type: ProjectType.PAM, name: getProjectTitle(ProjectType.PAM), isSingleton: false },
- { type: ProjectType.AI, name: getProjectTitle(ProjectType.AI), isSingleton: false }
+ }
];
// Render each product with its shared project icon (getProjectLucideIcon) so the select matches the
@@ -123,8 +121,86 @@ const ProductSingleValue = ({ children, ...props }: SingleValueProps<ProductDefi
const EmailSchema = z.string().email().min(1).trim().toLowerCase();
+// Zod's .email() accepts addresses the backend/DB reject: domain labels over 63 chars
+// (backend/src/lib/validator/validate-email.ts) and emails longer than the users table's
+// varchar(255) email/username columns. Mirror both here so oversized/malformed addresses are
+// caught inline instead of failing with a 400 (bad domain) or 500 (too long) from the API.
+const MAX_EMAIL_LENGTH = 255;
+const MAX_DOMAIN_LABEL_LENGTH = 63;
+const DOMAIN_LABEL_REGEX = /^[a-zA-Z0-9-]+$/;
+const TLD_REGEX = /^[a-zA-Z0-9]+$/;
+
+const isValidEmailDomain = (domain: string) => {
+ const labels = domain.split(".");
+ if (labels.length < 2) return false;
+
+ const tld = labels[labels.length - 1];
+ if (tld.length < 2 || !TLD_REGEX.test(tld)) return false;
+
+ return labels.every(
+ (label) =>
+ label.length > 0 &&
+ label.length <= MAX_DOMAIN_LABEL_LENGTH &&
+ !label.startsWith("-") &&
+ !label.endsWith("-") &&
+ DOMAIN_LABEL_REGEX.test(label)
+ );
+};
+
+const isValidEmail = (email: string) =>
+ email.length <= MAX_EMAIL_LENGTH &&
+ EmailSchema.safeParse(email).success &&
+ isValidEmailDomain(email.slice(email.indexOf("@") + 1));
+
+// Mirror the backend cap (inviteeEmails.array().max(100)) so oversized invites are rejected inline
+// before hitting the API.
+const MAX_INVITE_EMAILS = 100;
+
+const parseEmailList = (value: string) =>
+ value
+ .split(",")
+ .map((email) => email.trim())
+ .filter(Boolean);
+
const addMemberFormSchema = z.object({
- emails: z.string().min(1).trim().toLowerCase(),
+ emails: z
+ .string()
+ .trim()
+ .toLowerCase()
+ .superRefine((value, ctx) => {
+ const emails = parseEmailList(value);
+
+ if (!emails.length) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Please enter at least one email address."
+ });
+ return;
+ }
+
+ if (emails.length > MAX_INVITE_EMAILS) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: `You can invite up to ${MAX_INVITE_EMAILS} users at a time.`
+ });
+ }
+
+ const invalidEmails = emails.filter((email) => !isValidEmail(email));
+
+ if (invalidEmails.length) {
+ const preview = invalidEmails
+ .slice(0, 3)
+ .map((email) => (email.length > 40 ? `${email.slice(0, 40)}...` : email))
+ .join(", ");
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message:
+ invalidEmails.length > 3
+ ? `${invalidEmails.length} invalid email addresses (e.g. ${preview}).`
+ : `Invalid email address${invalidEmails.length > 1 ? "es" : ""}: ${preview}.`
+ });
+ }
+ }),
product: z
.object({
type: z.nativeEnum(ProjectType),
@@ -277,26 +353,7 @@ export const AddOrgMemberModal = ({
}
}
- const parsedEmails = emails
- .replace(/\s/g, "")
- .split(",")
- .map((email) => {
- if (EmailSchema.safeParse(email).success) {
- return email.trim();
- }
-
- return null;
- });
-
- if (parsedEmails.includes(null)) {
- createNotification({
- text: "Invalid email addresses provided.",
- type: "error"
- });
- return;
- }
-
- const usernames = emails.split(",").map((email) => email.trim());
+ const usernames = parseEmailList(emails);
const { data } = await addUsersMutateAsync({
organizationId: currentOrg?.id,
inviteeEmails: usernames,
@@ -371,7 +428,7 @@ export const AddOrgMemberModal = ({
<FieldLabel htmlFor="add-org-member-emails">Emails</FieldLabel>
<TextArea
id="add-org-member-emails"
- className="h-20"
+ className="h-24"
isError={Boolean(error)}
{...field}
@@ -442,6 +499,7 @@ export const AddOrgMemberModal = ({
</FieldLabel>
<FilterableSelect
inputId="add-org-member-product"
+ isClearable
value={value ?? null}
isLoading={isProjectsLoading}
onChange={(option) => {