Skip to content

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

fix(ui): honor secret input read-only and reference keyboard contracts (#8927)

Andrew Huangba75979c7b36
diff --git a/frontend/src/components/v3/platform/SecretInput/InfisicalSecretInput.tsx b/frontend/src/components/v3/platform/SecretInput/InfisicalSecretInput.tsx
index 507072817f..abc58ccc2b 100644
--- a/frontend/src/components/v3/platform/SecretInput/InfisicalSecretInput.tsx
+++ b/frontend/src/components/v3/platform/SecretInput/InfisicalSecretInput.tsx
@@ -81,7 +81,16 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
const isCrossProjectRefWithoutAccess =
referenceContent.startsWith("@") && !canCrossProjectShare;
- const isPopupOpen = openRefLeft !== -1 && isSuggestionActive && !isCrossProjectRefWithoutAccess;
+ const isPopupOpen =
+ openRefLeft !== -1 &&
+ isSuggestionActive &&
+ !isCrossProjectRefWithoutAccess &&
+ !props.readOnly &&
+ !props.isReadOnly &&
+ !props.disabled &&
+ !props.isDisabled &&
+ !props.isLoadingValue &&
+ !props.isErrorLoadingValue;
const replaceReferenceContent = (content: string, shouldCloseReference: boolean) => {
const left = openRefLeft + 1; // position right after ${
@@ -242,7 +251,7 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
ref={handleRef}
value={value}
onBlur={(evt) => {
- if (!(evt.relatedTarget?.getAttribute("aria-label") === "suggestion-item"))
+ if (!evt.relatedTarget?.hasAttribute("data-secret-reference-item"))
setIsSuggestionActive(false);
if (props.onBlur) props.onBlur(evt);
}}
@@ -276,6 +285,7 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
style={{ width: "var(--radix-popover-trigger-width)", minWidth: "320px" }}
>
<SecretReferenceWizard
+ inputRef={inputRef}
isEnabled={isPopupOpen}
onSelect={handleWizardSelect}
onNavigate={(content) => replaceReferenceContent(content, false)}
diff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx
index 2bd8ed939e..276e622cfb 100644
--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx
+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx
@@ -12,6 +12,10 @@ const meta = {
},
tags: ["autodocs"],
argTypes: {
+ valueAlwaysHidden: {
+ description:
+ "Visual-only mask for user-typed values. Focus still binds the real textarea value for editing and copying; isVisible overrides the mask. Not a permission boundary."
+ },
variant: {
control: "select",
options: ["default", "plain"]
diff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsx
index 6c380c3898..19359cfb46 100644
--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsx
+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsx
@@ -10,6 +10,16 @@ import { SecretInput } from "./SecretInput";
vi.mock("@app/hooks", async () => import("@app/hooks/useToggle"));
describe("SecretInput hidden values", () => {
+ it.each([
+ { readOnly: true },
+ { readOnly: false, isReadOnly: true },
+ { readOnly: false, isLoadingValue: true },
+ { readOnly: false, isErrorLoadingValue: true }
+ ])("honors read-only locks: %j", (props) => {
+ const markup = renderToStaticMarkup(<SecretInput value="example" {...props} />);
+ assert.ok(markup.includes('readOnly=""'));
+ });
+
it("renders the fixed mask and never the raw value while hidden", () => {
const markup = renderToStaticMarkup(<SecretInput value="hunter2" isVisible={false} readOnly />);
assert.ok(markup.includes(HIDDEN_SECRET_VALUE));
diff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx
index dd44d00f74..2f74aec49b 100644
--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx
+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx
@@ -182,6 +182,7 @@ export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(
onBlur,
isDisabled,
isReadOnly,
+ readOnly,
onFocus,
canEditButNotView,
isLoadingValue,
@@ -321,7 +322,7 @@ export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(
value={value && !shouldBindRealValue ? HIDDEN_SECRET_VALUE : (value ?? "")}
{...props}
aria-invalid={isError || props["aria-invalid"]}
- readOnly={isReadOnly || isLoadingValue || isErrorLoadingValue}
+ readOnly={readOnly || isReadOnly || isLoadingValue || isErrorLoadingValue}
/>
</div>
{invisibleChars.length > 0 && (
diff --git a/frontend/src/components/v3/platform/SecretInput/SecretReferenceWizard.tsx b/frontend/src/components/v3/platform/SecretInput/SecretReferenceWizard.tsx
index 2a7dc9fb1b..4ec957c532 100644
--- a/frontend/src/components/v3/platform/SecretInput/SecretReferenceWizard.tsx
+++ b/frontend/src/components/v3/platform/SecretInput/SecretReferenceWizard.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useRef, useState } from "react";
+import { RefObject, useEffect, useMemo, useRef, useState } from "react";
import {
ArrowLeftIcon,
ChevronRightIcon,
@@ -28,6 +28,7 @@ type WizardState = {
};
type Props = {
+ inputRef: RefObject<HTMLTextAreaElement | null>;
onSelect: (referenceContent: string) => void;
onNavigate: (referenceContent: string) => void;
isEnabled: boolean;
@@ -47,6 +48,7 @@ const INITIAL_STATE: WizardState = {
};
export const SecretReferenceWizard = ({
+ inputRef,
onSelect,
onNavigate,
isEnabled,
@@ -461,28 +463,31 @@ export const SecretReferenceWizard = ({
};
useEffect(() => {
- if (!isEnabled) return undefined;
+ const input = inputRef.current;
+ if (!isEnabled || !input) return undefined;
const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.defaultPrevented || e.isComposing) return;
const count = navigableCountRef.current;
- if (e.key === "Tab" && count === 0) return;
+ if (count === 0) return;
if (e.key === "ArrowDown" || (e.key === "Tab" && !e.shiftKey)) {
e.preventDefault();
- if (count === 0) return;
+ e.stopPropagation();
setHighlightedIndex((prev) => (prev + 1) % count);
} else if (e.key === "ArrowUp" || (e.key === "Tab" && e.shiftKey)) {
e.preventDefault();
- if (count === 0) return;
+ e.stopPropagation();
setHighlightedIndex((prev) => (prev - 1 + count) % count);
} else if (e.key === "Enter") {
e.preventDefault();
+ e.stopPropagation();
selectHighlightedRef.current();
}
};
- window.addEventListener("keydown", handleKeyDown, true);
- return () => window.removeEventListener("keydown", handleKeyDown, true);
- }, [isEnabled]);
+ input.addEventListener("keydown", handleKeyDown);
+ return () => input.removeEventListener("keydown", handleKeyDown);
+ }, [isEnabled, inputRef]);
const renderProjectStep = () => {
return (
@@ -500,7 +505,7 @@ export const SecretReferenceWizard = ({
<button
key={grant.sourceProjectId}
type="button"
- aria-label="suggestion-item"
+ data-secret-reference-item
data-nav-index={i}
onClick={() => {
onFocusItem();
@@ -532,7 +537,7 @@ export const SecretReferenceWizard = ({
{state.selectedProjectFolderGrant && (
<button
type="button"
- aria-label="suggestion-item"
+ data-secret-reference-item
onClick={() => {
onFocusItem();
onNavigate("@");
@@ -552,7 +557,7 @@ export const SecretReferenceWizard = ({
<button
key={env.slug}
type="button"
- aria-label="suggestion-item"
+ data-secret-reference-item
data-nav-index={i}
onClick={() => {
onFocusItem();
@@ -592,7 +597,7 @@ export const SecretReferenceWizard = ({
<button
key={`${secret.env}-${secret.id}`}
type="button"
- aria-label="suggestion-item"
+ data-secret-reference-item
data-nav-index={navIndex}
onClick={() => {
onFocusItem();
@@ -633,7 +638,7 @@ export const SecretReferenceWizard = ({
<div className="no-scrollbar flex min-w-0 items-center gap-0.5 overflow-x-auto border-b border-border px-2 py-1.5 text-xs text-muted">
<button
type="button"
- aria-label="suggestion-item"
+ data-secret-reference-item
onClick={() => {
onFocusItem();
handleBreadcrumbClick(-1);
@@ -647,7 +652,7 @@ export const SecretReferenceWizard = ({
<ChevronRightIcon className="size-3" />
<button
type="button"
- aria-label="suggestion-item"
+ data-secret-reference-item
onClick={() => {
onFocusItem();
handleBreadcrumbClick(i);
@@ -673,7 +678,7 @@ export const SecretReferenceWizard = ({
<button
key={folder.id}
type="button"
- aria-label="suggestion-item"
+ data-secret-reference-item
data-nav-index={i}
onClick={() => {
onFocusItem();
@@ -708,7 +713,7 @@ export const SecretReferenceWizard = ({
<button
key={secret.id}
type="button"
- aria-label="suggestion-item"
+ data-secret-reference-item
data-nav-index={navIndex}
onClick={() => {
onFocusItem();
diff --git a/frontend/src/pages/auth/CliRedirectPage/CliRedirectPage.tsx b/frontend/src/pages/auth/CliRedirectPage/CliRedirectPage.tsx
index 1ab970851d..3d7c1d000a 100644
--- a/frontend/src/pages/auth/CliRedirectPage/CliRedirectPage.tsx
+++ b/frontend/src/pages/auth/CliRedirectPage/CliRedirectPage.tsx
@@ -71,6 +71,8 @@ export const CliRedirectPage = () => {
</p>
<InputGroup>
<SecretInput
+ aria-label="CLI login token"
+ readOnly
variant="plain"
value={cliToken as string}
isVisible={isTokenVisible}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
index 32e0ae08fa..a70d7f30ec 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
@@ -1412,7 +1412,6 @@ export const SecretEditTableRow = ({
secretPath={secretPath}
environment={environment}
isImport={isImportedSecret}
- defaultValue={secretValueHidden ? "" : undefined}
canEditButNotView={secretValueHidden && !isManagedSecret}
onFocus={() => setIsFieldFocused.on()}
containerClassName={secretHasReference && isFieldActive ? "pl-6" : ""}