feat: add share --link mode with server-side allowlist - #12
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
为
share.js新增--link模式:以符号链接(而非复制)把外部文件/目录挂入shared/,配套服务端白名单机制,仅放行显式登记过的链接穿透既有的 realpath 反目录穿越防护。动机
复制模式对大文件/大目录既占磁盘又耗时;软链接模式零拷贝、即时生效。但服务端
resolveSharedEntry()的 realpath 防护会拒绝一切逃出shared/的路径(安全设计,不能简单放开),因此引入data/shared-links.json显式授权清单:只有用户通过share.js --link登记过的目标才允许穿透,未登记符号链接行为完全不变。改动
lib/shared-links.js(新增):白名单读写工具 —— 原子写(临时文件 + rename)、服务端 mtime 缓存读取、条目校验(key 仅限顶层 basename,value 必须是绝对 realpath)、跨平台路径比较(win32 大小写不敏感)share.js:--link <路径...>创建符号链接并登记(不复制、不调度云上传);--list显示名字 -> 目标 (链接);--clear同步清空登记文件server.js:resolveSharedEntry仅当路径第一段是已登记链接名且 realpath 在登记目标内时放行越界;walkDir只展示已登记顶层链接;tar.create增加follow: true(containsSymlink拦截不变,未登记/嵌套符号链接仍会导致打包被拒,不会泄露内容)scripts/integration-test.js:已登记链接可列出/下载/打包;未登记链接不可见且下载被拒;符号链接创建不可用时用例 skip 而非 failREADME.md/AGENTS.md:用法与模块说明同步更新跨平台兼容
junction(无需管理员权限,要求绝对路径——登记的本来就是 realpath);Windows 文件链接遇EPERM/EACCES/ENOTSUP给出中文提示(需管理员权限或开发者模式),建议改用复制模式dir/file类型符号链接realpath规范化,win32 下统一小写测试
npm test(smoke + integration)通过,链接用例真实执行(非 skip)--link/--list/--clear行为符合预期