Skip to content

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

add validation also when user provide a rotated statement

adilsonff3e95e1dbde
diff --git a/backend/src/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-fns.ts
index bb029fce5e..3a33740226 100644
--- a/backend/src/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-fns.ts
@@ -129,9 +129,11 @@ export const sqlCredentialsRotationFactory: TRotationFactory<
};
const $executeQuery = async (tx: Knex, username: string, password: string) => {
+ const filteredUsername = getRoleUsernameForHost(username, connection.credentials.host);
+
if (userProvidedRotationStatement) {
const revokeStatement = handlebars.compile(userProvidedRotationStatement)({
- username,
+ username: filteredUsername,
password,
database: connection.credentials.database
});
@@ -140,7 +142,6 @@ export const sqlCredentialsRotationFactory: TRotationFactory<
await tx.raw(query);
}
} else {
- const filteredUsername = getRoleUsernameForHost(username, connection.credentials.host);
await tx.raw(...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[connection.app]({ username: filteredUsername, password }));
}
};
diff --git a/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts b/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
index 6dddec196c..08c97698e1 100644
--- a/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
+++ b/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
@@ -264,10 +264,10 @@ export const validateSqlConnectionCredentials = async (
// the correct branch, but the underlying DB role is just `<user>`. Strip the branch suffix for
// role-level statements (ALTER USER / ALTER LOGIN). Only applies to PlanetScale hosts so that
// legitimate dotted usernames on other providers are left untouched.
-const PLANETSCALE_HOST_SUFFIX = "psdb.cloud";
+const PLANETSCALE_HOST_SUFFIX = ".psdb.cloud";
export const getRoleUsernameForHost = (username: string, host: string) => {
- const isPlanetScaleHost = host.toLowerCase().includes(PLANETSCALE_HOST_SUFFIX);
+ const isPlanetScaleHost = host.toLowerCase().endsWith(PLANETSCALE_HOST_SUFFIX);
if (isPlanetScaleHost && username.includes(".")) {
return username.slice(0, username.indexOf("."));
}