Skip to content

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

misc: moved host validity check to helper

Sheen Capadngan3552119c7d4c
diff --git a/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts b/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
new file mode 100644
index 0000000000..1e858c9884
--- /dev/null
+++ b/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
@@ -0,0 +1,18 @@
+import { getConfig } from "@app/lib/config/env";
+import { BadRequestError } from "@app/lib/errors";
+
+export const verifyHostInputValidity = (host: string) => {
+ const appCfg = getConfig();
+
+ if (
+ appCfg.isCloud &&
+ // localhost
+ // internal ips
+ (host === "host.docker.internal" || host.match(/^10\.\d+\.\d+\.\d+/) || host.match(/^192\.168\.\d+\.\d+/))
+ )
+ throw new BadRequestError({ message: "Invalid db host" });
+
+ if (host === "localhost" || host === "127.0.0.1") {
+ throw new BadRequestError({ message: "Invalid db host" });
+ }
+};
diff --git a/backend/src/ee/services/dynamic-secret/providers/sap-hana.ts b/backend/src/ee/services/dynamic-secret/providers/sap-hana.ts
index fb3a0da78e..d120cf4fef 100644
--- a/backend/src/ee/services/dynamic-secret/providers/sap-hana.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/sap-hana.ts
@@ -9,10 +9,10 @@ import hdb from "hdb";
import { customAlphabet } from "nanoid";
import { z } from "zod";
-import { getConfig } from "@app/lib/config/env";
import { BadRequestError } from "@app/lib/errors";
import { alphaNumericNanoId } from "@app/lib/nanoid";
+import { verifyHostInputValidity } from "../dynamic-secret-fns";
import { DynamicSecretSapHanaSchema, TDynamicProviderFns } from "./models";
const generatePassword = (size = 48) => {
@@ -26,23 +26,9 @@ const generateUsername = () => {
export const SapHanaProvider = (): TDynamicProviderFns => {
const validateProviderInputs = async (inputs: unknown) => {
- const appCfg = getConfig();
const providerInputs = await DynamicSecretSapHanaSchema.parseAsync(inputs);
- if (
- appCfg.isCloud &&
- // localhost
- // internal ips
- (providerInputs.host === "host.docker.internal" ||
- providerInputs.host.match(/^10\.\d+\.\d+\.\d+/) ||
- providerInputs.host.match(/^192\.168\.\d+\.\d+/))
- )
- throw new BadRequestError({ message: "Invalid db host" });
-
- if (providerInputs.host === "localhost" || providerInputs.host === "127.0.0.1") {
- throw new BadRequestError({ message: "Invalid db host" });
- }
-
+ verifyHostInputValidity(providerInputs.host);
return providerInputs;
};