跳转到正文
报告库
用途分类 / 其他用途

Golang Spf13 Cobra Skill 安全审计

作者说它能做什么(原文)

Golang CLI command tree library using spf13/cobra — cobra.Command, RunE vs Run, PersistentPreRunE hook chain, Args validators (NoArgs, ExactArgs, MatchAll, custom), persistent vs local flags, command groups, ValidArgsFunction, RegisterFlagCompletionFunc, ShellCompDirective, usage/help template customization, man-page and markdown doc generation, and testing with SetArgs/SetOut/SetErr. Apply when u

第三方安全检查结论

发现安全风险

已检查文件
7
发现的风险
3
会不会运行危险命令?检查是否下载程序后直接运行、让他人远程控制电脑,或藏起要运行的命令。发现 1 项风险
中风险

安装指令使用可变的 `@latest`,脚手架随后会执行下载的工具并写入项目

原文依据:3 处
发现了什么

Skill 建议获取 Cobra 和 cobra-cli 的最新版本,并展示立即通过 `go tool` 运行脚手架。`latest` 不固定到已审核版本,其解析结果会随时间变化。

为什么需要注意

执行时会访问依赖源并改变 Go 模块或工具配置;运行脚手架还会创建或修改项目文件。如果上游最新版本存在恶意发布、供应链入侵或不兼容变更,用户会直接承受其影响。

这些是文档示例而非自动安装逻辑,但它们确实建议用 `@latest` 获取未固定版本,并随后用 `go tool cobra-cli` 生成或修改项目文件。若代理或用户照做,实际下载和执行的版本会随时间变化,且脚手架会写入当前项目。用户可要求固定经审核的版本,并在隔离目录中预览生成结果后再合并。普通 Cobra 依赖的 `go get` 同样未固定版本,但所示立即执行脚手架的跨文件风险主要来自 cobra-cli。

SKILL.md:47来自说明文档打开原文件
```bashgo get github.com/spf13/cobra@latest```
查看另外 2 个位置
references/generators.md:63来自说明文档打开原文件
```bashgo get -tool github.com/spf13/cobra-cli@latest# Initialize a new cobra projectgo tool cobra-cli init myapp# Add a subcommandgo tool cobra-cli add servego tool cobra-cli add migrate
references/generators.md:61来自说明文档打开原文件
`cobra-cli` generates command files and wires them into your project:```bashgo get -tool github.com/spf13/cobra-cli@latest# Initialize a new cobra projectgo tool cobra-cli init myapp# Add a subcommandgo tool cobra-cli add servego tool cobra-cli add migrate
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。未发现风险
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。发现 1 项风险
低风险

补全安装示例会直接覆盖解析路径中的 `_myapp` 文件

原文依据:1 处
发现了什么

示例使用 shell 重定向把生成结果写入 `${fpath[1]}/_myapp`,没有先检查目标、确认目录归用户所有或备份已有文件。

为什么需要注意

如果该路径已有同名补全文件,它会被截断并替换;路径解析错误也可能把内容写入非预期位置。

这是明确标注的 zsh 安装示例,不会由 Skill 自动执行;但如果照抄,`>` 会在 `${fpath[1]}` 成功解析且目录可写时创建或截断 `_myapp`。若该路径已有同名补全文件,其内容会被无提示覆盖,影响现有 shell 补全。用户可先解析并检查目标、备份已有文件,或要求示例使用拒绝覆盖的写法。

references/completions.md:26来自说明文档打开原文件
# Install (example for zsh):myapp completion zsh > "${fpath[1]}/_myapp"```
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 1 项风险
中风险

工具权限包含未被工作流程明确需要的任意 Git 命令

原文依据:2 处
发现了什么

声明允许 `Bash(git:*)`、网络获取、代理调用以及读写编辑。正文需要 Go 和源码编辑来完成 Cobra 工作,但没有可见步骤需要任意 Git 命令;该范围可覆盖提交、分支和远端相关操作。

为什么需要注意

如果代理受到错误上下文或项目内提示的影响,这些权限会扩大其修改版本历史、暂存用户文件或触及远端仓库的能力。该证据只表明能力范围,不表明这些操作已经发生。

该声明向 Skill 开放所有匹配的 Git 命令,同时还开放文件写入、网络获取和代理能力;正文描述的核心工作是构建、扩展或审查 Cobra 命令树,并未给出需要提交、推送、删除分支等广泛 Git 操作的具体流程。风险仅在宿主实际执行模型生成的 Git 命令时出现,不能据此断言已经操作仓库。用户可要求作者把 Git 权限缩小到只读子命令,或在运行时禁用 Git 写操作和远端操作。

SKILL.md:18来自说明文档打开原文件
    skill-library-version: "1.10.2"allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent WebFetch mcp__context7__resolve-library-id mcp__context7__query-docs Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*paths:
查看另外 1 个位置
SKILL.md:27来自说明文档打开原文件
- **Build** — creating a new CLI from scratch: follow command tree setup, hook wiring, and flag sections sequentially.- **Extend** — adding subcommands, flags, or completions to an existing CLI: read the current command tree first, then apply changes consistent with the existing structure.- **Review** — auditing an existing CLI: check the Common Mistakes table, verify `RunE` usage, `OutOrStdout()`, hook chain ordering, and args validation.
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

