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
feat: added secret value blind index support
=4b5c7acb0ab2
diff --git a/backend/src/db/migrations/20260522180000_add-secret-value-blind-index.ts b/backend/src/db/migrations/20260522180000_add-secret-value-blind-index.tsnew file mode 100644index 0000000000..4a307c48b9--- /dev/null+++ b/backend/src/db/migrations/20260522180000_add-secret-value-blind-index.ts@@ -0,0 +1,46 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++export async function up(knex: Knex): Promise<void> {+ // Add secretValueBlindIndex to secrets_v2+ if (await knex.schema.hasTable(TableName.SecretV2)) {+ const hasColumn = await knex.schema.hasColumn(TableName.SecretV2, "secretValueBlindIndex");+ if (!hasColumn) {+ await knex.schema.alterTable(TableName.SecretV2, (t) => {+ // 64 chars = 32 bytes hex encoded (HMAC-SHA256 output)+ t.string("secretValueBlindIndex", 64).nullable();+ });+ }+ }++ // Add secretValueBlindIndex to secret_versions_v2 for history tracking+ if (await knex.schema.hasTable(TableName.SecretVersionV2)) {+ const hasColumn = await knex.schema.hasColumn(TableName.SecretVersionV2, "secretValueBlindIndex");+ if (!hasColumn) {+ await knex.schema.alterTable(TableName.SecretVersionV2, (t) => {+ t.string("secretValueBlindIndex", 64).nullable();+ });+ }+ }+}++export async function down(knex: Knex): Promise<void> {+ if (await knex.schema.hasTable(TableName.SecretV2)) {+ const hasColumn = await knex.schema.hasColumn(TableName.SecretV2, "secretValueBlindIndex");+ if (hasColumn) {+ await knex.schema.alterTable(TableName.SecretV2, (t) => {+ t.dropColumn("secretValueBlindIndex");+ });+ }+ }++ if (await knex.schema.hasTable(TableName.SecretVersionV2)) {+ const hasColumn = await knex.schema.hasColumn(TableName.SecretVersionV2, "secretValueBlindIndex");+ if (hasColumn) {+ await knex.schema.alterTable(TableName.SecretVersionV2, (t) => {+ t.dropColumn("secretValueBlindIndex");+ });+ }+ }+}diff --git a/backend/src/db/migrations/20260522180100_add-secret-value-blind-index-idx.ts b/backend/src/db/migrations/20260522180100_add-secret-value-blind-index-idx.tsnew file mode 100644index 0000000000..49b6ec8804--- /dev/null+++ b/backend/src/db/migrations/20260522180100_add-secret-value-blind-index-idx.ts@@ -0,0 +1,23 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++export async function up(knex: Knex): Promise<void> {+ if (await knex.schema.hasTable(TableName.SecretV2)) {+ // Partial index: only index rows where secretValueBlindIndex is not null+ // This saves space for secrets without a blind index (e.g., empty values)+ await knex.raw(`+ CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_secrets_v2_secret_value_blind_index+ ON ${TableName.SecretV2} ("secretValueBlindIndex")+ WHERE "secretValueBlindIndex" IS NOT NULL+ `);+ }+}++export async function down(knex: Knex): Promise<void> {+ await knex.raw(`DROP INDEX CONCURRENTLY IF EXISTS idx_secrets_v2_secret_value_blind_index`);+}++// CONCURRENTLY requires running outside a transaction+const config = { transaction: false };+export { config };diff --git a/backend/src/db/schemas/secret-versions-v2.ts b/backend/src/db/schemas/secret-versions-v2.tsindex af156797ab..ce3ef3975f 100644--- a/backend/src/db/schemas/secret-versions-v2.ts+++ b/backend/src/db/schemas/secret-versions-v2.ts@@ -32,7 +32,8 @@ export const SecretVersionsV2Schema = z.object({parentVersionId: z.string().uuid().nullable().optional(),isRedacted: z.boolean().default(false),redactedAt: z.date().nullable().optional(),- redactedByUserId: z.string().uuid().nullable().optional()+ redactedByUserId: z.string().uuid().nullable().optional(),+ secretValueBlindIndex: z.string().nullable().optional()});export type TSecretVersionsV2 = z.infer<typeof SecretVersionsV2Schema>;diff --git a/backend/src/db/schemas/secrets-v2.ts b/backend/src/db/schemas/secrets-v2.tsindex 18fa3b4762..296d3f166b 100644--- a/backend/src/db/schemas/secrets-v2.ts+++ b/backend/src/db/schemas/secrets-v2.ts@@ -23,7 +23,8 @@ export const SecretsV2Schema = z.object({userId: z.string().uuid().nullable().optional(),folderId: z.string().uuid(),createdAt: z.date(),- updatedAt: z.date()+ updatedAt: z.date(),+ secretValueBlindIndex: z.string().nullable().optional()});export type TSecretsV2 = z.infer<typeof SecretsV2Schema>;diff --git a/backend/src/ee/services/honey-token/honey-token-service.ts b/backend/src/ee/services/honey-token/honey-token-service.tsindex 225d3ad542..f6455ea1d3 100644--- a/backend/src/ee/services/honey-token/honey-token-service.ts+++ b/backend/src/ee/services/honey-token/honey-token-service.ts@@ -312,7 +312,7 @@ export const honeyTokenServiceFactory = ({plainText: Buffer.from(JSON.stringify(honeyTokenCredentials))}).cipherTextBlob;- const { encryptor: secretEncryptor } = await kmsService.createCipherPairWithDataKey({+ const { encryptor: secretEncryptor, generateSecretBlindIndex } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,projectId});@@ -362,17 +362,22 @@ export const honeyTokenServiceFactory = ({tx);- const createdSecrets = await fnSecretBulkInsert({- folderId: folder.id,- orgId: actor.orgId,- inputSecrets: secretEntries.map(({ key, value }) => ({+ const inputSecretsWithBlindIndex = await Promise.all(+ secretEntries.map(async ({ key, value }) => ({key,type: SecretType.Shared,encryptedValue: secretEncryptor({plainText: Buffer.from(value)}).cipherTextBlob,+ secretValueBlindIndex: await generateSecretBlindIndex(Buffer.from(value)),references: []- })),+ }))+ );++ const createdSecrets = await fnSecretBulkInsert({+ folderId: folder.id,+ orgId: actor.orgId,+ inputSecrets: inputSecretsWithBlindIndex,secretDAL,secretVersionDAL,secretVersionTagDAL,@@ -507,10 +512,11 @@ export const honeyTokenServiceFactory = ({decryptor({ cipherTextBlob: honeyToken.encryptedCredentials }).toString()) as Record<string, string>;- const { encryptor: secretEncryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });+ const { encryptor: secretEncryptor, generateSecretBlindIndex: generateBlindIndex } =+ await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });const secretEntries = Object.entries(nextSecretsMapping).map(([credentialField, secretKey]) => {const credentialValue = decryptedCredentials[credentialField];@@ -536,17 +542,22 @@ export const honeyTokenServiceFactory = ({tx});- const createdSecrets = await fnSecretBulkInsert({- folderId: honeyToken.folderId,- orgId: actor.orgId,- inputSecrets: secretEntries.map(({ key, value }) => ({+ const inputSecretsWithBlindIndex = await Promise.all(+ secretEntries.map(async ({ key, value }) => ({key,type: SecretType.Shared,encryptedValue: secretEncryptor({plainText: Buffer.from(value)}).cipherTextBlob,+ secretValueBlindIndex: await generateBlindIndex(Buffer.from(value)),references: []- })),+ }))+ );++ const createdSecrets = await fnSecretBulkInsert({+ folderId: honeyToken.folderId,+ orgId: actor.orgId,+ inputSecrets: inputSecretsWithBlindIndex,secretDAL,secretVersionDAL,secretVersionTagDAL,diff --git a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.tsindex 457699a751..2946d52840 100644--- a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts+++ b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts@@ -691,7 +691,11 @@ export const secretApprovalRequestServiceFactory = ({throw new NotFoundError({ message: `No secrets found in secret change request with ID '${approvalId}'` });}- const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({+ const {+ decryptor: secretManagerDecryptor,+ generateSecretBlindIndex,+ encryptor: secretManagerEncryptor+ } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,projectId});@@ -744,6 +748,12 @@ export const secretApprovalRequestServiceFactory = ({const secretDeletionCommits = secretApprovalSecrets.filter(({ op }) => op === SecretOperations.Delete);mergeStatus = await secretApprovalRequestDAL.transaction(async (tx) => {+ const creationBlindIndexes = await Promise.all(+ secretCreationCommits.map((el) =>+ el.encryptedValue ? generateSecretBlindIndex(el.encryptedValue) : Promise.resolve(undefined)+ )+ );+const newSecrets = secretCreationCommits.length? await fnSecretV2BridgeBulkInsert({tx,@@ -753,12 +763,13 @@ export const secretApprovalRequestServiceFactory = ({type: actor},orgId: actorOrgId,- inputSecrets: secretCreationCommits.map((el) => {+ inputSecrets: secretCreationCommits.map((el, idx) => {return {tagIds: el?.tags.map(({ id }) => id),version: 1,encryptedComment: el.encryptedComment,encryptedValue: el.encryptedValue,+ secretValueBlindIndex: creationBlindIndexes[idx],skipMultilineEncoding: el.skipMultilineEncoding,key: el.key,secretMetadata: (Array.isArray(el.secretMetadata)@@ -798,11 +809,6 @@ export const secretApprovalRequestServiceFactory = ({const folderPaths = await folderDAL.findSecretPathByFolderIds(projectId, [folderId], tx);const destinationSecretPath = folderPaths?.[0]?.path || "/";- const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });-const createdSecretsByKey = new Map(newSecrets.map((s) => [s.key, s]));for await (const moveCommit of moveSecretCommits) {@@ -836,11 +842,22 @@ export const secretApprovalRequestServiceFactory = ({folderDAL,encryptor: ({ plainText }) => secretManagerEncryptor({ plainText }),decryptor: ({ cipherTextBlob }) => secretManagerDecryptor({ cipherTextBlob }),+ generateSecretBlindIndex,tx});}}+ const updationBlindIndexes = await Promise.all(+ secretUpdationCommits.map((el) => {+ const shouldComputeBlindIndex =+ !el.secret?.isRotatedSecret && el.encryptedValue !== null && el.encryptedValue !== undefined;+ return shouldComputeBlindIndex+ ? generateSecretBlindIndex(el.encryptedValue as Buffer)+ : Promise.resolve(undefined);+ })+ );+const updatedSecrets = secretUpdationCommits.length? await fnSecretV2BridgeBulkUpdate({folderId,@@ -850,11 +867,12 @@ export const secretApprovalRequestServiceFactory = ({type: actor},tx,- inputSecrets: secretUpdationCommits.map((el) => {+ inputSecrets: secretUpdationCommits.map((el, idx) => {const encryptedValue =!el.secret?.isRotatedSecret && el.encryptedValue !== null && el.encryptedValue !== undefined? {encryptedValue: el.encryptedValue,+ secretValueBlindIndex: updationBlindIndexes[idx],references: el.encryptedValue? getAllSecretReferencesV2Bridge(secretManagerDecryptor({@@ -903,11 +921,6 @@ export const secretApprovalRequestServiceFactory = ({const folderPaths = await folderDAL.findSecretPathByFolderIds(projectId, [folderId], tx);const secretPath = folderPaths?.[0]?.path || "/";- const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });-for await (const rename of secretKeyRenames) {// eslint-disable-next-line no-continueif (!rename.secret || !rename.secretId) continue;@@ -928,6 +941,7 @@ export const secretApprovalRequestServiceFactory = ({folderDAL,encryptor: ({ plainText }) => secretManagerEncryptor({ plainText }),decryptor: ({ cipherTextBlob }) => secretManagerDecryptor({ cipherTextBlob }),+ generateSecretBlindIndex,tx});}diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.tsindex 79ead58a28..688c86854a 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts@@ -632,22 +632,27 @@ export const secretRotationV2ServiceFactory = ({const secretsPayload = rotationFactory.getSecretsPayload(newCredentials);- const { encryptor } = await kmsService.createCipherPairWithDataKey({+ const { encryptor, generateSecretBlindIndex } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,projectId});- const mappedSecrets = await fnSecretBulkInsert({- folderId: folder.id,- orgId: connection.orgId,- tx,- inputSecrets: secretsPayload.map(({ key, value }) => ({+ const inputSecretsWithBlindIndex = await Promise.all(+ secretsPayload.map(async ({ key, value }) => ({key,encryptedValue: encryptor({plainText: Buffer.from(value)}).cipherTextBlob,+ secretValueBlindIndex: await generateSecretBlindIndex(Buffer.from(value)),references: []- })),+ }))+ );++ const mappedSecrets = await fnSecretBulkInsert({+ folderId: folder.id,+ orgId: connection.orgId,+ tx,+ inputSecrets: inputSecretsWithBlindIndex,secretDAL: secretV2BridgeDAL,secretVersionDAL: secretVersionV2BridgeDAL,secretVersionTagDAL: secretVersionTagV2BridgeDAL,@@ -1027,11 +1032,14 @@ export const secretRotationV2ServiceFactory = ({const mappedKeys = Object.values(secretsMapping as TSecretRotationV2["secretsMapping"]);- const { encryptor: secretManagerEncryptor, decryptor: secretManagerDecryptor } =- await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });+ const {+ encryptor: secretManagerEncryptor,+ decryptor: secretManagerDecryptor,+ generateSecretBlindIndex+ } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });const updatedRotation = await secretRotationV2DAL.transaction(async (tx) => {const conflictingRotation = await secretRotationV2DAL.findOne({@@ -1114,6 +1122,7 @@ export const secretRotationV2ServiceFactory = ({secretQueueService,encryptor: ({ plainText }) => secretManagerEncryptor({ plainText }),decryptor: ({ cipherTextBlob }) => secretManagerDecryptor({ cipherTextBlob }),+ generateSecretBlindIndex,tx});}@@ -1262,17 +1271,14 @@ export const secretRotationV2ServiceFactory = ({return secretRotationV2DAL.transaction(async (tx) => {const secretsPayload = rotationFactory.getSecretsPayload(newCredentials);- const { encryptor } = await kmsService.createCipherPairWithDataKey({+ const { encryptor, generateSecretBlindIndex } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,projectId});// update mapped secrets with new credential values- await fnSecretBulkUpdate({- folderId,- orgId: connection.orgId,- tx,- inputSecrets: secretsPayload.map(({ key, value }) => ({+ const inputSecretsWithBlindIndex = await Promise.all(+ secretsPayload.map(async ({ key, value }) => ({filter: {key,folderId,@@ -1282,9 +1288,17 @@ export const secretRotationV2ServiceFactory = ({encryptedValue: encryptor({plainText: Buffer.from(value)}).cipherTextBlob,+ secretValueBlindIndex: await generateSecretBlindIndex(Buffer.from(value)),references: []}- })),+ }))+ );++ await fnSecretBulkUpdate({+ folderId,+ orgId: connection.orgId,+ tx,+ inputSecrets: inputSecretsWithBlindIndex,secretDAL: secretV2BridgeDAL,secretVersionDAL: secretVersionV2BridgeDAL,secretVersionTagDAL: secretVersionTagV2BridgeDAL,@@ -1941,13 +1955,14 @@ export const secretRotationV2ServiceFactory = ({});return secretRotationV2DAL.transaction(async (tx) => {- const { encryptor } = await kmsService.createCipherPairWithDataKey({+ const { encryptor, generateSecretBlindIndex } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,projectId});// Update the password secret with the new valueconst secretsMapping = secretRotation.secretsMapping as TLocalAccountRotation["secretsMapping"];+ const passwordBuffer = Buffer.from(localAccountCredentials.password);await fnSecretBulkUpdate({folderId,@@ -1962,8 +1977,9 @@ export const secretRotationV2ServiceFactory = ({},data: {encryptedValue: encryptor({- plainText: Buffer.from(localAccountCredentials.password)+ plainText: passwordBuffer}).cipherTextBlob,+ secretValueBlindIndex: await generateSecretBlindIndex(passwordBuffer),references: []}}diff --git a/backend/src/lib/crypto/blind-index.ts b/backend/src/lib/crypto/blind-index.tsnew file mode 100644index 0000000000..fce6e734b2--- /dev/null+++ b/backend/src/lib/crypto/blind-index.ts@@ -0,0 +1,50 @@+import crypto from "node:crypto";++const BLIND_INDEX_CONTEXT = "infisical-secret-value-blind-index-v1";++/**+ * Derives a blind index key from the KMS data key using HKDF.+ * The context string ensures domain separation — the derived key+ * can only be used for blind indexing, not for encryption/decryption.+ */+export const deriveSecretValueBlindIndexKey = async (kmsDataKey: Buffer): Promise<Buffer> => {+ return new Promise((resolve, reject) => {+ crypto.hkdf(+ "sha256",+ kmsDataKey,+ Buffer.alloc(0), // salt (empty is acceptable for key derivation from high-entropy input)+ Buffer.from(BLIND_INDEX_CONTEXT),+ 32, // 256-bit output key+ (err, derivedKey) => {+ if (err) reject(err);+ else resolve(Buffer.from(derivedKey));+ }+ );+ });+};++/**+ * Generates a blind index for a secret value using HMAC-SHA256.+ * Uses Web Crypto API for async, non-blocking operation.+ */+export const generateSecretValueBlindIndex = async (secretValue: Buffer, blindIndexKey: Buffer): Promise<string> => {+ const cryptoKey = await crypto.subtle.importKey("raw", blindIndexKey, { name: "HMAC", hash: "SHA-256" }, false, [+ "sign"+ ]);++ const signature = await crypto.subtle.sign("HMAC", cryptoKey, secretValue);++ return Buffer.from(signature).toString("hex");+};++/**+ * Convenience wrapper that derives the blind index key from KMS data key+ * and generates the blind index in one call.+ */+export const generateSecretValueBlindIndexFromKmsKey = async (+ secretValue: Buffer,+ kmsDataKey: Buffer+): Promise<string> => {+ const blindIndexKey = await deriveSecretValueBlindIndexKey(kmsDataKey);+ return generateSecretValueBlindIndex(secretValue, blindIndexKey);+};diff --git a/backend/src/lib/crypto/index.ts b/backend/src/lib/crypto/index.tsindex dd12c92da7..432677e71e 100644--- a/backend/src/lib/crypto/index.ts+++ b/backend/src/lib/crypto/index.ts@@ -1,3 +1,8 @@+export {+ deriveSecretValueBlindIndexKey,+ generateSecretValueBlindIndex,+ generateSecretValueBlindIndexFromKmsKey+} from "./blind-index";export { crypto, SymmetricKeySize } from "./cryptography";export { buildSecretBlindIndexFromName } from "./encryption";export { rsaPkcs1Decrypt, rsaPkcs1Encrypt, rsaSign, rsaVerify } from "./rsa";diff --git a/backend/src/services/external-migration/external-migration-fns/import.ts b/backend/src/services/external-migration/external-migration-fns/import.tsindex a409a0e08f..df749ea26f 100644--- a/backend/src/services/external-migration/external-migration-fns/import.ts+++ b/backend/src/services/external-migration/external-migration-fns/import.ts@@ -293,13 +293,14 @@ export const importDataIntoInfisicalFn = async ({});}- const { encryptor: secretManagerEncrypt } = await kmsService.createCipherPairWithDataKey(- {- type: KmsDataKey.SecretManager,- projectId: selectedProjectId- },- tx- );+ const { encryptor: secretManagerEncrypt, generateSecretBlindIndex } =+ await kmsService.createCipherPairWithDataKey(+ {+ type: KmsDataKey.SecretManager,+ projectId: selectedProjectId+ },+ tx+ );const secretBatches = chunkArray(secrets, 2500);for await (const secretBatch of secretBatches) {@@ -316,8 +317,9 @@ export const importDataIntoInfisicalFn = async ({message: `Secret already exists: ${secretsByKeys.map((el) => el.key).join(",")}`});}- await fnSecretBulkInsert({- inputSecrets: secretBatch.map((el) => {++ const inputSecretsWithBlindIndex = await Promise.all(+ secretBatch.map(async (el) => {const references = getAllSecretReferences(el.secretValue).nestedReferences;return {@@ -325,11 +327,18 @@ export const importDataIntoInfisicalFn = async ({encryptedValue: el.secretValue? secretManagerEncrypt({ plainText: Buffer.from(el.secretValue) }).cipherTextBlob: undefined,+ secretValueBlindIndex: el.secretValue+ ? await generateSecretBlindIndex(Buffer.from(el.secretValue))+ : undefined,key: el.secretKey,references,type: SecretType.Shared};- }),+ })+ );++ await fnSecretBulkInsert({+ inputSecrets: inputSecretsWithBlindIndex,folderId: selectedFolder.id,orgId: actorOrgId,resourceMetadataDAL,diff --git a/backend/src/services/folder-commit/folder-commit-service.ts b/backend/src/services/folder-commit/folder-commit-service.tsindex 5cd791188b..d2e7dc94f7 100644--- a/backend/src/services/folder-commit/folder-commit-service.ts+++ b/backend/src/services/folder-commit/folder-commit-service.ts@@ -1022,7 +1022,8 @@ export const folderCommitServiceFactory = ({encryptedValue: secretVersion.encryptedValue,encryptedComment: secretVersion.encryptedComment,userId: secretVersion.userId,- folderId+ folderId,+ secretValueBlindIndex: secretVersion.secretValueBlindIndex}];await secretV2BridgeDAL.insertMany(newSecret, tx);@@ -1060,6 +1061,7 @@ export const folderCommitServiceFactory = ({actorType: actorInfo.actorType,envId: secretVersion.envId,metadata: metadata ? JSON.stringify(metadata) : null,+ secretValueBlindIndex: secretVersion.secretValueBlindIndex,...(actorInfo.actorType === ActorType.IDENTITY && { identityActorId: actorInfo.actorId }),...(actorInfo.actorType === ActorType.USER && { userActorId: actorInfo.actorId })},@@ -1100,7 +1102,8 @@ export const folderCommitServiceFactory = ({reminderRepeatDays: secretVersion?.reminderRepeatDays,encryptedValue: secretVersion?.encryptedValue,encryptedComment: secretVersion?.encryptedComment,- userId: secretVersion?.userId+ userId: secretVersion?.userId,+ secretValueBlindIndex: secretVersion?.secretValueBlindIndex},tx);@@ -1139,6 +1142,7 @@ export const folderCommitServiceFactory = ({envId: secretVersion.envId,folderId,secretId: secretVersion.secretId,+ secretValueBlindIndex: secretVersion.secretValueBlindIndex,...(actorInfo.actorType === ActorType.IDENTITY && { identityActorId: actorInfo.actorId }),...(actorInfo.actorType === ActorType.USER && { userActorId: actorInfo.actorId })},diff --git a/backend/src/services/kms/kms-service.ts b/backend/src/services/kms/kms-service.tsindex 3c232c2c79..b26b06c74c 100644--- a/backend/src/services/kms/kms-service.ts+++ b/backend/src/services/kms/kms-service.ts@@ -15,6 +15,7 @@ import { THsmServiceFactory } from "@app/ee/services/hsm/hsm-service";import { THsmStatus } from "@app/ee/services/hsm/hsm-types";import { PgSqlLock } from "@app/keystore/keystore";import { TEnvConfig } from "@app/lib/config/env";+import { generateSecretValueBlindIndexFromKmsKey } from "@app/lib/crypto/blind-index";import { symmetricCipherService, SymmetricKeyAlgorithm } from "@app/lib/crypto/cipher";import { crypto } from "@app/lib/crypto/cryptography";import { AsymmetricKeyAlgorithm, signingService } from "@app/lib/crypto/sign";@@ -871,7 +872,8 @@ export const kmsServiceFactory = ({const cipherTextBlob = versionedCipherTextBlob.subarray(0, -KMS_VERSION_BLOB_LENGTH);const decryptedBlob = cipher.decrypt(cipherTextBlob, dataKey);return decryptedBlob;- }+ },+ generateSecretBlindIndex: (secretValue: Buffer) => generateSecretValueBlindIndexFromKmsKey(secretValue, dataKey)};};diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.tsindex 91633eef81..1236bfc47b 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts@@ -55,7 +55,8 @@ export const fnSecretBulkInsert = async ({version,reminderNote,encryptedValue,- reminderRepeatDays+ reminderRepeatDays,+ secretValueBlindIndex}) => ({skipMultilineEncoding,type,@@ -65,7 +66,8 @@ export const fnSecretBulkInsert = async ({version,reminderNote,encryptedValue,- reminderRepeatDays+ reminderRepeatDays,+ secretValueBlindIndex}));@@ -211,7 +213,10 @@ export const fnSecretBulkUpdate = async ({const actorType = actor?.type || ActorType.PLATFORM;const sanitizedInputSecrets = inputSecrets.map(- ({ filter, data: { skipMultilineEncoding, type, key, encryptedValue, userId, encryptedComment } }) => ({+ ({+ filter,+ data: { skipMultilineEncoding, type, key, encryptedValue, userId, encryptedComment, secretValueBlindIndex }+ }) => ({filter: { ...filter, folderId },data: {skipMultilineEncoding,@@ -219,7 +224,8 @@ export const fnSecretBulkUpdate = async ({key,userId,encryptedComment,- encryptedValue+ encryptedValue,+ secretValueBlindIndex}}));@@ -227,7 +233,20 @@ export const fnSecretBulkUpdate = async ({// const allHaveIds = sanitizedInputSecrets.every((s): s is typeof s & { filter: { id: string } } => !!s.filter.id);const newSecrets = await secretDAL.bulkUpdate(sanitizedInputSecrets, tx);const versionData = newSecrets.map(- ({ skipMultilineEncoding, type, key, userId, encryptedComment, version, encryptedValue, id: secretId }, index) => ({+ (+ {+ skipMultilineEncoding,+ type,+ key,+ userId,+ encryptedComment,+ version,+ encryptedValue,+ secretValueBlindIndex,+ id: secretId+ },+ index+ ) => ({skipMultilineEncoding,type,key,@@ -243,6 +262,7 @@ export const fnSecretBulkUpdate = async ({}))) || null,encryptedValue,+ secretValueBlindIndex,folderId,secretId,userActorId,@@ -648,6 +668,7 @@ type TFnUpdateSecretLinkedReferences = {secretQueueService: Pick<TSecretQueueFactory, "syncSecrets">;encryptor: (data: { plainText: Buffer }) => { cipherTextBlob: Buffer };decryptor: (data: { cipherTextBlob: Buffer }) => Buffer;+ generateSecretBlindIndex: (secretValue: Buffer) => Promise<string>;tx?: Knex;};@@ -671,6 +692,7 @@ export const fnUpdateSecretLinkedReferences = async ({secretQueueService,encryptor,decryptor,+ generateSecretBlindIndex,tx}: TFnUpdateSecretLinkedReferences) => {// case: nested references, can be inferred directly from the secret references table@@ -704,8 +726,10 @@ export const fnUpdateSecretLinkedReferences = async ({const allSecretsToUpdate: Array<TSecretsV2> = [...nestedSecretsToUpdate, ...secretsToCheck];// Use Map with secretId as key to avoid duplicates when a secret references the renamed secret multiple times- const updatedSecretsMap: Map<string, { secret: TSecretsV2; newEncryptedValue: Buffer; newVersion: number }> =- new Map();+ const updatedSecretsMap: Map<+ string,+ { secret: TSecretsV2; newEncryptedValue: Buffer; newVersion: number; newBlindIndex: string }+ > = new Map();for await (const secretToUpdate of allSecretsToUpdate) {if (!secretToUpdate.encryptedValue) {@@ -743,12 +767,14 @@ export const fnUpdateSecretLinkedReferences = async ({}if (newValue !== originalValue) {- const newEncryptedValue = encryptor({ plainText: Buffer.from(newValue) }).cipherTextBlob;+ const newValueBuffer = Buffer.from(newValue);+ const newEncryptedValue = encryptor({ plainText: newValueBuffer }).cipherTextBlob;+ const newBlindIndex = await generateSecretBlindIndex(newValueBuffer);// Update secret with version incrementconst updatedSecret = await secretDAL.updateById(secretToUpdate.id,- { encryptedValue: newEncryptedValue, $incr: { version: 1 } },+ { encryptedValue: newEncryptedValue, secretValueBlindIndex: newBlindIndex, $incr: { version: 1 } },tx);@@ -756,7 +782,8 @@ export const fnUpdateSecretLinkedReferences = async ({updatedSecretsMap.set(secretToUpdate.id, {secret: updatedSecret,newEncryptedValue,- newVersion: updatedSecret.version+ newVersion: updatedSecret.version,+ newBlindIndex});}}@@ -764,7 +791,7 @@ export const fnUpdateSecretLinkedReferences = async ({// Group updated secrets by folder for commit creationconst updatedSecretsByFolder: Map<string,- Array<{ secret: TSecretsV2; newEncryptedValue: Buffer; newVersion: number }>+ Array<{ secret: TSecretsV2; newEncryptedValue: Buffer; newVersion: number; newBlindIndex: string }>> = new Map();for (const [, data] of updatedSecretsMap) {const folderSecrets = updatedSecretsByFolder.get(data.secret.folderId) || [];@@ -774,7 +801,7 @@ export const fnUpdateSecretLinkedReferences = async ({for await (const [updateFolderId, folderSecrets] of updatedSecretsByFolder) {const secretVersions = await secretVersionDAL.insertMany(- folderSecrets.map(({ secret, newEncryptedValue, newVersion }) => ({+ folderSecrets.map(({ secret, newEncryptedValue, newVersion, newBlindIndex }) => ({secretId: secret.id,version: newVersion,key: secret.key,@@ -785,7 +812,8 @@ export const fnUpdateSecretLinkedReferences = async ({metadata: secret.metadata,folderId: secret.folderId,userId: secret.userId,- actorType: ActorType.PLATFORM+ actorType: ActorType.PLATFORM,+ secretValueBlindIndex: newBlindIndex})),tx);@@ -861,6 +889,7 @@ type TFnUpdateMovedSecretReferences = {secretQueueService: Pick<TSecretQueueFactory, "syncSecrets">;encryptor: (data: { plainText: Buffer }) => { cipherTextBlob: Buffer };decryptor: (data: { cipherTextBlob: Buffer }) => Buffer;+ generateSecretBlindIndex: (secretValue: Buffer) => Promise<string>;tx?: Knex;};@@ -889,11 +918,14 @@ export const fnUpdateMovedSecretReferences = async ({secretQueueService,encryptor,decryptor,+ generateSecretBlindIndex,tx}: TFnUpdateMovedSecretReferences) => {// Use Map with secretId as key to avoid duplicates when a secret references multiple moved secrets- const updatedSecretsMap: Map<string, { secret: TSecretsV2; newEncryptedValue: Buffer; newVersion: number }> =- new Map();+ const updatedSecretsMap: Map<+ string,+ { secret: TSecretsV2; newEncryptedValue: Buffer; newVersion: number; newBlindIndex: string }+ > = new Map();const destPathPart = destinationSecretPath === "/" ? "" : `.${destinationSecretPath.slice(1).replaceAll("/", ".")}`;const newNestedRef = `\${${destinationEnvironment}${destPathPart}.${secretKey}}`;@@ -928,12 +960,14 @@ export const fnUpdateMovedSecretReferences = async ({const newValue = originalValue.replace(new RE2(`\\$\\{${escapeRegex(secretKey)}\\}`, "g"), newNestedRef);if (newValue !== originalValue) {- const newEncryptedValue = encryptor({ plainText: Buffer.from(newValue) }).cipherTextBlob;+ const newValueBuffer = Buffer.from(newValue);+ const newEncryptedValue = encryptor({ plainText: newValueBuffer }).cipherTextBlob;+ const newBlindIndex = await generateSecretBlindIndex(newValueBuffer);// Update secret with version increment - use $incr to properly increment versionconst updatedSecret = await secretDAL.updateById(secretToUpdate.id,- { encryptedValue: newEncryptedValue, $incr: { version: 1 } },+ { encryptedValue: newEncryptedValue, secretValueBlindIndex: newBlindIndex, $incr: { version: 1 } },tx);@@ -941,7 +975,8 @@ export const fnUpdateMovedSecretReferences = async ({updatedSecretsMap.set(secretToUpdate.id, {secret: updatedSecret,newEncryptedValue,- newVersion: updatedSecret.version+ newVersion: updatedSecret.version,+ newBlindIndex});// update the secret references table (only for nested refs)@@ -993,12 +1028,14 @@ export const fnUpdateMovedSecretReferences = async ({const newValue = originalValue.split(oldNestedRef).join(localRef);if (newValue !== originalValue) {- const newEncryptedValue = encryptor({ plainText: Buffer.from(newValue) }).cipherTextBlob;+ const newValueBuffer = Buffer.from(newValue);+ const newEncryptedValue = encryptor({ plainText: newValueBuffer }).cipherTextBlob;+ const newBlindIndex = await generateSecretBlindIndex(newValueBuffer);// Update secret with version incrementconst updatedSecret = await secretDAL.updateById(secretToUpdate.id,- { encryptedValue: newEncryptedValue, $incr: { version: 1 } },+ { encryptedValue: newEncryptedValue, secretValueBlindIndex: newBlindIndex, $incr: { version: 1 } },tx);@@ -1006,7 +1043,8 @@ export const fnUpdateMovedSecretReferences = async ({updatedSecretsMap.set(secretToUpdate.id, {secret: updatedSecret,newEncryptedValue,- newVersion: updatedSecret.version+ newVersion: updatedSecret.version,+ newBlindIndex});const updatedNestedRefs = nestedReferences.filter(@@ -1044,12 +1082,14 @@ export const fnUpdateMovedSecretReferences = async ({const newValue = originalValue.split(oldNestedRef).join(newNestedRef);if (newValue !== originalValue) {- const newEncryptedValue = encryptor({ plainText: Buffer.from(newValue) }).cipherTextBlob;+ const newValueBuffer = Buffer.from(newValue);+ const newEncryptedValue = encryptor({ plainText: newValueBuffer }).cipherTextBlob;+ const newBlindIndex = await generateSecretBlindIndex(newValueBuffer);// Update secret with version incrementconst updatedSecret = await secretDAL.updateById(secretToUpdate.id,- { encryptedValue: newEncryptedValue, $incr: { version: 1 } },+ { encryptedValue: newEncryptedValue, secretValueBlindIndex: newBlindIndex, $incr: { version: 1 } },tx);@@ -1057,7 +1097,8 @@ export const fnUpdateMovedSecretReferences = async ({updatedSecretsMap.set(secretToUpdate.id, {secret: updatedSecret,newEncryptedValue,- newVersion: updatedSecret.version+ newVersion: updatedSecret.version,+ newBlindIndex});const updatedNestedRefs = nestedReferences.map((ref) => {@@ -1122,12 +1163,14 @@ export const fnUpdateMovedSecretReferences = async ({}if (valueChanged) {- const newEncryptedValue = encryptor({ plainText: Buffer.from(updatedValue) }).cipherTextBlob;+ const newValueBuffer = Buffer.from(updatedValue);+ const newEncryptedValue = encryptor({ plainText: newValueBuffer }).cipherTextBlob;+ const newBlindIndex = await generateSecretBlindIndex(newValueBuffer);// Update secret with version incrementconst updatedSecret = await secretDAL.updateById(destinationMovedSecret.id,- { encryptedValue: newEncryptedValue, $incr: { version: 1 } },+ { encryptedValue: newEncryptedValue, secretValueBlindIndex: newBlindIndex, $incr: { version: 1 } },tx);@@ -1135,7 +1178,8 @@ export const fnUpdateMovedSecretReferences = async ({updatedSecretsMap.set(destinationMovedSecret.id, {secret: updatedSecret,newEncryptedValue,- newVersion: updatedSecret.version+ newVersion: updatedSecret.version,+ newBlindIndex});const { nestedReferences: finalNestedReferences } = getAllSecretReferences(updatedValue);@@ -1149,7 +1193,7 @@ export const fnUpdateMovedSecretReferences = async ({// Group updated secrets by folder for commit creationconst updatedSecretsByFolder: Map<string,- Array<{ secret: TSecretsV2; newEncryptedValue: Buffer; newVersion: number }>+ Array<{ secret: TSecretsV2; newEncryptedValue: Buffer; newVersion: number; newBlindIndex: string }>> = new Map();for (const [, data] of updatedSecretsMap) {const folderSecrets = updatedSecretsByFolder.get(data.secret.folderId) || [];@@ -1159,7 +1203,7 @@ export const fnUpdateMovedSecretReferences = async ({for await (const [updateFolderId, folderSecrets] of updatedSecretsByFolder) {const secretVersions = await secretVersionDAL.insertMany(- folderSecrets.map(({ secret, newEncryptedValue, newVersion }) => ({+ folderSecrets.map(({ secret, newEncryptedValue, newVersion, newBlindIndex }) => ({secretId: secret.id,version: newVersion,key: secret.key,@@ -1170,7 +1214,8 @@ export const fnUpdateMovedSecretReferences = async ({metadata: secret.metadata,folderId: secret.folderId,userId: secret.userId,- actorType: ActorType.PLATFORM+ actorType: ActorType.PLATFORM,+ secretValueBlindIndex: newBlindIndex})),tx);diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.tsindex 52c39b59e6..ba0c5f268a 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts@@ -376,10 +376,14 @@ export const secretV2BridgeServiceFactory = ({await $validateSecretReferences(projectId, permission, allSecretReferences);- const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });+ const { encryptor: secretManagerEncryptor, generateSecretBlindIndex } =+ await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });+ const secretValueBlindIndex = inputSecretData.secretValue+ ? await generateSecretBlindIndex(Buffer.from(inputSecretData.secretValue))+ : undefined;const secret = await secretDAL.transaction(async (tx) => {const [createdSecret] = await fnSecretBulkInsert({folderId,@@ -395,6 +399,7 @@ export const secretV2BridgeServiceFactory = ({encryptedValue: inputSecretData.secretValue? secretManagerEncryptor({ plainText: Buffer.from(inputSecretData.secretValue) }).cipherTextBlob: undefined,+ secretValueBlindIndex,skipMultilineEncoding: inputSecretData.skipMultilineEncoding,key: secretName,userId: inputSecret.type === SecretType.Personal ? actorId : null,@@ -648,16 +653,20 @@ export const secretV2BridgeServiceFactory = ({await $validateSecretReferences(projectId, permission, allSecretReferences);}- const { encryptor: secretManagerEncryptor, decryptor: secretManagerDecryptor } =- await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });+ const {+ encryptor: secretManagerEncryptor,+ decryptor: secretManagerDecryptor,+ generateSecretBlindIndex+ } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });const encryptedValue =typeof secretValue === "string"? {encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(secretValue) }).cipherTextBlob,- references: getAllSecretReferences(secretValue).nestedReferences+ references: getAllSecretReferences(secretValue).nestedReferences,+ secretValueBlindIndex: await generateSecretBlindIndex(Buffer.from(secretValue))}: {};@@ -725,6 +734,7 @@ export const secretV2BridgeServiceFactory = ({secretQueueService,encryptor: ({ plainText }) => secretManagerEncryptor({ plainText }),decryptor: ({ cipherTextBlob }) => secretManagerDecryptor({ cipherTextBlob }),+ generateSecretBlindIndex,tx});}@@ -2018,13 +2028,19 @@ export const secretV2BridgeServiceFactory = ({});await $validateSecretReferences(projectId, permission, secretReferences);- const { encryptor: secretManagerEncryptor, decryptor: secretManagerDecryptor } =- await kmsService.createCipherPairWithDataKey({ type: KmsDataKey.SecretManager, projectId });+ const {+ encryptor: secretManagerEncryptor,+ decryptor: secretManagerDecryptor,+ generateSecretBlindIndex+ } = await kmsService.createCipherPairWithDataKey({ type: KmsDataKey.SecretManager, projectId });const executeBulkInsert = async (tx: Knex) => {- const modifiedSecretsInDB = await fnSecretBulkInsert({- inputSecrets: deduplicatedSecrets.map((el) => {+ const inputSecretsWithBlindIndex = await Promise.all(+ deduplicatedSecrets.map(async (el) => {const references = secretReferencesGroupByInputSecretKey[el.secretKey]?.nestedReferences;+ const secretValueBlindIndex = el.secretValue+ ? await generateSecretBlindIndex(Buffer.from(el.secretValue))+ : null;return {version: 1,@@ -2045,9 +2061,14 @@ export const secretV2BridgeServiceFactory = ({? secretManagerEncryptor({ plainText: Buffer.from(meta.value) }).cipherTextBlob: meta.value})),- type: SecretType.Shared+ type: SecretType.Shared,+ secretValueBlindIndex};- }),+ })+ );++ const modifiedSecretsInDB = await fnSecretBulkInsert({+ inputSecrets: inputSecretsWithBlindIndex,folderId,commitChanges,orgId: actorOrgId,@@ -2178,8 +2199,11 @@ export const secretV2BridgeServiceFactory = ({);const secretPaths = Object.keys(secretsToUpdateGroupByPath);- const { encryptor: secretManagerEncryptor, decryptor: secretManagerDecryptor } =- await kmsService.createCipherPairWithDataKey({ type: KmsDataKey.SecretManager, projectId });+ const {+ encryptor: secretManagerEncryptor,+ decryptor: secretManagerDecryptor,+ generateSecretBlindIndex+ } = await kmsService.createCipherPairWithDataKey({ type: KmsDataKey.SecretManager, projectId });// Function to execute the bulk update operationconst executeBulkUpdate = async (tx: Knex) => {@@ -2397,13 +2421,8 @@ export const secretV2BridgeServiceFactory = ({newSecretKey: string;}[] = [];- const bulkUpdatedSecrets = await fnSecretBulkUpdate({- folderId,- orgId: actorOrgId,- folderCommitService,- tx,- commitChanges,- inputSecrets: secretsToUpdate.map((el) => {+ const inputSecretsForUpdate = await Promise.all(+ secretsToUpdate.map(async (el) => {const originalSecret = secretsToUpdateInDBGroupedByKey[el.secretKey][0];const shouldUpdateValue = !originalSecret.isRotatedSecret && typeof el.secretValue !== "undefined";const shouldUpdateName = !originalSecret.isRotatedSecret && el.newSecretName;@@ -2420,7 +2439,8 @@ export const secretV2BridgeServiceFactory = ({shouldUpdateValue && el.secretValue !== undefined? {encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(el.secretValue) }).cipherTextBlob,- references: secretReferencesGroupByInputSecretKey[el.secretKey]?.nestedReferences+ references: secretReferencesGroupByInputSecretKey[el.secretKey]?.nestedReferences,+ secretValueBlindIndex: await generateSecretBlindIndex(Buffer.from(el.secretValue))}: {};@@ -2443,7 +2463,16 @@ export const secretV2BridgeServiceFactory = ({...encryptedValue}};- }),+ })+ );++ const bulkUpdatedSecrets = await fnSecretBulkUpdate({+ folderId,+ orgId: actorOrgId,+ folderCommitService,+ tx,+ commitChanges,+ inputSecrets: inputSecretsForUpdate,secretDAL,secretVersionDAL,secretTagDAL,@@ -2473,6 +2502,7 @@ export const secretV2BridgeServiceFactory = ({secretQueueService,encryptor: ({ plainText }) => secretManagerEncryptor({ plainText }),decryptor: ({ cipherTextBlob }) => secretManagerDecryptor({ cipherTextBlob }),+ generateSecretBlindIndex,tx});}@@ -2487,9 +2517,12 @@ export const secretV2BridgeServiceFactory = ({);if (updateMode === SecretUpdateMode.Upsert) {- const bulkInsertedSecrets = await fnSecretBulkInsert({- inputSecrets: secretsToCreate.map((el) => {+ const inputSecretsForCreate = await Promise.all(+ secretsToCreate.map(async (el) => {const references = secretReferencesGroupByInputSecretKey[el.secretKey]?.nestedReferences;+ const secretValueBlindIndex = el.secretValue+ ? await generateSecretBlindIndex(Buffer.from(el.secretValue))+ : null;return {version: 1,@@ -2510,9 +2543,14 @@ export const secretV2BridgeServiceFactory = ({? secretManagerEncryptor({ plainText: Buffer.from(meta.value) }).cipherTextBlob: meta.value})),- type: SecretType.Shared+ type: SecretType.Shared,+ secretValueBlindIndex};- }),+ })+ );++ const bulkInsertedSecrets = await fnSecretBulkInsert({+ inputSecrets: inputSecretsForCreate,folderId,orgId: actorOrgId,secretDAL,@@ -2992,11 +3030,14 @@ export const secretV2BridgeServiceFactory = ({});}- const { encryptor: secretManagerEncryptor, decryptor: secretManagerDecryptor } =- await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });+ const {+ encryptor: secretManagerEncryptor,+ decryptor: secretManagerDecryptor,+ generateSecretBlindIndex+ } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });const decryptedSourceSecrets = sourceSecrets.map((secret) => ({...secret,value: secret.encryptedValue@@ -3170,6 +3211,27 @@ export const secretV2BridgeServiceFactory = ({let createdSecrets: { id: string; key: string }[] = [];if (locallyCreatedSecrets.length) {+ const inputSecretsForCreate = await Promise.all(+ locallyCreatedSecrets.map(async (doc) => ({+ type: doc.type,+ metadata: doc.metadata,+ key: doc.key,+ encryptedValue: doc.encryptedValue,+ encryptedComment: doc.encryptedComment,+ skipMultilineEncoding: doc.skipMultilineEncoding,+ reminderNote: doc.reminderNote,+ reminderRepeatDays: doc.reminderRepeatDays,+ secretMetadata: doc.secretMetadata?.map(({ key, value, encryptedValue }) => ({+ key,+ value: value || undefined,+ encryptedValue: encryptedValue || undefined+ })) as { key: string; value?: string; encryptedValue?: Buffer }[] | undefined,+ references: doc.value ? getAllSecretReferences(doc.value).nestedReferences : [],+ tagIds: doc.tags.map((tag) => tag.id),+ secretValueBlindIndex: doc.value ? await generateSecretBlindIndex(Buffer.from(doc.value)) : undefined+ }))+ );+createdSecrets = await fnSecretBulkInsert({folderId: destinationFolder.id,orgId: actorOrgId,@@ -3184,28 +3246,43 @@ export const secretV2BridgeServiceFactory = ({type: actor,actorId},- inputSecrets: locallyCreatedSecrets.map((doc) => {- return {- type: doc.type,+ inputSecrets: inputSecretsForCreate+ });+ }+ if (locallyUpdatedSecrets.length) {+ const inputSecretsForUpdate = await Promise.all(+ locallyUpdatedSecrets.map(async (doc) => ({+ filter: {+ folderId: destinationFolder.id,+ id: destinationSecretsGroupedByKey[doc.key][0].id+ },+ data: {metadata: doc.metadata,key: doc.key,- encryptedValue: doc.encryptedValue,encryptedComment: doc.encryptedComment,skipMultilineEncoding: doc.skipMultilineEncoding,- reminderNote: doc.reminderNote,- reminderRepeatDays: doc.reminderRepeatDays,secretMetadata: doc.secretMetadata?.map(({ key, value, encryptedValue }) => ({key,- value: value || undefined,- encryptedValue: encryptedValue || undefined+ value,+ encryptedValue})) as { key: string; value?: string; encryptedValue?: Buffer }[] | undefined,- references: doc.value ? getAllSecretReferences(doc.value).nestedReferences : [],- tagIds: doc.tags.map((tag) => tag.id)- };- })- });- }- if (locallyUpdatedSecrets.length) {+ tags: doc.tags.map((tag) => tag.id),+ ...(doc.encryptedValue+ ? {+ encryptedValue: doc.encryptedValue,+ references: doc.value ? getAllSecretReferences(doc.value).nestedReferences : [],+ secretValueBlindIndex: doc.value+ ? await generateSecretBlindIndex(Buffer.from(doc.value))+ : undefined+ }+ : {+ encryptedValue: undefined,+ references: undefined+ })+ }+ }))+ );+await fnSecretBulkUpdate({folderId: destinationFolder.id,orgId: actorOrgId,@@ -3220,35 +3297,7 @@ export const secretV2BridgeServiceFactory = ({type: actor,actorId},- inputSecrets: locallyUpdatedSecrets.map((doc) => {- return {- filter: {- folderId: destinationFolder.id,- id: destinationSecretsGroupedByKey[doc.key][0].id- },- data: {- metadata: doc.metadata,- key: doc.key,- encryptedComment: doc.encryptedComment,- skipMultilineEncoding: doc.skipMultilineEncoding,- secretMetadata: doc.secretMetadata?.map(({ key, value, encryptedValue }) => ({- key,- value,- encryptedValue- })) as { key: string; value?: string; encryptedValue?: Buffer }[] | undefined,- tags: doc.tags.map((tag) => tag.id),- ...(doc.encryptedValue- ? {- encryptedValue: doc.encryptedValue,- references: doc.value ? getAllSecretReferences(doc.value).nestedReferences : []- }- : {- encryptedValue: undefined,- references: undefined- })- }- };- })+ inputSecrets: inputSecretsForUpdate});}@@ -3354,6 +3403,7 @@ export const secretV2BridgeServiceFactory = ({secretQueueService,encryptor: ({ plainText }) => secretManagerEncryptor({ plainText }),decryptor: ({ cipherTextBlob }) => secretManagerDecryptor({ cipherTextBlob }),+ generateSecretBlindIndex,tx});}@@ -3980,6 +4030,7 @@ export const secretV2BridgeServiceFactory = ({const updatedSecretVersion = await secretVersionDAL.updateById(versionId, {encryptedValue,+ secretValueBlindIndex: null,isRedacted: true,redactedAt: new Date(),redactedByUserId: actorIddiff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.tsindex 5951adf654..6940bff4de 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts@@ -185,6 +185,7 @@ export type TFnSecretBulkInsert = {references: TSecretReference[];secretMetadata?: { key: string; value?: string | null; encryptedValue?: Buffer | null }[];parentSecretVersionId?: string;+ secretValueBlindIndex?: string | null;}>;resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "insertMany">;@@ -203,10 +204,12 @@ type TRequireReferenceIfValue =| (Omit<TSecretsV2Update, "encryptedValue" | "metadata"> & {encryptedValue: Buffer | null;references: TSecretReference[];+ secretValueBlindIndex?: string | null;})| (Omit<TSecretsV2Update, "encryptedValue" | "metadata"> & {encryptedValue?: never;references?: never;+ secretValueBlindIndex?: never;});export type TFnSecretBulkUpdate = {diff --git a/backend/src/services/secret/secret-fns.ts b/backend/src/services/secret/secret-fns.tsindex 405a6b0394..275037afcc 100644--- a/backend/src/services/secret/secret-fns.ts+++ b/backend/src/services/secret/secret-fns.ts@@ -804,10 +804,11 @@ export const createManySecretsRawFnFactory = ({});const folderId = folder.id;if (shouldUseSecretV2Bridge) {- const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });+ const { encryptor: secretManagerEncryptor, generateSecretBlindIndex } =+ await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });const secretsStoredInDB = await secretV2BridgeDAL.findBySecretKeys(folderId,@@ -821,12 +822,22 @@ export const createManySecretsRawFnFactory = ({message: `Secret already exists: ${secretsStoredInDB.map((el) => el.key).join(",")}`});- const inputSecrets = secrets.map((secret) => {+ const encryptedSecrets = secrets.map((secret) => ({+ secret,+ encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(secret.secretValue) }).cipherTextBlob+ }));++ const blindIndexes = await Promise.all(+ encryptedSecrets.map(({ encryptedValue }) => generateSecretBlindIndex(encryptedValue))+ );++ const inputSecrets = encryptedSecrets.map(({ secret, encryptedValue }, idx) => {return {type: secret.type,userId: secret.type === SecretType.Personal ? userId : null,key: secret.secretName,- encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(secret.secretValue) }).cipherTextBlob,+ encryptedValue,+ secretValueBlindIndex: blindIndexes[idx],encryptedComent: secret.secretComment? secretManagerEncryptor({ plainText: Buffer.from(secret.secretComment) }).cipherTextBlob: null,@@ -988,10 +999,11 @@ export const updateManySecretsRawFnFactory = ({});const folderId = folder.id;if (shouldUseSecretV2Bridge) {- const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });+ const { encryptor: secretManagerEncryptor, generateSecretBlindIndex } =+ await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });const secretsToUpdate = await secretV2BridgeDAL.findBySecretKeys(folderId,@@ -1021,7 +1033,17 @@ export const updateManySecretsRawFnFactory = ({}const secretsToUpdateInDBGroupedByKey = groupBy(secretsToUpdate, (i) => i.key);- const inputSecrets = secrets.map((secret) => {++ const encryptedSecrets = secrets.map((secret) => ({+ secret,+ encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(secret.secretValue) }).cipherTextBlob+ }));++ const blindIndexes = await Promise.all(+ encryptedSecrets.map(({ encryptedValue }) => generateSecretBlindIndex(encryptedValue))+ );++ const inputSecrets = encryptedSecrets.map(({ secret, encryptedValue }, idx) => {if (secret.newSecretName === "") {throw new BadRequestError({ message: "New secret name cannot be empty" });}@@ -1030,7 +1052,8 @@ export const updateManySecretsRawFnFactory = ({type: secret.type,userId: secret.type === SecretType.Personal ? userId : null,key: secret.newSecretName || secret.secretName,- encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(secret.secretValue) }).cipherTextBlob,+ encryptedValue,+ secretValueBlindIndex: blindIndexes[idx],encryptedComent: secret.secretComment? secretManagerEncryptor({ plainText: Buffer.from(secret.secretComment) }).cipherTextBlob: null,