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
enhancementÇ add warnings so users know the unicode that is causing the problem
adilson36c4eaf152ae
diff --git a/frontend/src/components/v2/SecretInput/SecretInput.test.tsx b/frontend/src/components/v2/SecretInput/SecretInput.test.tsxdeleted file mode 100644index 524f1713a8..0000000000--- a/frontend/src/components/v2/SecretInput/SecretInput.test.tsx+++ /dev/null@@ -1,86 +0,0 @@-import assert from "node:assert/strict";-import { renderToStaticMarkup } from "react-dom/server";-import { describe, it, vi } from "vitest";--import { HIDDEN_SECRET_VALUE } from "@app/const/secrets";--import { SecretInput as SecretInputV3 } from "../../v3/platform/SecretInput/SecretInput";-import { SecretInput as SecretInputV2 } from "./SecretInput";--// The @app/hooks barrel pulls in the router and API client, which cannot load outside the app.-vi.mock("@app/hooks", async () => import("@app/hooks/useToggle"));--const MARKER_REGEX = /<span class="[^"]*bg-warning\/25[^"]*">([^<]*)<\/span>/g;--const markedChars = (markup: string) => [...markup.matchAll(MARKER_REGEX)].map(([, char]) => char);--describe.each([- { name: "v2", SecretInput: SecretInputV2 },- { name: "v3", SecretInput: SecretInputV3 }-])("$name SecretInput invisible characters", ({ SecretInput }) => {- const render = (value: string, isVisible = true) =>- renderToStaticMarkup(<SecretInput value={value} isVisible={isVisible} />);-- it("marks nothing in a value made of ordinary characters", () => {- assert.deepEqual(markedChars(render('{ "KEY": "value with spaces\ttab" }')), []);- });-- it("marks a non-breaking space", () => {- assert.deepEqual(markedChars(render('"URL": "https://example.com"')), [" "]);- });-- it("marks zero-width characters and a byte order mark", () => {- assert.deepEqual(markedChars(render("TIMEOUT=30")), [- "",- "",- "",- ""- ]);- });-- it("marks control characters but leaves tabs and newlines alone", () => {- assert.deepEqual(markedChars(render("a\u0000b\u001fc\u007fd\t\ne\r")), [- "\u0000",- "\u001f",- "\u007f"- ]);- });-- it("marks soft hyphens, bidi controls, and unicode space separators", () => {- assert.deepEqual(markedChars(render("xyzw v u ")), [- "",- "",- "",- " ",- " ",- " "- ]);- });-- it("marks each character in a run separately and keeps the surrounding text", () => {- const markup = render("before after");- assert.deepEqual(markedChars(markup), [" ", " "]);- assert.match(markup, /before<span/);- assert.match(markup, /<\/span>after/);- });-- it("marks a non-breaking space that stops a reference from resolving", () => {- const markup = render("${FOO BAR}");- assert.deepEqual(markedChars(markup), [" "]);- assert.doesNotMatch(markup, /text-warning\/80/);- });-- it("still highlights a valid reference and marks invisible characters around it", () => {- const markup = render("${env.FOO} ");- assert.deepEqual(markedChars(markup), ["", " "]);- assert.match(markup, /role="button"[^>]*>env<\/span>/);- assert.match(markup, /role="button"[^>]*>FOO<\/span>/);- });-- it("does not reveal or mark anything while the value is hidden", () => {- const markup = render("secret value", false);- assert.deepEqual(markedChars(markup), []);- assert.match(markup, new RegExp(HIDDEN_SECRET_VALUE.replace(/[*]/g, "\\*")));- assert.doesNotMatch(markup, /secret value/);- });-});diff --git a/frontend/src/components/v2/SecretInput/SecretInput.tsx b/frontend/src/components/v2/SecretInput/SecretInput.tsxindex 9190568747..9887916560 100644--- a/frontend/src/components/v2/SecretInput/SecretInput.tsx+++ b/frontend/src/components/v2/SecretInput/SecretInput.tsx@@ -1,5 +1,5 @@/* eslint-disable react/no-danger */-import { forwardRef, ReactNode, TextareaHTMLAttributes, useEffect, useState } from "react";+import { forwardRef, TextareaHTMLAttributes, useEffect, useState } from "react";import { twMerge } from "tailwind-merge";import { HIDDEN_SECRET_VALUE } from "@app/const/secrets";@@ -7,33 +7,6 @@ import { useToggle } from "@app/hooks";const REGEX = /(\${([@a-zA-Z0-9-_. ]+)})/g;-const INVISIBLE_CHAR_REGEX =- // eslint-disable-next-line no-control-regex- /([\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u00a0\u00ad\u1680\u2000-\u200f\u2028-\u202f\u205f\u2060\u2066-\u2069\u3000\ufeff])/g;--const markInvisibleChars = (text: string, chunkKey: number) => {- const nodes: ReactNode[] = [];- let offset = 0;-- text.split(INVISIBLE_CHAR_REGEX).forEach((part, index) => {- if (index % 2 === 1) {- nodes.push(- <span- key={`secret-value-invisible-${chunkKey}-${offset}`}- className="rounded-xs bg-warning/25 outline outline-1 outline-warning/70"- >- {part}- </span>- );- } else if (part) {- nodes.push(part);- }- offset += part.length;- });-- return nodes;-};-const syntaxHighlight = (content?: string | null,isVisible?: boolean,@@ -105,7 +78,7 @@ const syntaxHighlight = (}}}>- {markInvisibleChars(segment, i)}+ {segment}</span>{segmentIndex < parts.length - 1 && (<span className="ph-no-capture pointer-events-none text-warning/80">.</span>@@ -121,7 +94,7 @@ const syntaxHighlight = (skipNext = false;return [];}- return markInvisibleChars(el, i);+ return el;});// akhilmhdh: Dont remove this br. I am still clueless how this works but weirdly enoughdiff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsxindex 389034082a..ab0b52c24e 100644--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx@@ -76,6 +76,20 @@ export const InvisibleCharacters: Story = {}};+export const InvisibleCharactersMasked: Story = {+ args: {+ value: 'API_URL=\u00a0"https://example.com"\u200b'+ },+ parameters: {+ docs: {+ description: {+ story:+ "The warning icon stays visible while the value is masked, and its tooltip lists the invisible characters by type without revealing the value."+ }+ }+ }+};+export const Plain: Story = {args: {variant: "plain"diff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsxnew file mode 100644index 0000000000..5ed8b9284e--- /dev/null+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsx@@ -0,0 +1,129 @@+/* eslint-disable no-template-curly-in-string */+import { renderToStaticMarkup } from "react-dom/server";+import assert from "node:assert/strict";+import { describe, it, vi } from "vitest";++import { HIDDEN_SECRET_VALUE } from "@app/const/secrets";++import { getInvisibleCharacterSummary } from "./invisibleCharacters";+import { SecretInput } from "./SecretInput";++// The @app/hooks barrel pulls in the router and API client, which cannot load outside the app.+vi.mock("@app/hooks", async () => import("@app/hooks/useToggle"));++const MARKER_REGEX = /<span class="[^"]*bg-warning\/25[^"]*">([^<]*)<\/span>/g;+const WARNING_ICON = 'aria-label="Value contains invisible characters"';++const markedChars = (markup: string) => [...markup.matchAll(MARKER_REGEX)].map(([, char]) => char);++const render = (value: string, isVisible = true) =>+ renderToStaticMarkup(<SecretInput value={value} isVisible={isVisible} readOnly />);++describe("SecretInput invisible characters", () => {+ it("marks nothing in a value made of ordinary characters", () => {+ assert.deepEqual(markedChars(render('{ "KEY": "value with spaces\ttab" }')), []);+ });++ it("marks a non-breaking space", () => {+ assert.deepEqual(markedChars(render('"URL":\u00a0"https://example.com"')), ["\u00a0"]);+ });++ it("marks zero-width characters and a byte order mark", () => {+ assert.deepEqual(markedChars(render("\ufeffTIMEOUT=30\u200b\u200d\u2060")), [+ "\ufeff",+ "\u200b",+ "\u200d",+ "\u2060"+ ]);+ });++ it("marks control characters but leaves tabs and newlines alone", () => {+ assert.deepEqual(markedChars(render("a\u0001b\u001fc\u007fd\t\ne\r")), [+ "\u0001",+ "\u001f",+ "\u007f"+ ]);+ });++ it("marks soft hyphens, bidi controls, and unicode space separators", () => {+ assert.deepEqual(markedChars(render("x\u00ady\u202ez\u2066w\u2003v\u3000u\u1680")), [+ "\u00ad",+ "\u202e",+ "\u2066",+ "\u2003",+ "\u3000",+ "\u1680"+ ]);+ });++ it("marks each character in a run separately and keeps the surrounding text", () => {+ const markup = render("before\u00a0\u00a0after");+ assert.deepEqual(markedChars(markup), ["\u00a0", "\u00a0"]);+ assert.match(markup, /before<span/);+ assert.match(markup, /<\/span>after/);+ });++ it("marks a non-breaking space that stops a reference from resolving", () => {+ assert.deepEqual(markedChars(render("${FOO\u00a0BAR}")), ["\u00a0"]);+ assert.deepEqual(markedChars(render("url=${env.FOO\u00a0BAR}")), ["\u00a0"]);+ });++ it("still highlights a valid reference and marks invisible characters around it", () => {+ const markup = render("\u200b${env.FOO}\u00a0");+ assert.deepEqual(markedChars(markup), ["\u200b", "\u00a0"]);+ assert.match(markup, /role="button"[^>]*>env<\/span>/);+ assert.match(markup, /role="button"[^>]*>FOO<\/span>/);+ });++ it("does not reveal or mark anything while the value is hidden", () => {+ const markup = render("secret\u00a0value", false);+ assert.deepEqual(markedChars(markup), []);+ assert.ok(markup.includes(HIDDEN_SECRET_VALUE));+ assert.ok(!markup.includes("secret\u00a0value"));+ });+});++describe("SecretInput invisible characters warning icon", () => {+ it("shows the warning icon when the value contains invisible characters", () => {+ assert.ok(render("KEY=\u00a0value").includes(WARNING_ICON));+ });++ it("shows the warning icon while the value is masked", () => {+ assert.ok(render("KEY=\u200bvalue", false).includes(WARNING_ICON));+ });++ it("does not show the warning icon for an ordinary value", () => {+ assert.ok(!render("KEY=value with spaces\ttab\n").includes(WARNING_ICON));+ });++ it("does not show the warning icon while loading or after a load error", () => {+ const props = { value: "KEY=\u00a0value", isVisible: true, readOnly: true };+ assert.ok(+ !renderToStaticMarkup(<SecretInput {...props} isLoadingValue />).includes(WARNING_ICON)+ );+ assert.ok(+ !renderToStaticMarkup(<SecretInput {...props} isErrorLoadingValue />).includes(WARNING_ICON)+ );+ });+});++describe("getInvisibleCharacterSummary", () => {+ it("returns nothing for ordinary text", () => {+ assert.deepEqual(getInvisibleCharacterSummary("plain value\twith\ttabs\n"), []);+ });++ it("groups characters by code point in first-seen order", () => {+ assert.deepEqual(getInvisibleCharacterSummary("\u00a0a\u00a0\u200b\u0001"), [+ { codePoint: "U+00A0", label: "Non-breaking space", count: 2 },+ { codePoint: "U+200B", label: "Zero-width space", count: 1 },+ { codePoint: "U+0001", label: "Control character", count: 1 }+ ]);+ });++ it("labels characters that fall back to a range", () => {+ assert.deepEqual(+ getInvisibleCharacterSummary("\u2003\u202e\u0085").map(({ label }) => label),+ ["Unicode space", "Bidirectional control", "Control character"]+ );+ });+});diff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.tsxindex 3e85ac0d52..d0c74232fe 100644--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx@@ -1,17 +1,16 @@/* eslint-disable react/no-danger */-import { forwardRef, ReactNode, TextareaHTMLAttributes, useEffect, useState } from "react";+import { forwardRef, ReactNode, TextareaHTMLAttributes, useEffect, useMemo, useState } from "react";+import { TriangleAlertIcon } from "lucide-react";import { HIDDEN_SECRET_VALUE } from "@app/const/secrets";import { useToggle } from "@app/hooks";+import { Tooltip, TooltipContent, TooltipTrigger } from "../../generic/Tooltip";import { cn } from "../../utils";+import { getInvisibleCharacterSummary, INVISIBLE_CHAR_REGEX } from "./invisibleCharacters";const REGEX = /(\${([@a-zA-Z0-9-_. ]+)})/g;-const INVISIBLE_CHAR_REGEX =- // eslint-disable-next-line no-control-regex- /([\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u00a0\u00ad\u1680\u2000-\u200f\u2028-\u202f\u205f\u2060\u2066-\u2069\u3000\ufeff])/g;-const markInvisibleChars = (text: string, chunkKey: number) => {const nodes: ReactNode[] = [];let offset = 0;@@ -215,15 +214,21 @@ export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(const shouldShowMask =!isErrorLoadingValue && (isLoadingValue || (Boolean(value) && !shouldRevealValue));+ const invisibleChars = useMemo(+ () =>+ value && !isLoadingValue && !isErrorLoadingValue ? getInvisibleCharacterSummary(value) : [],+ [value, isLoadingValue, isErrorLoadingValue]+ );+return (<divdata-slot="secret-input"data-variant={variant}data-invalid={isError}className={cn(- "no-scrollbar w-full overflow-auto bg-transparent text-foreground",+ "no-scrollbar flex w-full overflow-auto bg-transparent text-foreground",variant === "default" &&- "flex min-h-9 items-center rounded-md border border-border shadow-xs transition-[color,box-shadow] focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50 data-[invalid=true]:border-danger data-[invalid=true]:ring-danger/40",+ "min-h-9 items-center rounded-md border border-border shadow-xs transition-[color,box-shadow] focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50 data-[invalid=true]:border-danger data-[invalid=true]:ring-danger/40",containerClassName)}style={{ maxHeight: `${21 * 7}px` }}@@ -293,6 +298,32 @@ export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(readOnly={isReadOnly || isLoadingValue || isErrorLoadingValue}/></div>+ {invisibleChars.length > 0 && (+ <Tooltip>+ <TooltipTrigger asChild>+ <button+ type="button"+ aria-label="Value contains invisible characters"+ className={cn(+ "sticky top-0 flex h-5 shrink-0 items-center self-start",+ variant === "default" && "mt-1 mr-2.5"+ )}+ >+ <TriangleAlertIcon className="size-4 text-warning" />+ </button>+ </TooltipTrigger>+ <TooltipContent className="max-w-72">+ <p>This value contains invisible characters that can break it when used:</p>+ <ul className="mt-1 list-disc pl-4">+ {invisibleChars.map(({ codePoint, label, count }) => (+ <li key={codePoint}>+ {count}x {label} ({codePoint})+ </li>+ ))}+ </ul>+ </TooltipContent>+ </Tooltip>+ )}</div>);}diff --git a/frontend/src/components/v3/platform/SecretInput/invisibleCharacters.ts b/frontend/src/components/v3/platform/SecretInput/invisibleCharacters.tsnew file mode 100644index 0000000000..869ad0e2ce--- /dev/null+++ b/frontend/src/components/v3/platform/SecretInput/invisibleCharacters.ts@@ -0,0 +1,54 @@+export const INVISIBLE_CHAR_REGEX =+ // eslint-disable-next-line no-control-regex+ /([\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u00a0\u00ad\u1680\u2000-\u200f\u2028-\u202f\u205f\u2060\u2066-\u2069\u3000\ufeff])/g;++export type InvisibleCharacterSummary = {+ codePoint: string;+ label: string;+ count: number;+};++const CHARACTER_LABELS: Record<number, string> = {+ 0x00a0: "Non-breaking space",+ 0x00ad: "Soft hyphen",+ 0x1680: "Ogham space mark",+ 0x200b: "Zero-width space",+ 0x200c: "Zero-width non-joiner",+ 0x200d: "Zero-width joiner",+ 0x200e: "Left-to-right mark",+ 0x200f: "Right-to-left mark",+ 0x2028: "Line separator",+ 0x2029: "Paragraph separator",+ 0x202f: "Narrow no-break space",+ 0x205f: "Medium mathematical space",+ 0x2060: "Word joiner",+ 0x3000: "Ideographic space",+ 0xfeff: "Byte order mark"+};++const getCharacterLabel = (code: number) => {+ if (CHARACTER_LABELS[code]) return CHARACTER_LABELS[code];+ if (code <= 0x001f || (code >= 0x007f && code <= 0x009f)) return "Control character";+ if (code >= 0x2000 && code <= 0x200a) return "Unicode space";+ return "Bidirectional control";+};++export const getInvisibleCharacterSummary = (value: string): InvisibleCharacterSummary[] => {+ const summary = new Map<number, InvisibleCharacterSummary>();++ Array.from(value.matchAll(INVISIBLE_CHAR_REGEX)).forEach(([char]) => {+ const code = char.charCodeAt(0);+ const entry = summary.get(code);+ if (entry) {+ entry.count += 1;+ return;+ }+ summary.set(code, {+ codePoint: `U+${code.toString(16).toUpperCase().padStart(4, "0")}`,+ label: getCharacterLabel(code),+ count: 1+ });+ });++ return Array.from(summary.values());+};