mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
fix(secrets-service): throw on invalid env / path
This commit is contained in:
@@ -22,6 +22,26 @@ const INTERPOLATION_TEST_REGEX = new RE2(INTERPOLATION_PATTERN_STRING);
|
||||
|
||||
export const shouldUseSecretV2Bridge = (version: number) => version === 3;
|
||||
|
||||
export const validateSecretPath = async (
|
||||
data: {
|
||||
projectId: string;
|
||||
environment: string;
|
||||
secretPath: string;
|
||||
},
|
||||
folderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath">
|
||||
) => {
|
||||
const { projectId, environment, secretPath } = data;
|
||||
|
||||
const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);
|
||||
|
||||
if (!folder) {
|
||||
throw new NotFoundError({
|
||||
message: `Folder with path '${secretPath}' in environment '${environment}' was not found. Please ensure the environment slug and secret path is correct.`,
|
||||
name: "SecretPathNotFound"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Grabs and processes nested secret references from a string
|
||||
*
|
||||
|
||||
@@ -64,7 +64,8 @@ import {
|
||||
generatePaths,
|
||||
getAllSecretReferences,
|
||||
recursivelyGetSecretPaths,
|
||||
reshapeBridgeSecret
|
||||
reshapeBridgeSecret,
|
||||
validateSecretPath
|
||||
} from "./secret-v2-bridge-fns";
|
||||
import {
|
||||
SecretOperations,
|
||||
@@ -1040,6 +1041,15 @@ export const secretV2BridgeServiceFactory = ({
|
||||
projectId
|
||||
});
|
||||
|
||||
await validateSecretPath(
|
||||
{
|
||||
projectId,
|
||||
environment,
|
||||
secretPath: path
|
||||
},
|
||||
folderDAL
|
||||
);
|
||||
|
||||
const encryptedCachedSecrets = await keyStore.getItem(cacheKey);
|
||||
if (encryptedCachedSecrets) {
|
||||
try {
|
||||
|
||||
@@ -97,6 +97,7 @@ import {
|
||||
} from "./secret-types";
|
||||
import { TSecretVersionDALFactory } from "./secret-version-dal";
|
||||
import { TSecretVersionTagDALFactory } from "./secret-version-tag-dal";
|
||||
import { validateSecretPath } from "../secret-v2-bridge/secret-v2-bridge-fns";
|
||||
|
||||
type TSecretServiceFactoryDep = {
|
||||
secretDAL: TSecretDALFactory;
|
||||
@@ -616,6 +617,15 @@ export const secretServiceFactory = ({
|
||||
actionProjectType: ActionProjectType.SecretManager
|
||||
});
|
||||
|
||||
await validateSecretPath(
|
||||
{
|
||||
projectId,
|
||||
environment,
|
||||
secretPath: path
|
||||
},
|
||||
folderDAL
|
||||
);
|
||||
|
||||
let paths: { folderId: string; path: string }[] = [];
|
||||
|
||||
if (recursive) {
|
||||
|
||||
Reference in New Issue
Block a user