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

Golang Samber Hot Skill 安全审计

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

In-memory caching in Golang using samber/hot — eviction algorithms (LRU, LFU, TinyLFU, W-TinyLFU, S3FIFO, ARC, TwoQueue, SIEVE, FIFO), TTL, cache loaders, sharding, stale-while-revalidate, missing key caching, and Prometheus metrics. Apply when using or adopting samber/hot, when the codebase imports github.com/samber/hot, or when the project repeatedly loads the same medium-to-low cardinality reso

第三方安全检查结论

发现安全风险

已检查文件
5
发现的风险
3
会不会运行危险命令?检查是否下载程序后直接运行、让他人远程控制电脑,或藏起要运行的命令。未发现风险
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 1 项风险
中风险

示例的浅拷贝不能隔离结构体中的切片、映射或嵌套指针

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

文档称该模式适用于 pointers、slices、maps,并表示变更不会影响缓存,但示例只执行 copy := *u。这只复制顶层结构体;其中的切片、映射和嵌套指针仍共享底层数据。

为什么需要注意

调用者修改嵌套可变字段时,仍可能改变缓存中的共享对象,引发数据串扰或并发竞态;这正是该配置声称要避免的问题。

文档把该模式称为缓存可变指针、切片和映射时的必需措施,并声称调用方修改不会影响缓存,但示例中的 `copy := *u` 只是浅拷贝。若 User 含切片、映射或嵌套指针,底层数据仍被共享,并发修改仍可能造成竞态或污染缓存。仅含值字段时该示例可正常隔离。用户可要求作者明确浅拷贝限制、提供深拷贝示例,并对含引用字段的类型运行竞态测试。

references/production-patterns.md:151来自说明文档打开原文件
## Copy-on-Read / Copy-on-WriteRequired when cached values are mutable (pointers, slices, maps):```gocache := hot.NewHotCache[string, *User](hot.WTinyLFU, 10_000).    WithTTL(5 * time.Minute).    WithCopyOnRead(func(u *User) *User {        copy := *u        return &copy    }).    WithCopyOnWrite(func(u *User) *User {        copy := *u        return &copy    }).    WithJanitor().    Build()defer cache.StopJanitor()```
查看另外 1 个位置
references/production-patterns.md:171来自说明文档打开原文件
- **CopyOnRead** — clones at retrieval: callers get independent copies, mutations don't affect cache- **CopyOnWrite** — clones at storage: cache holds a snapshot, external mutations to the original don't corrupt cached value- Use both when callers read and write concurrently. Use only one when the mutation direction is known.
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。发现 1 项风险
中风险

安装命令使用 -u,可能升级项目现有依赖

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

推荐命令是 go get -u github.com/samber/hot,而不是固定版本。-u 会让 Go 解析较新的模块版本,并可能更新项目的 go.mod 和 go.sum,不只是在内存中试用该库。

为什么需要注意

项目可能获得未经当前任务单独审查的直接或间接依赖版本,造成构建变化、兼容性问题或供应链暴露;这些变更会持久保存在仓库工作区。

这是正文中的实际安装建议,不是测试或警告。执行 `go get -u` 会修改当前 Go 模块的依赖文件,并可能选择较新的相关模块版本;因此可能带来未经审查的兼容性或供应链变化。它不会仅因文档存在而自动执行。用户可要求作者提供固定版本且不带 `-u` 的命令,并在隔离分支中审查 go.mod、go.sum 的差异。

SKILL.md:40来自说明文档打开原文件
```bashgo get -u github.com/samber/hot```
查看另外 1 个位置
SKILL.md:34来自说明文档打开原文件
This skill is not exhaustive — refer to library documentation and code examples for more information:- For Go package docs, symbols, versions, importers, and known vulnerabilities, → See `samber/cc-skills-golang@golang-pkg-go-dev` skill (`godig`), preferred over Context7 for Go package facts.- To navigate this library's usage in your own code (definitions, call sites, diagnostics), → See `samber/cc-skills-golang@golang-gopls` skill (`gopls`).- Context7 remains a fallback for docs not indexed on pkg.go.dev.```bashgo get -u github.com/samber/hot```
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 1 项风险
中风险

声明的工具权限明显超出缓存配置所需范围

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

该 Skill 请求 Edit、Write、所有 go、git 和 golangci-lint 命令,以及代理和网络读取能力。尤其是 Bash(git:*) 没有限制为只读操作,而正文没有给出必须修改 Git 历史、分支或远端的缓存工作流程。

为什么需要注意

如果宿主按此字段授予权限,受该 Skill 驱动的代理可能修改项目文件、依赖和 Git 状态,或访问网络;错误指令或后续不可信内容会因权限范围过大而扩大影响。证据只表明权限被请求,不表明这些操作已经发生。

