mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
misc: moved host validity check to helper
This commit is contained in:
18
backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
Normal file
18
backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
Normal file
@@ -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" });
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -9,10 +9,10 @@ import hdb from "hdb";
|
|||||||
import { customAlphabet } from "nanoid";
|
import { customAlphabet } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { getConfig } from "@app/lib/config/env";
|
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
import { alphaNumericNanoId } from "@app/lib/nanoid";
|
import { alphaNumericNanoId } from "@app/lib/nanoid";
|
||||||
|
|
||||||
|
import { verifyHostInputValidity } from "../dynamic-secret-fns";
|
||||||
import { DynamicSecretSapHanaSchema, TDynamicProviderFns } from "./models";
|
import { DynamicSecretSapHanaSchema, TDynamicProviderFns } from "./models";
|
||||||
|
|
||||||
const generatePassword = (size = 48) => {
|
const generatePassword = (size = 48) => {
|
||||||
@@ -26,23 +26,9 @@ const generateUsername = () => {
|
|||||||
|
|
||||||
export const SapHanaProvider = (): TDynamicProviderFns => {
|
export const SapHanaProvider = (): TDynamicProviderFns => {
|
||||||
const validateProviderInputs = async (inputs: unknown) => {
|
const validateProviderInputs = async (inputs: unknown) => {
|
||||||
const appCfg = getConfig();
|
|
||||||
const providerInputs = await DynamicSecretSapHanaSchema.parseAsync(inputs);
|
const providerInputs = await DynamicSecretSapHanaSchema.parseAsync(inputs);
|
||||||
|
|
||||||
if (
|
verifyHostInputValidity(providerInputs.host);
|
||||||
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" });
|
|
||||||
}
|
|
||||||
|
|
||||||
return providerInputs;
|
return providerInputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user