跳转到正文
报告库
用途分类 / 开发辅助

Golang Safety Skill 安全审计

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

Defensive Golang coding against accidental bugs — nil panics, typed-nil interfaces, `append` backing-array aliasing, silent int64-to-int32 truncation, float `==` comparison, `defer` inside loops, defensive copies of slices and maps, and usable zero values. Use when a Go program panics on a nil map write or nil pointer dereference, when reviewing code for nil-safety, numeric conversion overflow, or

第三方安全检查结论

发现安全风险

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

标为推荐的数据库惰性初始化示例丢弃错误并禁止重试

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

示例在 sync.Once 内调用 sql.Open 时用下划线丢弃错误,随后无条件返回 db.conn。由于 Once 只执行一次,首次初始化失败后不会再次尝试。

为什么需要注意

如果代理把该示例用于实际数据库代码,配置、驱动或连接初始化错误可能被隐藏;调用方可能收到 nil 或不可用连接,导致后续失败或服务不可用,同时失去自动恢复机会。

这是教学示例而非自动执行代码,但若用户采纳,风险成立:sync.Once 使初始化体只运行一次,而 sql.Open 的错误被 `_` 丢弃,调用方也无法判断初始化是否成功或触发重试;失败时可能得到 nil/不可用连接并在后续操作中出错。用户可要求作者提供返回 `(*sql.DB, error)`、保存并检查初始化错误且明确重试策略的示例。

