awesome-skill-market 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import { ensureHub, registerSkill, updateLock, quarantinePath, cacheDir } from '
6
6
  import { parseRef } from '../lib/ref.js';
7
7
  import { fetchRef } from '../lib/registries/index.js';
8
8
  import { auditDir, stripFilter, stripSummary, writeScan } from '../lib/audit.js';
9
- import { readSkillDir, copyDir, rmDir, walk, treeHash } from '../lib/package.js';
9
+ import { readSkillDir, copyDir, rmDir, walk, treeHash, safeName } from '../lib/package.js';
10
10
  import { projectSkill, resolveTargets } from '../lib/project.js';
11
11
  import { primaryDir } from '../lib/scanner.js';
12
12
  import { cacheLookup, historySnapshot } from '../lib/state.js';
@@ -91,6 +91,7 @@ export async function run(ctx) {
91
91
  const pkg = readSkillDir(srcDir);
92
92
  if (!pkg) { fail(L(`不是合法 skill(缺 SKILL.md): ${srcDir}`, `not a valid skill (missing SKILL.md): ${srcDir}`)); return 1; }
93
93
  const name = pkg.name;
94
+ if (!safeName(name)) { fail(L(`非法 skill 名(含路径字符): ${name}`, `invalid skill name (path chars): ${name}`)); return 1; }
94
95
 
95
96
  // ② 审核闸门
96
97
  const audit = auditDir(srcDir, { strip: !flags.keepScripts });
@@ -6,7 +6,7 @@ import { extractRulesLLM } from '../lib/ai.js';
6
6
  import { detectConflicts, conflictsDir, loadConflicts } from '../lib/conflicts.js';
7
7
  import { autoArbitrate } from '../lib/autoarb.js';
8
8
  import { tokens, jaccard, writeYAML } from '../../pipeline/lib/util.js';
9
- import { treeHash } from '../lib/package.js';
9
+ import { treeHash, safeName } from '../lib/package.js';
10
10
  import { ok, warn, fail, info } from '../lib/render.js';
11
11
  import { L } from '../lib/i18n.js';
12
12
 
@@ -28,6 +28,7 @@ export async function run(ctx) {
28
28
  const names = ctx.args.filter((a) => !a.startsWith('--'));
29
29
  if (names.length < 2) { fail(L('用法: skillmkt merge <a> <b> [更多…] [--name 名字]', 'usage: skillmkt merge <a> <b> [more…] [--name n]')); return 1; }
30
30
  const outName = ctx.flags.raw.name || `merged-${names.length}skills`;
31
+ if (!safeName(outName)) { fail(L(`非法产物名(含路径字符): ${outName}`, `invalid artifact name (path chars): ${outName}`)); return 1; }
31
32
 
32
33
  const useLlm = ctx.flags.raw.llm && ctx.llm;
33
34
  const prog = (o) => console.log(`[prog]${JSON.stringify({ ...o, tokens: ctx.llm?.tokens || 0 })}`); // 流式进度行——serve 解析转发 SSE
@@ -1,6 +1,7 @@
1
1
  // serve — 本地 daemon:node:http + token + SSE + 静态 SPA;--daemon 内部模式 / --stop / --wait
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
+ import os from 'node:os';
4
5
  import http from 'node:http';
5
6
  import crypto from 'node:crypto';
6
7
  import { daemonFile, readDaemon, openURL } from '../lib/daemon.js';
@@ -167,7 +168,11 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
167
168
  return { versions: historyList(ctx.hub, n), current: fs.existsSync(dir) ? treeHash(dir) : null };
168
169
  },
169
170
  };
170
- const body = (req) => new Promise((r) => { let b = ''; req.on('data', (c) => b += c); req.on('end', () => r(b || '{}')); });
171
+ const body = (req) => new Promise((r, j) => {
172
+ let b = '';
173
+ req.on('data', (c) => { b += c; if (b.length > 1e6) { req.destroy(); j(new Error('body too large')); } }); // 1MB 上限——防内存 DoS
174
+ req.on('end', () => r(b || '{}'));
175
+ });
171
176
 
172
177
  // 只记关键事件:打开网页 + 真正落盘的写操作;点击/读取/静态资源一律不打扰
173
178
  const action = (req, u) => {
@@ -220,6 +225,7 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
220
225
  const c = loadConflicts(ctx.hub).find((x) => x.id === b.id);
221
226
  if (!c) { res.writeHead(404); return res.end('{"error":"not found"}'); }
222
227
  if (!b.reason?.trim()) { res.writeHead(400); return res.end('{"error":"reason required"}'); }
228
+ if (!['keep-a', 'keep-b', 'merge', 'dismissed'].includes(b.resolution)) { res.writeHead(400); return res.end('{"error":"bad resolution"}'); }
223
229
  req.logNote = L(`裁决了一个冲突(${{ 'keep-a': '采用方案 A', 'keep-b': '采用方案 B', merge: '合并两条', dismissed: '其实不冲突' }[b.resolution] || b.resolution})`,
224
230
  `decided a conflict (${{ 'keep-a': 'kept A', 'keep-b': 'kept B', merge: 'merged', dismissed: 'not a conflict' }[b.resolution] || b.resolution})`);
225
231
  decide(ctx.hub, c, { resolution: b.resolution, custom: b.custom || null, reason: b.reason, by: 'web-ui' });
@@ -300,7 +306,7 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
300
306
  if (b.auto) args.push('--auto'); // AI 仲裁检出的新冲突
301
307
  args.push('--', ...names);
302
308
  const r = await cliStream(args, { onProg: (o) => emit('mgprog', o) });
303
- emit('library', {});
309
+ if (r.code === 0) emit('library', {});
304
310
  return res.end(JSON.stringify(r));
305
311
  }
