Skip to content

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

add validation for external users

adilson58e10dbf7f5d
diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts
index 38ac0b89bf..a131fb8596 100644
--- a/backend/src/services/secret-sharing/secret-sharing-service.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts
@@ -159,6 +159,19 @@ export const secretSharingServiceFactory = ({
const encryptWithRoot = kmsService.encryptWithRootKey();
+ // makes sure the user is not sharing secrets with users that don't have an account
+ if (emails && emails.length > 0 && accessType === SecretSharingAccessType.Organization && !allowExternalEmails) {
+ const platformUsers = await userDAL.findUsersByEmails(emails);
+ const platformEmailSet = new Set(platformUsers.map((u) => u.email!.toLowerCase()));
+ const hasUnregisteredEmail = emails.some((e) => !platformEmailSet.has(e.toLowerCase()));
+
+ if (hasUnregisteredEmail) {
+ throw new BadRequestError({
+ message: "One or more emails are not registered on Infisical! Use allowExternalEmails to share secrets with users outside of Infisical."
+ });
+ }
+ }
+
const orgMemberEmails: string[] = [];
if (emails && emails.length > 0) {
diff --git a/backend/src/services/user/user-dal.ts b/backend/src/services/user/user-dal.ts
index 88cd1a7347..4a5e2428b0 100644
--- a/backend/src/services/user/user-dal.ts
+++ b/backend/src/services/user/user-dal.ts
@@ -31,6 +31,17 @@ export const userDALFactory = (db: TDbClient) => {
isEmailVerified: true
});
+ const findUsersByEmails = async (emails: string[], tx?: Knex) => {
+ if (emails.length === 0) return [];
+
+ return (tx || db.replicaNode())(TableName.Users)
+ .whereRaw(
+ `lower("email") IN (${emails.map(() => "?").join(",")})`,
+ emails.map((e) => e.toLowerCase())
+ )
+ .where({ isEmailVerified: true });
+ };
+
const getUsersByFilter = async ({
limit,
offset,
@@ -264,6 +275,7 @@ export const userDALFactory = (db: TDbClient) => {
createUserAction,
getUsersByFilter,
findAllMyAccounts,
- findUserByEmail
+ findUserByEmail,
+ findUsersByEmails
};
};