Skip to content

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

Merge

x032205151ede6cbf36
diff --cc backend/src/services/secret-sharing/secret-sharing-service.ts
index e216cb9391,e56b10e46e..7020783644
--- a/backend/src/services/secret-sharing/secret-sharing-service.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts
@@@ -95,21 -97,32 +99,46 @@@ export const secretSharingServiceFactor
throw new BadRequestError({ message: "Shared secret value too long" });
}
+ // Check lifetime is within org allowance
+ const expiresAtTimestamp = new Date(expiresAt).getTime();
+ const lifetime = expiresAtTimestamp - new Date().getTime();
+
+ // org.maxSharedSecretLifetime is in seconds
+ if (org.maxSharedSecretLifetime && lifetime / 1000 > org.maxSharedSecretLifetime) {
+ throw new BadRequestError({ message: "Secret lifetime exceeds organization limit" });
+ }
+
+ // Check max view count is within org allowance
+ if (org.maxSharedSecretViewLimit && (!expiresAfterViews || expiresAfterViews > org.maxSharedSecretViewLimit)) {
+ throw new BadRequestError({ message: "Secret max views parameter exceeds organization limit" });
+ }
+
const encryptWithRoot = kmsService.encryptWithRootKey();
+
+ let salt: string | undefined;
+ let encryptedSalt: Buffer | undefined;
+ const orgEmails = [];
+
+ 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 emails) {
+ if (allOrgMembers.some((v) => v.user.email === email)) {
+ orgEmails.push(email);
+ // If the email is not part of the org, but access type / org settings require it
+ } else if (!org.allowSecretSharingOutsideOrganization || accessType === SecretSharingAccessType.Organization) {
+ throw new BadRequestError({
+ message: "Organization does not allow sharing secrets to members outside of this organization"
+ });
+ }
+ }
+
+ // Generate salt for signing email hashes (if emails are provided)
+ salt = crypto.randomBytes(32).toString("hex");
+ encryptedSalt = encryptWithRoot(Buffer.from(salt));
+ }
+
const encryptedSecret = encryptWithRoot(Buffer.from(secretValue));
const id = crypto.randomBytes(32).toString("hex");
diff --cc frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
index 7e99bee4b9,0380cde0cd..322aa20ae6
--- a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
+++ b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx
@@@ -49,11 -76,9 +78,11 @@@ type Props =
export const ShareSecretForm = ({
isPublic,
value,
- allowSecretSharingOutsideOrganization = true
+ allowSecretSharingOutsideOrganization = true,
+ maxSharedSecretLifetime,
+ maxSharedSecretViewLimit
}: Props) => {
- const [secretLink, setSecretLink] = useState("");
+ const [secretLink, setSecretLink] = useState<string | null>(null);
const [, isCopyingSecret, setCopyTextSecret] = useTimedReset<string>({
initialState: "Copy to clipboard"
});
@@@ -79,7 -95,9 +108,10 @@@
} = useForm<FormData>({
resolver: zodResolver(schema),
defaultValues: {
- secret: value || ""
+ secret: value || "",
- viewLimit: "-1",
- expiresIn: "3600000"
++ viewLimit: filteredViewLimitOptions[filteredViewLimitOptions.length - 1].value.toString(),
++ expiresIn:
++ filteredExpiresInOptions[Math.min(filteredExpiresInOptions.length - 1, 2)].value.toString()
}
});
@@@ -262,18 -224,161 +238,161 @@@
</FormControl>
)}
/>
- )}
- <Button
- className="mt-4"
- size="sm"
- type="submit"
- isLoading={isSubmitting}
- isDisabled={isSubmitting}
- >
- Create Secret Link
- </Button>
- </form>
- ) : (
+
+ {!isPublic && (
+ <Controller
+ control={control}
+ name="accessType"
+ defaultValue={SecretSharingAccessType.Organization}
+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (
+ <FormControl
+ helperText={
+ allowSecretSharingOutsideOrganization ? undefined : (
+ <span className="text-red-500">Feature enforced by organization</span>
+ )
+ }
+ errorText={error?.message}
+ isError={Boolean(error)}
+ >
+ <Switch
+ className={`ml-0 mr-2 bg-mineshaft-400/50 shadow-inner data-[state=checked]:bg-primary ${!allowSecretSharingOutsideOrganization ? "opacity-50" : ""}`}
+ thumbClassName="bg-mineshaft-800"
+ containerClassName="flex-row-reverse w-fit"
+ isChecked={
+ field.value === SecretSharingAccessType.Organization ||
+ !allowSecretSharingOutsideOrganization
+ }
+ isDisabled={!allowSecretSharingOutsideOrganization}
+ onCheckedChange={(v) =>
+ onChange(
+ v ? SecretSharingAccessType.Organization : SecretSharingAccessType.Anyone
+ )
+ }
+ id="org-access-only"
+ >
+ Limit access to people within organization
+ </Switch>
+ </FormControl>
+ )}
+ />
+ )}
+
+ <Accordion type="single" collapsible className="w-full">
+ <AccordionItem value="advance-settings" className="data-[state=open]:border-none">
+ <AccordionTrigger className="h-fit flex-none pl-1 text-sm">
+ <div className="order-1 ml-3">Advanced Settings</div>
+ </AccordionTrigger>
+ <AccordionContent childrenClassName="p-0">
+ <Controller
+ control={control}
+ name="expiresIn"
+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (
+ <FormControl
+ label="Expires In"
+ errorText={error?.message}
+ isError={Boolean(error)}
+ >
+ <Select
+ defaultValue={field.value}
+ {...field}
+ onValueChange={(e) => onChange(e)}
+ className="w-full"
+ >
- {expiresInOptions.map(({ label, value: expiresInValue }) => (
++ {filteredExpiresInOptions.map(({ label, value: expiresInValue }) => (
+ <SelectItem value={String(expiresInValue || "")} key={label}>
+ {label}
+ </SelectItem>
+ ))}
+ </Select>
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="viewLimit"
+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (
+ <FormControl
+ label="Max Views"
+ errorText={error?.message}
+ isError={Boolean(error)}
+ >
+ <Select
+ defaultValue={field.value}
+ {...field}
+ onValueChange={(e) => onChange(e)}
+ className="w-full"
+ >
- {viewLimitOptions.map(({ label, value: viewLimitValue }) => (
++ {filteredViewLimitOptions.map(({ label, value: viewLimitValue }) => (
+ <SelectItem value={String(viewLimitValue || "")} key={label}>
+ {label}
+ </SelectItem>
+ ))}
+ </Select>
+ </FormControl>
+ )}
+ />
+
+ {!isPublic && (
+ <Controller
+ control={control}
+ name="emails"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Authorized Emails"
+ isOptional
+ tooltipText="Unique secret links will be emailed to each individual. The secret will only be accessible to those links."
+ tooltipClassName="max-w-sm"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ >
+ <Input
+ {...field}
+ autoComplete="off"
+ />
+ </FormControl>
+ )}
+ />
+ )}
+ </AccordionContent>
+ </AccordionItem>
+ </Accordion>
+
+ <div className="flex w-full justify-end">
+ <Button
+ className="mt-4"
+ size="sm"
+ type="submit"
+ isLoading={isSubmitting}
+ isDisabled={isSubmitting}
+ >
+ Create Secret Link
+ </Button>
+ </div>
+ </form>
+ );
+
+ if (secretLink === "")
+ return (
+ <>
+ <div className="mt-1 flex w-full items-center justify-center gap-2">
+ <FontAwesomeIcon icon={faCheck} className="text-green-500" />
+ <span>Shared secret link has been emailed to select users.</span>
+ </div>
+ <Button
+ className="mt-6 w-full bg-mineshaft-700 py-3 text-bunker-200"
+ colorSchema="primary"
+ variant="outline_bg"
+ size="sm"
+ onClick={() => setSecretLink(null)}
+ rightIcon={<FontAwesomeIcon icon={faRedo} className="pl-2" />}
+ >
+ Share Another Secret
+ </Button>
+ </>
+ );
+
+ return (
<>
<div className="mr-2 flex items-center justify-end rounded-md bg-white/[0.05] p-2 text-base text-gray-400">
<p className="mr-4 break-all">{secretLink}</p>