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(secrets): clarify copy preview access errors (#8184)
Andrew Huang327260157609
diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsxindex bcf989da36..94e7c475fc 100644--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx@@ -729,6 +729,8 @@ const OverviewPageContent = () => {const canCreateFolders = canFolderActionInVisibleEnv(ProjectPermissionActions.Create);+ const canReadFolders = canFolderActionInVisibleEnv(ProjectPermissionActions.Read);+const canEditFolders = canFolderActionInVisibleEnv(ProjectPermissionActions.Edit);const canDeleteFolders = canFolderActionInVisibleEnv(ProjectPermissionActions.Delete);@@ -2619,6 +2621,7 @@ const OverviewPageContent = () => {sourcePath: secretPath,sourceEnvironmentSlug: singleVisibleEnv?.slug ?? ""}),+ canCopySecrets: canReadSecrets || canReadFolders,isCopySecretsDisabled: hasPendingBatchChanges,copySecretsDisabledReason: hasPendingBatchChanges? "Commit or discard pending changes first"diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsxindex 192295c719..a8653c38ac 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx@@ -40,6 +40,7 @@ export type AddResourceButtonsProps = {onAddSecretImport: () => void;onImportSecrets: () => void;onCopySecrets: () => void;+ canCopySecrets: boolean;isCopySecretsDisabled: boolean;copySecretsDisabledReason?: string;onImportFromVault: () => void;@@ -68,6 +69,7 @@ export function AddResourceButtons({onAddSecretImport,onImportSecrets,onCopySecrets,+ canCopySecrets,isCopySecretsDisabled,copySecretsDisabledReason,onImportFromVault,@@ -218,15 +220,20 @@ export function AddResourceButtons({</TooltipTrigger><TooltipContent side="left">Access Restricted</TooltipContent></Tooltip>- <Tooltip open={isCopySecretsDisabled ? undefined : false}>+ <Tooltip open={isCopySecretsDisabled || !canCopySecrets ? undefined : false}><TooltipTrigger className="block w-full">- <DropdownMenuItem onClick={onCopySecrets} isDisabled={isCopySecretsDisabled}>+ <DropdownMenuItem+ onClick={onCopySecrets}+ isDisabled={isCopySecretsDisabled || !canCopySecrets}+ ><ClipboardPasteIcon className="text-accent" />Copy Secrets</DropdownMenuItem></TooltipTrigger><TooltipContent side="left">- {copySecretsDisabledReason ?? "Copy secrets is unavailable"}+ {!canCopySecrets+ ? "Access Restricted"+ : (copySecretsDisabledReason ?? "Copy secrets is unavailable")}</TooltipContent></Tooltip>{(hasVaultConnection || hasDopplerConnection) && (diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsxindex 72fb4bc3b7..7052e98244 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx@@ -51,6 +51,7 @@ import {} from "@app/hooks/api/secretFolders/queries";import { useDuplicateSecret } from "@app/hooks/api/secrets";+import { type CopySecretsErrorKind, getCopySecretsErrorKind } from "./copySecrets.data";import type {CopySecretsAttributes,CopySecretsEnvironment,@@ -89,6 +90,21 @@ type Props = {const DOCUMENTATION_URL ="https://infisical.com/docs/documentation/platform/folder#replicating-folder-contents";+const CopySecretsAccessError = ({ kind }: { kind: Exclude<CopySecretsErrorKind, "unknown"> }) => (+ <div className="flex h-full items-center">+ <Alert variant="danger">+ <AlertTitle>+ {kind === "unauthorized" ? "Organization access required" : "Access denied"}+ </AlertTitle>+ <AlertDescription>+ {kind === "unauthorized"+ ? "Your session doesn't include access to this organization. Sign in again or switch organizations."+ : "You don't have permission to view secrets at this location."}+ </AlertDescription>+ </Alert>+ </div>+);+const CopySecretsSession = ({projectId,isOpen,@@ -203,19 +219,22 @@ const CopySecretsSession = ({existingFolderPaths.add(path);}});+ const sourceErrorKind = getCopySecretsErrorKind(foldersQuery.error, sourceQuery.error);+ const destinationErrorKind = getCopySecretsErrorKind(foldersQuery.error, destinationQuery.error);const isSourceLoading =- !isSourcePathSettled ||- foldersQuery.isPending ||- foldersQuery.isFetching ||- sourceQuery.isPending ||- sourceQuery.isFetching;- const isSourceError = sourceQuery.isError || foldersQuery.isError;+ !sourceErrorKind &&+ (!isSourcePathSettled ||+ foldersQuery.isPending ||+ foldersQuery.isFetching ||+ sourceQuery.isPending ||+ sourceQuery.isFetching);const isDestinationLoading =- !isDestinationPathSettled ||- foldersQuery.isPending ||- foldersQuery.isFetching ||- destinationQuery.isPending ||- destinationQuery.isFetching;+ !destinationErrorKind &&+ (!isDestinationPathSettled ||+ foldersQuery.isPending ||+ foldersQuery.isFetching ||+ destinationQuery.isPending ||+ destinationQuery.isFetching);const unavailableValueCount = includeValues? selectedSecrets.filter(({ isValueHidden }) => isValueHidden).length: 0;@@ -239,7 +258,7 @@ const CopySecretsSession = ({).length;if (!sourceEnvironment) {bulkSelectionSummary = `${count} selected items. Choose a source environment to confirm availability.`;- } else if (isSourceLoading && !isSourceError) {+ } else if (isSourceLoading) {bulkSelectionSummary = "Checking selected items in this source…";} else if (availableSecretCount + availableFolderCount < count) {bulkSelectionSummary = `${availableSecretCount + availableFolderCount} of ${count} originally selected items are available in ${sourceEnvironment.name} at ${normalizedSourcePath}. Unavailable items won’t be copied.`;@@ -299,8 +318,12 @@ const CopySecretsSession = ({}))return "Choose a different destination path";- if (isSourceError) return "Source secrets couldn't be loaded";+ if (sourceErrorKind === "unauthorized") return "Organization access is required";+ if (sourceErrorKind === "forbidden") return "Source access is required";+ if (sourceErrorKind) return "Source secrets couldn't be loaded";if (isSourceLoading) return "Loading source secrets";+ if (destinationErrorKind === "unauthorized") return "Organization access is required";+ if (destinationErrorKind === "forbidden") return "Destination access is required";if (isDestinationLoading) return "Loading destination secrets";if (!selectedItemCount) return "Select at least one secret or folder";if (@@ -451,7 +474,7 @@ const CopySecretsSession = ({</EmptyHeader></Empty>);- } else if (isSourceLoading && !isSourceError) {+ } else if (isSourceLoading) {sourceContent = (<divclassName="flex h-full flex-col gap-3 rounded-md border border-border bg-container p-4"@@ -462,25 +485,29 @@ const CopySecretsSession = ({))}</div>);- } else if (isSourceError) {+ } else if (sourceErrorKind === "unauthorized" || sourceErrorKind === "forbidden") {+ sourceContent = <CopySecretsAccessError kind={sourceErrorKind} />;+ } else if (sourceErrorKind) {sourceContent = (- <Alert variant="danger" className="h-full content-center">- <AlertTitle>Couldn't load secrets</AlertTitle>- <AlertDescription>- Check your source location and access, then try again.- <Button- type="button"- size="xs"- variant="outline"- onClick={() => {- foldersQuery.refetch();- sourceQuery.refetch();- }}- >- Retry- </Button>- </AlertDescription>- </Alert>+ <div className="flex h-full items-center">+ <Alert variant="danger">+ <AlertTitle>Couldn't load secrets</AlertTitle>+ <AlertDescription>+ Check your source location and access, then try again.+ <Button+ type="button"+ size="xs"+ variant="outline"+ onClick={() => {+ foldersQuery.refetch();+ sourceQuery.refetch();+ }}+ >+ Retry+ </Button>+ </AlertDescription>+ </Alert>+ </div>);}@@ -518,15 +545,29 @@ const CopySecretsSession = ({))}</div>);- } else if (destinationQuery.isError) {+ } else if (destinationErrorKind === "unauthorized" || destinationErrorKind === "forbidden") {+ destinationContent = <CopySecretsAccessError kind={destinationErrorKind} />;+ } else if (destinationErrorKind) {destinationContent = (- <Alert variant="warning" className="h-full content-center">- <AlertTitle>Destination contents unavailable</AlertTitle>- <AlertDescription>- You can still copy here, but existing secrets can't be previewed with your current- access.- </AlertDescription>- </Alert>+ <div className="flex h-full items-center">+ <Alert variant="warning">+ <AlertTitle>Couldn't preview destination</AlertTitle>+ <AlertDescription>+ Existing secrets couldn't be loaded. You can still copy here, or try again.+ <Button+ type="button"+ size="xs"+ variant="outline"+ onClick={() => {+ foldersQuery.refetch();+ destinationQuery.refetch();+ }}+ >+ Retry+ </Button>+ </AlertDescription>+ </Alert>+ </div>);}diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/copySecrets.data.test.ts b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/copySecrets.data.test.tsindex 13be2ba012..012f106b52 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/copySecrets.data.test.ts+++ b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/copySecrets.data.test.ts@@ -3,7 +3,11 @@ import { describe, it } from "node:test";import type { TSecretMetadataPage } from "@app/hooks/api/dashboard/types";-import { fetchCopySecrets, getCopySecretsRetryDelay } from "./copySecrets.data";+import {+ fetchCopySecrets,+ getCopySecretsErrorKind,+ getCopySecretsRetryDelay+} from "./copySecrets.data";const secret = (id: string,@@ -196,3 +200,18 @@ describe("copy rate-limit timing", () => {assert.equal(getCopySecretsRetryDelay(requestError(403)), null);});});++describe("copy request errors", () => {+ it("distinguishes authentication and permission failures from load errors", () => {+ assert.equal(getCopySecretsErrorKind(requestError(401)), "unauthorized");+ assert.equal(getCopySecretsErrorKind(requestError(403)), "forbidden");+ assert.equal(getCopySecretsErrorKind(requestError(500)), "unknown");+ assert.equal(getCopySecretsErrorKind(new Error("Network error")), "unknown");+ assert.equal(getCopySecretsErrorKind(null, undefined), null);+ });++ it("prioritizes access failures across folder and metadata requests", () => {+ assert.equal(getCopySecretsErrorKind(requestError(500), requestError(403)), "forbidden");+ assert.equal(getCopySecretsErrorKind(requestError(403), requestError(401)), "unauthorized");+ });+});diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/copySecrets.data.ts b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/copySecrets.data.tsindex f7d96c945c..470fe3f17f 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/copySecrets.data.ts+++ b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/copySecrets.data.ts@@ -4,6 +4,17 @@ import type { TSecretMetadataPage } from "@app/hooks/api/dashboard/types";import type { CopySecretsSource } from "./copySecrets.types";+export type CopySecretsErrorKind = "unauthorized" | "forbidden" | "unknown";++export const getCopySecretsErrorKind = (...errors: unknown[]): CopySecretsErrorKind | null => {+ const statuses = errors.flatMap((error) =>+ isAxiosError(error) && error.response?.status ? [error.response.status] : []+ );+ if (statuses.includes(401)) return "unauthorized";+ if (statuses.includes(403)) return "forbidden";+ return errors.some(Boolean) ? "unknown" : null;+};+export const getCopySecretsRetryDelay = (error: unknown, now = Date.now()) => {if (!isAxiosError(error) || error.response?.status !== 429) return null;const retryAfter = error.response.headers["retry-after"];diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsxindex 83854b20d9..33c69e9be6 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx@@ -905,6 +905,11 @@ export const SecretEditTableRow = ({ProjectPermissionSecretActions.DescribeSecret,{ environment, secretPath, secretName, secretTags: ["*"] });+ const canDuplicateSecret = hasSecretReadValueOrDescribePermission(+ permission,+ ProjectPermissionSecretActions.DescribeSecret,+ { environment, secretPath, secretName, secretTags: tags?.map(({ slug }) => slug) ?? [] }+ );const isReadOnly =isPendingDelete ||@@ -1739,7 +1744,11 @@ export const SecretEditTableRow = ({</TooltipContent></Tooltip><Tooltip- open={isPendingBatchChange || isManagedSecret || isCreatable ? undefined : false}+ open={+ isPendingBatchChange || isManagedSecret || isCreatable || !canDuplicateSecret+ ? undefined+ : false+ }disableHoverableContent><TooltipTrigger className="block w-full">@@ -1750,6 +1759,7 @@ export const SecretEditTableRow = ({isPendingBatchChange ||isManagedSecret ||isCreatable ||+ !canDuplicateSecret ||!secretId ||!onCopySecret}@@ -1761,13 +1771,15 @@ export const SecretEditTableRow = ({<TooltipContent side="left">{isPendingBatchChange? "Discard Pending Changes First"- : isCreatable- ? "Create Secret First"- : isHoneyTokenSecret- ? "Cannot Copy Honey Token Secret"- : isRotatedSecret- ? "Cannot Copy Rotated Secret"- : "Copy Secret"}+ : !canDuplicateSecret+ ? "Access Denied"+ : isCreatable+ ? "Create Secret First"+ : isHoneyTokenSecret+ ? "Cannot Copy Honey Token Secret"+ : isRotatedSecret+ ? "Cannot Copy Rotated Secret"+ : "Copy Secret"}</TooltipContent></Tooltip>