From vuln-skills
Audits Go code for path traversal (CWE-22/59) in file paths, archive extraction, symlinks, container mounts, and HTTP file serving.
npx claudepluginhub yhy0/ghsa-skill-builder --plugin vuln-skillsThis skill uses the workspace's default tool permissions.
当审计 Go 代码中涉及文件路径操作、归档解压、符号链接处理、容器卷挂载时加载此 Skill。
Detects path traversal and Zip Slip vulnerabilities in JS/TS/Python/Go where user-controlled paths escape directories. Audit file uploads, archive extractions, static servers.
Detects path traversal vulnerabilities in file operations using user-supplied paths. Enforces canonicalization, symlink resolution, and root containment checks before read/write/delete.
Detects path traversal vulnerabilities in PHP code including directory traversal, LFI/RFI, file uploads, symlink attacks, zip slip, and null byte injection.
Share bugs, ideas, or general feedback.
当审计 Go 代码中涉及文件路径操作、归档解压、符号链接处理、容器卷挂载时加载此 Skill。
Sources(攻击入口):
r.URL.Query().Get("file"))tar.Header.Name, zip.File.Name)multipart.FileHeader.Filename)Sinks(危险操作):
os.Open(path), os.Create(path), os.ReadFile(path)os.WriteFile(path, data, perm)filepath.Join(base, userInput) -- 当 userInput 为绝对路径时覆盖 baseos.Symlink(target, link), os.Readlink(path)http.ServeFile(w, r, path), http.FileServer(http.Dir(root))io.Copy 写入用户控制的路径Sanitization(路径安全屏障):
filepath.Clean(path) -- 规范化路径但不防止绝对路径filepath.Rel(base, target) -- 计算相对路径,返回 .. 开头则越界strings.HasPrefix(filepath.Clean(path), base) -- Clean 后前缀检查filepath.EvalSymlinks(path) -- 解析所有符号链接后再检查securejoin.SecureJoin(base, path) -- filepath-securejoin 库检测路径:
# filepath.Join 与用户输入
grep -rn "filepath.Join" --include="*.go"
# 文件操作
grep -rn "os.Open\|os.Create\|os.ReadFile\|os.WriteFile\|os.MkdirAll" --include="*.go"
# Archive 解压
grep -rn "tar.NewReader\|zip.OpenReader\|archive/tar\|archive/zip" --include="*.go"
# Symlink 操作
grep -rn "os.Symlink\|os.Readlink\|os.Lstat\|filepath.EvalSymlinks" --include="*.go"
# HTTP 文件服务
grep -rn "http.ServeFile\|http.FileServer\|http.Dir" --include="*.go"
# 路径安全检查
grep -rn "filepath.Clean\|filepath.Rel\|securejoin\|SecureJoin" --include="*.go"
os.Open, os.Create, http.ServeFile 等)filepath.Join(base, input) 是否考虑了 input 为绝对路径的情况?.. 或绝对路径?filepath.EvalSymlinks 再做路径检查(防止 symlink TOCTOU)?http.FileServer 的 root 目录是否限制了访问范围?filepath.Join 绝对路径覆盖审计 (CWE-22):filepath.Join("/safe/base", userInput) 当 userInput = "/etc/passwd" 时,结果为 /etc/passwd 而非 /safe/base/etc/passwd。必须在 Join 后检查结果是否仍在 base 目录下。tar.NewReader/zip.OpenReader 解压时,是否检查 header.Name 不包含 .. 且不是绝对路径?是否使用 filepath.Clean 后再验证前缀?os.Lstat 检查文件类型,然后 os.Open 读取?攻击者可在检查后、读取前将文件替换为 symlink。应使用 filepath.EvalSymlinks 或 O_NOFOLLOW。http.ServeFile/http.FileServer 审计 (CWE-22):路径参数是否来自用户输入?http.Dir 是否限制在预期目录?是否处理了 ../ 编码变体(%2e%2e%2f)?worktree.Checkout 是否验证文件路径?恶意 Git 仓库是否能通过精心构造的 tree object 写入任意位置?helm install 是否跟随了恶意 symlink?filepath.EvalSymlinks 使用时机审计 (CWE-59):路径安全检查是否在 EvalSymlinks 之后执行?先检查再 Eval 可能被 symlink 绕过。以下模式不是此类漏洞:
filepath.Join 用于拼接硬编码路径 -- 如 filepath.Join(configDir, "settings.yaml"),无用户输入http.FileServer 仅服务静态资源目录 -- 且路径参数不可被用户控制os.ReadFile 读取配置文件 -- 路径来自环境变量或命令行参数(非 HTTP 输入)t.TempDir() 中的文件操作以下模式需要深入检查:
filepath.Clean 后直接使用 -- Clean 不防止绝对路径,需要额外的前缀检查strings.Contains(path, "..") 作为唯一检查 -- 可被 ....// 等变体绕过io.Copy 目标路径来自 archive header -- Zip Slip 经典模式详见 references/cases.md(7 个真实案例,需要时加载)。