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
only show the unicode category
adilsona79dbe0b84a5
diff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsxindex c7584388d4..2bd8ed939e 100644--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.stories.tsx@@ -59,7 +59,7 @@ export const InvisibleCharacters: Story = {value: ["{",' "BASE_URL":\u00a0"https://example.com",',- ' "API_KEY": "a1b2c3d4e5",',+ ' "API_KEY": "a1b2\u2062c3d4e5",',' "TIMEOUT": 30\u200b',"\ufeff}",REFERENCE_WITH_NBSP@@ -70,7 +70,7 @@ export const InvisibleCharacters: Story = {docs: {description: {story:- "Codepoints that paint as a normal space, or as nothing at all, are marked so they can be spotted in a pasted value. Left to right: a non-breaking space (U+00A0), a zero-width space (U+200B), a byte order mark (U+FEFF), and a non-breaking space inside a secret reference, which stops the reference resolving."+ "Codepoints that paint as a normal space, or as nothing at all, are marked so they can be spotted in a pasted value. Detection uses Unicode categories (control, format, and space or separator characters) rather than a fixed list. Left to right: a non-breaking space (U+00A0), an invisible times (U+2062), a zero-width space (U+200B), a byte order mark (U+FEFF), and a non-breaking space inside a secret reference, which stops the reference resolving."}}}@@ -90,6 +90,27 @@ export const InvisibleCharactersMasked: Story = {}};+export const UnicodeText: Story = {+ args: {+ isVisible: true,+ value: [+ "GREETING=caf\u00e9 na\u00efve \u03a9\u03bc\u03ad\u03b3\u03b1",+ "CJK=\u65e5\u672c\u8a9e \ud55c\uad6d\uc5b4",+ "RTL=\u0645\u0631\u062d\u0628\u0627",+ "EMOJI=\u{1F600} \u{1F44D}\u{1F3FD} \u{1F468}\u200d\u{1F469}\u200d\u{1F467} \u{1F3F3}\ufe0f\u200d\u{1F308} \u{1F3F4}\u{E0067}\u{E0062}\u{E0065}\u{E006E}\u{E0067}\u{E007F}"+ ].join("\n"),+ variant: "plain"+ },+ parameters: {+ docs: {+ description: {+ story:+ "Ordinary non-ASCII text is not flagged: accented letters, CJK, right-to-left scripts, and emoji, including emoji joined with zero-width joiners or tag characters."+ }+ }+ }+};+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.tsxindex 454419e418..0c4cff5186 100644--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsx+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.test.tsx@@ -6,7 +6,7 @@ import { describe, it, vi } from "vitest";import { HIDDEN_SECRET_VALUE } from "@app/const/secrets";-import { getInvisibleCharacterSummary } from "./invisibleCharacters";+import { getInvisibleCharacterSummary, isSuspiciousCharacter } from "./invisibleCharacters";import { SecretInput } from "./SecretInput";// The @app/hooks barrel pulls in the router and API client, which cannot load outside the app.@@ -38,6 +38,12 @@ const tooltipItems = (markup: string) =>const render = (value: string, isVisible = true) =>renderToStaticMarkup(<SecretInput value={value} isVisible={isVisible} readOnly />);+const UNICODE_TEXT =+ "caf\u00e9 na\u00efve \u03a9\u03bc\u03ad\u03b3\u03b1 \u65e5\u672c\u8a9e \ud55c\uad6d\uc5b4 \u0645\u0631\u062d\u0628\u0627 \u{1F600} \u{1F44D}\u{1F3FD}";+const FAMILY_EMOJI = "\u{1F468}\u200d\u{1F469}\u200d\u{1F467}";+const RAINBOW_FLAG_EMOJI = "\u{1F3F3}\ufe0f\u200d\u{1F308}";+const ENGLAND_FLAG_EMOJI = "\u{1F3F4}\u{E0067}\u{E0062}\u{E0065}\u{E006E}\u{E0067}\u{E007F}";+describe("SecretInput invisible characters", () => {it("marks nothing in a value made of ordinary characters", () => {assert.deepEqual(markedChars(render('{ "KEY": "value with spaces\ttab" }')), []);@@ -82,6 +88,32 @@ describe("SecretInput invisible characters", () => {assert.match(markup, /<\/span>after/);});+ it("marks nothing in accented, CJK, RTL, or emoji text", () => {+ const markup = render(UNICODE_TEXT);+ assert.deepEqual(markedChars(markup), []);+ assert.ok(!markup.includes(WARNING_ICON));+ });++ it("marks nothing in emoji built from joiners or tag characters", () => {+ const markup = render(`${FAMILY_EMOJI} ${RAINBOW_FLAG_EMOJI} ${ENGLAND_FLAG_EMOJI}`);+ assert.deepEqual(markedChars(markup), []);+ assert.ok(!markup.includes(WARNING_ICON));+ });++ it("marks a joiner that is not part of an emoji sequence", () => {+ assert.deepEqual(markedChars(render("a\u200db")), ["\u200d"]);+ assert.deepEqual(markedChars(render("\u{1F600}\u200d")), ["\u200d"]);+ });++ it("marks invisible characters outside a hardcoded list", () => {+ assert.deepEqual(markedChars(render("a\u2062b\u180ec\u061cd\u{E0001}")), [+ "\u2062",+ "\u180e",+ "\u061c",+ "\u{E0001}"+ ]);+ });+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"]);@@ -135,13 +167,13 @@ describe("SecretInput invisible characters tooltip", () => {const markup = render("\u00a0a\u00a0\u200b\u0001");assert.ok(markup.includes(TOOLTIP_INTRO));assert.deepEqual(tooltipItems(markup), [- "2x Non-breaking space (U+00A0)",- "1x Zero-width space (U+200B)",+ "2x Unicode space (U+00A0)",+ "1x Formatting character (U+200B)","1x Control character (U+0001)"]);});- it("uses the range label when a character has no specific name", () => {+ it("labels each character by its Unicode category", () => {assert.deepEqual(tooltipItems(render("\u2003\u202e\u0085")), ["1x Unicode space (U+2003)","1x Bidirectional control (U+202E)",@@ -151,7 +183,7 @@ describe("SecretInput invisible characters tooltip", () => {it("lists the same characters while the value is masked", () => {const markup = render("secret\u00a0value", false);- assert.deepEqual(tooltipItems(markup), ["1x Non-breaking space (U+00A0)"]);+ assert.deepEqual(tooltipItems(markup), ["1x Unicode space (U+00A0)"]);assert.ok(!markup.includes("secret\u00a0value"));});@@ -170,6 +202,24 @@ describe("SecretInput invisible characters tooltip", () => {});});+describe("isSuspiciousCharacter", () => {+ it("allows the whitespace SecretInput supports", () => {+ [" ", "\t", "\n", "\r"].forEach((char) => assert.equal(isSuspiciousCharacter(char), false));+ });++ it("allows ordinary non-ASCII characters", () => {+ ["\u00e9", "\u00df", "\u65e5", "\u0645", "\u{1F600}"].forEach((char) =>+ assert.equal(isSuspiciousCharacter(char), false)+ );+ });++ it("flags control, format, and separator characters", () => {+ ["\u0001", "\u0085", "\u200b", "\u00a0", "\u3000", "\u2028", "\u2029", "\u{1D173}"].forEach(+ (char) => assert.equal(isSuspiciousCharacter(char), true)+ );+ });+});+describe("getInvisibleCharacterSummary", () => {it("returns nothing for ordinary text", () => {assert.deepEqual(getInvisibleCharacterSummary("plain value\twith\ttabs\n"), []);@@ -177,16 +227,44 @@ describe("getInvisibleCharacterSummary", () => {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+00A0", label: "Unicode space", count: 2 },+ { codePoint: "U+200B", label: "Formatting character", count: 1 },{ codePoint: "U+0001", label: "Control character", count: 1 }]);});- it("labels characters that fall back to a range", () => {+ it("labels characters by their Unicode category", () => {+ assert.deepEqual(+ getInvisibleCharacterSummary(+ "\u2003\u00a0\u202e\u200e\u0085\u061c\u2062\ufeff\u2028\u2029"+ ).map(({ label }) => label),+ [+ "Unicode space",+ "Unicode space",+ "Bidirectional control",+ "Bidirectional control",+ "Control character",+ "Bidirectional control",+ "Formatting character",+ "Formatting character",+ "Line separator",+ "Paragraph separator"+ ]+ );+ });++ it("reports astral characters by their full code point", () => {+ assert.deepEqual(getInvisibleCharacterSummary("a\u{1D173}b\u{1D173}"), [+ { codePoint: "U+1D173", label: "Formatting character", count: 2 }+ ]);+ });++ it("returns nothing for accented, CJK, RTL, or emoji text", () => {assert.deepEqual(- getInvisibleCharacterSummary("\u2003\u202e\u0085").map(({ label }) => label),- ["Unicode space", "Bidirectional control", "Control character"]+ getInvisibleCharacterSummary(+ `${UNICODE_TEXT} ${FAMILY_EMOJI} ${RAINBOW_FLAG_EMOJI} ${ENGLAND_FLAG_EMOJI}`+ ),+ []);});});diff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.tsxindex 65ecd1b0bb..3b07c70367 100644--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx@@ -8,7 +8,7 @@ import { useToggle } from "@app/hooks";import { IconButton } from "../../generic/IconButton";import { Tooltip, TooltipContent, TooltipTrigger } from "../../generic/Tooltip";import { cn } from "../../utils";-import { getInvisibleCharacterSummary, INVISIBLE_CHAR_REGEX } from "./invisibleCharacters";+import { getInvisibleCharacterSummary, splitSuspiciousCharacters } from "./invisibleCharacters";const REGEX = /(\${([@a-zA-Z0-9-_. ]+)})/g;@@ -16,8 +16,8 @@ const markInvisibleChars = (text: string, chunkKey: number) => {const nodes: ReactNode[] = [];let offset = 0;- text.split(INVISIBLE_CHAR_REGEX).forEach((part, index) => {- if (index % 2 === 1) {+ splitSuspiciousCharacters(text).forEach(({ text: part, isSuspicious }) => {+ if (isSuspicious) {nodes.push(<spankey={`secret-value-invisible-${chunkKey}-${offset}`}@@ -26,7 +26,7 @@ const markInvisibleChars = (text: string, chunkKey: number) => {{part}</span>);- } else if (part) {+ } else {nodes.push(part);}offset += part.length;diff --git a/frontend/src/components/v3/platform/SecretInput/invisibleCharacters.ts b/frontend/src/components/v3/platform/SecretInput/invisibleCharacters.tsindex 869ad0e2ce..b659292388 100644--- a/frontend/src/components/v3/platform/SecretInput/invisibleCharacters.ts+++ b/frontend/src/components/v3/platform/SecretInput/invisibleCharacters.ts@@ -1,43 +1,73 @@-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"+export type SecretValuePart = {+ text: string;+ isSuspicious: boolean;+};++const ALLOWED_WHITESPACE = new Set([" ", "\t", "\n", "\r"]);++const SUSPICIOUS_CATEGORY_REGEX = /^[\p{Cc}\p{Cf}\p{Zs}\p{Zl}\p{Zp}]$/u;++const EMOJI_SEQUENCE_REGEX =+ /\p{Extended_Pictographic}(?:\p{Emoji_Modifier}|\uFE0F)*(?:\u200D\p{Extended_Pictographic}(?:\p{Emoji_Modifier}|\uFE0F)*)+|\u{1F3F4}[\u{E0020}-\u{E007E}]+\u{E007F}/gu;++export const isSuspiciousCharacter = (char: string) =>+ !ALLOWED_WHITESPACE.has(char) && SUSPICIOUS_CATEGORY_REGEX.test(char);++const getCharacterLabel = (char: string) => {+ if (/\p{Bidi_Control}/u.test(char)) return "Bidirectional control";+ if (/\p{Cc}/u.test(char)) return "Control character";+ if (/\p{Zs}/u.test(char)) return "Unicode space";+ if (/\p{Zl}/u.test(char)) return "Line separator";+ if (/\p{Zp}/u.test(char)) return "Paragraph separator";+ return "Formatting character";};-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 splitSuspiciousCharacters = (value: string): SecretValuePart[] => {+ const parts: SecretValuePart[] = [];++ const pushPlain = (text: string) => {+ const last = parts[parts.length - 1];+ if (last && !last.isSuspicious) {+ last.text += text;+ } else {+ parts.push({ text, isSuspicious: false });+ }+ };++ const scan = (text: string) => {+ Array.from(text).forEach((char) => {+ if (isSuspiciousCharacter(char)) {+ parts.push({ text: char, isSuspicious: true });+ } else {+ pushPlain(char);+ }+ });+ };++ let offset = 0;+ Array.from(value.matchAll(EMOJI_SEQUENCE_REGEX)).forEach((match) => {+ const index = match.index ?? 0;+ scan(value.slice(offset, index));+ pushPlain(match[0]);+ offset = index + match[0].length;+ });+ scan(value.slice(offset));++ return parts;};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);+ splitSuspiciousCharacters(value).forEach(({ text, isSuspicious }) => {+ if (!isSuspicious) return;+ const code = text.codePointAt(0) ?? 0;const entry = summary.get(code);if (entry) {entry.count += 1;@@ -45,7 +75,7 @@ export const getInvisibleCharacterSummary = (value: string): InvisibleCharacterS}summary.set(code, {codePoint: `U+${code.toString(16).toUpperCase().padStart(4, "0")}`,- label: getCharacterLabel(code),+ label: getCharacterLabel(text),count: 1});});