SKILL.md:40来自说明文档打开原文件
10. **Design useful zero values** — nil map fields panic on first write; use lazy init11. **Use `sync.Once` for lazy init** — guarantees exactly-once even under concurrency
查看另外 1 个位置
SKILL.md:232来自说明文档打开原文件
func (db *DB) connection() *sql.DB {    db.once.Do(func() {        db.conn, _ = sql.Open("postgres", connStr)    })    return db.conn}```
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。未发现风险
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 1 项风险
中风险

权限声明超出只读 Go 安全审查所需范围

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

Skill 声明可编辑和写入文件、运行所有匹配 git:* 的命令,并调用 Agent。其说明包含代码编写场景,但没有把这些权限限制在目标 Go 文件、测试命令或用户批准的变更内。

为什么需要注意

如果宿主按该声明授予权限,调用此 Skill 的代理在一次普通安全审查中也可能具备修改仓库和改变 Git 状态的能力。仅凭这些权限不能证明它会这样做,但扩大了误操作或受其他提示影响时的影响范围。

该权限声明确实允许 Edit、Write、任意匹配 git:* 的命令及 Agent;其中 git:* 可能包括提交、重置或推送等会改变文件、仓库或远端账户状态的操作。Skill 的用途也包含编写代码,因此编辑权限并非完全无关,但正文未限定 Git/Agent 的具体用途或要求用户逐次批准。只有在宿主实际授予这些工具且模型选择调用时才会产生影响。用户可要求作者收窄为必要的 Go/测试命令,并由宿主禁用写操作、远端 Git 与 Agent。

SKILL.md:3来自说明文档打开原文件
name: golang-safetydescription: "Defensive Golang coding against accidental bugs — nil panics, typed-nil interfaces, `append` backing-array aliasing, silent int64-to-int32 truncation, float `==` comparison, `defer` inside loops, defensive copies of slices and maps, and usable zero values. Use when a Go program panics on a nil map write or nil pointer dereference, when reviewing code for nil-safety, numeric conversion overflow, or resource lifecycle, or when designing a type whose zero value must be safe. Not for designing concurrent access with goroutines, channels, or sync primitives (→ See `samber/cc-skills-golang@golang-concurrency` skill), not for exploitable vulnerabilities such as injection, weak crypto, or leaked secrets (→ See `samber/cc-skills-golang@golang-security` skill), and not for debugging an already-failing program (→ See `samber/cc-skills-golang@golang-troubleshooting` skill)."user-invocable: true
查看另外 1 个位置
SKILL.md:17来自说明文档打开原文件
    install: []allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agentpaths:
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

8 个说明模块

该 Skill 的主要用途是指导 Go 代码中的 nil、切片别名、数值转换、资源释放和零值设计;提供的是说明与代码示例,而不是安装脚本。

查看原文
SKILL.md:24来自说明文档打开原文件
# Go Safety: Correctness & Defensive CodingPrevents programmer mistakes — bugs, panics, and silent data corruption in normal (non-adversarial) code. Security handles attackers; safety handles ourselves.

声明的安装列表为空,仅列出 Go 为所需程序;所提供文件没有可见的依赖安装或网络下载步骤。

查看原文
SKILL.md:13来自说明文档打开原文件
    homepage: https://github.com/samber/cc-skills-golang    requires:      bins:        - go    install: []allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent

evals/evals.json 中的内容是测试提示、陷阱描述和断言,不是 Skill 的实时操作指令;它们主要检查生成的 Go 代码是否符合防御性规则。

查看原文
evals/evals.json:3来自说明文档打开原文件
  {    "id": 1,    "name": "typed-nil-error-interface-trap",    "description": "Returns untyped nil on success, not typed *ConfigError nil pointer through error interface",    "prompt": "In package `validator`, write a function `Validate(cfg Config) error` where Config has fields `Host string` and `Port int`. The function should check if Host is empty or Port is out of range (1-65535). Use a local `*ConfigError` variable to accumulate the first error found, then return it at the end. ConfigError is a struct with a `Field string` and an `Error() string` method.\n\nWrite the full code including the Config struct, ConfigError struct with its Error method, and the Validate function.",    "trap": "Model declares `var configErr *ConfigError` and returns it directly — `return configErr` wraps a typed nil pointer in the error interface, making the returned error non-nil even when configErr is nil",    "assertions": [      {        "id": "1.1",        "text": "Returns untyped nil on valid config — the success path must use `return nil` (not `return configErr` where configErr is *ConfigError), because a typed nil pointer wrapped in an error interface is non-nil"      },
从这里开始 · 工作说明SKILL.md
golang-safety
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。 另有 2 个章节,可在原文件中查看。

文件引用关系图

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

检查范围与遗漏

逐文件查看涉及的内容

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

  • SKILL.md已纳入全文
  • references/nil-safety.md已纳入全文
  • references/slice-map-safety.md已纳入全文
  • evals/evals.json已纳入全文

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

  • SKILL.md工作说明
  • evals/evals.json配套文件
  • references/nil-safety.md配套文件
  • references/slice-map-safety.md配套文件

代码和说明中提到的操作

连接外部网站
SKILL.md:12来自说明文档打开原文件
    emoji: "🛡"    homepage: https://github.com/samber/cc-skills-golang    requires:
evals/evals.json:535来自说明文档打开原文件
    "description": "Both OnRequest and OnResponse checked for nil before calling",    "prompt": "In package `http`, write a struct `Client` with fields `OnRequest func(url string)` and `OnResponse func(status int)`. Add a `Fetch(url string) (int, error)` method that calls OnRequest before fetching, does the fetch (simulate with status 200), and calls OnResponse after. Keep it simple.",    "trap": "Model guards OnRequest but forgets OnResponse, or neither — calling a nil func panics at runtime for any callback that was never set",
evals/evals.json:548来自说明文档打开原文件
        "id": "22.3",        "text": "Client is usable with zero-value callbacks — `Client{}.Fetch(url)` should not panic"      },
运行命令
SKILL.md:17来自说明文档打开原文件
    install: []allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agentpaths:
读取文件
SKILL.md:167来自说明文档打开原文件
for _, path := range paths {    f, _ := os.Open(path)    defer f.Close() // deferred until function exits
SKILL.md:177来自说明文档打开原文件
func processOne(path string) error {    f, err := os.Open(path)    if err != nil { return err }
SKILL.md:234来自说明文档打开原文件
    db.once.Do(func() {        db.conn, _ = sql.Open("postgres", connStr)    })
读取了多少行
1,638
文件校验值(用于核对版本)
e09227a62185071158b9f78c2b5737779601f60047b5df551efc50ccad1cada1