Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/package-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 17 additions & 4 deletions scripts/lib/rules/manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
Expand All @@ -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);
Expand Down
46 changes: 45 additions & 1 deletion test/manifest.test.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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, []);
});