该声明会在宿主实际执行 allowed-tools 时授予读写文件、任意 go/git/golangci-lint 子命令、代理及网络读取能力;其中 git:* 包含可能改动分支、历史或远端的操作,而正文描述的是 Go 缓存选型与集成,未给出需要这些广泛 Git 权限的具体流程。风险是否发生取决于宿主如何强制该字段及代理随后生成的命令。用户可要求作者缩小到必要的只读检查和明确的构建命令,并在宿主中禁用写入、代理、网络及 Git 写操作。

SKILL.md:18来自说明文档打开原文件
    skill-library-version: "0.13.0"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 AskUserQuestion Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*paths:
查看另外 1 个位置
SKILL.md:3来自说明文档打开原文件
name: golang-samber-hotdescription: "In-memory caching in Golang using samber/hot — eviction algorithms (LRU, LFU, TinyLFU, W-TinyLFU, S3FIFO, ARC, TwoQueue, SIEVE, FIFO), TTL, cache loaders, sharding, stale-while-revalidate, missing key caching, and Prometheus metrics. Apply when using or adopting samber/hot, when the codebase imports github.com/samber/hot, or when the project repeatedly loads the same medium-to-low cardinality resources at high frequency and needs to reduce latency or backend pressure."user-invocable: true
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

6 个说明模块

该 Skill 的用途是指导代理在 Go 项目中引入和配置 samber/hot 内存缓存,包括 TTL、自动加载、淘汰算法和监控。

查看原文
SKILL.md:25来自说明文档打开原文件
# Using samber/hot for In-Memory Caching in GoGeneric, type-safe in-memory caching library for Go 1.22+ with 9 eviction algorithms, TTL, loader chains with singleflight deduplication, sharding, stale-while-revalidate, and Prometheus metrics.

缓存未命中时,配置的 loader 会查询数据库等后端;并发请求同一缺失键时会共享一次调用。这是明确的读取行为,但实际可访问的数据取决于用户项目传入的 loader。

查看原文
SKILL.md:85来自说明文档打开原文件
Loaders fetch missing keys automatically with singleflight deduplication — concurrent `Get()` calls for the same missing key share one loader invocation:```gocache := hot.NewHotCache[int, *User](hot.WTinyLFU, 10_000).    WithTTL(5 * time.Minute).    WithLoaders(func(ids []int) (map[int]*User, error) {        return db.GetUsersByIDs(ctx, ids) // batch query    }).

生产模式允许在 TTL 后暂时返回旧值并后台刷新;示例在刷新失败时保留旧值,但只到硬过期时间。

查看原文
references/production-patterns.md:31来自说明文档打开原文件
cache := hot.NewHotCache[string, *Config](hot.WTinyLFU, 1_000).    WithTTL(5 * time.Minute).                              // stale after 5min    WithRevalidation(1 * time.Minute, refreshLoader).       // hard-expire after 6min total    WithRevalidationErrorPolicy(hot.KeepOnError).           // keep stale value if refresh fails    WithJitter(0.1, 30*time.Second).                        // spread expirations    WithJanitor().    Build()defer cache.StopJanitor()```
从这里开始 · 工作说明SKILL.md
golang-samber-hot
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。

文件引用关系图

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

检查范围与遗漏

逐文件查看涉及的内容

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

  • SKILL.md已纳入全文
  • references/algorithm-guide.md已纳入全文
  • references/api-reference.md已纳入全文
  • references/production-patterns.md已纳入全文
  • evals/evals.json已纳入全文

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

  • SKILL.md工作说明
  • evals/evals.json配套文件
  • references/algorithm-guide.md配套文件
  • references/api-reference.md配套文件
  • references/production-patterns.md配套文件

代码和说明中提到的操作

连接外部网站
SKILL.md:12来自说明文档打开原文件
    emoji: "🔥"    homepage: https://github.com/samber/cc-skills-golang    requires:
SKILL.md:31来自说明文档打开原文件
- [pkg.go.dev/github.com/samber/hot](https://pkg.go.dev/github.com/samber/hot)- [github.com/samber/hot](https://github.com/samber/hot)
SKILL.md:32来自说明文档打开原文件
- [pkg.go.dev/github.com/samber/hot](https://pkg.go.dev/github.com/samber/hot)- [github.com/samber/hot](https://github.com/samber/hot)
运行命令
SKILL.md:18来自说明文档打开原文件
    skill-library-version: "0.13.0"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 AskUserQuestion Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*paths:
SKILL.md:40来自说明文档打开原文件
```bashgo get -u github.com/samber/hot
修改文件
references/production-patterns.md:63来自说明文档打开原文件
        h := fnv.New64a()        h.Write([]byte(key))        return h.Sum64()
读取了多少行
945
文件校验值(用于核对版本)
ade54f4eef7f01fb666ced2a39a2a5603154e56d6c7f75b7999a4e78aa0893e1