Skip to content

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

Update backend/src/db/sanitized-schema.ts

Maidul Islam1fc4d38022a2
diff --git a/backend/src/db/sanitized-schema.ts b/backend/src/db/sanitized-schema.ts
index c16483cbde..f9c8a021d6 100644
--- a/backend/src/db/sanitized-schema.ts
+++ b/backend/src/db/sanitized-schema.ts
@@ -71,6 +71,13 @@ type TGrantArgs = TArgs & {
};
export const grantSanitizedSchemaAccess = async ({ db, logger, role }: TGrantArgs): Promise<void> => {
+ // Validate role name to prevent SQL injection
+ if (!/^[a-zA-Z0-9_-]+$/.test(role)) {
+ throw new Error(
+ `SANITIZED_SCHEMA_SECURITY_VIOLATION: Invalid role name. Only alphanumeric characters, underscores, and hyphens are allowed. Got: ${role}`
+ );
+ }
+
// eslint-disable-next-line import/no-extraneous-dependencies
const { generateGrantReadAccessSQL } = await import("@infisical/pg-view-generator");
@@ -78,3 +85,4 @@ export const grantSanitizedSchemaAccess = async ({ db, logger, role }: TGrantArg
await db.raw(sql);
logger.info(`Granted read access on sanitized schema to role: ${role}`);
};
+};