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
fix(aws-auth): escape regex metacharacters in ARN allowlist matching (#6344)
Saif Ur Rahmanf141150413f4
diff --git a/backend/src/ee/services/resource-auth-method/aws-auth-fns.ts b/backend/src/ee/services/resource-auth-method/aws-auth-fns.tsindex a5259c7761..3c7b5e8d23 100644--- a/backend/src/ee/services/resource-auth-method/aws-auth-fns.ts+++ b/backend/src/ee/services/resource-auth-method/aws-auth-fns.ts@@ -151,7 +151,7 @@ export const validateAllowlists = ({.filter((principalArn) => principalArn.length > 0).some((principalArn) => {// Convert wildcard to regex; arnRegex in validators ensures safe input.- const regex = new RE2(`^${principalArn.replaceAll("*", ".*")}$`);+ const regex = new RE2(`^${principalArn.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replaceAll("*", ".*")}$`);return regex.test(formattedArn) || regex.test(extractPrincipalArn(Arn, true));});diff --git a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts b/backend/src/services/identity-aws-auth/identity-aws-auth-service.tsindex 2e0976474b..6dbcbcf209 100644--- a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts@@ -195,7 +195,7 @@ export const identityAwsAuthServiceFactory = ({// convert wildcard ARN to a regular expression: "arn:aws:iam::123456789012:*" -> "^arn:aws:iam::123456789012:.*$"// considers exact matches + wildcard matches// heavily validated in router- const regex = new RE2(`^${principalArn.replaceAll("*", ".*")}$`);+ const regex = new RE2(`^${principalArn.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replaceAll("*", ".*")}$`);return regex.test(formattedArn) || regex.test(extractPrincipalArn(Arn, true));});diff --git a/backend/src/services/identity-aws-auth/identity-aws-auth-validators.ts b/backend/src/services/identity-aws-auth/identity-aws-auth-validators.tsindex 270b202d67..d7d1da955a 100644--- a/backend/src/services/identity-aws-auth/identity-aws-auth-validators.ts+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-validators.ts@@ -51,7 +51,11 @@ export const validatePrincipalArns = zconst arns = data.split(",");// Return true only if every item matches one of the allowed ARN formats// and checks whether the provided regex is safe- return arns.map((el) => el.trim()).every((arn) => safe(`^${arn.replaceAll("*", ".*")}$`) && arnRegex.test(arn));+ return arns+ .map((el) => el.trim())+ .every(+ (arn) => safe(`^${arn.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replaceAll("*", ".*")}$`) && arnRegex.test(arn)+ );},{message: