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
fix(insights): smooth value search loading and link to the exact secret
Calvin83fbbde69091
diff --git a/frontend/src/components/secrets/GoToSecretButton.tsx b/frontend/src/components/secrets/GoToSecretButton.tsxindex a95cce7534..a83c9b81bd 100644--- a/frontend/src/components/secrets/GoToSecretButton.tsx+++ b/frontend/src/components/secrets/GoToSecretButton.tsx@@ -15,6 +15,7 @@ const overviewRoute =type Props = {orgId: string;projectId: string;+ secretKey: string;secretPath: string;environmentSlug: string;isProjectMember: boolean;@@ -23,9 +24,10 @@ type Props = {// Org-wide value results include projects the user is not a member of, and the project overview// cannot load for them, so the link is disabled rather than sending them to a failing page.-export const GoToSecretFolderButton = ({+export const GoToSecretButton = ({orgId,projectId,+ secretKey,secretPath,environmentSlug,isProjectMember,@@ -42,14 +44,14 @@ export const GoToSecretFolderButton = ({<IconButtonvariant="ghost"size="sm"- aria-label="Go to secret folder"+ aria-label="Go to secret"isDisabled={!isProjectMember}onClick={() => {onNavigate?.();navigate({to: overviewRoute,params: { orgId, projectId },- search: { secretPath, environments: [environmentSlug] }+ search: { secretPath, environments: [environmentSlug], search: secretKey }});}}>@@ -58,7 +60,7 @@ export const GoToSecretFolderButton = ({</span></TooltipTrigger><TooltipContent>- {isProjectMember ? "Go to secret folder" : "You don't have access to this project"}+ {isProjectMember ? "Go to secret" : "You don't have access to this project"}</TooltipContent></Tooltip></TooltipProvider>diff --git a/frontend/src/components/secrets/SecretValueSearchSheet.tsx b/frontend/src/components/secrets/SecretValueSearchSheet.tsxindex b90733f402..99384d5281 100644--- a/frontend/src/components/secrets/SecretValueSearchSheet.tsx+++ b/frontend/src/components/secrets/SecretValueSearchSheet.tsx@@ -24,10 +24,14 @@ import {TableHeader,TableRow} from "@app/components/v3";+import { useDelayedLoading } from "@app/hooks";import { useGetUserProjects } from "@app/hooks/api";-import { useSearchSecretsByValue } from "@app/hooks/api/secretInsights";+import {+ TSearchSecretsByValueResponse,+ useSearchSecretsByValue+} from "@app/hooks/api/secretInsights";-import { GoToSecretFolderButton } from "./GoToSecretFolderButton";+import { GoToSecretButton } from "./GoToSecretButton";import { SecretValueTrackingPrompt, useOrgSecretValueTracking } from "./SecretValueTrackingGate";// Mirrors SECRET_VALUE_SEARCH_LIMIT on the server, which truncates without saying so.@@ -43,6 +47,11 @@ const SearchContent = ({ orgId, onClose }: { orgId: string; onClose: () => voidconst [value, setValue] = useState("");const [isRevealed, setIsRevealed] = useState(false);const search = useSearchSecretsByValue();+ // Held in state rather than read off the mutation, so the last answer stays on screen while a+ // repeat search runs instead of blanking out and back.+ const [matches, setMatches] = useState<TSearchSecretsByValueResponse["secrets"] | null>(null);+ // Most searches return well under the delay, so the skeleton only shows for a slow one.+ const isSearchSlow = useDelayedLoading(search.isPending, { delay: 300, minDuration: 500 });const { data: memberProjects } = useGetUserProjects();const memberProjectIds = useMemo(() => new Set(memberProjects?.map((project) => project.id)),@@ -51,11 +60,12 @@ const SearchContent = ({ orgId, onClose }: { orgId: string; onClose: () => voidconst tracking = useOrgSecretValueTracking({ orgId, enabled: true });- if (!tracking.isTrackingOn) {+ if (!tracking.isReady) {return (<div className="p-4"><SecretValueTrackingPrompttracking={tracking}+ featureName="secret value search"description="Enable secret value search to find every project, environment and path where a value is used."/></div>@@ -65,16 +75,14 @@ const SearchContent = ({ orgId, onClose }: { orgId: string; onClose: () => void// Each search is an audited event, so it runs on submit rather than on every keystroke.const handleSubmit = (event: FormEvent) => {event.preventDefault();- if (!value) return;- search.mutate({ secretValue: value });+ if (!value || search.isPending) return;+ search.mutate({ secretValue: value }, { onSuccess: (data) => setMatches(data.secrets) });};- const matches = search.data?.secrets ?? [];-const renderResults = () => {- if (search.isPending) return <Skeleton className="h-[240px] w-full" />;+ if (isSearchSlow) return <Skeleton className="h-[240px] w-full" />;- if (!search.data) {+ if (!matches) {return (<Empty variant="unstyled"><EmptyHeader>@@ -147,9 +155,10 @@ const SearchContent = ({ orgId, onClose }: { orgId: string; onClose: () => void</div></TableCell><TableCell variant="action">- <GoToSecretFolderButton+ <GoToSecretButtonorgId={orgId}projectId={match.projectId}+ secretKey={match.key}secretPath={match.secretPath}environmentSlug={match.environment.slug}isProjectMember={memberProjectIds.has(match.projectId)}@@ -183,7 +192,8 @@ const SearchContent = ({ orgId, onClose }: { orgId: string; onClose: () => voidonChange={(e) => {setValue(e.target.value);// Results belong to the value that was searched, not the one now in the box.- if (search.data) search.reset();+ setMatches(null);+ search.reset();}}onKeyDown={(e) => {// A textarea would otherwise take Enter as a newline rather than a search.@@ -202,7 +212,7 @@ const SearchContent = ({ orgId, onClose }: { orgId: string; onClose: () => void{isRevealed ? <EyeOffIcon /> : <EyeIcon />}</IconButton></div>- <Button type="submit" variant="org" isDisabled={!value} isPending={search.isPending}>+ <Button type="submit" variant="org" isDisabled={!value} isPending={isSearchSlow}>Search</Button></form>@@ -215,7 +225,7 @@ export const SecretValueSearchSheet = ({ orgId, isOpen, onOpenChange }: Props) =<Sheet open={isOpen} onOpenChange={onOpenChange}><SheetContent size="workspace" className="flex flex-col overflow-hidden"><SheetHeader>- <SheetTitle>Search by Secret Value</SheetTitle>+ <SheetTitle>Locate Secrets by Value</SheetTitle><SheetDescription>Find every project, environment and path where a secret value is used. Only the full valuematches, exactly as stored: partial values and values differing in whitespace are notdiff --git a/frontend/src/components/secrets/SecretValueTrackingGate.tsx b/frontend/src/components/secrets/SecretValueTrackingGate.tsxindex 2b79d22724..8d7ec41128 100644--- a/frontend/src/components/secrets/SecretValueTrackingGate.tsx+++ b/frontend/src/components/secrets/SecretValueTrackingGate.tsx@@ -9,6 +9,7 @@ import {EmptyTitle,Skeleton} from "@app/components/v3";+import { useDelayedLoading } from "@app/hooks";import {TGetOrgSecretValueTrackingStatusResponse,useEnableOrgSecretValueTracking,@@ -17,7 +18,10 @@ import {type TOrgSecretValueTracking = {isLoading: boolean;+ isLoadingVisible: boolean;isTrackingOn: boolean;+ // Tracking is on and no loading state is still being held on screen.+ isReady: boolean;status?: TGetOrgSecretValueTrackingStatusResponse;isEnablePending: boolean;enable: () => void;@@ -34,11 +38,18 @@ export const useOrgSecretValueTracking = ({}): TOrgSecretValueTracking => {const enableTracking = useEnableOrgSecretValueTracking();const { data: status, isPending } = useGetOrgSecretValueTrackingStatus(orgId, { enabled });+ const isLoading = enabled && isPending;+ // The status usually comes back before the sheet or card finishes rendering, so the skeleton+ // only appears on a slow request, and then stays long enough not to flash.+ const isLoadingVisible = useDelayedLoading(isLoading, { delay: 300, minDuration: 500 });+ // The status route reports completed whenever the org flag is set, so this is the durable answer.+ const isTrackingOn = status?.status === "completed";return {- isLoading: enabled && isPending,- // The status route reports completed whenever the org flag is set, so this is the durable answer.- isTrackingOn: status?.status === "completed",+ isLoading,+ isLoadingVisible,+ isTrackingOn,+ isReady: isTrackingOn && !isLoadingVisible,status,isEnablePending: enableTracking.isPending,enable: () => enableTracking.mutate({ orgId })@@ -46,24 +57,28 @@ export const useOrgSecretValueTracking = ({};// Renders whatever stands between the caller and a finished index. Callers render their own-// content once `tracking.isTrackingOn` is true.+// content once `tracking.isReady` is true.export const SecretValueTrackingPrompt = ({tracking,+ featureName,description}: {tracking: TOrgSecretValueTracking;+ // Lowercase, as it reads mid-sentence (eg "duplicate secret detection").+ featureName: string;description: string;}) => {- const { status, isLoading, isEnablePending, enable } = tracking;+ const { status, isLoading, isLoadingVisible, isEnablePending, enable } = tracking;- if (isLoading) return <Skeleton className="h-[200px] w-full" />;+ if (isLoadingVisible) return <Skeleton className="h-[200px] w-full" />;+ if (isLoading) return null;if (status?.status === "failed" && !isEnablePending) {return (<div className="flex h-[200px] flex-col items-center justify-center gap-3"><AlertTriangleIcon className="size-6 text-danger" /><p className="text-sm text-danger">- Could not enable secret value search: {status.message ?? "Unknown error"}+ Could not enable {featureName}: {status.message ?? "Unknown error"}</p><Button variant="outline" onClick={enable}>Retry@@ -78,11 +93,11 @@ export const SecretValueTrackingPrompt = ({<Loader2Icon className="size-6 animate-spin text-org" /><p className="text-sm text-foreground">{status?.projectsTotal- ? `Enabling secret value search: ${status.projectsDone} of ${status.projectsTotal} projects ready`- : "Enabling secret value search"}+ ? `Enabling ${featureName}: ${status.projectsDone} of ${status.projectsTotal} projects ready`+ : `Enabling ${featureName}`}</p><p className="max-w-md text-sm text-muted">- You can leave this page. Search is ready here when this finishes.+ You can leave this page. This finishes in the background.</p></div>);@@ -91,11 +106,14 @@ export const SecretValueTrackingPrompt = ({return (<Empty className="border"><EmptyHeader>- <EmptyTitle>Secret value search is not enabled</EmptyTitle>+ <EmptyTitle>+ {featureName.charAt(0).toUpperCase()}+ {featureName.slice(1)} is not enabled+ </EmptyTitle><EmptyDescription>{description}</EmptyDescription><EmptyContent><Button variant="org" size="xs" onClick={enable}>- Enable Secret Value Search+ Enable</Button></EmptyContent></EmptyHeader>diff --git a/frontend/src/hooks/api/secretInsights/mutations.tsx b/frontend/src/hooks/api/secretInsights/mutations.tsxindex 4da1d1dac5..fce2b24141 100644--- a/frontend/src/hooks/api/secretInsights/mutations.tsx+++ b/frontend/src/hooks/api/secretInsights/mutations.tsx@@ -38,8 +38,8 @@ export const useSearchSecretsByValue = () =>useMutation<TSearchSecretsByValueResponse, object, { secretValue: string }>({mutationFn: async ({ secretValue }) => {const { data } = await apiRequest.post<TSearchSecretsByValueResponse>(- "/api/v4/secrets/search-by-value",- { secretValue, scope: "organization" }+ "/api/v1/insights/secrets/search-by-value",+ { secretValue });return data;}diff --git a/frontend/src/hooks/useDelayedLoading.ts b/frontend/src/hooks/useDelayedLoading.tsindex 1a43e59234..e87667ffde 100644--- a/frontend/src/hooks/useDelayedLoading.ts+++ b/frontend/src/hooks/useDelayedLoading.ts@@ -1,25 +1,52 @@-import { useEffect, useState } from "react";+import { useEffect, useRef, useState } from "react";type UseDelayedLoadingOptions = {delay?: number;+ // Once shown, keep the loading state up at least this long, so a request that lands just after+ // `delay` does not flash it on and straight back off.+ minDuration?: number;resetKey?: string | number;};export const useDelayedLoading = (isLoading: boolean,- { delay = 200, resetKey }: UseDelayedLoadingOptions = {}+ { delay = 200, minDuration = 0, resetKey }: UseDelayedLoadingOptions = {}) => {const [isDelayedLoading, setIsDelayedLoading] = useState(false);+ const shownAtRef = useRef<number | null>(null);useEffect(() => {- setIsDelayedLoading(false);-if (!isLoading) return undefined;- const timeout = window.setTimeout(() => setIsDelayedLoading(true), delay);+ shownAtRef.current = null;+ setIsDelayedLoading(false);++ const timeout = window.setTimeout(() => {+ shownAtRef.current = Date.now();+ setIsDelayedLoading(true);+ }, delay);return () => window.clearTimeout(timeout);}, [delay, isLoading, resetKey]);- return isLoading && isDelayedLoading;+ useEffect(() => {+ if (isLoading) return undefined;++ const hide = () => {+ shownAtRef.current = null;+ setIsDelayedLoading(false);+ };++ const remaining =+ shownAtRef.current === null ? 0 : minDuration - (Date.now() - shownAtRef.current);+ if (remaining <= 0) {+ hide();+ return undefined;+ }++ const timeout = window.setTimeout(hide, remaining);+ return () => window.clearTimeout(timeout);+ }, [isLoading, minDuration]);++ return minDuration > 0 ? isDelayedLoading : isLoading && isDelayedLoading;};diff --git a/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/ProjectSearchInput.tsx b/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/ProjectSearchInput.tsxindex cf153902f9..b572e1eb04 100644--- a/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/ProjectSearchInput.tsx+++ b/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/ProjectSearchInput.tsx@@ -1,6 +1,7 @@import { FocusEvent, KeyboardEvent, useRef, useState } from "react";-import { SearchIcon, ShieldAlertIcon } from "lucide-react";+import { KeyIcon, SearchIcon } from "lucide-react";+import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";import { SecretValueSearchSheet } from "@app/components/secrets/SecretValueSearchSheet";import {InputGroup,@@ -11,6 +12,7 @@ import {PopoverTrigger} from "@app/components/v3";import { cn } from "@app/components/v3/utils";+import { useSubscription } from "@app/context";import { useSlashFocusSearch } from "@app/hooks";type Props = {@@ -26,6 +28,8 @@ export const ProjectSearchInput = ({ orgId, value, onChange, canSearchByValue }:const [isFocused, setIsFocused] = useState(false);const [isOptionHighlighted, setIsOptionHighlighted] = useState(false);const [isValueSearchOpen, setIsValueSearchOpen] = useState(false);+ const [isUpgradeOpen, setIsUpgradeOpen] = useState(false);+ const { subscription } = useSubscription();useSlashFocusSearch(inputRef);const close = () => {@@ -36,7 +40,9 @@ export const ProjectSearchInput = ({ orgId, value, onChange, canSearchByValue }:const openValueSearch = () => {close();inputRef.current?.blur();- setIsValueSearchOpen(true);+ // Value search is part of secret insights, so a plan without it gets the upgrade prompt.+ if (subscription?.secretAccessInsights) setIsValueSearchOpen(true);+ else setIsUpgradeOpen(true);};const input = (@@ -113,8 +119,8 @@ export const ProjectSearchInput = ({ orgId, value, onChange, canSearchByValue }:}}onClick={openValueSearch}>- <ShieldAlertIcon className="size-4 shrink-0 text-muted" />- <span className="truncate">Search by secret value</span>+ <KeyIcon className="size-4 shrink-0 text-muted" />+ <span className="truncate">Locate secrets by value</span></button></PopoverContent></Popover>@@ -123,6 +129,12 @@ export const ProjectSearchInput = ({ orgId, value, onChange, canSearchByValue }:isOpen={isValueSearchOpen}onOpenChange={setIsValueSearchOpen}/>+ <UpgradePlanModal+ paywallKey="organization.secret-insights"+ isOpen={isUpgradeOpen}+ onOpenChange={setIsUpgradeOpen}+ text="Your current plan does not include access to secret insights. To unlock this feature, please upgrade your Infisical plan."+ /></>);};diff --git a/frontend/src/pages/organization/SecretInsightsPage/components/DuplicateGroupList.tsx b/frontend/src/pages/organization/SecretInsightsPage/components/DuplicateGroupList.tsxindex ab2ee02fe1..91557970d5 100644--- a/frontend/src/pages/organization/SecretInsightsPage/components/DuplicateGroupList.tsx+++ b/frontend/src/pages/organization/SecretInsightsPage/components/DuplicateGroupList.tsx@@ -2,7 +2,7 @@ import { useMemo } from "react";import { useParams } from "@tanstack/react-router";import { FolderIcon, KeyIcon, LayersIcon, LockIcon } from "lucide-react";-import { GoToSecretFolderButton } from "@app/components/secrets/GoToSecretFolderButton";+import { GoToSecretButton } from "@app/components/secrets/GoToSecretButton";import {Accordion,AccordionContent,@@ -107,9 +107,10 @@ export const DuplicateGroupList = ({ groups }: Props) => {</div></TableCell><TableCell variant="action">- <GoToSecretFolderButton+ <GoToSecretButtonorgId={orgId as string}projectId={entry.projectId}+ secretKey={entry.key}secretPath={entry.secretPath}environmentSlug={entry.environment.slug}isProjectMember={memberProjectIds.has(entry.projectId)}diff --git a/frontend/src/pages/organization/SecretInsightsPage/components/DuplicatedSecretsCard.tsx b/frontend/src/pages/organization/SecretInsightsPage/components/DuplicatedSecretsCard.tsxindex 6eaa32a3b1..74af81bfb9 100644--- a/frontend/src/pages/organization/SecretInsightsPage/components/DuplicatedSecretsCard.tsx+++ b/frontend/src/pages/organization/SecretInsightsPage/components/DuplicatedSecretsCard.tsx@@ -79,11 +79,12 @@ export const DuplicatedSecretsCard = ({ isPlanRestricted }: Props) => {);}- if (!tracking.isTrackingOn) {+ if (!tracking.isReady) {return (<SecretValueTrackingPrompttracking={tracking}- description="Enable secret value search to find secrets that share a value across the organization."+ featureName="duplicate secret detection"+ description="Enable duplicate secret detection to find secrets that share a value across the organization."/>);}