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
Use re2 for identifier validation
Fang-Pen Line5168e88e4b2
diff --git a/backend/src/ee/services/pki-acme/pki-acme-fns.ts b/backend/src/ee/services/pki-acme/pki-acme-fns.tsindex d828778912..eabfc78026 100644--- a/backend/src/ee/services/pki-acme/pki-acme-fns.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-fns.ts@@ -1,3 +1,5 @@+import { getConfig } from "@app/lib/config/env";+import RE2 from "re2";import { z } from "zod";import { getConfig } from "@app/lib/config/env";@@ -17,3 +19,10 @@ export const extractAccountIdFromKid = (kid: string, profileId: string): string}return z.string().uuid().parse(kid.slice(kidPrefix.length));};++export const validateDnsIdentifier = (identifier: string): boolean => {+ // DNS label pattern: 1-63 chars, alphanumeric or hyphen, but not starting or ending with hyphen+ const labelPattern = new RE2(/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/);+ const labels = identifier.split(".");+ return labels.every((label) => label.length >= 1 && label.length <= 63 && labelPattern.test(label));+};diff --git a/backend/src/ee/services/pki-acme/pki-acme-schemas.ts b/backend/src/ee/services/pki-acme/pki-acme-schemas.tsindex baa686e595..58ca7e8333 100644--- a/backend/src/ee/services/pki-acme/pki-acme-schemas.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-schemas.ts@@ -1,4 +1,3 @@-import RE2 from "re2";import { z } from "zod";export enum AcmeIdentifierType {@@ -84,19 +83,12 @@ export const CreateAcmeAccountResponseSchema = z.object({orders: z.string().optional()});-export const ValidDNSIdentifierRegex = /^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*$/;-// New Order payload schemaexport const CreateAcmeOrderBodySchema = z.object({identifiers: z.array(z.object({- type: z.enum(Object.values(AcmeIdentifierType) as [string, ...string[]]),- value: z.string().refine((val) => {- // DNS label pattern: 1-63 chars, alphanumeric or hyphen, but not starting or ending with hyphen- const labelPattern = new RE2(/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/);- const labels = val.split(".");- return labels.every((label) => label.length >= 1 && label.length <= 63 && labelPattern.test(label));- }, "Invalid DNS identifier")+ type: z.string(),+ value: z.string()})),notBefore: z.string().optional(),diff --git a/backend/src/ee/services/pki-acme/pki-acme-service.ts b/backend/src/ee/services/pki-acme/pki-acme-service.tsindex 3190f98efb..51f530264f 100644--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts@@ -43,7 +43,7 @@ import {AcmeServerInternalError,AcmeUnsupportedIdentifierError} from "./pki-acme-errors";-import { buildUrl, extractAccountIdFromKid } from "./pki-acme-fns";+import { buildUrl, extractAccountIdFromKid, validateDnsIdentifier } from "./pki-acme-fns";import { TPkiAcmeOrderAuthDALFactory } from "./pki-acme-order-auth-dal";import { TPkiAcmeOrderDALFactory } from "./pki-acme-order-dal";import {@@ -53,8 +53,7 @@ import {AcmeIdentifierType,AcmeOrderStatus,CreateAcmeAccountBodySchema,- ProtectedHeaderSchema,- ValidDNSIdentifierRegex+ ProtectedHeaderSchema} from "./pki-acme-schemas";import {TAcmeOrderResource,@@ -497,7 +496,7 @@ export const pkiAcmeServiceFactory = ({if (payload.identifiers.some((identifier) =>- !ValidDNSIdentifierRegex.test(identifier.value) ||+ !validateDnsIdentifier(identifier.value) ||isPrivateIp(identifier.value) ||(!getConfig().isDevelopmentMode && identifier.value.toLowerCase() === "localhost"))