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
dummy signature check
Matheus Nogueira818e9c146318
diff --git a/backend/src/ee/services/honey-token/honey-token-service.ts b/backend/src/ee/services/honey-token/honey-token-service.tsindex f2f67616dd..c2e545cc0e 100644--- a/backend/src/ee/services/honey-token/honey-token-service.ts+++ b/backend/src/ee/services/honey-token/honey-token-service.ts@@ -961,33 +961,38 @@ export const honeyTokenServiceFactory = ({}const honeyTokenWithOrg = await honeyTokenDAL.findOneByTokenIdentifier(eventMetadata.accessKeyId);- if (!honeyTokenWithOrg) {- throw new UnauthorizedError({ message: "Invalid webhook request" });- }- const config = await honeyTokenConfigDAL.findOne({- orgId: honeyTokenWithOrg.orgId,- type: HoneyTokenType.AWS,- status: HoneyTokenConfigStatus.Complete- });- if (!config?.encryptedConfig) {- throw new UnauthorizedError({ message: "Invalid webhook request" });- }+ let webhookSigningKey: string | null = null;+ if (honeyTokenWithOrg) {+ const config = await honeyTokenConfigDAL.findOne({+ orgId: honeyTokenWithOrg.orgId,+ type: HoneyTokenType.AWS,+ status: HoneyTokenConfigStatus.Complete+ });- const { decryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.Organization,- orgId: honeyTokenWithOrg.orgId- });- const decrypted = decryptor({ cipherTextBlob: config.encryptedConfig });- const storedConfig = AwsHoneyTokenConfigSchema.parse(JSON.parse(decrypted.toString()) as unknown);+ if (config?.encryptedConfig) {+ const { decryptor } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.Organization,+ orgId: honeyTokenWithOrg.orgId+ });+ const decrypted = decryptor({ cipherTextBlob: config.encryptedConfig });+ const storedConfig = AwsHoneyTokenConfigSchema.parse(JSON.parse(decrypted.toString()) as unknown);+ webhookSigningKey = storedConfig.webhookSigningKey;+ }+ }+ // Always compute HMAC to prevent timing side-channel that reveals token existence+ const dummySigningKey = "0".repeat(64);const expectedSignature = crypto.nativeCrypto- .createHmac("sha256", storedConfig.webhookSigningKey)+ .createHmac("sha256", webhookSigningKey ?? dummySigningKey).update(`${timestamp}.${rawBody}`).digest("hex");const expectedBuf = Buffer.from(expectedSignature, "hex");const receivedBuf = Buffer.from(signatureHash, "hex");+if (+ !honeyTokenWithOrg ||+ !webhookSigningKey ||expectedBuf.byteLength !== receivedBuf.byteLength ||!crypto.nativeCrypto.timingSafeEqual(expectedBuf, receivedBuf)) {