Skip to content

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

fix(identity-tls-cert-auth): require trust anchor to be a CA in chain mode

Alexander Sinnott8a5c844c3a3e
diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts
index 7b225e1fd2..26d9f97877 100644
--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts
+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.test.ts
@@ -396,6 +396,29 @@ describe("verifyClientCertificateChain", () => {
expect(result).toEqual({ ok: false, reasonCode: "certificate_not_yet_valid" });
});
+ test("rejects a leaf signed directly by a non-CA configured anchor", async () => {
+ // A configured certificate that is not marked CA:TRUE must not anchor a path even when it
+ // cryptographically signed the leaf. Otherwise chain mode would authenticate against a non-CA
+ // issuer despite being documented as trust-anchor (CA) validation.
+ const nonCaAnchorKeys = await crypto.webcrypto.subtle.generateKey(alg, true, ["sign", "verify"]);
+ const nonCaAnchor = await x509.X509CertificateGenerator.createSelfSigned({
+ serialNumber: "0a",
+ name: "CN=Non-CA Anchor",
+ notBefore: NOT_BEFORE,
+ notAfter: FAR_FUTURE,
+ keys: nonCaAnchorKeys,
+ extensions: [new x509.BasicConstraintsExtension(false)]
+ });
+ const leaf = await makeLeaf("workload", { cert: nonCaAnchor, keys: nonCaAnchorKeys });
+ const result = verifyClientCertificateChain({
+ leaf: toNative(leaf.cert),
+ presentedChain: [],
+ trustAnchor: toNative(nonCaAnchor),
+ now: NOW
+ });
+ expect(result).toEqual({ ok: false, reasonCode: "ca_verification_failed" });
+ });
+
test("rejects when the intermediate has expired", async () => {
const expiredIntermediate = await makeIntermediate("Expired Intermediate", root, {
notAfter: new Date("2026-06-10T00:00:00Z")
diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts
index 8a67e6514e..8bcba1f41d 100644
--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts
+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-fns.ts
@@ -15,7 +15,8 @@ const isWithinValidityWindow = (cert: TNativeX509, at: Date): boolean =>
* Unlike single-hop verification (leaf signed directly by the configured CA), this builds a
* path from the leaf through the presented intermediates up to the configured trust anchor and
* verifies, at every hop: the issuer relationship (subject/issuer match + signature), that each
- * issuer is a CA, and that every certificate on the path is within its validity window.
+ * issuer is a CA (including the trust anchor itself), and that every certificate on the path is
+ * within its validity window.
*
* The trust anchor is the only trusted input. Presented intermediates are untrusted: a forged or
* unrelated intermediate cannot create a path to the anchor, so it is rejected. This mirrors how
@@ -86,8 +87,11 @@ export const verifyClientCertificateChain = ({
// Reached the trust anchor: the path is complete and valid.
if (isAnchor(current)) return { ok: true };
- // The configured anchor directly issued the current certificate.
- if (issuedBy(current, trustAnchor)) {
+ // The configured anchor directly issued the current certificate. The anchor must itself be a
+ // CA to sign certificates: presented intermediates are gated on `candidate.ca` below, and the
+ // trust anchor is held to the same bar so a non-CA cert can't anchor a path. Without this, a
+ // configured end-entity (CA:FALSE) certificate would still be accepted as the leaf's issuer.
+ if (trustAnchor.ca && issuedBy(current, trustAnchor)) {
if (!isWithinValidityWindow(trustAnchor, now)) {
return {
ok: false,