MCPcopy Create free account
hub / github.com/DerekYRC/mini-claude-code / PathGuard

Class PathGuard

src/main/java/org/miniclaudecode/tool/PathGuard.java:12–28  ·  view source on GitHub ↗

文件工具的最小路径边界。 s02 还没有权限系统,但文件读写至少要被限制在 workdir 内, 避免模型通过相对路径访问项目目录之外的文件。

Source from the content-addressed store, hash-verified

10 * 避免模型通过相对路径访问项目目录之外的文件。
11 */
12public class PathGuard {
13
14 private final File workdir;
15
16 public PathGuard(File workdir) {
17 this.workdir = workdir;
18 }
19
20 public File resolve(String path) throws IOException {
21 File target = new File(workdir, path).getCanonicalFile();
22 File root = workdir.getCanonicalFile();
23 if (!target.toPath().startsWith(root.toPath())) {
24 throw new IOException("Path escapes workspace: " + path);
25 }
26 return target;
27 }
28}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected