Skip to content

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

address review comments

adilson20b3c38baf16
diff --git a/backend/src/ee/routes/v1/pit-router.ts b/backend/src/ee/routes/v1/pit-router.ts
index 544ed817e8..822e3fd42a 100644
--- a/backend/src/ee/routes/v1/pit-router.ts
+++ b/backend/src/ee/routes/v1/pit-router.ts
@@ -296,9 +296,7 @@ export const registerPITRouter = async (server: FastifyZodProvider) => {
}),
querystring: z.object({
folderId: z.string().trim(),
- environment: z.string().trim(),
deepRollback: booleanSchema.default(false),
- secretPath: z.string().trim().default("/").transform(removeTrailingSlash),
projectId: z.string().trim()
}),
response: {
@@ -314,7 +312,7 @@ export const registerPITRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
handler: async (req) => {
- const result = await server.services.pit.compareCommitChanges({
+ const { diffs, environment, folderPath } = await server.services.pit.compareCommitChanges({
actor: req.permission?.type,
actorId: req.permission?.id,
actorOrgId: req.permission?.orgId,
@@ -334,14 +332,14 @@ export const registerPITRouter = async (server: FastifyZodProvider) => {
targetCommitId: req.params.commitId,
folderId: req.query.folderId,
deepRollback: req.query.deepRollback,
- diffsCount: result.length.toString(),
- environment: req.query.environment,
- folderPath: req.query.secretPath
+ diffsCount: diffs.length.toString(),
+ environment,
+ folderPath
}
}
});
- return result;
+ return diffs;
}
});
diff --git a/backend/src/ee/services/pit/pit-service.test.ts b/backend/src/ee/services/pit/pit-service.test.ts
index 1b71c80e73..e3f83d92b3 100644
--- a/backend/src/ee/services/pit/pit-service.test.ts
+++ b/backend/src/ee/services/pit/pit-service.test.ts
@@ -19,7 +19,7 @@ const buildService = ({ commitFolderId = "folder-1" }: { commitFolderId?: string
fromVersion: "1"
}
]);
- const findEnv = vi.fn().mockResolvedValue({ id: "env-prod" });
+ const findEnv = vi.fn().mockResolvedValue({ id: "env-prod", slug: "prod" });
const service = pitServiceFactory({
folderCommitService: {
getLatestCommit: vi.fn().mockResolvedValue({ id: "latest-commit" }),
@@ -46,7 +46,7 @@ describe("compareCommitChanges", () => {
test("checks secret versions against the absolute path of the commit's folder", async () => {
const { service, getChangeVersions } = buildService();
- const diffs = await service.compareCommitChanges({
+ const { diffs } = await service.compareCommitChanges({
actor: ActorType.USER,
actorId: "user-1",
actorOrgId: "org-1",
@@ -75,10 +75,10 @@ describe("compareCommitChanges", () => {
expect(diffs[0]?.folderPath).toBe("/app/backend");
});
- test("resolves the environment from the commit", async () => {
+ test("resolves the environment and folder path from the commit", async () => {
const { service, findEnv } = buildService();
- await service.compareCommitChanges({
+ const { environment, folderPath } = await service.compareCommitChanges({
actor: ActorType.USER,
actorId: "user-1",
actorOrgId: "org-1",
@@ -90,6 +90,8 @@ describe("compareCommitChanges", () => {
});
expect(findEnv).toHaveBeenCalledWith({ projectId: "project-1", id: "env-prod" });
+ expect(environment).toBe("prod");
+ expect(folderPath).toBe("/app/backend");
});
test("rejects a commit that belongs to a different folder", async () => {
diff --git a/backend/src/ee/services/pit/pit-service.ts b/backend/src/ee/services/pit/pit-service.ts
index 9d24d2588d..ccba59201d 100644
--- a/backend/src/ee/services/pit/pit-service.ts
+++ b/backend/src/ee/services/pit/pit-service.ts
@@ -298,6 +298,14 @@ export const pitServiceFactory = ({
throw new NotFoundError({ message: "Latest commit not found" });
}
+ const folderData = await folderService.getFolderById({
+ actor,
+ actorId,
+ actorOrgId,
+ actorAuthMethod,
+ id: folderId
+ });
+
let diffs;
if (deepRollback) {
diffs = await folderCommitService.deepCompareFolder({
@@ -306,14 +314,6 @@ export const pitServiceFactory = ({
projectId
});
} else {
- const folderData = await folderService.getFolderById({
- actor,
- actorId,
- actorOrgId,
- actorAuthMethod,
- id: folderId
- });
-
diffs = [
{
folderId: folderData.id,
@@ -360,7 +360,7 @@ export const pitServiceFactory = ({
}
}
- return diffs;
+ return { diffs, environment: env.slug, folderPath: folderData.path };
};
const rollbackToCommit = async ({
diff --git a/backend/src/server/routes/v1/dashboard-router.ts b/backend/src/server/routes/v1/dashboard-router.ts
index 87bae927c9..bc95678730 100644
--- a/backend/src/server/routes/v1/dashboard-router.ts
+++ b/backend/src/server/routes/v1/dashboard-router.ts
@@ -38,7 +38,7 @@ import {
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
import { SecretMetadataQuerySchema, SecretMetadataResponseSchema } from "./dashboard-secret-metadata-schemas";
-import { isSecretPathMatch, resolveSecretDeepSearch } from "./dashboard-secret-search-fns";
+import { isInSecretSearchScope, resolveSecretDeepSearch } from "./dashboard-secret-search-fns";
const MAX_DEEP_SEARCH_LIMIT = 500; // arbitrary limit to prevent excessive results
const DEEP_SEARCH_DEFAULT_PAGE_LIMIT = 25;
@@ -1694,7 +1694,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
}
const matchedSecrets = searchPath
- ? secrets.filter((secret) => isSecretPathMatch(secret.secretPath, searchPath))
+ ? secrets.filter((secret) => isInSecretSearchScope(secret.secretPath, searchPath, secretPath))
: secrets;
// page secrets by rendered entry (env + path + key): a shared secret and its personal override
@@ -1713,11 +1713,11 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
const secretUnits = [...secretUnitsByEntry.values()];
const matchedDynamicSecrets = searchPath
- ? dynamicSecrets.filter((dynamicSecret) => isSecretPathMatch(dynamicSecret.path, searchPath))
+ ? dynamicSecrets.filter((dynamicSecret) => isInSecretSearchScope(dynamicSecret.path, searchPath, secretPath))
: dynamicSecrets;
const matchedSecretRotations = searchPath
- ? secretRotations.filter((rotation) => isSecretPathMatch(rotation.folder.path, searchPath))
+ ? secretRotations.filter((rotation) => isInSecretSearchScope(rotation.folder.path, searchPath, secretPath))
: secretRotations;
const matchedFolders = allFolders.filter((folder) => {
@@ -1727,7 +1727,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
if (searchPath) {
if (searchPath === "/") {
// only show root folders if no folder name search
- if (!searchName) return folderPath === searchPath;
+ if (!searchName) return isInSecretSearchScope(folderPath, searchPath, secretPath);
// start partial match on root folders
return folderName.toLowerCase().startsWith(searchName.toLowerCase());
@@ -1735,7 +1735,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
// support ending partial path match
return (
- isSecretPathMatch(folderPath, searchPath) && folderName.toLowerCase().startsWith(searchName.toLowerCase())
+ isInSecretSearchScope(folderPath, searchPath, secretPath) && folderName.toLowerCase().startsWith(searchName.toLowerCase())
);
}
diff --git a/backend/src/server/routes/v1/dashboard-secret-search-fns.test.ts b/backend/src/server/routes/v1/dashboard-secret-search-fns.test.ts
index 4338d193e0..66b5ca9fc9 100644
--- a/backend/src/server/routes/v1/dashboard-secret-search-fns.test.ts
+++ b/backend/src/server/routes/v1/dashboard-secret-search-fns.test.ts
@@ -1,4 +1,9 @@
-import { isSecretPathMatch, parseSecretPathSearch, resolveSecretDeepSearch } from "./dashboard-secret-search-fns";
+import {
+ isInSecretSearchScope,
+ isSecretPathMatch,
+ parseSecretPathSearch,
+ resolveSecretDeepSearch
+} from "./dashboard-secret-search-fns";
describe("parseSecretPathSearch", () => {
test.each([
@@ -26,6 +31,25 @@ describe("isSecretPathMatch", () => {
});
});
+describe("isInSecretSearchScope", () => {
+ test("scopes a root search path to the environment root", () => {
+ expect(isInSecretSearchScope("/", "/", "/")).toBe(true);
+ expect(isInSecretSearchScope("/db", "/", "/")).toBe(false);
+ });
+
+ test("scopes a root search path to a nested search root", () => {
+ expect(isInSecretSearchScope("/app/backend", "/", "/app/backend")).toBe(true);
+ expect(isInSecretSearchScope("/App/Backend", "/", "/app/backend")).toBe(true);
+ expect(isInSecretSearchScope("/app/backend/db", "/", "/app/backend")).toBe(false);
+ expect(isInSecretSearchScope("/", "/", "/app/backend")).toBe(false);
+ });
+
+ test("matches an ending path segment for any other search path", () => {
+ expect(isInSecretSearchScope("/app/backend/db", "/db", "/app/backend")).toBe(true);
+ expect(isInSecretSearchScope("/app/backend", "/db", "/app/backend")).toBe(false);
+ });
+});
+
describe("resolveSecretDeepSearch", () => {
const folderPaths = ["/", "/prod", "/prod/api", "/eu/Staging", "/a/b", "/a/b/c"];
diff --git a/backend/src/server/routes/v1/dashboard-secret-search-fns.ts b/backend/src/server/routes/v1/dashboard-secret-search-fns.ts
index 293d56000f..18c0099ab3 100644
--- a/backend/src/server/routes/v1/dashboard-secret-search-fns.ts
+++ b/backend/src/server/routes/v1/dashboard-secret-search-fns.ts
@@ -39,6 +39,9 @@ export const parseSecretPathSearch = (search?: string) => {
/** Case-insensitive because the search path derived by `parseSecretPathSearch` is lowercased. */
export const isSecretPathMatch = (path: string, searchPath: string) => path.toLowerCase().endsWith(searchPath);
+export const isInSecretSearchScope = (path: string, searchPath: string, rootPath: string) =>
+ searchPath === "/" ? path.toLowerCase() === rootPath.toLowerCase() : isSecretPathMatch(path, searchPath);
+
/**
* Resolves a deep search query into the free-text search term and the folder path scope.
*
diff --git a/frontend/src/components/secrets/CommitHistorySheet/CommitRestoreView.tsx b/frontend/src/components/secrets/CommitHistorySheet/CommitRestoreView.tsx
index d7f2dd7403..65aab6ab2c 100644
--- a/frontend/src/components/secrets/CommitHistorySheet/CommitRestoreView.tsx
+++ b/frontend/src/components/secrets/CommitHistorySheet/CommitRestoreView.tsx
@@ -80,7 +80,7 @@ export const CommitRestoreView = ({
isPlaceholderData,
isError,
refetch
- } = useGetRollbackPreview(folderId, commitId, environment, projectId, isDeepRollback, secretPath);
+ } = useGetRollbackPreview(folderId, commitId, projectId, isDeepRollback);
const { mutateAsync: rollback, isPending: isRollingBack } = useCommitRollback({
projectId,
diff --git a/frontend/src/hooks/api/folderCommits/queries.tsx b/frontend/src/hooks/api/folderCommits/queries.tsx
index 498ebf48cf..de3190165d 100644
--- a/frontend/src/hooks/api/folderCommits/queries.tsx
+++ b/frontend/src/hooks/api/folderCommits/queries.tsx
@@ -54,16 +54,14 @@ export const commitKeys = {
rollbackPreview: ({
folderId,
commitId,
- envSlug,
projectId,
deepRollback
}: {
folderId: string;
commitId: string;
- envSlug: string;
projectId: string;
deepRollback: boolean;
- }) => [{ folderId, commitId, envSlug, projectId, deepRollback }, "rollback-preview"] as const
+ }) => [{ folderId, commitId, projectId, deepRollback }, "rollback-preview"] as const
};
const fetchFolderCommitsCount = async ({
@@ -156,19 +154,15 @@ export const fetchCommitDetails = async (projectId: string, commitId: string) =>
export const fetchRollbackPreview = async (
folderId: string,
commitId: string,
- envSlug: string,
projectId: string,
- deepRollback: boolean,
- secretPath: string
+ deepRollback: boolean
): Promise<RollbackPreview[]> => {
const { data } = await apiRequest.get<RollbackPreview[]>(
`/api/v1/pit/commits/${commitId}/compare`,
{
params: {
folderId,
- environment: envSlug,
deepRollback,
- secretPath,
projectId
}
}
@@ -376,15 +370,12 @@ export const useGetCommitDetails = (projectId: string, commitId: string) => {
export const useGetRollbackPreview = (
folderId: string,
commitId: string,
- envSlug: string,
projectId: string,
- deepRollback: boolean,
- secretPath: string
+ deepRollback: boolean
) => {
return useQuery({
- queryKey: commitKeys.rollbackPreview({ folderId, commitId, envSlug, projectId, deepRollback }),
- queryFn: () =>
- fetchRollbackPreview(folderId, commitId, envSlug, projectId, deepRollback, secretPath),
+ queryKey: commitKeys.rollbackPreview({ folderId, commitId, projectId, deepRollback }),
+ queryFn: () => fetchRollbackPreview(folderId, commitId, projectId, deepRollback),
enabled: Boolean(folderId) && Boolean(commitId),
// Toggling deep rollback swaps query keys, so hold the previous preview instead of
// tearing the whole panel down to skeletons on every toggle