Skip to content

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

Address greptile comments

Carlos Monastyrskia5982ab9e157
diff --git a/backend/src/services/certificate-common/certificate-constants.ts b/backend/src/services/certificate-common/certificate-constants.ts
index beb5490edb..4fea94d078 100644
--- a/backend/src/services/certificate-common/certificate-constants.ts
+++ b/backend/src/services/certificate-common/certificate-constants.ts
@@ -367,6 +367,7 @@ export enum CertExtensionCriticality {
}
export const CUSTOM_EXTENSION_PRESET_OIDS = {
+ TLS_FEATURE: "1.3.6.1.5.5.7.1.24",
NTDS_SID: "1.3.6.1.4.1.311.25.2",
MS_CERTIFICATE_TEMPLATE_NAME: "1.3.6.1.4.1.311.20.2",
MS_CERTIFICATE_TEMPLATE_INFORMATION: "1.3.6.1.4.1.311.21.7"
diff --git a/backend/src/services/certificate-common/certificate-extension-fns.test.ts b/backend/src/services/certificate-common/certificate-extension-fns.test.ts
index 27d4d85557..5670a6b28f 100644
--- a/backend/src/services/certificate-common/certificate-extension-fns.test.ts
+++ b/backend/src/services/certificate-common/certificate-extension-fns.test.ts
@@ -112,6 +112,7 @@ describe("preset encoders", () => {
it("every preset declares a spec-correct criticality", () => {
expect(Object.values(CUSTOM_EXTENSION_PRESETS_BY_OID).map((preset) => preset.critical)).toEqual([
+ false,
false,
false,
false
@@ -671,6 +672,7 @@ describe("findUnsatisfiedCustomExtensionOids", () => {
describe("preset registry", () => {
it("round-trips every preset through encode and describe", () => {
const samples: Record<string, string> = {
+ "1.3.6.1.5.5.7.1.24": "5",
[SID_OID]: SID,
[TEMPLATE_NAME_OID]: "Machine",
[TEMPLATE_INFO_OID]: "1.3.6.1.4.1.311.21.8.1.2:100.3"
@@ -720,16 +722,25 @@ describe("toCarriedCustomExtensions", () => {
// This used to fail renewal with the very error this change removes.
describe("parseImportedCustomExtensions", () => {
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 qcStatements = Buffer.from([0x30, 0x08, 0x30, 0x06, 0x06, 0x04, 0x00, 0x8e, 0x46, 0x01]);
+ const certificate = await buildCertificateWithExtension("1.3.6.1.5.5.7.1.3", qcStatements);
const stored = parseImportedCustomExtensions(certificate);
- expect(stored).toEqual([{ oid: "1.3.6.1.5.5.7.1.24", critical: false, value: "MAMCAQU=" }]);
+ expect(stored).toEqual([{ oid: "1.3.6.1.5.5.7.1.3", critical: false, value: qcStatements.toString("base64") }]);
expect(() => toRequestCustomExtensions(stored)).toThrow(/cannot be read back into a value/);
expect(toCarriedCustomExtensions(stored)).toEqual([]);
});
+ // Dropping must-staple would hand back a renewed certificate with a weaker security posture than
+ // the one it replaces, so TLS Feature has a preset and round-trips.
+ it("carries must-staple rather than dropping it", () => {
+ const mustStaple = [{ oid: "1.3.6.1.5.5.7.1.24", critical: false, value: "MAMCAQU=" }];
+
+ expect(toCarriedCustomExtensions(mustStaple)).toEqual([{ oid: "1.3.6.1.5.5.7.1.24", value: "5", critical: false }]);
+ expect(toCarriedCustomExtensions([{ ...mustStaple[0], issuerAdded: true }])).toEqual([]);
+ });
+
it("keeps a readable extension an import carried, since nothing says the issuer wrote it", async () => {
const certificate = await buildCertificateWithExtension(
CUSTOM_OID,
diff --git a/backend/src/services/certificate-common/certificate-extension-fns.ts b/backend/src/services/certificate-common/certificate-extension-fns.ts
index 6f21c21c62..56a0561868 100644
--- a/backend/src/services/certificate-common/certificate-extension-fns.ts
+++ b/backend/src/services/certificate-common/certificate-extension-fns.ts
@@ -143,7 +143,37 @@ const asn1StringPreset = ({
}
});
+// RFC 7633 TLS Feature, a SEQUENCE OF INTEGER. Without a preset its DER reads back as nothing a
+// request can carry, so a renewal would silently drop must-staple and issue a weaker certificate.
+const TLS_FEATURE_PATTERN = new RE2("^[0-9]{1,5}(,[0-9]{1,5})*$");
+
+const encodeTlsFeature = (value: string): Buffer =>
+ toDerBuffer(
+ new asn1js.Sequence({
+ value: value.split(",").map((entry) => new asn1js.Integer({ value: Number(entry.trim()) }))
+ })
+ );
+
+const describeTlsFeature = (der: Buffer): string | null => {
+ const parsed = parseSingleDerValue(der);
+ if (!(parsed instanceof asn1js.Sequence)) return null;
+
+ const features = parsed.valueBlock.value;
+ if (!features.length || !features.every((entry) => entry instanceof asn1js.Integer)) return null;
+
+ return features.map((entry) => (entry as asn1js.Integer).valueBlock.valueDec).join(",");
+};
+
export const CUSTOM_EXTENSION_PRESETS_BY_OID: Record<string, TCustomExtensionPreset> = {
+ [CUSTOM_EXTENSION_PRESET_OIDS.TLS_FEATURE]: {
+ critical: false,
+ validateInput: (value) =>
+ TLS_FEATURE_PATTERN.test(value)
+ ? null
+ : "Value must be a comma-separated list of TLS feature numbers, for example 5 for OCSP must-staple",
+ encode: encodeTlsFeature,
+ describe: describeTlsFeature
+ },
[CUSTOM_EXTENSION_PRESET_OIDS.NTDS_SID]: {
critical: false,
validateInput: (value) =>
diff --git a/backend/src/services/certificate/certificate-fns.test.ts b/backend/src/services/certificate/certificate-fns.test.ts
index 8488933021..8f29132ed9 100644
--- a/backend/src/services/certificate/certificate-fns.test.ts
+++ b/backend/src/services/certificate/certificate-fns.test.ts
@@ -227,7 +227,9 @@ describe("extractExternallyIssuedCertificateFields", () => {
expect(fields.altNames).toBe("issued.example.com,added.example.com");
});
- test("drops subject alternative names that would not fit the column rather than truncating one", async () => {
+ // Records the names that fit rather than dropping the list, and never cuts a name in half, so the
+ // stored value is always a valid prefix of what the authority issued.
+ test("keeps as many whole subject alternative names as the column holds", async () => {
const many = Array.from({ length: 200 }, (_, index) => ({
type: "dns" as const,
value: `host-${String(index).padStart(3, "0")}.${"padding".repeat(4)}.example.com`
@@ -235,9 +237,14 @@ describe("extractExternallyIssuedCertificateFields", () => {
const pem = await buildIssuedCert([new x509.SubjectAlternativeNameExtension(many)]);
const fields = extractExternallyIssuedCertificateFields(pem);
+ const kept = fields.altNames!.split(",");
expect(many.map((san) => san.value).join(",").length).toBeGreaterThan(4096);
- expect(fields).not.toHaveProperty("altNames");
+ expect(fields.altNames!.length).toBeLessThanOrEqual(4096);
+ expect(kept.length).toBeGreaterThan(0);
+ expect(kept.length).toBeLessThan(many.length);
+ // every kept entry is a whole name, in order, taken from the front of the issued list
+ expect(kept).toEqual(many.slice(0, kept.length).map((san) => san.value));
});
test("leaves the requested subject alternative names in place when the certificate carries none", async () => {
diff --git a/backend/src/services/certificate/certificate-fns.ts b/backend/src/services/certificate/certificate-fns.ts
index 302cfe4ea7..f41c9c5753 100644
--- a/backend/src/services/certificate/certificate-fns.ts
+++ b/backend/src/services/certificate/certificate-fns.ts
@@ -437,13 +437,22 @@ const extractIssuedAltNames = (decryptedCertificate: Buffer, serialNumber?: stri
if (!values.length) return null;
- const joined = values.join(",");
- if (joined.length <= PKI_ALT_NAMES_COLUMN_MAX_LENGTH) return joined;
+ const kept: string[] = [];
+ let length = 0;
+ for (const value of values) {
+ const next = length ? length + 1 + value.length : value.length;
+ if (next > PKI_ALT_NAMES_COLUMN_MAX_LENGTH) break;
+ kept.push(value);
+ length = next;
+ }
- logger?.warn(
- `Issued certificate carries ${values.length} subject alternative names, over the ${PKI_ALT_NAMES_COLUMN_MAX_LENGTH} the column holds, so none were recorded [serialNumber=${serialNumber ?? "unknown"}]`
- );
- return null;
+ if (kept.length < values.length) {
+ logger?.warn(
+ `Issued certificate carries ${values.length} subject alternative names, over the ${PKI_ALT_NAMES_COLUMN_MAX_LENGTH} characters the column holds, so only the first ${kept.length} were recorded [serialNumber=${serialNumber ?? "unknown"}]`
+ );
+ }
+
+ return kept.length ? kept.join(",") : null;
} catch (err) {
logger?.warn(
err,
diff --git a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants.ts b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants.ts
index 71630c2545..ab98c17138 100644
--- a/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants.ts
+++ b/frontend/src/pages/cert-manager/PoliciesPage/components/CertificatePoliciesTab/shared/certificate-constants.ts
@@ -350,6 +350,7 @@ export enum CertExtensionCriticality {
const MAX_CUSTOM_EXTENSION_VALUE_BYTES = 2048;
const OID_PATTERN_SOURCE = "[0-2](\\.(0|[1-9][0-9]{0,14})){1,20}";
+const TLS_FEATURE_PATTERN = /^[0-9]{1,5}(,[0-9]{1,5})*$/;
const SID_PATTERN = /^S-1-[0-9]{1,10}(-[0-9]{1,10}){1,14}$/;
const TEMPLATE_INFORMATION_PATTERN = new RegExp(
`^(${OID_PATTERN_SOURCE}):(0|[1-9][0-9]{0,4})(\\.(0|[1-9][0-9]{0,4}))?$`
@@ -364,6 +365,15 @@ export const CUSTOM_EXTENSION_PRESETS: Record<
validate: (value: string) => string | null;
}
> = {
+ "1.3.6.1.5.5.7.1.24": {
+ critical: false,
+ label: "TLS feature (must-staple)",
+ placeholder: "5",
+ validate: (value) =>
+ TLS_FEATURE_PATTERN.test(value)
+ ? null
+ : "Value must be a comma-separated list of TLS feature numbers, for example 5 for OCSP must-staple"
+ },
"1.3.6.1.4.1.311.25.2": {
critical: false,
label: "AD SID security extension",