diff --git a/backend/src/server/routes/v1/organization-router.ts b/backend/src/server/routes/v1/organization-router.ts index 604b5a355..c39c0ab4d 100644 --- a/backend/src/server/routes/v1/organization-router.ts +++ b/backend/src/server/routes/v1/organization-router.ts @@ -282,8 +282,12 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => { sshProductEnabled: z.boolean().optional(), scannerProductEnabled: z.boolean().optional(), shareSecretsProductEnabled: z.boolean().optional(), - maxSharedSecretLifetime: z.number().optional(), - maxSharedSecretViewLimit: z.number().nullable().optional() + maxSharedSecretLifetime: z.number().max(2592000, "Max Shared Secret lifetime cannot exceed 30 days").optional(), + maxSharedSecretViewLimit: z + .number() + .max(1000, "Max Shared Secret view count cannot exceed 1000") + .nullable() + .optional() }), response: { 200: z.object({ diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts index ed2ad41df..a40861790 100644 --- a/backend/src/services/secret-sharing/secret-sharing-service.ts +++ b/backend/src/services/secret-sharing/secret-sharing-service.ts @@ -97,6 +97,7 @@ export const secretSharingServiceFactory = ({ 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" }); } diff --git a/frontend/src/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal.tsx b/frontend/src/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal.tsx index b176ff653..a9450993f 100644 --- a/frontend/src/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal.tsx +++ b/frontend/src/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal.tsx @@ -30,8 +30,8 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => { allowSecretSharingOutsideOrganization={ currentOrg?.allowSecretSharingOutsideOrganization ?? true } - maxSharedSecretLifetime={currentOrg.maxSharedSecretLifetime} - maxSharedSecretViewLimit={currentOrg.maxSharedSecretViewLimit} + maxSharedSecretLifetime={currentOrg?.maxSharedSecretLifetime} + maxSharedSecretViewLimit={currentOrg?.maxSharedSecretViewLimit} /> diff --git a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx index ebc8dae4e..7e99bee4b 100644 --- a/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx +++ b/frontend/src/pages/public/ShareSecretPage/components/ShareSecretForm.tsx @@ -62,6 +62,7 @@ export const ShareSecretForm = ({ const privateSharedSecretCreator = useCreateSharedSecret(); const createSharedSecret = isPublic ? publicSharedSecretCreator : privateSharedSecretCreator; + // Note: maxSharedSecretLifetime is in seconds const filteredExpiresInOptions = maxSharedSecretLifetime ? expiresInOptions.filter((v) => v.value / 1000 <= maxSharedSecretLifetime) : expiresInOptions;