Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
api documentation
Daniel Hougaard8e47b44f27f4
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex d327f17b1d..1f2d982c35 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -79,6 +79,7 @@ export enum ApiDocsTags {KmsEncryption = "KMS Encryption",KmsSigning = "KMS Signing",SecretScanning = "Secret Scanning",+ SecretSharing = "Secret Sharing",OidcSso = "OIDC SSO",SamlSso = "SAML SSO",LdapSso = "LDAP SSO",@@ -3331,3 +3332,35 @@ export const EventSubscriptions = {register: "List of events you want to subscribe to"}};++export const SECRET_SHARING = {+ LIST: {+ offset: "The offset to start listing shared secrets from. Used for pagination.",+ limit: "The maximum number of shared secrets to return. Max is 100."+ },+ GET_BY_ID: {+ id: "The ID of the shared secret to retrieve."+ },+ ACCESS: {+ id: "The ID of the shared secret to access.",+ password:+ "The password for accessing a password-protected shared secret. Only required if the secret is password protected."+ },+ CREATE: {+ name: "An optional name for the shared secret for easier identification.",+ secretValue: "The secret value to share.",+ expiresIn:+ "The duration after which the shared secret will expire. Accepts formats like '30d', '24h', '1w'. Maximum is 30 days, minimum is 5 minutes.",+ password:+ "An optional password to protect the shared secret. Recipients will need to provide this password to access the secret.",+ maxViews:+ "The maximum number of times the shared secret can be viewed before it expires. If not provided, unlimited views are allowed.",+ 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."+ },+ DELETE: {+ id: "The ID of the shared secret to delete."+ }+} as const;diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.tsindex 64da05fd5a..e4d6d72750 100644--- a/backend/src/server/routes/v1/secret-sharing-router.ts+++ b/backend/src/server/routes/v1/secret-sharing-router.ts@@ -2,6 +2,7 @@ import fastifyMultipart from "@fastify/multipart";import { z } from "zod";import { EventType } from "@app/ee/services/audit-log/audit-log-types";+import { ApiDocsTags, SECRET_SHARING } from "@app/lib/api-docs";import { BadRequestError, NotFoundError } from "@app/lib/errors";import { ms } from "@app/lib/ms";import { SecretSharingAccessType } from "@app/lib/types";@@ -44,12 +45,13 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>},schema: {hide: false,+ tags: [ApiDocsTags.SecretSharing],description:"List all shared secrets created by the authenticated user or identity in their current organization.",operationId: "listSharedSecrets",querystring: z.object({- offset: z.coerce.number().min(0).max(100).default(0),- limit: z.coerce.number().min(1).max(100).default(25)+ offset: z.coerce.number().min(0).max(100).default(0).describe(SECRET_SHARING.LIST.offset),+ limit: z.coerce.number().min(1).max(100).default(25).describe(SECRET_SHARING.LIST.limit)}),response: {200: z.object({@@ -84,15 +86,16 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>},schema: {hide: false,+ tags: [ApiDocsTags.SecretSharing],description:"Returns the full shared secret object without revealing the secret value. Authentication is required for shared secrets that are scoped to an organization.",operationId: "getSharedSecretById",params: z.object({- id: z.string().describe("The ID of the shared secret")+ id: z.string().describe(SECRET_SHARING.GET_BY_ID.id)}),response: {200: SanitizedSecretSharingSchema.extend({- isPasswordProtected: z.boolean()+ isPasswordProtected: z.boolean().describe("Whether the shared secret is protected by a password.")})}},@@ -114,19 +117,15 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>schema: {hide: false,+ tags: [ApiDocsTags.SecretSharing],description:"Access a shared secret by its ID. If the secret is password protected, you must provide the password in the request body. Returns the secret value if access is granted, or an error if access is denied. The endpoint requires authentication if the shared secret is scoped to an organization.",operationId: "accessSharedSecret",params: z.object({- id: z.string().describe("The ID of the shared secret to access")+ id: z.string().describe(SECRET_SHARING.ACCESS.id)}),body: z.object({- password: z- .string()- .optional()- .describe(- "The password for accessing a password-protected shared secret. This field is only required if the secret is password protected."- )+ password: z.string().optional().describe(SECRET_SHARING.ACCESS.password)}),response: {200: SanitizedSecretSharingSchema.extend({@@ -220,23 +219,28 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>},schema: {hide: false,+ tags: [ApiDocsTags.SecretSharing],description: "Create a new shared secret that can be accessed by a link.",operationId: "createSharedSecret",body: z.object({- name: z.string().max(50).optional(),- password: z.string().optional(),- secretValue: z.string(),- expiresIn: z.string().default("30d"),- maxViews: z.number().min(1).optional(),- accessType: z.nativeEnum(SecretSharingAccessType).default(SecretSharingAccessType.Organization),- emails: z+ name: z.string().max(50).optional().describe(SECRET_SHARING.CREATE.name),+ password: z.string().optional().describe(SECRET_SHARING.CREATE.password),+ secretValue: z.string().describe(SECRET_SHARING.CREATE.secretValue),+ expiresIn: z.string().default("30d").describe(SECRET_SHARING.CREATE.expiresIn),+ maxViews: z.number().min(1).optional().describe(SECRET_SHARING.CREATE.maxViews),+ accessType: z+ .nativeEnum(SecretSharingAccessType)+ .default(SecretSharingAccessType.Organization)+ .describe(SECRET_SHARING.CREATE.accessType),+ authorizedEmails: z.string().email().array().max(100).optional().transform((val) => (val ? [...new Set(val)] : undefined))+ .describe(SECRET_SHARING.CREATE.authorizedEmails)}).superRefine((data, ctx) => {const duration = ms(data.expiresIn);@@ -258,7 +262,9 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>}}),response: {- 200: SanitizedSecretSharingSchema+ 200: SanitizedSecretSharingSchema.extend({+ sharedSecretLink: z.string()+ })}},onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),@@ -300,10 +306,11 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>},schema: {hide: false,+ tags: [ApiDocsTags.SecretSharing],description: "Delete a shared secret by its ID.",operationId: "deleteSharedSecret",params: z.object({- id: z.string().describe("The ID of the shared secret to delete")+ id: z.string().describe(SECRET_SHARING.DELETE.id)}),response: {200: SanitizedSecretSharingSchemadiff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.tsindex e1eedb31cd..1a27940e53 100644--- a/backend/src/services/secret-sharing/secret-sharing-service.ts+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts@@ -108,7 +108,7 @@ export const secretSharingServiceFactory = ({accessType,expiresIn,maxViews,- emails+ authorizedEmails}: TCreateSharedSecretDTO) => {const appCfg = getConfig();@@ -156,11 +156,11 @@ export const secretSharingServiceFactory = ({const orgEmails = [];- if (emails && emails.length > 0) {+ if (authorizedEmails && authorizedEmails.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) {+ for (const email of authorizedEmails) {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@@ -195,20 +195,20 @@ export const secretSharingServiceFactory = ({...(actor === ActorType.IDENTITY && { identityId: actorId }),orgId,accessType,- authorizedEmails: emails && emails.length > 0 ? JSON.stringify(emails) : undefined+ authorizedEmails: authorizedEmails && authorizedEmails.length > 0 ? JSON.stringify(authorizedEmails) : undefined});const mappedSharedSecret = mapIdentifierToId(newSharedSecret);// Loop through recipients and send out emails with unique access links- if (emails) {+ if (authorizedEmails) {const user = await userDAL.findById(actorId);if (!user) {throw new NotFoundError({ message: `User with ID '${actorId}' not found` });}- for await (const email of emails) {+ for await (const email of authorizedEmails) {try {// Only show the username to emails which are part of the organizationconst respondentUsername = orgEmails.includes(email) ? user.username : undefined;@@ -229,7 +229,10 @@ export const secretSharingServiceFactory = ({}}- return mappedSharedSecret;+ return {+ ...mappedSharedSecret,+ sharedSecretLink: `${appCfg.SITE_URL}/shared/secret/${mappedSharedSecret.id}`+ };};const createSecretRequest = async ({diff --git a/backend/src/services/secret-sharing/secret-sharing-types.ts b/backend/src/services/secret-sharing/secret-sharing-types.tsindex cfaa0ef955..dd67d3d372 100644--- a/backend/src/services/secret-sharing/secret-sharing-types.ts+++ b/backend/src/services/secret-sharing/secret-sharing-types.ts@@ -22,7 +22,7 @@ export type TSharedSecretPermission = {accessType?: SecretSharingAccessType;name?: string;password?: string;- emails?: string[];+ authorizedEmails?: string[];};export type TCreatePublicSharedSecretDTO = {