Skip to content

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

fix(server): updated secret rotation to pick on db host in validation

Akhil Mohancb828200e15f
diff --git a/backend/src/ee/services/secret-rotation/secret-rotation-queue/secret-rotation-queue-fn.ts b/backend/src/ee/services/secret-rotation/secret-rotation-queue/secret-rotation-queue-fn.ts
index c67477bfd9..5a2e478e16 100644
--- a/backend/src/ee/services/secret-rotation/secret-rotation-queue/secret-rotation-queue-fn.ts
+++ b/backend/src/ee/services/secret-rotation/secret-rotation-queue/secret-rotation-queue-fn.ts
@@ -9,6 +9,7 @@ import jmespath from "jmespath";
import knex from "knex";
import { getConfig } from "@app/lib/config/env";
+import { getDbConnectionHost } from "@app/lib/knex";
import { alphaNumericNanoId } from "@app/lib/nanoid";
import { TAssignOp, TDbProviderClients, TDirectAssignOp, THttpProviderFunction } from "../templates/types";
@@ -89,7 +90,7 @@ export const secretRotationDbFn = async ({
const appCfg = getConfig();
const ssl = ca ? { rejectUnauthorized: false, ca } : undefined;
- if (host === "localhost" || host === "127.0.0.1" || appCfg.DB_CONNECTION_URI.includes(host))
+ if (host === "localhost" || host === "127.0.0.1" || getDbConnectionHost(appCfg.DB_CONNECTION_URI) === host)
throw new Error("Invalid db host");
const db = knex({
diff --git a/backend/src/lib/knex/connection.ts b/backend/src/lib/knex/connection.ts
new file mode 100644
index 0000000000..993615a0b8
--- /dev/null
+++ b/backend/src/lib/knex/connection.ts
@@ -0,0 +1,11 @@
+import { URL } from "url"; // Import the URL class
+
+export const getDbConnectionHost = (urlString: string) => {
+ try {
+ const url = new URL(urlString);
+ // Split hostname and port (if provided)
+ return url.hostname.split(":")[0];
+ } catch (error) {
+ return null;
+ }
+};
diff --git a/backend/src/lib/knex/index.ts b/backend/src/lib/knex/index.ts
index 37fae624ef..d780208098 100644
--- a/backend/src/lib/knex/index.ts
+++ b/backend/src/lib/knex/index.ts
@@ -4,6 +4,7 @@ import { Tables } from "knex/types/tables";
import { DatabaseError } from "../errors";
+export * from "./connection";
export * from "./join";
export * from "./select";