Skip to content

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

checkpoint

Daniel Hougaard9f8b872395e1
diff --git a/backend/src/server/routes/sanitizedSchemas.ts b/backend/src/server/routes/sanitizedSchemas.ts
index d0faff6fd8..2eb0c90f8b 100644
--- a/backend/src/server/routes/sanitizedSchemas.ts
+++ b/backend/src/server/routes/sanitizedSchemas.ts
@@ -10,6 +10,7 @@ import {
ProjectRolesSchema,
ProjectsSchema,
SecretApprovalPoliciesSchema,
+ SecretSharingSchema,
SecretTagsSchema,
UsersSchema
} from "@app/db/schemas";
@@ -295,3 +296,15 @@ export const InternalCertificateAuthorityResponseSchema = CertificateAuthorities
notAfter: z.string().optional(),
notBefore: z.string().optional()
});
+
+export const SanitizedSecretSharingSchema = SecretSharingSchema.omit({
+ encryptedSecret: true,
+ hashedHex: true,
+ iv: true,
+ tag: true,
+ encryptedValue: true,
+ password: true,
+ identifier: true // we map identifier -> id
+}).extend({
+ id: z.string() // override from uuid -> string
+});
diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.ts
index 127051440d..043a048db3 100644
--- a/backend/src/server/routes/v1/secret-sharing-router.ts
+++ b/backend/src/server/routes/v1/secret-sharing-router.ts
@@ -15,6 +15,8 @@ import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
import { SecretSharingType } from "@app/services/secret-sharing/secret-sharing-types";
+import { SanitizedSecretSharingSchema } from "../sanitizedSchemas";
+
const ALLOWED_IMAGE_CONTENT_TYPES = [
"image/png",
"image/jpeg",
@@ -42,13 +44,14 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
},
schema: {
operationId: "listSharedSecrets",
+ hide: false,
querystring: z.object({
offset: z.coerce.number().min(0).max(100).default(0),
limit: z.coerce.number().min(1).max(100).default(25)
}),
response: {
200: z.object({
- secrets: z.array(SecretSharingSchema),
+ secrets: z.array(SanitizedSecretSharingSchema),
totalCount: z.number()
})
}
@@ -73,17 +76,18 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
server.route({
method: "POST",
- url: "/public/:id",
+ url: "/public/:sharedSecretId",
config: {
rateLimit: publicEndpointLimit
},
schema: {
+ description:
+ "Retrieve the secret value of a shared secret by it's ID. If the secret is password protected, you must provide the password in the request body.",
operationId: "getPublicSharedSecret",
params: z.object({
- id: z.string()
+ sharedSecretId: z.string()
}),
body: z.object({
- hashedHex: z.string().min(1).optional(),
password: z.string().optional()
}),
response: {
@@ -98,9 +102,6 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
})
.optional(),
secret: SecretSharingSchema.pick({
- encryptedValue: true,
- iv: true,
- tag: true,
expiresAt: true,
expiresAfterViews: true,
accessType: true
@@ -116,8 +117,7 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
},
handler: async (req) => {
const sharedSecret = await req.server.services.secretSharing.getSharedSecretById({
- sharedSecretId: req.params.id,
- hashedHex: req.body.hashedHex,
+ sharedSecretId: req.params.sharedSecretId,
password: req.body.password,
orgId: req.permission?.orgId,
actorId: req.permission?.id
@@ -125,8 +125,8 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
let brandingConfig;
- if (sharedSecret.secretOrgId) {
- const orgBrandConfig = await req.server.services.secretSharing.getOrgBrandConfig(sharedSecret.secretOrgId);
+ if (sharedSecret.orgId) {
+ const orgBrandConfig = await req.server.services.secretSharing.getOrgBrandConfig(sharedSecret.orgId);
if (orgBrandConfig) {
brandingConfig = {
@@ -140,12 +140,12 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
// Verify that secret was actually returned
if (sharedSecret.secret) {
await server.services.auditLog.createAuditLog({
- orgId: sharedSecret.secretOrgId,
+ orgId: sharedSecret.orgId,
...req.auditLogInfo,
event: {
type: EventType.READ_SHARED_SECRET,
metadata: {
- id: req.params.id,
+ id: req.params.sharedSecretId,
name: sharedSecret.secret.name || undefined,
accessType: sharedSecret.secret.accessType
}
@@ -259,7 +259,7 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
sharedSecretId: z.string()
}),
response: {
- 200: SecretSharingSchema
+ 200: SanitizedSecretSharingSchema
}
},
onRequest: verifyAuth([AuthMode.JWT]),
diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts
index 4a08dcd158..0d024ff656 100644
--- a/backend/src/services/secret-sharing/secret-sharing-service.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts
@@ -44,6 +44,21 @@ type TSecretSharingServiceFactoryDep = {
export type TSecretSharingServiceFactory = ReturnType<typeof secretSharingServiceFactory>;
+const mapIdentifierToId = (sharedSecret: TSecretSharing): Omit<TSecretSharing, "identifier"> => {
+ const { identifier, ...rest } = sharedSecret;
+
+ if (!identifier) {
+ throw new BadRequestError({
+ message: `Shared secret created at ${sharedSecret.createdAt.toISOString()} has no identifier`
+ });
+ }
+
+ return {
+ ...rest,
+ id: Buffer.from(identifier, "hex").toString("base64url")
+ };
+};
+
export const secretSharingServiceFactory = ({
permissionService,
secretSharingDAL,
@@ -177,7 +192,7 @@ export const secretSharingServiceFactory = ({
authorizedEmails: emails && emails.length > 0 ? JSON.stringify(emails) : undefined
});
- const idToReturn = `${Buffer.from(newSharedSecret.identifier!, "hex").toString("base64url")}`;
+ const mappedSharedSecret = mapIdentifierToId(newSharedSecret);
// Loop through recipients and send out emails with unique access links
if (emails) {
@@ -198,7 +213,7 @@ export const secretSharingServiceFactory = ({
substitutions: {
name,
respondentUsername,
- secretRequestUrl: `${appCfg.SITE_URL}/shared/secret/${idToReturn}`
+ secretRequestUrl: `${appCfg.SITE_URL}/shared/secret/${mappedSharedSecret.id}`
},
template: SmtpTemplates.SecretRequestCompleted
});
@@ -208,7 +223,7 @@ export const secretSharingServiceFactory = ({
}
}
- return { id: idToReturn };
+ return mappedSharedSecret;
};
const createSecretRequest = async ({
@@ -450,7 +465,7 @@ export const secretSharingServiceFactory = ({
accessType
});
- return { id: `${Buffer.from(newSharedSecret.identifier!, "hex").toString("base64url")}` };
+ return mapIdentifierToId(newSharedSecret);
};
const getSharedSecrets = async ({
@@ -490,7 +505,7 @@ export const secretSharingServiceFactory = ({
});
return {
- secrets,
+ secrets: secrets.map(mapIdentifierToId),
totalCount: count
};
};
@@ -509,28 +524,17 @@ export const secretSharingServiceFactory = ({
};
/** Gets password-less secret. validates all secret's requested (must be fresh). */
- const getSharedSecretById = async ({
- sharedSecretId,
- hashedHex,
- orgId,
- actorId,
- password
- }: TGetActiveSharedSecretByIdDTO) => {
- const sharedSecret = isUuidV4(sharedSecretId)
- ? await secretSharingDAL.findOne({
- id: sharedSecretId,
- type: SecretSharingType.Share,
- hashedHex
- })
- : await secretSharingDAL.findOne({
- type: SecretSharingType.Share,
- identifier: Buffer.from(sharedSecretId, "base64url").toString("hex")
- });
+ const getSharedSecretById = async ({ sharedSecretId, orgId, actorId, password }: TGetActiveSharedSecretByIdDTO) => {
+ const sharedSecret = await secretSharingDAL.findOne({
+ type: SecretSharingType.Share,
+ identifier: Buffer.from(sharedSecretId, "base64url").toString("hex")
+ });
- if (!sharedSecret)
+ if (!sharedSecret) {
throw new NotFoundError({
message: `Shared secret with ID '${sharedSecretId}' not found`
});
+ }
const { accessType, expiresAt, expiresAfterViews } = sharedSecret;
@@ -554,8 +558,8 @@ export const secretSharingServiceFactory = ({
if (!(sharedSecret.authorizedEmails as string[]).includes(user.email))
return {
isPasswordProtected: false,
- secretOrgId: sharedSecret.orgId,
- error: "You are not authorized to view this secret"
+ error: "You are not authorized to view this secret",
+ orgId: sharedSecret.orgId
};
}
@@ -566,7 +570,7 @@ export const secretSharingServiceFactory = ({
await secretSharingDAL.softDeleteById(sharedSecret.id);
return {
isPasswordProtected: false,
- secretOrgId: sharedSecret.orgId,
+ orgId: sharedSecret.orgId,
error: "Unable to view secret: secret has expired"
};
}
@@ -576,7 +580,7 @@ export const secretSharingServiceFactory = ({
await secretSharingDAL.softDeleteById(sharedSecret.id);
return {
isPasswordProtected: false,
- secretOrgId: sharedSecret.orgId,
+ orgId: sharedSecret.orgId,
error: "Unable to view secret: view limit reached"
};
}
@@ -589,7 +593,7 @@ export const secretSharingServiceFactory = ({
const isMatch = await crypto.hashing().compareHash(password as string, sharedSecret.password as string);
if (!isMatch) throw new UnauthorizedError({ message: "Invalid credentials" });
} else {
- return { isPasswordProtected, secretOrgId: sharedSecret.orgId };
+ return { isPasswordProtected, orgId: sharedSecret.orgId };
}
}
@@ -606,9 +610,9 @@ export const secretSharingServiceFactory = ({
return {
isPasswordProtected,
- secretOrgId: sharedSecret.orgId,
+ orgId: sharedSecret.orgId,
secret: {
- ...sharedSecret,
+ ...mapIdentifierToId(sharedSecret),
...(decryptedSecretValue && {
secretValue: decryptedSecretValue.toString()
}),
@@ -650,19 +654,14 @@ export const secretSharingServiceFactory = ({
const deletedSharedSecret = await secretSharingDAL.deleteById(sharedSecret.id);
- return deletedSharedSecret;
+ return mapIdentifierToId(deletedSharedSecret);
};
const getSharedSecretOrgId = async (sharedSecretId: string) => {
- const sharedSecret = isUuidV4(sharedSecretId)
- ? await secretSharingDAL.findOne({
- id: sharedSecretId,
- type: SecretSharingType.Share
- })
- : await secretSharingDAL.findOne({
- identifier: Buffer.from(sharedSecretId, "base64url").toString("hex"),
- type: SecretSharingType.Share
- });
+ const sharedSecret = await secretSharingDAL.findOne({
+ identifier: Buffer.from(sharedSecretId, "base64url").toString("hex"),
+ type: SecretSharingType.Share
+ });
return sharedSecret?.orgId ?? null;
};
diff --git a/backend/src/services/secret-sharing/secret-sharing-types.ts b/backend/src/services/secret-sharing/secret-sharing-types.ts
index 3d968edf30..84aed6ed39 100644
--- a/backend/src/services/secret-sharing/secret-sharing-types.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-types.ts
@@ -35,7 +35,6 @@ export type TCreatePublicSharedSecretDTO = {
export type TGetActiveSharedSecretByIdDTO = {
sharedSecretId: string;
- hashedHex?: string;
orgId?: string;
actorId?: string;
password?: string;