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
Address greptile comments
Carlos Monastyrskibda294b9b05b
diff --git a/backend/src/services/certificate-common/certificate-extension-fns.test.ts b/backend/src/services/certificate-common/certificate-extension-fns.test.tsindex da0c8eb409..27d4d85557 100644--- a/backend/src/services/certificate-common/certificate-extension-fns.test.ts+++ b/backend/src/services/certificate-common/certificate-extension-fns.test.ts@@ -719,16 +719,27 @@ describe("toCarriedCustomExtensions", () => {// This used to fail renewal with the very error this change removes.describe("parseImportedCustomExtensions", () => {- it("marks every extension issuer-added so a renewal never asks for it back", async () => {+ it("invents no provenance, and a renewal drops what it cannot express rather than refusing", async () => {const mustStaple = Buffer.from([0x30, 0x03, 0x02, 0x01, 0x05]);const certificate = await buildCertificateWithExtension("1.3.6.1.5.5.7.1.24", mustStaple);const stored = parseImportedCustomExtensions(certificate);- expect(stored).toEqual([{ oid: "1.3.6.1.5.5.7.1.24", critical: false, value: "MAMCAQU=", issuerAdded: true }]);+ expect(stored).toEqual([{ oid: "1.3.6.1.5.5.7.1.24", critical: false, value: "MAMCAQU=" }]);expect(() => toRequestCustomExtensions(stored)).toThrow(/cannot be read back into a value/);expect(toCarriedCustomExtensions(stored)).toEqual([]);});++ it("keeps a readable extension an import carried, since nothing says the issuer wrote it", async () => {+ const certificate = await buildCertificateWithExtension(+ CUSTOM_OID,+ Buffer.from(encodeCustomExtensionValue(CUSTOM_OID, "retain-me"), "base64")+ );++ expect(toCarriedCustomExtensions(parseImportedCustomExtensions(certificate))).toEqual([+ { oid: CUSTOM_OID, value: "retain-me", critical: false }+ ]);+ });});describe("parseExternallyIssuedCustomExtensions", () => {@@ -743,14 +754,16 @@ describe("parseExternallyIssuedCustomExtensions", () => {).toEqual([{ oid: SCT_LIST_OID, critical: false, value: "BAIAQg==" }]);});- // The CA can rewrite what it was asked for, so the record has to come off the certificate.- it("records the value the certificate carries when the CA rewrote a requested extension", async () => {+ // The CA can rewrite what it was asked for, so the record has to come off the certificate. Matching on+ // the OID alone would treat the rewritten value as the requester's own and replay it on renewal.+ it("records the value the certificate carries and flags it when the CA rewrote a requested extension", async () => {const certificate = await buildCertificateWithExtension(CUSTOM_OID, Buffer.from([0x04, 0x02, 0x00, 0x43]));- expect(- parseExternallyIssuedCustomExtensions(certificate, [- { oid: CUSTOM_OID, critical: false, value: encodeCustomExtensionValue(CUSTOM_OID, "ops-prod") }- ])- ).toEqual([{ oid: CUSTOM_OID, critical: false, value: "BAIAQw==" }]);+ const stored = parseExternallyIssuedCustomExtensions(certificate, [+ { oid: CUSTOM_OID, critical: false, value: encodeCustomExtensionValue(CUSTOM_OID, "ops-prod") }+ ]);++ expect(stored).toEqual([{ oid: CUSTOM_OID, critical: false, value: "BAIAQw==", issuerAdded: true }]);+ expect(toCarriedCustomExtensions(stored)).toEqual([]);});});diff --git a/backend/src/services/certificate-common/certificate-extension-fns.ts b/backend/src/services/certificate-common/certificate-extension-fns.tsindex 9caa019e97..6f21c21c62 100644--- a/backend/src/services/certificate-common/certificate-extension-fns.ts+++ b/backend/src/services/certificate-common/certificate-extension-fns.ts@@ -3,6 +3,7 @@ import * as asn1js from "asn1js";import RE2 from "re2";import { BadRequestError } from "@app/lib/errors";+import { logger } from "@app/lib/logger";import { matchesNormalizedPattern } from "../certificate-policy/certificate-policy-fns";import {@@ -279,21 +280,21 @@ export const parseIssuedCustomExtensions = (};export const parseImportedCustomExtensions = (certificateDer: Buffer): TIssuedCustomExtension[] =>- withDisplayValue(parseCustomExtensionsFromCertificate(certificateDer)).map((extension) => ({- ...extension,- issuerAdded: true- }));+ withDisplayValue(parseCustomExtensionsFromCertificate(certificateDer));export const parseExternallyIssuedCustomExtensions = (certificateDer: Buffer,requested?: TResolvedCustomExtension[]): TIssuedCustomExtension[] => {- const requestedOids = new Set((requested ?? []).map((extension) => extension.oid));+ const requestedByOid = new Map((requested ?? []).map((extension) => [extension.oid, extension]));return withDisplayValue(- parseCustomExtensionsFromCertificate(certificateDer).map((extension) =>- requestedOids.has(extension.oid) ? extension : { ...extension, issuerAdded: true }- )+ parseCustomExtensionsFromCertificate(certificateDer).map((extension) => {+ const asked = requestedByOid.get(extension.oid);+ const issuedAsAsked = asked && asked.value === extension.value && asked.critical === extension.critical;++ return issuedAsAsked ? extension : { ...extension, issuerAdded: true };+ }));};@@ -359,11 +360,18 @@ export const toRequestCustomExtensions = (stored: unknown): TRequestCustomExtens});export const toCarriedCustomExtensions = (stored: unknown): TRequestCustomExtension[] =>- toRequestCustomExtensions(- readStoredCustomExtensions(stored).filter(- (extension) => !extension.issuerAdded && !isIssuerGeneratedExtensionOid(extension.oid)- )- );+ readStoredCustomExtensions(stored)+ .filter((extension) => !extension.issuerAdded && !isIssuerGeneratedExtensionOid(extension.oid))+ .flatMap((extension) => {+ const value = describeCustomExtensionValue(extension.oid, extension.value);+ if (value === null) {+ logger?.warn(+ `Custom extension '${extension.oid}' cannot be read back into a value a request can carry, so the renewal omits it`+ );+ return [];+ }+ return [{ oid: extension.oid, value, critical: extension.critical }];+ });export const assertAwsPcaCustomExtensionLimit = (count: number): void => {if (count > MAX_CUSTOM_EXTENSIONS_PER_AWS_PCA_PROFILE) {