@getnote/mcp 1.7.1 → 1.7.2

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.
Files changed (3) hide show
  1. package/dist/index.js +10 -16
  2. package/package.json +1 -1
  3. package/src/index.ts +10 -19
package/dist/index.js CHANGED
@@ -63,10 +63,9 @@ const SERVER_VERSION = pkg.version;
63
63
  * - 拒绝 null byte:底层 syscall 会在 \0 处截断字符串,可绕过后续校验。
64
64
  * - 拒绝绝对路径(以 / 或 \ 开头,或平台判定为绝对路径)。
65
65
  * - 拒绝包含 ".." 的路径段:避免跳出工作目录 / 允许目录。
66
- * - 若设置了 GETNOTE_MCP_ALLOWED_ROOT:用 realpathSync + resolve 解开符号链接
67
- * 后,确保最终真实路径严格位于该目录内(防止软链逃逸)。
68
- * - 若未设置:默认只允许相对路径(上面已拒绝绝对路径与 ".."),相对当前
69
- * 工作目录读取。
66
+ * - 用 realpathSync + resolve 解开符号链接,确保最终真实路径严格位于允许
67
+ * 目录内(防止软链逃逸)。未设置 GETNOTE_MCP_ALLOWED_ROOT 时,默认使用
68
+ * 当前工作目录作为允许目录。
70
69
  *
71
70
  * @returns 经校验、可安全读取的最终路径。
72
71
  */
