Skip to content

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

feat: secrets expire either with time or views

ShubhamPalriwala29b106c5bd69
diff --git a/backend/src/db/migrations/20240530044702_universal-text-in-secret-sharing.ts b/backend/src/db/migrations/20240530044702_universal-text-in-secret-sharing.ts
index 63d9dd81c5..e23d134db8 100644
--- a/backend/src/db/migrations/20240530044702_universal-text-in-secret-sharing.ts
+++ b/backend/src/db/migrations/20240530044702_universal-text-in-secret-sharing.ts
@@ -8,8 +8,7 @@ export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable(TableName.SecretSharing, (t) => {
if (!hasExpiresAfterViewsColumn) {
- t.integer("expiresAfterViews").nullable();
- t.timestamp("expiresAt").nullable().alter();
+ t.integer("expiresAfterViews");
}
if (hasSecretNameColumn) {
@@ -25,7 +24,6 @@ export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable(TableName.SecretSharing, (t) => {
if (hasExpiresAfterViewsColumn) {
t.dropColumn("expiresAfterViews");
- t.timestamp("expiresAt").notNullable().alter();
}
if (!hasSecretNameColumn) {
diff --git a/backend/src/db/schemas/secret-sharing.ts b/backend/src/db/schemas/secret-sharing.ts
index 541cd1fc01..6fa104ebeb 100644
--- a/backend/src/db/schemas/secret-sharing.ts
+++ b/backend/src/db/schemas/secret-sharing.ts
@@ -13,7 +13,7 @@ export const SecretSharingSchema = z.object({
iv: z.string(),
tag: z.string(),
hashedHex: z.string(),
- expiresAt: z.date().nullable().optional(),
+ expiresAt: z.date(),
userId: z.string().uuid(),
orgId: z.string().uuid(),
createdAt: z.date(),
diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.ts
index f1016576cd..6cb5516986 100644
--- a/backend/src/server/routes/v1/secret-sharing-router.ts
+++ b/backend/src/server/routes/v1/secret-sharing-router.ts
@@ -84,9 +84,8 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
hashedHex: z.string(),
expiresAt: z
.string()
- .optional()
.refine((date) => date === undefined || new Date(date) > new Date(), "Expires at should be a future date"),
- expiresAfterViews: z.number().optional()
+ expiresAfterViews: z.number()
}),
response: {
200: z.object({
@@ -107,7 +106,7 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
iv,
tag,
hashedHex,
- expiresAt: expiresAt ? new Date(expiresAt) : undefined,
+ expiresAt: new Date(expiresAt),
expiresAfterViews
});
return { id: sharedSecret.id };
diff --git a/backend/src/services/secret-sharing/secret-sharing-types.ts b/backend/src/services/secret-sharing/secret-sharing-types.ts
index 5af475c529..5f35b28483 100644
--- a/backend/src/services/secret-sharing/secret-sharing-types.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-types.ts
@@ -13,8 +13,8 @@ export type TCreateSharedSecretDTO = {
iv: string;
tag: string;
hashedHex: string;
- expiresAt?: Date;
- expiresAfterViews?: number;
+ expiresAt: Date;
+ expiresAfterViews: number;
} & TSharedSecretPermission;
export type TDeleteSharedSecretDTO = {
diff --git a/docs/documentation/platform/secret-sharing.mdx b/docs/documentation/platform/secret-sharing.mdx
index 525f3512e0..680751820a 100644
--- a/docs/documentation/platform/secret-sharing.mdx
+++ b/docs/documentation/platform/secret-sharing.mdx
@@ -1,11 +1,11 @@
---
title: "Secret Sharing"
sidebarTitle: "Secret Sharing"
-description: "Learn how to share time or view-count bound secrets securely with anyone on the internet."
+description: "Learn how to share time & view-count bound secrets securely with anyone on the internet."
---
Developers frequently need to share secrets with team members, contractors, or other third parties, which can be risky due to potential leaks or misuse.
-Infisical offers a secure solution for sharing secrets over the internet in a time-bound manner as well as view count bound manner.
+Infisical offers a secure solution for sharing secrets over the internet in a time and view count bound manner.
With its zero-knowledge architecture, secrets shared via Infisical remain unreadable even to Infisical itself.
@@ -21,15 +21,9 @@ With its zero-knowledge architecture, secrets shared via Infisical remain unread
zero knowledge architecture.
</Note>
-3. Click on the **Share Secret** button.
+3. Click on the **Share Secret** button. Set the secret, its expiration time as well as the number of views allowed. It expires as soon as any of the conditions are met.
- a. Time-bound secret: Set the expiration time in minutes, hours, days, or weeks.
-
- ![Add Time-Bound Sharing Secret](../../images/platform/secret-sharing/new-time-bound-secret.png)
-
- b. View Count-bound secret: Set the number of views after which the secret will expire.
-
- ![Add View-Bound Sharing Secret](../../images/platform/secret-sharing/new-view-bound-secret.png)
+ ![Add View-Bound Sharing Secret](../../images/platform/secret-sharing/create-new-secret.png)
<Note>
Secret once set cannot be changed. This is to ensure that the secret is not
diff --git a/docs/images/platform/secret-sharing/create-new-secret.png b/docs/images/platform/secret-sharing/create-new-secret.png
new file mode 100644
index 0000000000..335fca2b25
Binary files /dev/null and b/docs/images/platform/secret-sharing/create-new-secret.png differ
diff --git a/docs/images/platform/secret-sharing/new-secret.png b/docs/images/platform/secret-sharing/new-secret.png
deleted file mode 100644
index 7ac97c132e..0000000000
Binary files a/docs/images/platform/secret-sharing/new-secret.png and /dev/null differ
diff --git a/docs/images/platform/secret-sharing/new-time-bound-secret.png b/docs/images/platform/secret-sharing/new-time-bound-secret.png
deleted file mode 100644
index fb00ccbd0a..0000000000
Binary files a/docs/images/platform/secret-sharing/new-time-bound-secret.png and /dev/null differ
diff --git a/docs/images/platform/secret-sharing/new-view-bound-secret.png b/docs/images/platform/secret-sharing/new-view-bound-secret.png
deleted file mode 100644
index bc88c3bf5a..0000000000
Binary files a/docs/images/platform/secret-sharing/new-view-bound-secret.png and /dev/null differ
diff --git a/docs/images/platform/secret-sharing/public-view.png b/docs/images/platform/secret-sharing/public-view.png
index f1bd9482f7..8b4077c652 100644
Binary files a/docs/images/platform/secret-sharing/public-view.png and b/docs/images/platform/secret-sharing/public-view.png differ
diff --git a/frontend/src/hooks/api/secretSharing/types.ts b/frontend/src/hooks/api/secretSharing/types.ts
index 272100bc6a..424e3525c7 100644
--- a/frontend/src/hooks/api/secretSharing/types.ts
+++ b/frontend/src/hooks/api/secretSharing/types.ts
@@ -11,8 +11,8 @@ export type TCreateSharedSecretRequest = {
iv: string;
tag: string;
hashedHex: string;
- expiresAt?: Date;
- expiresAfterViews?: number;
+ expiresAt: Date;
+ expiresAfterViews: number;
};
export type TViewSharedSecretResponse = {
diff --git a/frontend/src/views/ShareSecretPage/components/AddShareSecretModal.tsx b/frontend/src/views/ShareSecretPage/components/AddShareSecretModal.tsx
index 107c9beb40..5fae1067a5 100644
--- a/frontend/src/views/ShareSecretPage/components/AddShareSecretModal.tsx
+++ b/frontend/src/views/ShareSecretPage/components/AddShareSecretModal.tsx
@@ -20,7 +20,7 @@ import {
ModalContent,
SecretInput,
Select,
- SelectItem,
+ SelectItem
} from "@app/components/v2";
import { useOrganization } from "@app/context";
import { useTimedReset } from "@app/hooks";
@@ -62,10 +62,9 @@ const expirationUnitsAndActions = [
const schema = yup.object({
value: yup.string().max(10000).required().label("Shared Secret Value"),
- expiryOption: yup.string().optional().label("Expiration Option").default("Time"),
- expiresAfterViews: yup.number().min(1).optional().label("Expires After Views"),
- expiresInValue: yup.number().min(1).optional().label("Expiration Value"),
- expiresInUnit: yup.string().optional().label("Expiration Unit")
+ expiresAfterViews: yup.number().min(1).required().label("Expires After Views"),
+ expiresInValue: yup.number().min(1).required().label("Expiration Value"),
+ expiresInUnit: yup.string().required().label("Expiration Unit")
});
export type FormData = yup.InferType<typeof schema>;
@@ -90,7 +89,6 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
const createSharedSecret = useCreateSharedSecret();
const { currentOrg } = useOrganization();
const [newSharedSecret, setnewSharedSecret] = useState("");
- const [expiryOption, setExpiryOption] = useState<"Time" | "Views">("Time");
const hasSharedSecret = Boolean(newSharedSecret);
const [isUrlCopied, , setIsUrlCopied] = useTimedReset<boolean>({
initialState: false
@@ -134,8 +132,8 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
iv,
tag,
hashedHex,
- expiresAt: expiryOption === "Time" ? expiresAt : undefined,
- expiresAfterViews: expiryOption === "Views" ? expiresAfterViews : undefined
+ expiresAt,
+ expiresAfterViews
});
setnewSharedSecret(
`${window.location.origin}/shared/secret/${id}?key=${encodeURIComponent(
@@ -198,98 +196,72 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
)}
/>
<div className="flex w-full flex-row">
- <div className="flex w-1/5">
+ <div className="w-2/7 flex">
<Controller
control={control}
- name="expiryOption"
- defaultValue="Time"
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
+ name="expiresAfterViews"
+ defaultValue={1}
+ render={({ field, fieldState: { error } }) => (
<FormControl
- label="Expire On"
- errorText={error?.message}
+ className="mb-4 w-full"
+ label="Expires After Views"
isError={Boolean(error)}
+ errorText={error?.message}
>
- <Select
- defaultValue={field.value}
- {...field}
- onValueChange={(e: "Time" | "Views") => setExpiryOption(e)}
- value={expiryOption}
- className="w-full"
- >
- {["Time", "Views"].map((unit) => (
- <SelectItem value={unit} key={unit}>
- {unit}
- </SelectItem>
- ))}
- </Select>
+ <Input {...field} type="number" min={1} />
</FormControl>
)}
/>
</div>
- <div className="flex w-4/5">
- {expiryOption === "Views" ? (
- <Controller
- control={control}
- name="expiresAfterViews"
- defaultValue={1}
- render={({ field, fieldState: { error } }) => (
- <FormControl
- className="mb-4 w-full"
- label="Expires After Views"
- isError={Boolean(error)}
- errorText={error?.message}
- >
- <Input {...field} type="number" min={1} />
- </FormControl>
- )}
- />
- ) : (
- <div className="flex w-full">
- <div className="w-3/5">
- <Controller
- control={control}
- name="expiresInValue"
- defaultValue={1}
- render={({ field, fieldState: { error } }) => (
- <FormControl
- label="Expiration Value"
- isError={Boolean(error)}
- errorText={error?.message}
- >
- <Input {...field} type="number" min={0} />
- </FormControl>
- )}
- />
- </div>
- <div className="w-2/5 pl-4">
- <Controller
- control={control}
- name="expiresInUnit"
- defaultValue={expirationUnitsAndActions[0].unit}
- render={({ field: { onChange, ...field }, fieldState: { error } }) => (
- <FormControl
- label="Expiration Unit"
- errorText={error?.message}
- isError={Boolean(error)}
+ <div className="w-1/7 flex items-center justify-center px-2">
+ <p className="px-4 text-sm text-gray-400">OR</p>
+ </div>
+ <div className="w-4/7 flex">
+ <div className="flex w-full">
+ <div className="flex w-2/5 w-full justify-center">
+ <Controller
+ control={control}
+ name="expiresInValue"
+ defaultValue={1}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Expires after Time"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ >
+ <Input {...field} type="number" min={0} />
+ </FormControl>
+ )}
+ />
+ </div>
+ <div className="flex w-3/5 w-full justify-center">
+ <Controller
+ control={control}
+ name="expiresInUnit"
+ defaultValue={expirationUnitsAndActions[0].unit}
+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (
+ <FormControl
+ label="Unit"
+ errorText={error?.message}
+ isError={Boolean(error)}
+ >
+ <Select
+ defaultValue={field.value}
+ {...field}
+ onValueChange={(e) => onChange(e)}
+ className="w-full"
>
- <Select
- defaultValue={field.value}
- {...field}
- onValueChange={(e) => onChange(e)}
- className="w-full"
- >
- {expirationUnitsAndActions.map(({ unit }) => (
- <SelectItem value={unit} key={unit}>
- {unit}
- </SelectItem>
- ))}
- </Select>
- </FormControl>
- )}
- />
- </div>
+ {expirationUnitsAndActions.map(({ unit }) => (
+ <SelectItem value={unit} key={unit}>
+ {unit}
+ </SelectItem>
+ ))}
+ </Select>
+ </FormControl>
+ )}
+ />
</div>
- )}
+ </div>
</div>
</div>
<div className="flex items-center">
diff --git a/frontend/src/views/ShareSecretPage/components/ShareSecretsRow.tsx b/frontend/src/views/ShareSecretPage/components/ShareSecretsRow.tsx
index f26ecd61a1..f731fe19b5 100644
--- a/frontend/src/views/ShareSecretPage/components/ShareSecretsRow.tsx
+++ b/frontend/src/views/ShareSecretPage/components/ShareSecretsRow.tsx
@@ -110,22 +110,17 @@ export const ShareSecretsRow = ({
<p className="text-xs text-gray-500">{formatDate(row.createdAt)}</p>
</Td>
<Td>
- {row.expiresAfterViews ? (
- <p
- className={`text-sm ${row.expiresAfterViews <= 0 ? "text-red-500" : "text-green-500"}`}
- >
- Valid for {row.expiresAfterViews} more views
+ <>
+ <p className={`text-sm ${isExpired(row.expiresAt) ? "text-red-500" : "text-green-500"}`}>
+ {getValidityStatusText(row.expiresAt!) + timeAgo(row.expiresAt!, currentTime)}
</p>
- ) : (
- <>
- <p
- className={`text-sm ${isExpired(row.expiresAt) ? "text-red-500" : "text-green-500"}`}
- >
- {getValidityStatusText(row.expiresAt!) + timeAgo(row.expiresAt!, currentTime)}
- </p>
- <p className="text-xs text-gray-500">{formatDate(row.expiresAt!)}</p>
- </>
- )}
+ <p className="text-xs text-gray-500">{formatDate(row.expiresAt!)}</p>
+ </>
+ </Td>
+ <Td>
+ <p className={`text-sm ${row.expiresAfterViews <= 0 ? "text-red-500" : "text-green-500"}`}>
+ {row.expiresAfterViews}
+ </p>
</Td>
<Td>
<IconButton
diff --git a/frontend/src/views/ShareSecretPage/components/ShareSecretsTable.tsx b/frontend/src/views/ShareSecretPage/components/ShareSecretsTable.tsx
index ee03d60144..fe02af8649 100644
--- a/frontend/src/views/ShareSecretPage/components/ShareSecretsTable.tsx
+++ b/frontend/src/views/ShareSecretPage/components/ShareSecretsTable.tsx
@@ -33,15 +33,11 @@ export const ShareSecretsTable = ({ handlePopUpOpen }: Props) => {
const { isLoading, data = [] } = useGetSharedSecrets();
let tableData = data.filter(
- (secret) =>
- (secret.expiresAt && new Date(secret.expiresAt) > new Date()) ||
- (secret.expiresAfterViews && secret.expiresAfterViews > 0)
+ (secret) => new Date(secret.expiresAt) > new Date() && secret.expiresAfterViews > 0
);
const handleSecretExpiration = () => {
tableData = data.filter(
- (secret) =>
- (secret.expiresAt && new Date(secret.expiresAt) > new Date()) ||
- (secret.expiresAfterViews && secret.expiresAfterViews > 0)
+ (secret) => new Date(secret.expiresAt) > new Date() && secret.expiresAfterViews > 0
);
};
@@ -50,7 +46,7 @@ export const ShareSecretsTable = ({ handlePopUpOpen }: Props) => {
<Table>
<THead>
<Tr>
- <Th>Encrypted Secret</Th> <Th>Created</Th> <Th>Valid Until</Th>
+ <Th>Encrypted Secret</Th> <Th>Created</Th> <Th>Valid Until</Th> <Th>Views Left</Th>
<Th aria-label="button" />
</Tr>
</THead>
diff --git a/frontend/src/views/ShareSecretPublicPage/components/SecretTable.tsx b/frontend/src/views/ShareSecretPublicPage/components/SecretTable.tsx
index 526798871f..14c5092e77 100644
--- a/frontend/src/views/ShareSecretPublicPage/components/SecretTable.tsx
+++ b/frontend/src/views/ShareSecretPublicPage/components/SecretTable.tsx
@@ -27,7 +27,7 @@ export const SecretTable = ({
)}
{!isLoading && decryptedSecret && (
<>
- <div className="max-w-[20rem] flex-1 break-words pr-4">
+ <div className="min-w-[12rem] max-w-[20rem] flex-1 break-words pr-4">
<SecretInput isVisible value={decryptedSecret} readOnly />
</div>
<IconButton