fix: reject hard-linked project files and verify retained Windows proposals
This commit is contained in:
@@ -46,6 +46,10 @@ export function safePath(project, relative = '', allowMissing = false) {
|
||||
// A project-local link or Windows alias must not turn a public path into
|
||||
// access to protected Git metadata or credentials, including new files.
|
||||
if (restricted(path.relative(root, real))) throw new Error('实际路径指向受保护的项目目录或凭据。');
|
||||
const actual = fs.statSync(real);
|
||||
// realpath cannot reveal the other names of a hard-linked file. Refuse
|
||||
// ambiguous file scope before reading bytes or preparing a replacement.
|
||||
if (actual.isFile() && actual.nlink !== 1) throw new Error('硬链接文件有多个路径,无法核对完整作用范围;请使用独立文件副本。');
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -65,8 +69,10 @@ export function listFiles(project, relative = '', depth = 4, limit = 700) {
|
||||
const relativePath = path.relative(project.root, absolute).replaceAll('\\', '/');
|
||||
if (entry.isSymbolicLink()) continue;
|
||||
const directory = entry.isDirectory();
|
||||
const info = directory ? null : fs.statSync(absolute);
|
||||
if (!directory && (!info.isFile() || info.nlink !== 1)) continue;
|
||||
files.push({ path: relativePath, name: entry.name, kind: directory ? 'directory' : 'file',
|
||||
bytes: directory ? 0 : fs.statSync(absolute).size });
|
||||
bytes: directory ? 0 : info.size });
|
||||
if (files.length >= limit) { truncated = true; break; }
|
||||
if (directory && current.depth < Math.min(12, Math.max(0, depth))) queue.push({ absolute, depth: current.depth + 1 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user