Merge pull request #2755 from Infisical/empty-secret-value-fixes

Fix: Handle Empty Secret Values in Update, Bulk Create and Bulk Update Secret(s)
This commit is contained in:
Scott Wilson
2024-11-19 08:45:38 -08:00
committed by GitHub
@@ -414,7 +414,8 @@ export const secretV2BridgeServiceFactory = ({
type: KmsDataKey.SecretManager, type: KmsDataKey.SecretManager,
projectId projectId
}); });
const encryptedValue = secretValue const encryptedValue =
typeof secretValue === "string"
? { ? {
encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(secretValue) }).cipherTextBlob, encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(secretValue) }).cipherTextBlob,
references: getAllSecretReferences(secretValue).nestedReferences references: getAllSecretReferences(secretValue).nestedReferences
@@ -1165,7 +1166,7 @@ export const secretV2BridgeServiceFactory = ({
const newSecrets = await secretDAL.transaction(async (tx) => const newSecrets = await secretDAL.transaction(async (tx) =>
fnSecretBulkInsert({ fnSecretBulkInsert({
inputSecrets: inputSecrets.map((el) => { inputSecrets: inputSecrets.map((el) => {
const references = secretReferencesGroupByInputSecretKey[el.secretKey].nestedReferences; const references = secretReferencesGroupByInputSecretKey[el.secretKey]?.nestedReferences;
return { return {
version: 1, version: 1,
@@ -1372,7 +1373,7 @@ export const secretV2BridgeServiceFactory = ({
typeof el.secretValue !== "undefined" typeof el.secretValue !== "undefined"
? { ? {
encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(el.secretValue) }).cipherTextBlob, encryptedValue: secretManagerEncryptor({ plainText: Buffer.from(el.secretValue) }).cipherTextBlob,
references: secretReferencesGroupByInputSecretKey[el.secretKey].nestedReferences references: secretReferencesGroupByInputSecretKey[el.secretKey]?.nestedReferences
} }
: {}; : {};