From 8e47fb3414780c2f69a0ae424cdf47a932650d76 Mon Sep 17 00:00:00 2001 From: Apageoflove <126883848+Apageoflove@users.noreply.github.com> Date: Thu, 26 Nov 2026 21:40:37 -0500 Subject: [PATCH] =?UTF-8?q?fix(validate):=20plugin.json=20=E9=87=8C?= =?UTF-8?q?=E7=9A=84=E8=B7=AF=E5=BE=84=E4=B9=9F=E6=8C=89=E5=8F=AF=E7=A7=BB?= =?UTF-8?q?=E6=A4=8D=E6=80=A7=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/package-contract.md | 6 +++++ scripts/lib/rules/manifest.mjs | 21 +++++++++++++--- test/manifest.test.mjs | 46 +++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/docs/package-contract.md b/docs/package-contract.md index 9e2f1898..a2370d6b 100644 --- a/docs/package-contract.md +++ b/docs/package-contract.md @@ -287,6 +287,12 @@ Every path inside the package, and every path written in a manifest, must be por - No symbolic links or hard links anywhere in the package, and the package directory itself is not a symbolic link. +A path in `plugin.json` (`icon`, `darkIcon`, `apps`, `mcpServers`, `hooks`, `skills`, `hostBindings`, +`agents`) is checked with the same rules as a path in `miniapp.json`: `sub/../icon.png` and +`../shared/icon.png` are errors even when the file they resolve to exists. `npm run check` reports +them as `MANIFEST_FIELD_INVALID` for `icon` and `darkIcon`, and as `MANIFEST_REFERENCE_INVALID` for +the other six fields, and it checks the path before it looks for the file on disk. + ## Package limits At most 1024 files, 16 MiB per file, and 64 MiB in total. diff --git a/scripts/lib/rules/manifest.mjs b/scripts/lib/rules/manifest.mjs index d8a2aeac..a54b810f 100644 --- a/scripts/lib/rules/manifest.mjs +++ b/scripts/lib/rules/manifest.mjs @@ -19,6 +19,7 @@ import { VERSION_MAX_LENGTH, } from '../contract.mjs'; import { isRecord, pathExists, readJsonFile } from '../fs.mjs'; +import { normalizePluginPath } from '../paths.mjs'; const FILE = '.minimax-plugin/plugin.json'; @@ -109,7 +110,12 @@ function imagePath(report, value, label, required) { report.error('MANIFEST_FIELD_INVALID', `${label} must be a plugin-relative .png, .jpg, .jpeg, or .webp path`, FILE); return undefined; } - return trimmed; + const portable = normalizePluginPath(trimmed); + if (!portable.ok) { + report.error('MANIFEST_FIELD_INVALID', `${label} ${portable.reason}`, FILE); + return undefined; + } + return portable.value; } function stringArray(report, value, label) { @@ -136,7 +142,12 @@ async function references(report, packageDir, value, label, pattern, { required, report.error('MANIFEST_REFERENCE_INVALID', `${label} entry "${item}" must match ${pattern.source}`, FILE); continue; } - if (mustExist && !(await pathExists(path.join(packageDir, ...item.split('/')), 'file'))) { + const portable = normalizePluginPath(item); + if (!portable.ok) { + report.error('MANIFEST_REFERENCE_INVALID', `${label} entry "${item}" ${portable.reason}`, FILE); + continue; + } + if (mustExist && !(await pathExists(path.join(packageDir, ...portable.value.split('/')), 'file'))) { report.error('MANIFEST_REFERENCE_MISSING', `${label} entry "${item}" does not exist`, item); } } @@ -148,8 +159,10 @@ async function checkApps(report, packageDir, apps) { const providers = new Set(); // references() already reported bad patterns, missing files, and repeated paths. for (const item of new Set(apps)) { - const absolutePath = path.join(packageDir, ...item.split('/')); - if (!APP_PATH.test(item) || !(await pathExists(absolutePath, 'file'))) continue; + const portable = normalizePluginPath(item); + if (!portable.ok || !APP_PATH.test(portable.value)) continue; + const absolutePath = path.join(packageDir, ...portable.value.split('/')); + if (!(await pathExists(absolutePath, 'file'))) continue; const file = await readJsonFile(absolutePath); if (!file.ok) { report.error('MANIFEST_APP_INVALID', `${item} ${file.detail}`, item); diff --git a/test/manifest.test.mjs b/test/manifest.test.mjs index 1afa3709..1472ae0a 100644 --- a/test/manifest.test.mjs +++ b/test/manifest.test.mjs @@ -1,6 +1,6 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; -import { mkdir, writeFile } from 'node:fs/promises'; +import { mkdir, readFile, writeFile } from 'node:fs/promises'; import path from 'node:path'; import { checkManifest } from '../scripts/lib/rules/manifest.mjs'; import { createReport } from '../scripts/lib/report.mjs'; @@ -130,3 +130,47 @@ test('manifest: non-object is a single error', async () => { const { report } = await run(() => null); assert.deepEqual(codes(report.diagnostics), ['MANIFEST_NOT_OBJECT']); }); + +test('manifest: a path with a dot segment is an error, even when it resolves inside the package', async () => { + // `sub/../icon.png` names a file inside the package, but the segment is not portable and the Host + // rejects it as PATH_TRAVERSAL, so a package that passed here would fail at install time. + const inside = await run((m) => ({ ...m, icon: 'sub/../icon.png' }), async (dir) => { + await mkdir(path.join(dir, 'sub')); + }); + assert.deepEqual(codes(inside.report.diagnostics), ['MANIFEST_FIELD_INVALID']); +}); + +test('manifest: an image path must stay inside the package', async () => { + // `../shared/icon.png` resolves outside the package. The validator must not read that file, so the + // test places a real PNG one level up: a traversal that is accepted would otherwise pass silently. + const shared = async (dir) => { + const target = path.join(path.dirname(dir), 'shared'); + await mkdir(target, { recursive: true }); + await writeFile(path.join(target, 'icon.png'), await readFile(path.join(dir, 'icon.png'))); + }; + const escapedIcon = await run((m) => ({ ...m, icon: '../shared/icon.png' }), shared); + assert.deepEqual(codes(escapedIcon.report.diagnostics), ['MANIFEST_FIELD_INVALID']); + const escapedDarkIcon = await run((m) => ({ ...m, darkIcon: '../shared/icon.png' }), shared); + assert.deepEqual(codes(escapedDarkIcon.report.diagnostics), ['MANIFEST_FIELD_INVALID']); +}); + +test('manifest: a reference with a dot segment is an error', async () => { + const skills = await run((m) => ({ ...m, skills: ['skills/../SKILL.md'] })); + assert.deepEqual(codes(skills.report.diagnostics), ['MANIFEST_REFERENCE_INVALID']); + const servers = await run((m) => ({ ...m, mcpServers: ['../shared/probe.mcp.json'] })); + assert.deepEqual(codes(servers.report.diagnostics), ['MANIFEST_REFERENCE_INVALID']); + const hooks = await run((m) => ({ ...m, hooks: ['../shared/probe.json'] })); + assert.deepEqual(codes(hooks.report.diagnostics), ['MANIFEST_REFERENCE_INVALID']); +}); + +test('manifest: canonical image and reference paths keep passing', async () => { + const plain = await run((m) => m); + assert.deepEqual(plain.report.diagnostics, []); + const dotted = await run((m) => ({ ...m, icon: './icon.png' })); + assert.deepEqual(dotted.report.diagnostics, []); + const app = await run( + (m) => ({ ...m, apps: ['./notion.app.json'] }), + async (dir) => writeFile(path.join(dir, 'notion.app.json'), `${JSON.stringify({ schemaVersion: 1, provider: 'notion' })}\n`), + ); + assert.deepEqual(app.report.diagnostics, []); +});