Skip to content

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

Address veria comment

Carlos Monastyrskice7332b37d4e
diff --git a/backend/src/services/certificate-authority/certificate-authority-fns.test.ts b/backend/src/services/certificate-authority/certificate-authority-fns.test.ts
index 52602184f6..3e8bb1915e 100644
--- a/backend/src/services/certificate-authority/certificate-authority-fns.test.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-fns.test.ts
@@ -279,8 +279,8 @@ describe("extractDnParts", () => {
expect(parse("DC=com, DC=example, DC=corp, CN=host").domainComponents).toEqual(["corp", "example", "com"]);
});
- it("should read a forward-encoded chain in display order", () => {
- expect(parse("CN=host, DC=corp, DC=example, DC=com").domainComponents).toEqual(["corp", "example", "com"]);
+ it("should read a chain encoded leaf first as the chain those bytes denote", () => {
+ expect(parse("CN=host, DC=corp, DC=example, DC=com").domainComponents).toEqual(["com", "example", "corp"]);
});
it("should read a chain carrying no other attributes as root first", () => {
diff --git a/backend/src/services/certificate-authority/certificate-authority-fns.ts b/backend/src/services/certificate-authority/certificate-authority-fns.ts
index 3db82cd76a..38e53678f0 100644
--- a/backend/src/services/certificate-authority/certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-fns.ts
@@ -80,29 +80,21 @@ const getNameField = (name: x509.Name, field: string): string | undefined => {
const DOMAIN_COMPONENT_RDN_KEYS = new Set(["DC", "0.9.2342.19200300.100.1.25"]);
-/** Reads a DC chain in display order, whichever direction the DN encoded it in. */
+/**
+ * Reads a DC chain into display order, most specific component first. An RDNSequence is encoded
+ * root-first, so the encoded order is reversed. Reading it any other way would let the same bytes
+ * denote two different domains, and a CSR forwarded to an external CA keeps whatever it encoded.
+ */
const extractDomainComponentsInDisplayOrder = (name: x509.Name): string[] | undefined => {
- const rdns = name.toJSON();
- const domainComponents: string[] = [];
- let lastDomainComponentIndex = -1;
- let lastOtherAttributeIndex = -1;
-
- rdns.forEach((rdn, index) => {
- const isDomainComponent = Object.keys(rdn).some((key) => DOMAIN_COMPONENT_RDN_KEYS.has(key));
- if (isDomainComponent) {
- lastDomainComponentIndex = index;
- Object.entries(rdn).forEach(([key, values]) => {
- if (DOMAIN_COMPONENT_RDN_KEYS.has(key)) domainComponents.push(...values);
- });
- } else {
- lastOtherAttributeIndex = index;
- }
- });
+ const domainComponents = name
+ .toJSON()
+ .flatMap((rdn) =>
+ Object.entries(rdn).flatMap(([key, values]) => (DOMAIN_COMPONENT_RDN_KEYS.has(key) ? values : []))
+ );
if (domainComponents.length === 0) return undefined;
- const isEncodedRootFirst = lastOtherAttributeIndex === -1 || lastDomainComponentIndex < lastOtherAttributeIndex;
- return isEncodedRootFirst ? domainComponents.reverse() : domainComponents;
+ return domainComponents.reverse();
};
/**
diff --git a/backend/src/services/certificate-common/certificate-csr-utils.test.ts b/backend/src/services/certificate-common/certificate-csr-utils.test.ts
index 060bb77b10..af3ec82b1d 100644
--- a/backend/src/services/certificate-common/certificate-csr-utils.test.ts
+++ b/backend/src/services/certificate-common/certificate-csr-utils.test.ts
@@ -75,8 +75,8 @@ describe("extractCertificateRequestFromCSR domain components", () => {
expect(extractCertificateRequestFromCSR(WINDOWS_ORDER_CSR).domainComponents).toEqual(["corp", "example", "com"]);
});
- it("should read a chain encoded after the common name, as older Infisical releases wrote it", () => {
- expect(extractCertificateRequestFromCSR(FORWARD_ORDER_CSR).domainComponents).toEqual(["corp", "example", "com"]);
+ it("should read a chain encoded after the common name as the chain those bytes denote", () => {
+ expect(extractCertificateRequestFromCSR(FORWARD_ORDER_CSR).domainComponents).toEqual(["com", "example", "corp"]);
});
it("should read a chain with no other subject attribute as encoded root first", () => {
diff --git a/docs/documentation/platform/pki/settings/policies.mdx b/docs/documentation/platform/pki/settings/policies.mdx
index 877e523513..3015386ac2 100644
--- a/docs/documentation/platform/pki/settings/policies.mdx
+++ b/docs/documentation/platform/pki/settings/policies.mdx
@@ -94,12 +94,15 @@ For each attribute, configure enforcement:
Common Name. Domain components form an ordered chain in the distinguished name, so a DC rule
constrains whole sequences rather than individual labels:
- - Enter the full sequence in distinguished name order, separated by commas. `corp,example,com`
- matches `CN=host,DC=corp,DC=example,DC=com`.
+ - Enter the full sequence most specific component first, separated by commas. `corp,example,com`
+ describes the domain `corp.example.com`.
- A request matches a sequence only when its components line up position by position, so the same
- labels in another order are rejected. Requests are read in distinguished name order whichever way
- the client encoded the name, so a CSR from Windows, Active Directory or Intune matches the same
- rule as one from OpenSSL.
+ labels in another order are rejected.
+ - A request's domain components are read the way the standard defines the encoding, with the
+ top-level component first, which is how Windows, Active Directory, Intune and OpenSSL all write
+ them. A CSR built with `openssl req -subj "/DC=com/DC=example/DC=corp/CN=host"` matches
+ `corp,example,com`. Writing the same subject in the reverse order describes `com.example.corp`
+ instead, and is rejected against this rule.
- Wildcards apply within a single component. `*,example,com` matches any three-component sequence
ending in `example`, `com`.
- Deny is the exception to position-by-position matching: a denied sequence is rejected wherever it