Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
requested changes
Daniel Hougaard8d50a7946223
diff --git a/backend/src/lib/gateway-v2/gateway-v2.ts b/backend/src/lib/gateway-v2/gateway-v2.tsindex b1b630244b..e8f614666d 100644--- a/backend/src/lib/gateway-v2/gateway-v2.ts+++ b/backend/src/lib/gateway-v2/gateway-v2.ts@@ -1,7 +1,7 @@import net from "node:net";import tls from "node:tls";-import axios, { AxiosError } from "axios";+import axios from "axios";import https from "https";import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns";@@ -277,10 +277,6 @@ export const withGatewayV2Proxy = async <T>(errorMessage = (err.response?.data as { message: string }).message;}- if (err instanceof AxiosError) {- throw err;- }-throw new BadRequestError({ message: errorMessage });} finally {// Ensure cleanup happens regardless of success or failurediff --git a/backend/src/services/secret-sync/hc-vault/hc-vault-sync-fns.ts b/backend/src/services/secret-sync/hc-vault/hc-vault-sync-fns.tsindex a30b000b89..39920ba3ec 100644--- a/backend/src/services/secret-sync/hc-vault/hc-vault-sync-fns.ts+++ b/backend/src/services/secret-sync/hc-vault/hc-vault-sync-fns.ts@@ -2,6 +2,7 @@ import { isAxiosError } from "axios";import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";+import { BadRequestError } from "@app/lib/errors";import { removeTrailingSlash } from "@app/lib/fn";import {getHCVaultAccessToken,@@ -117,9 +118,13 @@ const listHCVaultVariables = async (return data.data;} catch (error: unknown) {// Returning an empty set when a path isn't found allows that path to be created by a later POST request- if (isAxiosError(error) && error.response?.status === 404) {+ if (+ (isAxiosError(error) && error.response?.status === 404) ||+ (error instanceof BadRequestError && error.message === "Request failed with status code 404")+ ) {return {};}+throw error;}};@@ -272,6 +277,24 @@ export const HCVaultSyncFns = {}try {+ // if no secrets remain after removal+ if (Object.keys(variables).length === 0) {+ // for kv v1: must DELETE the path entirely (empty secrets not allowed)+ // for kv v2: can write empty data to keep the path with metadata+ if (mountVersion === KvVersion.V1) {+ const urlPath = `${removeTrailingSlash(mount)}/${path}`;+ await requestWithHCVaultGateway(connection, gatewayService, gatewayV2Service, {+ url: `${instanceUrl}/v1/${urlPath}`,+ method: "DELETE",+ headers: {+ "X-Vault-Token": accessToken,+ ...(namespace ? { "X-Vault-Namespace": namespace } : {})+ }+ });+ return;+ }+ }+await updateHCVaultVariables({ accessToken, instanceUrl, namespace, mount, mountVersion, path, data: variables },connection,