diff --git a/docs/plugin-platform/contract-and-sdk.md b/docs/plugin-platform/contract-and-sdk.md index 5170c7256..15e8c1c58 100644 --- a/docs/plugin-platform/contract-and-sdk.md +++ b/docs/plugin-platform/contract-and-sdk.md @@ -60,9 +60,13 @@ declares one or both execution entrypoints: } ``` -Paths use relative POSIX syntax. Absolute paths, drive-letter paths, -backslashes, `.` and `..` segments, Unicode normalization ambiguity, Windows -reserved names, and platform-specific trailing dots or spaces are rejected. +Paths use relative POSIX syntax and are limited to 128 Unicode code points and +512 UTF-8 bytes. The schema and package validator reject absolute paths, +drive-letter paths, repeated separators, backslashes, `.` and `..` segments, +Windows reserved names, control or platform-special characters, and +platform-specific trailing dots or spaces. The semantic package validator also +requires NFC-normalized text; every official host consumer must run it after +schema validation because JSON Schema cannot express Unicode normalization. Every entrypoint, view document, and companion executable must exist in the package. @@ -148,6 +152,9 @@ later: slow plugin cannot retain an unbounded host request. 9. Stream sequence numbers and receive windows are part of the public protocol; producers must stop when the receiver's advertised capacity is exhausted. +10. Manifest schema validation is followed by semantic package validation. + This enforces NFC paths and content-dependent rules that JSON Schema cannot + represent by itself. ## Repository commands diff --git a/electron/plugins/generated/plugin-contract.schema.json b/electron/plugins/generated/plugin-contract.schema.json index caf9de6bd..5ac97aeda 100644 --- a/electron/plugins/generated/plugin-contract.schema.json +++ b/electron/plugins/generated/plugin-contract.schema.json @@ -43,8 +43,8 @@ "RelativePackagePath": { "type": "string", "minLength": 1, - "maxLength": 512, - "pattern": "^(?!/)(?![A-Za-z]:)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\)(?!.*(?:^|/)\\.(?:/|$)).+$" + "maxLength": 128, + "pattern": "^(?!/)(?![A-Za-z]:)(?!.*//)(?!.*\\\\)(?!.*[\\u0000-\\u001F<>:\"|?*])(?!\\.{1,2}(?:/|$))(?!.*\\/\\.{1,2}(?:/|$))(?!(?:[Cc][Oo][Nn]|[Pp][Rr][Nn]|[Aa][Uu][Xx]|[Nn][Uu][Ll]|[Cc][Oo][Mm][1-9]|[Ll][Pp][Tt][1-9])(?:\\.[^/]*)?(?:/|$))(?!.*\\/(?:[Cc][Oo][Nn]|[Pp][Rr][Nn]|[Aa][Uu][Xx]|[Nn][Uu][Ll]|[Cc][Oo][Mm][1-9]|[Ll][Pp][Tt][1-9])(?:\\.[^/]*)?(?:/|$))(?!.*[. ](?:/|$))[^/]+(?:/[^/]+)*$" }, "Identifier": { "type": "string", diff --git a/packages/plugin-cli/src/cli.test.ts b/packages/plugin-cli/src/cli.test.ts index 0274dd081..506d5be7f 100644 --- a/packages/plugin-cli/src/cli.test.ts +++ b/packages/plugin-cli/src/cli.test.ts @@ -46,9 +46,23 @@ async function createPlugin(root: string): Promise { } test("path validation rejects traversal, platform aliases, and duplicates", () => { - for (const unsafe of ["../escape", "/absolute", "C:/drive", "a\\b", "a/../b", "CON", "a//b"]) { + for (const unsafe of [ + "../escape", + "/absolute", + "C:/drive", + "a\\b", + "a/../b", + "CON", + "assets/PRN.txt", + "file.", + "folder/file ", + "folder/file?.js", + "a//b", + "😀".repeat(129), + ]) { assert.throws(() => assertSafePackagePath(unsafe)); } + assert.equal(assertSafePackagePath("😀".repeat(128)), "😀".repeat(128)); const registry = new PackagePathRegistry(); registry.add("dist/Plugin.js"); assert.throws(() => registry.add("dist/plugin.js"), /case-colliding/); diff --git a/packages/plugin-cli/src/constants.ts b/packages/plugin-cli/src/constants.ts index 4c28457c9..3968a99e5 100644 --- a/packages/plugin-cli/src/constants.ts +++ b/packages/plugin-cli/src/constants.ts @@ -4,6 +4,7 @@ export const PACKAGE_LIMITS = Object.freeze({ singleFileBytes: 50 * 1024 * 1024, manifestBytes: 1024 * 1024, fileCount: 5_000, + pathCharacters: 128, pathBytes: 512, }); diff --git a/packages/plugin-cli/src/packagePath.ts b/packages/plugin-cli/src/packagePath.ts index 41eaf31d1..dc912d07f 100644 --- a/packages/plugin-cli/src/packagePath.ts +++ b/packages/plugin-cli/src/packagePath.ts @@ -11,6 +11,11 @@ export function assertSafePackagePath(input: string): string { if (!input || input !== input.normalize("NFC")) { throw new Error(`Package path must be non-empty NFC text: ${JSON.stringify(input)}`); } + if ([...input].length > PACKAGE_LIMITS.pathCharacters) { + throw new Error( + `Package path exceeds ${PACKAGE_LIMITS.pathCharacters} Unicode characters: ${input}`, + ); + } if (Buffer.byteLength(input, "utf8") > PACKAGE_LIMITS.pathBytes) { throw new Error(`Package path exceeds ${PACKAGE_LIMITS.pathBytes} UTF-8 bytes: ${input}`); } diff --git a/packages/plugin-contract/schema/plugin-contract.schema.json b/packages/plugin-contract/schema/plugin-contract.schema.json index bb5f6b936..2ed868039 100644 --- a/packages/plugin-contract/schema/plugin-contract.schema.json +++ b/packages/plugin-contract/schema/plugin-contract.schema.json @@ -26,8 +26,8 @@ "RelativePackagePath": { "type": "string", "minLength": 1, - "maxLength": 512, - "pattern": "^(?!/)(?![A-Za-z]:)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\)(?!.*(?:^|/)\\.(?:/|$)).+$" + "maxLength": 128, + "pattern": "^(?!/)(?![A-Za-z]:)(?!.*//)(?!.*\\\\)(?!.*[\\u0000-\\u001F<>:\"|?*])(?!\\.{1,2}(?:/|$))(?!.*\\/\\.{1,2}(?:/|$))(?!(?:[Cc][Oo][Nn]|[Pp][Rr][Nn]|[Aa][Uu][Xx]|[Nn][Uu][Ll]|[Cc][Oo][Mm][1-9]|[Ll][Pp][Tt][1-9])(?:\\.[^/]*)?(?:/|$))(?!.*\\/(?:[Cc][Oo][Nn]|[Pp][Rr][Nn]|[Aa][Uu][Xx]|[Nn][Uu][Ll]|[Cc][Oo][Mm][1-9]|[Ll][Pp][Tt][1-9])(?:\\.[^/]*)?(?:/|$))(?!.*[. ](?:/|$))[^/]+(?:/[^/]+)*$" }, "Identifier": { "type": "string", diff --git a/packages/plugin-contract/src/contract.test.ts b/packages/plugin-contract/src/contract.test.ts index 2841dcb56..af6c5d2cd 100644 --- a/packages/plugin-contract/src/contract.test.ts +++ b/packages/plugin-contract/src/contract.test.ts @@ -38,15 +38,28 @@ const validManifest = { test("plugin manifest schema accepts the internal contract", () => { const validate = validator("PluginManifest"); assert.equal(validate(validManifest), true, JSON.stringify(validate.errors)); + assert.equal( + validate({ ...validManifest, main: { browser: "😀".repeat(128) } }), + true, + JSON.stringify(validate.errors), + ); }); test("plugin manifest schema rejects unknown properties and traversal", () => { const validate = validator("PluginManifest"); assert.equal(validate({ ...validManifest, unexpected: true }), false); - assert.equal( - validate({ ...validManifest, main: { browser: "../outside.js" } }), - false, - ); + for (const browser of [ + "../outside.js", + "dist//chunk.js", + "CON", + "assets/PRN.txt", + "file.", + "folder/file ", + "folder/file?.js", + "😀".repeat(129), + ]) { + assert.equal(validate({ ...validManifest, main: { browser } }), false, browser); + } }); test("RPC, stream, permission, and provider schemas validate independently", () => {