Skip to content

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

add support for unauthorized emails

adilson9904bb135589
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 845917774f..ce64fa80e2 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3516,7 +3516,9 @@ export const SECRET_SHARING = {
accessType:
"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."
+ "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:
+ "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: {
id: "The ID of the shared secret to delete."
diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.ts
index 8f582503e1..e7063f9e18 100644
--- a/backend/src/server/routes/v1/secret-sharing-router.ts
+++ b/backend/src/server/routes/v1/secret-sharing-router.ts
@@ -266,14 +266,15 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
.nativeEnum(SecretSharingAccessType)
.default(SecretSharingAccessType.Organization)
.describe(SECRET_SHARING.CREATE.accessType),
- authorizedEmails: z
+ emails: z
.string()
.email()
.array()
.max(100)
.optional()
.transform((val) => (val ? [...new Set(val)] : undefined))
- .describe(SECRET_SHARING.CREATE.authorizedEmails)
+ .describe(SECRET_SHARING.CREATE.authorizedEmails),
+ allowUnauthorizedEmails: z.boolean().optional().describe(SECRET_SHARING.CREATE.allowUnauthorizedEmails)
})
.superRefine((data, ctx) => {
const duration = ms(data.expiresIn);
diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts
index c6abd1f8ff..777128caba 100644
--- a/backend/src/services/secret-sharing/secret-sharing-service.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts
@@ -112,7 +112,8 @@ export const secretSharingServiceFactory = ({
accessType,
expiresIn,
maxViews,
- authorizedEmails
+ emails,
+ allowUnauthorizedEmails
}: TCreateSharedSecretDTO) => {
const appCfg = getConfig();
@@ -158,17 +159,18 @@ export const secretSharingServiceFactory = ({
const encryptWithRoot = kmsService.encryptWithRootKey();
- const orgEmails = [];
+ const authorizedEmails: string[] = [];
- if (authorizedEmails && authorizedEmails.length > 0) {
+ if (emails && emails.length > 0) {
const allOrgMembers = await orgDAL.findAllOrgMembers(orgId);
// Check to see that all emails are a part of the organization (if enforced) while also collecting a list of emails which are in the org
- for (const email of authorizedEmails) {
+ for (const email of emails) {
if (allOrgMembers.some((v) => v.user.email === email)) {
- orgEmails.push(email);
+ authorizedEmails.push(email);
// If the email is not part of the org, but access type / org settings require it
} else if (
+ !allowUnauthorizedEmails ||
!rootOrg.allowSecretSharingOutsideOrganization ||
accessType === SecretSharingAccessType.Organization
) {
@@ -179,6 +181,15 @@ 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)) : [];
+
+ if (nonAuthorizedEmails.length > 0 && !password) {
+ throw new BadRequestError({
+ message: "A password is required when sharing secrets with users outside your organization"
+ });
+ }
+
const encryptedSecret = encryptWithRoot(Buffer.from(secretValue));
const id = crypto.randomBytes(32).toString("hex");
@@ -199,7 +210,7 @@ export const secretSharingServiceFactory = ({
...(actor === ActorType.IDENTITY && { identityId: actorId }),
orgId,
accessType,
- authorizedEmails: authorizedEmails && authorizedEmails.length > 0 ? JSON.stringify(authorizedEmails) : undefined
+ authorizedEmails: authorizedEmails.length > 0 ? JSON.stringify(authorizedEmails) : undefined
});
const mappedSharedSecret = mapIdentifierToId(newSharedSecret);
@@ -226,10 +237,13 @@ export const secretSharingServiceFactory = ({
displayUsername = `${identity.name} (Machine Identity)`;
}
- for await (const email of authorizedEmails) {
+ const allEmails = [...new Set([...authorizedEmails, ...nonAuthorizedEmails])];
+
+ for await (const email of allEmails) {
try {
// Only show the username to emails which are part of the organization
- const senderUsername = orgEmails.includes(email) ? displayUsername : undefined;
+ const senderUsername = authorizedEmails.includes(email) ? displayUsername : undefined;
+ const isExternalEmail = !authorizedEmails.includes(email);
await smtpService.sendMail({
recipients: [email],
@@ -237,7 +251,8 @@ export const secretSharingServiceFactory = ({
substitutions: {
name,
senderUsername,
- secretRequestUrl: `${appCfg.SITE_URL}/shared/secret/${mappedSharedSecret.id}`
+ secretRequestUrl: `${appCfg.SITE_URL}/shared/secret/${mappedSharedSecret.id}`,
+ isPasswordProtected: isExternalEmail && Boolean(password)
},
template: SmtpTemplates.SecretRequestCompleted
});
@@ -543,6 +558,26 @@ export const secretSharingServiceFactory = ({
};
};
+ const $validateAuthorizedEmails = async (sharedSecret: TSecretSharing, actorId?: string) => {
+ if (sharedSecret.authorizedEmails && (sharedSecret.authorizedEmails as string[]).length > 0) {
+ if (actorId) {
+ // Authenticated user — verify email is in authorized list
+ const user = await userDAL.findById(actorId);
+ if (!user || !user.email) {
+ throw new UnauthorizedError({ message: "Authentication required to view this secret" });
+ }
+
+ if (!(sharedSecret.authorizedEmails as string[]).includes(user.email)) {
+ throw new ForbiddenRequestError({ message: "You are not authorized to view this secret" });
+ }
+ } else if (!sharedSecret.password) {
+ // Unauthenticated and no password — must log in
+ throw new UnauthorizedError({ message: "Authentication required to view this secret" });
+ }
+ // Unauthenticated + password-protected: fall through to password check
+ }
+ };
+
const getSharedSecretById = async (sharedSecretId: string, orgId?: string, actorId?: string) => {
const sharedSecret = await secretSharingDAL.findOne({
type: SecretSharingType.Share,
@@ -577,21 +612,7 @@ export const secretSharingServiceFactory = ({
throw new NotFoundError({ message: "The shared secret has reached its view limit" });
}
- // Check authorized emails if set
- if (sharedSecret.authorizedEmails && (sharedSecret.authorizedEmails as string[]).length > 0) {
- if (!actorId) {
- throw new UnauthorizedError({ message: "Authentication required to view this secret" });
- }
-
- const user = await userDAL.findById(actorId);
- if (!user || !user.email) {
- throw new UnauthorizedError({ message: "Authentication required to view this secret" });
- }
-
- if (!(sharedSecret.authorizedEmails as string[]).includes(user.email)) {
- throw new ForbiddenRequestError({ message: "You are not authorized to view this secret" });
- }
- }
+ await $validateAuthorizedEmails(sharedSecret, actorId);
return {
...mapIdentifierToId(sharedSecret),
@@ -638,16 +659,7 @@ export const secretSharingServiceFactory = ({
throw new ForbiddenRequestError();
}
- // If the secret was shared with specific emails, verify that the current user's session email is authorized
- if (sharedSecret.authorizedEmails && (sharedSecret.authorizedEmails as string[]).length > 0) {
- if (!actorId) throw new UnauthorizedError();
-
- const user = await userDAL.findById(actorId);
- if (!user || !user.email) throw new UnauthorizedError();
-
- if (!(sharedSecret.authorizedEmails as string[]).includes(user.email))
- throw new ForbiddenRequestError({ message: "You are not authorized to view this secret" });
- }
+ await $validateAuthorizedEmails(sharedSecret, actorId);
// all secrets pass through here, meaning we check if its expired first and then check if it needs verification
// or can be safely sent to the client.
diff --git a/backend/src/services/secret-sharing/secret-sharing-types.ts b/backend/src/services/secret-sharing/secret-sharing-types.ts
index dd67d3d372..1143a981e4 100644
--- a/backend/src/services/secret-sharing/secret-sharing-types.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-types.ts
@@ -22,7 +22,8 @@ export type TSharedSecretPermission = {
accessType?: SecretSharingAccessType;
name?: string;
password?: string;
- authorizedEmails?: string[];
+ emails?: string[];
+ allowUnauthorizedEmails?: boolean;
};
export type TCreatePublicSharedSecretDTO = {
diff --git a/backend/src/services/smtp/emails/SecretRequestCompletedTemplate.tsx b/backend/src/services/smtp/emails/SecretRequestCompletedTemplate.tsx
index cdb14232df..6997b2914f 100644
--- a/backend/src/services/smtp/emails/SecretRequestCompletedTemplate.tsx
+++ b/backend/src/services/smtp/emails/SecretRequestCompletedTemplate.tsx
@@ -8,13 +8,15 @@ interface SecretRequestCompletedTemplateProps extends Omit<BaseEmailWrapperProps
name?: string;
senderUsername?: string;
secretRequestUrl: string;
+ isPasswordProtected?: boolean;
}
export const SecretRequestCompletedTemplate = ({
name,
siteUrl,
senderUsername,
- secretRequestUrl
+ secretRequestUrl,
+ isPasswordProtected
}: SecretRequestCompletedTemplateProps) => {
return (
<BaseEmailWrapper title="Shared Secret" preview="A secret has been shared with you." siteUrl={siteUrl}>
@@ -31,6 +33,11 @@ export const SecretRequestCompletedTemplate = ({
)}{" "}
with you.
</Text>
+ {isPasswordProtected && (
+ <Text className="text-[13px] text-gray-500">
+ This secret is password protected. You will need the password provided by the sender to view it.
+ </Text>
+ )}
</Section>
<Section className="text-center">
<BaseButton href={secretRequestUrl}>View Secret</BaseButton>
diff --git a/docs/documentation/platform/secret-sharing.mdx b/docs/documentation/platform/secret-sharing.mdx
index cc0b2e95b5..6dce3377ec 100644
--- a/docs/documentation/platform/secret-sharing.mdx
+++ b/docs/documentation/platform/secret-sharing.mdx
@@ -24,7 +24,8 @@ Infisical offers a secure solution for sharing secrets over the internet in a ti
- **Expires In:** The time it'll take for the secret to expire.
- **Max Views:** How many times the secret can be viewed before it's destroyed.
- - **Authorized 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.
+ - **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.
</Step>
<Step title="Copy Link and Share Secret">
After creating the shared secret, its link will be displayed. Share this with the intended recipients.
@@ -40,6 +41,7 @@ Infisical offers a secure solution for sharing secrets over the internet in a ti
![Access Shared Secret](../../images/platform/secret-sharing/public-view.png)
</Step>
+
</Steps>
## Deleting a Shared Secret
@@ -75,6 +77,7 @@ To delete a shared secret, click the **Trash Can** icon on the relevant shared s
![Request Secret Page](../../images/platform/secret-sharing/request-secret-page.png)
</Step>
+
</Steps>
## Custom Branding
@@ -83,6 +86,7 @@ To delete a shared secret, click the **Trash Can** icon on the relevant shared s
Custom branding for shared secret pages is a paid feature.
If you're using Infisical Cloud, then it is available under the **Enterprise Tier**. If you're self-hosting Infisical, then you should contact [email protected] to purchase an enterprise license to use it.
+
</Info>
You can customize the branding of your shared secret pages and secret request pages by providing your own logo and colors.
@@ -96,7 +100,8 @@ If custom branding is added, the shared secret page will display your custom log
## FAQ
<AccordionGroup>
- <Accordion title="Can secrets be changed after they are shared?">
- No, secrets cannot be changed after they've been created. This is to ensure that secrets are not tampered with.
- </Accordion>
+ <Accordion title="Can secrets be changed after they are shared?">
+ No, secrets cannot be changed after they've been created. This is to ensure
+ that secrets are not tampered with.
+ </Accordion>
</AccordionGroup>
diff --git a/frontend/src/hooks/api/secretSharing/types.ts b/frontend/src/hooks/api/secretSharing/types.ts
index 5d98e785e3..049dd2ab4b 100644
--- a/frontend/src/hooks/api/secretSharing/types.ts
+++ b/frontend/src/hooks/api/secretSharing/types.ts
@@ -32,7 +32,8 @@ export type TCreateSharedSecretRequest = {
expiresIn: string;
maxViews?: number;
accessType?: SecretSharingAccessType;
- authorizedEmails?: string[];
+ emails?: string[];
+ allowUnauthorizedEmails?: 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 22a5138cbe..565058b849 100644
--- a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
+++ b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useEffect, 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";
@@ -65,7 +65,8 @@ const schema = z.object({
{
message: "Must be a comma-separated list of valid emails (max 100) or empty."
}
- )
+ ),
+ allowUnauthorizedEmails: z.boolean().optional()
});
export type FormData = z.infer<typeof schema>;
@@ -108,7 +109,8 @@ export const ShareSecretForm = ({
reset,
handleSubmit,
formState: { isSubmitting },
- watch
+ watch,
+ setValue
} = useForm<FormData>({
resolver: zodResolver(schema),
defaultValues: {
@@ -121,6 +123,17 @@ export const ShareSecretForm = ({
});
const isLimitingView = watch("shouldLimitView");
+ const isAllowingUnauthorizedEmails = watch("allowUnauthorizedEmails");
+ const accessType = watch("accessType");
+
+ const isOrgAccess =
+ accessType === SecretSharingAccessType.Organization || !allowSecretSharingOutsideOrganization;
+
+ useEffect(() => {
+ if (isOrgAccess) {
+ setValue("allowUnauthorizedEmails", false);
+ }
+ }, [isOrgAccess, setValue]);
const onFormSubmit = async ({
name,
@@ -128,9 +141,9 @@ export const ShareSecretForm = ({
secret,
expiresIn,
viewLimit,
- accessType,
emails,
- shouldLimitView
+ shouldLimitView,
+ allowUnauthorizedEmails
}: FormData) => {
const processedEmails = emails ? emails.split(",").map((e) => e.trim()) : undefined;
@@ -141,7 +154,8 @@ export const ShareSecretForm = ({
expiresIn,
maxViews: shouldLimitView ? Number(viewLimit) : undefined,
accessType,
- authorizedEmails: processedEmails
+ emails: processedEmails,
+ allowUnauthorizedEmails
});
if (processedEmails && processedEmails.length > 0) {
@@ -388,37 +402,78 @@ export const ShareSecretForm = ({
)}
</div>
{!isPublic && (
- <Controller
- control={control}
- name="emails"
- render={({ field, fieldState: { error } }) => (
- <FormControl
- label="Authorized Emails"
- isOptional
- helperText="Recipients must have an Infisical account to verify identity"
- tooltipText={
- <>
+ <>
+ <Controller
+ control={control}
+ name="emails"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Authorized Emails"
+ isOptional
+ helperText={
+ isAllowingUnauthorizedEmails
+ ? "External recipients will receive a link and need the password to access the secret."
+ : "Recipients must have an Infisical account to verify identity"
+ }
+ tooltipText={
+ <>
+ <p>
+ Unique secret links will be emailed to each individual. The secret
+ will only be accessible to those links.
+ </p>
+ <p className="mt-2">
+ {isAllowingUnauthorizedEmails
+ ? "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>
+ </>
+ }
+ tooltipClassName="max-w-sm"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ >
+ <Input
+ {...field}
+ autoComplete="off"
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="allowUnauthorizedEmails"
+ render={({
+ field: { onChange, value: isChecked, ...field },
+ fieldState: { error }
+ }) => (
+ <FormControl
+ errorText={error?.message}
+ isError={Boolean(error)}
+ tooltipText={
<p>
- Unique secret links will be emailed to each individual. The secret will
- only be accessible to those links.
+ When enabled, emails not registered in Infisical will receive the secret
+ link via email but will need the password to access the secret.
</p>
- <p className="mt-2">
- Recipients must have an Infisical account to verify their identity.
- </p>
- </>
- }
- tooltipClassName="max-w-sm"
- isError={Boolean(error)}
- errorText={error?.message}
- >
- <Input
- {...field}
- autoComplete="off"
- />
- </FormControl>
- )}
- />
+ }
+ tooltipClassName="max-w-sm"
+ >
+ <Switch
+ className={`mr-2 ml-0 bg-mineshaft-400/50 shadow-inner data-[state=checked]:bg-primary ${isOrgAccess ? "opacity-50" : ""}`}
+ thumbClassName="bg-mineshaft-800"
+ containerClassName="flex-row-reverse w-fit"
+ isChecked={isOrgAccess ? false : (isChecked ?? false)}
+ onCheckedChange={onChange}
+ isDisabled={isOrgAccess}
+ id="allow-unauthorized-emails"
+ {...field}
+ >
+ Allow unauthorized emails
+ </Switch>
+ </FormControl>
+ )}
+ />
+ </>
)}
</AccordionContent>
</AccordionItem>