306
312
  if (u.pathname === '/api/build') {
@@ -338,9 +344,9 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
338
344
  if (r.code === 0) emit('library', {}); // 失败不推 SSE——保留详情框里的错误文案
339
345
  return res.end(JSON.stringify(r));
340
346
  }
341
- if (u.pathname === '/api/open') { // 系统文件管理器打开目录
342
- const p = path.resolve(String(b.path || ''));
343
- if (!fs.existsSync(p) || !fs.statSync(p).isDirectory()) return res.end(JSON.stringify({ ok: false, error: 'not a dir' }));
347
+ if (u.pathname === '/api/open') { // 系统文件管理器打开目录——限 home 下(挡 /System 之类的任意路径)
348
+ const p = path.resolve(String(b.path || '')), home = os.homedir();
349
+ if (!(p === home || p.startsWith(home + path.sep)) || !fs.existsSync(p) || !fs.statSync(p).isDirectory()) return res.end(JSON.stringify({ ok: false, error: 'not a dir under home' }));
344
350
  execFile(process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'explorer' : 'xdg-open', [p], () => {});
345
351
  return res.end('{"ok":true}');
346
352
  }
@@ -357,14 +363,15 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
357
363
  // 静态:public/ 公开;/evidence/ 需鉴权且锁死在 hub/evidence 内(防 ../ 穿越读 config.yml 等)
358
364
  const p = u.pathname === '/' ? '/index.html' : u.pathname;
359
365
  let file;
366
+ const inside = (base, f) => { const r = path.resolve(f), b = path.resolve(base); return r === b || r.startsWith(b + path.sep); }; // 带分隔符——挡 /hub/evidence-evil 同前缀兄弟目录
360
367
  if (p.startsWith('/evidence/')) {
361
368
  if (!authed) { res.writeHead(401); return res.end(); }
362
369
  const evDir = path.join(ctx.hub, 'evidence');
363
370
  file = path.join(evDir, p.slice('/evidence/'.length));
364
- if (!path.resolve(file).startsWith(path.resolve(evDir))) { res.writeHead(403); return res.end(); }
371
+ if (!inside(evDir, file)) { res.writeHead(403); return res.end(); }
365
372
  } else {
366
373
  file = path.join(PUB, p);
367
- if (!path.resolve(file).startsWith(PUB)) { res.writeHead(403); return res.end(); }
374
+ if (!inside(PUB, file)) { res.writeHead(403); return res.end(); }
368
375
  }
369
376
  if (!fs.existsSync(file) || fs.statSync(file).isDirectory()) { res.writeHead(404); return res.end('nf'); }
370
377
  res.setHeader('content-type', MIME[path.extname(file)] || 'application/octet-stream');
package/client/lib/hub.js CHANGED
@@ -3,6 +3,7 @@ import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import os from 'node:os';
5
5
  import YAML from 'yaml';
6
+ import { safeName } from './package.js';
6
7
 
7
8
  export function expandHome(p) {
8
9
  return p && p.startsWith('~') ? path.join(os.homedir(), p.slice(1)) : p;
@@ -66,6 +67,7 @@ export const readLock = (hub) => readYAMLFile(F(hub, 'lock.yml'), { version: 1,
66
67
  export const writeLock = (hub, d) => writeYAMLFile(F(hub, 'lock.yml'), d);
67
68
 
68
69
  export function registerSkill(hub, name, entry) {
70
+ if (!safeName(name)) throw new Error(`unsafe skill name: ${name}`); // 写入边界兜底——坏名永远进不了 library
69
71
  const lib = readLibrary(hub);
70
72
  lib.skills[name] = entry;
71
73
  writeLibrary(hub, lib);
@@ -6,6 +6,9 @@ import YAML from 'yaml';
6
6
 
7
7
  const FRONT_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
8
8
 
9
+ // skill 名安全字集:Unicode 字母/数字 + . _ -,首字符须字母数字——挡 / \ .. 路径逃逸(name 来自不可信 SKILL.md frontmatter)
10
+ export const safeName = (n) => typeof n === 'string' && /^[\p{L}\p{N}][\p{L}\p{N}._-]{0,79}$/u.test(n);
11
+
9
12
  export function parseFrontmatter(file) {
10
13
  try {
11
14
  const src = fs.readFileSync(file, 'utf8');
@@ -1,5 +1,5 @@
1
1
  <!doctype html>
2
- <html lang="zh"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
2
+ <html lang="zh"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="referrer" content="no-referrer">
3
3
  <title>skillmkt — 本地 skill 管理面板</title>
4
4
  <style>
5
5
  /* skillmkt panel — 依 skill/SKILL.md 规则:light-first、OKLCH 角色 token、单强调色、
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awesome-skill-market",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "type": "module",
5
5
  "description": "Local-first agent skill manager CLI (skillmkt): search, install, audit and merge SKILL.md agent skills for Claude Code, Codex, Cursor, OpenCode, Pi, Devin — skills.sh / GitHub / well-known sources, supply-chain audit, conflict arbitration, version pinning, local web UI.",
6
6
  "author": "terry2010",