Skip to content

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

fix(template): add opt-in escaped-only validation for permission templates

Vlad Ligai07450f163c71
diff --git a/backend/src/ee/services/project-template/project-template-service.ts b/backend/src/ee/services/project-template/project-template-service.ts
index de4bce5694..99e4ade816 100644
--- a/backend/src/ee/services/project-template/project-template-service.ts
+++ b/backend/src/ee/services/project-template/project-template-service.ts
@@ -18,6 +18,7 @@ import {
TUnpackedPermission
} from "@app/ee/services/project-template/project-template-types";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
+import { validateHandlebarTemplate } from "@app/lib/template/validate-handlebars";
import { unpackPermissions } from "@app/server/routes/sanitizedSchema/permission";
import { TIdentityDALFactory } from "@app/services/identity/identity-dal";
import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";
@@ -265,6 +266,16 @@ export const projectTemplateServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.ProjectTemplates);
+ // Template roles are materialized into project custom roles (rendered by the same permission
+ // templating), so validate them the same way role creation does.
+ roles.forEach((role) => {
+ validateHandlebarTemplate("Project Template Role", JSON.stringify(role.permissions || []), {
+ allowedExpressions: (val) => val.includes("identity."),
+ allowedHelpers: ["stripPrefix"],
+ rejectUnescaped: true
+ });
+ });
+
if (type === ProjectType.AI) {
throw new BadRequestError({ message: "Agent Sentinel project templates are not supported" });
}
@@ -509,6 +520,19 @@ export const projectTemplateServiceFactory = ({
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.ProjectTemplates);
+
+ if (roles) {
+ // Template roles are materialized into project custom roles, so validate them the same way
+ // role update does.
+ roles.forEach((role) => {
+ validateHandlebarTemplate("Project Template Role", JSON.stringify(role.permissions || []), {
+ allowedExpressions: (val) => val.includes("identity."),
+ allowedHelpers: ["stripPrefix"],
+ rejectUnescaped: true
+ });
+ });
+ }
+
if (projectTemplate.type !== ProjectType.SecretManager && environments)
throw new BadRequestError({ message: "Cannot configure environments for non-SecretManager project templates" });