8 个说明模块

该 Skill 是面向 Go 项目的 Cobra 开发指南,会指导代理新建、扩展或审查命令树,并可能修改现有 Go 源码。

查看原文
SKILL.md:27来自说明文档打开原文件
- **Build** — creating a new CLI from scratch: follow command tree setup, hook wiring, and flag sections sequentially.- **Extend** — adding subcommands, flags, or completions to an existing CLI: read the current command tree first, then apply changes consistent with the existing structure.- **Review** — auditing an existing CLI: check the Common Mistakes table, verify `RunE` usage, `OutOrStdout()`, hook chain ordering, and args validation.

元数据没有声明自动安装步骤,但正文提供了下载依赖和脚手架工具的命令;因此是否产生网络访问或项目变更取决于代理是否执行这些示例。

查看原文
SKILL.md:13来自说明文档打开原文件
    homepage: https://github.com/samber/cc-skills-golang    requires:      bins:        - go    install: []    skill-library-version: "1.10.2"
SKILL.md:47来自说明文档打开原文件
```bashgo get github.com/spf13/cobra@latest```
references/generators.md:63来自说明文档打开原文件
```bashgo get -tool github.com/spf13/cobra-cli@latest# Initialize a new cobra projectgo tool cobra-cli init myapp# Add a subcommandgo tool cobra-cli add servego tool cobra-cli add migrate

所提供内容主要是文档、测试样例和代码片段;没有可见的捆绑可执行脚本,也没有可见的凭据读取或数据上传实现。缺少此类证据不代表未来生成或修改的项目代码必然安全。

查看原文
SKILL.md:31来自说明文档打开原文件
# Using spf13/cobra for CLI command trees in GoCobra is the de facto standard for Go CLI applications. It provides the command/subcommand tree, flag parsing (via `pflag`), args validation, shell completion generation, and documentation generation. It does **not** handle configuration layering — that's viper's job.
从这里开始 · 工作说明SKILL.md
golang-spf13-cobra
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。 另有 3 个章节,可在原文件中查看。

文件引用关系图

5 处引用
哪些文件发起引用引用了什么
连线表示真实的文件引用,不是运行顺序。点击节点可高亮相关连线,并查看具体文件和原文位置。虚线表示还有文件需要定位。
文件与检查记录7 个文件

检查范围与遗漏

逐文件查看涉及的内容

下方列出本次涉及的原文范围;纳入检查不代表已查清所有问题。

  • SKILL.md已纳入全文
  • references/commands-and-args.md已纳入全文
  • references/completions.md已纳入全文
  • references/flags.md已纳入全文
  • references/generators.md已纳入全文
  • references/testing.md已纳入全文
  • evals/evals.json已纳入全文

这份报告只针对上方版本。我们看了拿到的代码和说明文件,没有实际运行 Skill,也没有检查它另外安装的软件包。因此,这不是“保证安全”的承诺;换了版本或使用环境,结果也可能不同。

  • SKILL.md工作说明
  • evals/evals.json配套文件
  • references/commands-and-args.md配套文件
  • references/completions.md配套文件
  • references/flags.md配套文件
  • references/generators.md配套文件
  • references/testing.md配套文件

代码和说明中提到的操作

连接外部网站
SKILL.md:12来自说明文档打开原文件
    emoji: "🐍"    homepage: https://github.com/samber/cc-skills-golang    requires:
SKILL.md:37来自说明文档打开原文件
- [pkg.go.dev/github.com/spf13/cobra](https://pkg.go.dev/github.com/spf13/cobra)- [github.com/spf13/cobra](https://github.com/spf13/cobra)
SKILL.md:38来自说明文档打开原文件
- [pkg.go.dev/github.com/spf13/cobra](https://pkg.go.dev/github.com/spf13/cobra)- [github.com/spf13/cobra](https://github.com/spf13/cobra)- [cobra.dev](https://cobra.dev)
运行命令
SKILL.md:18来自说明文档打开原文件
    skill-library-version: "1.10.2"allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent WebFetch mcp__context7__resolve-library-id mcp__context7__query-docs Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*paths:
SKILL.md:47来自说明文档打开原文件
```bashgo get github.com/spf13/cobra@latest
references/completions.md:3来自说明文档打开原文件
Cobra generates shell completion scripts for bash, zsh, fish, and PowerShell automatically. Subcommand names and flag names are completed for free. You add completions for flag values and positional arguments.
读取文件
evals/evals.json:259来自说明文档打开原文件
        "id": "11.5",        "text": "Does NOT say cobra reads config files or viper defines subcommands"      }
references/testing.md:101来自说明文档打开原文件
    }    want, _ := os.ReadFile(golden)    assert.Equal(t, string(want), buf.String())
修改文件
references/testing.md:99来自说明文档打开原文件
    if *update {  // -update flag        os.WriteFile(golden, buf.Bytes(), 0644)    }
读取了多少行
1,352
文件校验值(用于核对版本)
fb04080a28edfc077898e3cc756b5247ed8c9c22b58519dace7f69f202817101