@@ -86,18 +85,13 @@ function resolveSafeImagePath(imagePath) {
86
85
  if (imagePath.split(/[/\\]/).includes("..")) {
87
86
  throw new Error('image_path must not contain ".." path segments');
88
87
  }
89
- const allowedRoot = process.env.GETNOTE_MCP_ALLOWED_ROOT;
90
- if (allowedRoot) {
91
- // realpathSync 解开符号链接,防止用软链把路径指向允许目录之外的文件
92
- const rootReal = (0, node_fs_1.realpathSync)((0, node_path_1.resolve)(allowedRoot));
93
- const target = (0, node_fs_1.realpathSync)((0, node_path_1.resolve)(rootReal, imagePath));
94
- if (target !== rootReal && !target.startsWith(rootReal + node_path_1.sep)) {
95
- throw new Error("image_path resolves outside of GETNOTE_MCP_ALLOWED_ROOT");
96
- }
97
- return target;
88
+ const allowedRoot = process.env.GETNOTE_MCP_ALLOWED_ROOT || process.cwd();
89
+ const rootReal = (0, node_fs_1.realpathSync)((0, node_path_1.resolve)(allowedRoot));
90
+ const target = (0, node_fs_1.realpathSync)((0, node_path_1.resolve)(rootReal, imagePath));
91
+ if (target !== rootReal && !target.startsWith(rootReal + node_path_1.sep)) {
92
+ throw new Error("image_path resolves outside of the allowed root");
98
93
  }
99
- // 未配置允许目录:仅允许相对路径(已校验),相对 cwd 解析
100
- return (0, node_path_1.resolve)(process.cwd(), imagePath);
94
+ return target;
101
95
  }
102
96
  // ─── Config ──────────────────────────────────────────────────────────────────
103
97
  function getApiKey() {
@@ -517,7 +511,7 @@ const TOOLS = [
517
511
  properties: {
518
512
  image_path: {
519
513
  type: "string",
520
- description: "本地图片文件路径。出于安全考虑仅接受相对路径:不允许绝对路径(以 / 或 \\ 开头)、不允许包含 \"..\" 的路径段、不允许 null byte。默认相对当前工作目录解析;若设置了环境变量 GETNOTE_MCP_ALLOWED_ROOT,则路径必须落在该目录内(含符号链接解析后)。",
514
+ description: "本地图片文件路径。出于安全考虑仅接受相对路径:不允许绝对路径(以 / 或 \\ 开头)、不允许包含 \"..\" 的路径段、不允许 null byte。默认限制在当前工作目录内;若设置了环境变量 GETNOTE_MCP_ALLOWED_ROOT,则限制在指定目录内。符号链接解析后也不得离开该目录。",
521
515
  },
522
516
  image_base64: {
523
517
  type: "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getnote/mcp",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "MCP server for 得到大脑(Get笔记) — manage notes and knowledge bases from AI assistants",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -39,10 +39,9 @@ const SERVER_VERSION: string = pkg.version;
39
39
  * - 拒绝 null byte:底层 syscall 会在 \0 处截断字符串,可绕过后续校验。
40
40
  * - 拒绝绝对路径(以 / 或 \ 开头,或平台判定为绝对路径)。
41
41
  * - 拒绝包含 ".." 的路径段:避免跳出工作目录 / 允许目录。
42
- * - 若设置了 GETNOTE_MCP_ALLOWED_ROOT:用 realpathSync + resolve 解开符号链接
43
- * 后,确保最终真实路径严格位于该目录内(防止软链逃逸)。
44
- * - 若未设置:默认只允许相对路径(上面已拒绝绝对路径与 ".."),相对当前
45
- * 工作目录读取。
42
+ * - 用 realpathSync + resolve 解开符号链接,确保最终真实路径严格位于允许
43
+ * 目录内(防止软链逃逸)。未设置 GETNOTE_MCP_ALLOWED_ROOT 时,默认使用
44
+ * 当前工作目录作为允许目录。
46
45
  *
47
46
  * @returns 经校验、可安全读取的最终路径。
48
47
  */
@@ -65,21 +64,13 @@ function resolveSafeImagePath(imagePath: string): string {
65
64
  throw new Error('image_path must not contain ".." path segments');
66
65
  }
67
66
 
68
- const allowedRoot = process.env.GETNOTE_MCP_ALLOWED_ROOT;
69
- if (allowedRoot) {
70
- // realpathSync 解开符号链接,防止用软链把路径指向允许目录之外的文件
71
- const rootReal = realpathSync(resolve(allowedRoot));
72
- const target = realpathSync(resolve(rootReal, imagePath));
73
- if (target !== rootReal && !target.startsWith(rootReal + sep)) {
74
- throw new Error(
75
- "image_path resolves outside of GETNOTE_MCP_ALLOWED_ROOT"
76
- );
77
- }
78
- return target;
67
+ const allowedRoot = process.env.GETNOTE_MCP_ALLOWED_ROOT || process.cwd();
68
+ const rootReal = realpathSync(resolve(allowedRoot));
69
+ const target = realpathSync(resolve(rootReal, imagePath));
70
+ if (target !== rootReal && !target.startsWith(rootReal + sep)) {
71
+ throw new Error("image_path resolves outside of the allowed root");
79
72
  }
80
-
81
- // 未配置允许目录:仅允许相对路径(已校验),相对 cwd 解析
82
- return resolve(process.cwd(), imagePath);
73
+ return target;
83
74
  }
84
75
 
85
76
  // ─── Config ──────────────────────────────────────────────────────────────────
@@ -522,7 +513,7 @@ const TOOLS: Tool[] = [
522
513
  image_path: {
523
514
  type: "string",
524
515
  description:
525
- "本地图片文件路径。出于安全考虑仅接受相对路径:不允许绝对路径(以 / 或 \\ 开头)、不允许包含 \"..\" 的路径段、不允许 null byte。默认相对当前工作目录解析;若设置了环境变量 GETNOTE_MCP_ALLOWED_ROOT,则路径必须落在该目录内(含符号链接解析后)。",
516
+ "本地图片文件路径。出于安全考虑仅接受相对路径:不允许绝对路径(以 / 或 \\ 开头)、不允许包含 \"..\" 的路径段、不允许 null byte。默认限制在当前工作目录内;若设置了环境变量 GETNOTE_MCP_ALLOWED_ROOT,则限制在指定目录内。符号链接解析后也不得离开该目录。",
526
517
  },
527
518
  image_base64: {
528
519
  type: "string",