Skip to content

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

change unauthorized name to external and add a migration for external emails

adilsone126ed78567b
diff --git a/backend/src/db/migrations/20260324200000_secret-sharing-unauthorized-emails.ts b/backend/src/db/migrations/20260324200000_secret-sharing-unauthorized-emails.ts
new file mode 100644
index 0000000000..1383f37355
--- /dev/null
+++ b/backend/src/db/migrations/20260324200000_secret-sharing-unauthorized-emails.ts
@@ -0,0 +1,21 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ const hasColumn = await knex.schema.hasColumn(TableName.SecretSharing, "externalEmails");
+ if (!hasColumn) {
+ await knex.schema.alterTable(TableName.SecretSharing, (t) => {
+ t.json("externalEmails").nullable();
+ });
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ const hasColumn = await knex.schema.hasColumn(TableName.SecretSharing, "externalEmails");
+ if (hasColumn) {
+ await knex.schema.alterTable(TableName.SecretSharing, (t) => {
+ t.dropColumn("externalEmails");
+ });
+ }
+}
diff --git a/backend/src/db/schemas/secret-sharing.ts b/backend/src/db/schemas/secret-sharing.ts
index 01222ded40..2f197230af 100644
--- a/backend/src/db/schemas/secret-sharing.ts
+++ b/backend/src/db/schemas/secret-sharing.ts
@@ -29,6 +29,7 @@ export const SecretSharingSchema = z.object({
identifier: z.string().nullable().optional(),
type: z.string().default("share"),
authorizedEmails: z.unknown().nullable().optional(),
+ externalEmails: z.unknown().nullable().optional(),
identityId: z.string().uuid().nullable().optional()
});
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index ce64fa80e2..436401ad8e 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3517,7 +3517,7 @@ export const SECRET_SHARING = {
"Determines who can access the shared secret. 'organization' restricts access to users within your organization. 'anyone' allows access to anyone with the link. Defaults to 'organization'.",
authorizedEmails:
"An optional array of email addresses that are authorized to view this secret. Only users with these email addresses will be able to access the secret. Maximum 100 emails.",
- allowUnauthorizedEmails:
+ allowExternalEmails:
"When true, emails not belonging to organization members are allowed. External recipients will receive the secret link via email and must use the password to access it."
},
DELETE: {
diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.ts
index e7063f9e18..6358528180 100644
--- a/backend/src/server/routes/v1/secret-sharing-router.ts
+++ b/backend/src/server/routes/v1/secret-sharing-router.ts
@@ -274,7 +274,7 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
.optional()
.transform((val) => (val ? [...new Set(val)] : undefined))
.describe(SECRET_SHARING.CREATE.authorizedEmails),
- allowUnauthorizedEmails: z.boolean().optional().describe(SECRET_SHARING.CREATE.allowUnauthorizedEmails)
+ allowExternalEmails: z.boolean().optional().describe(SECRET_SHARING.CREATE.allowExternalEmails)
})
.superRefine((data, ctx) => {
const duration = ms(data.expiresIn);
@@ -302,6 +302,22 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
path: ["expiresIn"]
});
}
+
+ if (data.allowExternalEmails && (!data.emails || data.emails.length === 0)) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Emails are required when allowing external emails",
+ path: ["emails"]
+ });
+ }
+
+ if (data.allowExternalEmails && data.accessType === SecretSharingAccessType.Organization) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Cannot allow external emails when access is restricted to organization members",
+ path: ["allowExternalEmails"]
+ });
+ }
}),
response: {
200: SanitizedSecretSharingSchema.extend({
diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts
index 777128caba..2ca22f76c6 100644
--- a/backend/src/services/secret-sharing/secret-sharing-service.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts
@@ -113,7 +113,7 @@ export const secretSharingServiceFactory = ({
expiresIn,
maxViews,
emails,
- allowUnauthorizedEmails
+ allowExternalEmails
}: TCreateSharedSecretDTO) => {
const appCfg = getConfig();
@@ -170,7 +170,7 @@ export const secretSharingServiceFactory = ({
authorizedEmails.push(email);
// If the email is not part of the org, but access type / org settings require it
} else if (
- !allowUnauthorizedEmails ||
+ !allowExternalEmails ||
!rootOrg.allowSecretSharingOutsideOrganization ||
accessType === SecretSharingAccessType.Organization
) {
@@ -182,9 +182,9 @@ export const secretSharingServiceFactory = ({
}
// When non-org emails are present, a password is required so external recipients can authenticate
- const nonAuthorizedEmails = emails ? emails.filter((e) => !authorizedEmails.includes(e)) : [];
+ const externalEmails = emails ? emails.filter((e) => !authorizedEmails.includes(e)) : [];
- if (nonAuthorizedEmails.length > 0 && !password) {
+ if (externalEmails.length > 0 && !password) {
throw new BadRequestError({
message: "A password is required when sharing secrets with users outside your organization"
});
@@ -210,13 +210,14 @@ export const secretSharingServiceFactory = ({
...(actor === ActorType.IDENTITY && { identityId: actorId }),
orgId,
accessType,
- authorizedEmails: authorizedEmails.length > 0 ? JSON.stringify(authorizedEmails) : undefined
+ authorizedEmails: authorizedEmails.length > 0 ? JSON.stringify(authorizedEmails) : undefined,
+ externalEmails: externalEmails.length > 0 ? JSON.stringify(externalEmails) : undefined
});
const mappedSharedSecret = mapIdentifierToId(newSharedSecret);
- // Loop through recipients and send out emails with unique access links
- if (authorizedEmails) {
+ // Loop through recipients and send out emails
+ if (authorizedEmails.length > 0 || externalEmails.length > 0) {
let displayUsername: string | undefined;
if (actor === ActorType.USER) {
@@ -237,12 +238,12 @@ export const secretSharingServiceFactory = ({
displayUsername = `${identity.name} (Machine Identity)`;
}
- const allEmails = [...new Set([...authorizedEmails, ...nonAuthorizedEmails])];
+ const allEmails = [...new Set([...authorizedEmails, ...externalEmails])];
for await (const email of allEmails) {
try {
// Only show the username to emails which are part of the organization
- const senderUsername = authorizedEmails.includes(email) ? displayUsername : undefined;
+ const senderUsername = allEmails.includes(email) ? displayUsername : undefined;
const isExternalEmail = !authorizedEmails.includes(email);
await smtpService.sendMail({
@@ -252,7 +253,7 @@ export const secretSharingServiceFactory = ({
name,
senderUsername,
secretRequestUrl: `${appCfg.SITE_URL}/shared/secret/${mappedSharedSecret.id}`,
- isPasswordProtected: isExternalEmail && Boolean(password)
+ isPasswordProtected: isExternalEmail && Boolean(password) // password protected is only necessary for external users
},
template: SmtpTemplates.SecretRequestCompleted
});
@@ -558,8 +559,12 @@ export const secretSharingServiceFactory = ({
};
};
+ // Validates that the current user is authorized to view a secret shared to specific emails.
const $validateAuthorizedEmails = async (sharedSecret: TSecretSharing, actorId?: string) => {
- if (sharedSecret.authorizedEmails && (sharedSecret.authorizedEmails as string[]).length > 0) {
+ const hasAuthorizedEmails = sharedSecret.authorizedEmails && (sharedSecret.authorizedEmails as string[]).length > 0;
+ const hasExternalEmails = sharedSecret.externalEmails && (sharedSecret.externalEmails as string[]).length > 0;
+
+ if (hasAuthorizedEmails || hasExternalEmails) {
if (actorId) {
// Authenticated user — verify email is in authorized list
const user = await userDAL.findById(actorId);
@@ -567,7 +572,7 @@ export const secretSharingServiceFactory = ({
throw new UnauthorizedError({ message: "Authentication required to view this secret" });
}
- if (!(sharedSecret.authorizedEmails as string[]).includes(user.email)) {
+ if (hasAuthorizedEmails && !(sharedSecret.authorizedEmails as string[]).includes(user.email)) {
throw new ForbiddenRequestError({ message: "You are not authorized to view this secret" });
}
} else if (!sharedSecret.password) {
diff --git a/backend/src/services/secret-sharing/secret-sharing-types.ts b/backend/src/services/secret-sharing/secret-sharing-types.ts
index 1143a981e4..36912abad9 100644
--- a/backend/src/services/secret-sharing/secret-sharing-types.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-types.ts
@@ -23,7 +23,7 @@ export type TSharedSecretPermission = {
name?: string;
password?: string;
emails?: string[];
- allowUnauthorizedEmails?: boolean;
+ allowExternalEmails?: boolean;
};
export type TCreatePublicSharedSecretDTO = {
diff --git a/docs/documentation/platform/secret-sharing.mdx b/docs/documentation/platform/secret-sharing.mdx
index 6dce3377ec..9a7e5b965d 100644
--- a/docs/documentation/platform/secret-sharing.mdx
+++ b/docs/documentation/platform/secret-sharing.mdx
@@ -25,7 +25,7 @@ Infisical offers a secure solution for sharing secrets over the internet in a ti
- **Max Views:** How many times the secret can be viewed before it's destroyed.
- **Emails (optional):** Emails which are authorized to view this secret. Enabling this feature requires secret viewers to log into Infisical. Each email will receive the shared secret link in their inbox after creation.
- - ** Allow unauthorized emails (optional):** Allow emails that are not inside Infisical to access the secret being shared.
+ - **Allow external recipients (optional):** When enabled, emails not belonging to organization members can receive the shared secret link. External recipients will need the password to access the secret.
</Step>
<Step title="Copy Link and Share Secret">
After creating the shared secret, its link will be displayed. Share this with the intended recipients.
diff --git a/frontend/src/hooks/api/secretSharing/types.ts b/frontend/src/hooks/api/secretSharing/types.ts
index 049dd2ab4b..cabd426f2d 100644
--- a/frontend/src/hooks/api/secretSharing/types.ts
+++ b/frontend/src/hooks/api/secretSharing/types.ts
@@ -33,7 +33,7 @@ export type TCreateSharedSecretRequest = {
maxViews?: number;
accessType?: SecretSharingAccessType;
emails?: string[];
- allowUnauthorizedEmails?: boolean;
+ allowExternalEmails?: boolean;
};
export type TCreateSecretRequestRequestDTO = {
diff --git a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
index 565058b849..94b14f8791 100644
--- a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
+++ b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState } from "react";
+import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { faCheck, faCopy, faRedo } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -66,7 +66,7 @@ const schema = z.object({
message: "Must be a comma-separated list of valid emails (max 100) or empty."
}
),
- allowUnauthorizedEmails: z.boolean().optional()
+ allowExternalEmails: z.boolean().optional()
});
export type FormData = z.infer<typeof schema>;
@@ -109,8 +109,7 @@ export const ShareSecretForm = ({
reset,
handleSubmit,
formState: { isSubmitting },
- watch,
- setValue
+ watch
} = useForm<FormData>({
resolver: zodResolver(schema),
defaultValues: {
@@ -123,27 +122,22 @@ export const ShareSecretForm = ({
});
const isLimitingView = watch("shouldLimitView");
- const isAllowingUnauthorizedEmails = watch("allowUnauthorizedEmails");
+ const isAllowingExternalEmails = watch("allowExternalEmails");
const accessType = watch("accessType");
const isOrgAccess =
accessType === SecretSharingAccessType.Organization || !allowSecretSharingOutsideOrganization;
- useEffect(() => {
- if (isOrgAccess) {
- setValue("allowUnauthorizedEmails", false);
- }
- }, [isOrgAccess, setValue]);
-
const onFormSubmit = async ({
name,
password,
secret,
expiresIn,
viewLimit,
+ accessType: formAccessType,
emails,
shouldLimitView,
- allowUnauthorizedEmails
+ allowExternalEmails
}: FormData) => {
const processedEmails = emails ? emails.split(",").map((e) => e.trim()) : undefined;
@@ -153,9 +147,9 @@ export const ShareSecretForm = ({
secretValue: secret,
expiresIn,
maxViews: shouldLimitView ? Number(viewLimit) : undefined,
- accessType,
+ accessType: formAccessType,
emails: processedEmails,
- allowUnauthorizedEmails
+ allowExternalEmails
});
if (processedEmails && processedEmails.length > 0) {
@@ -411,7 +405,7 @@ export const ShareSecretForm = ({
label="Authorized Emails"
isOptional
helperText={
- isAllowingUnauthorizedEmails
+ isAllowingExternalEmails
? "External recipients will receive a link and need the password to access the secret."
: "Recipients must have an Infisical account to verify identity"
}
@@ -422,7 +416,7 @@ export const ShareSecretForm = ({
will only be accessible to those links.
</p>
<p className="mt-2">
- {isAllowingUnauthorizedEmails
+ {isAllowingExternalEmails
? "External recipients (not in your organization) will need the password to view the secret. Authorized recipients will be able to view the secret without a password."
: "Recipients must have an Infisical account to verify their identity."}
</p>
@@ -442,7 +436,7 @@ export const ShareSecretForm = ({
/>
<Controller
control={control}
- name="allowUnauthorizedEmails"
+ name="allowExternalEmails"
render={({
field: { onChange, value: isChecked, ...field },
fieldState: { error }
@@ -465,10 +459,10 @@ export const ShareSecretForm = ({
isChecked={isOrgAccess ? false : (isChecked ?? false)}
onCheckedChange={onChange}
isDisabled={isOrgAccess}
- id="allow-unauthorized-emails"
+ id="allow-external-emails"
{...field}
>
- Allow unauthorized emails
+ Allow external recipients
</Switch>
</FormControl>
)}