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

Golang Samber Do Skill 安全审计

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

Dependency injection in Golang using samber/do — service containers, lifecycle management, scopes, health checks, graceful shutdown, and module organization. Apply when using or adopting samber/do, when the codebase imports github.com/samber/do or github.com/samber/do/v2, or when refactoring manual constructor injection into a DI container.

第三方安全检查结论

先别安装或运行

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

完整启动示例可能因依赖失败而 panic,也会丢弃服务器启动错误

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

指南说明 `MustInvoke` 遇错会 panic,但完整 `main` 示例在组合根使用它;这里没有外层 `Invoke` 将 panic 转回错误。示例还在 goroutine 中调用 `ListenAndServe` 并忽略返回值。

为什么需要注意

提供者初始化失败会直接终止进程;端口占用或监听失败则可能留下仍在等待信号、却没有提供 HTTP 服务的进程,影响可用性和故障检测。

指南明确说 `MustInvoke` 出错会 panic,只有在提供者内部、由外层 `Invoke` 捕获时才安全;但完整 `main` 示例直接在组合根调用 `MustInvoke`,因此初始化失败可终止进程。示例还在 goroutine 中丢弃 `ListenAndServe` 的错误,端口占用或监听失败时程序仍可能等待关闭信号而没有提供服务。用户可要求显式处理解析和服务器启动错误。

SKILL.md:103来自说明文档打开原文件
// (e.g. an HTTP handler that must degrade gracefully instead of crashing)db, err := do.Invoke[Database](injector)// MustInvoke panics on error — preferred in providers, recovered by do.Invoke on the parent calldb := do.MustInvoke[Database](injector)```
查看另外 4 个位置
SKILL.md:185来自说明文档打开原文件
    server := do.MustInvoke[*http.Server](injector)    go server.ListenAndServe()    _ = injector.ShutdownOnSignalsWithContext(context.Background(), os.Interrupt)}
SKILL.md:223来自说明文档打开原文件
| -------------------------- | ----------------------------------------- || `do.Invoke[T]()`           | Get service (with error)                  || `do.InvokeNamed[T]()`      | Get named service                         || `do.InvokeAs[T]()`         | Get first service matching interface      || `do.InvokeStruct[T]()`     | Inject into struct fields using tags      || `do.MustInvoke[T]()`       | Get service (panic on error)              || `do.MustInvokeNamed[T]()`  | Get named service (panic on error)        |
SKILL.md:101来自说明文档打开原文件
```go// Invoke with error handling — reserve for call sites outside the DI graph// (e.g. an HTTP handler that must degrade gracefully instead of crashing)db, err := do.Invoke[Database](injector)// MustInvoke panics on error — preferred in providers, recovered by do.Invoke on the parent calldb := do.MustInvoke[Database](injector)```Inside a provider function, always use `do.MustInvoke` (or `MustInvokeAs`/`MustInvokeNamed`/`MustInvokeStruct`) rather than the error-returning variant:- A provider already returns `(T, error)`, so propagating a dependency failure with `do.Invoke` costs an extra `if err != nil { return nil, err }` on every call.- `do.MustInvoke` panics instead, but samber/do correctly catches and recovers that panic at the enclosing `Invoke` call and converts it back into a regular error — this recover happens inside the library itself, not in caller code, so `MustInvoke` is safe to use inside providers.- The failure still surfaces as an error at the composition root, just without the manual boilerplate in every provider.
SKILL.md:174来自说明文档打开原文件
## Full Application Setup```gofunc main() {    injector := do.New(        infrastructure.Package,        repository.Package,        service.Package,        transport.Package,    )    server := do.MustInvoke[*http.Server](injector)    go server.ListenAndServe()    _ = injector.ShutdownOnSignalsWithContext(context.Background(), os.Interrupt)}```
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 1 项风险
高风险

“请求级”示例只创建一个作用域,复用时可能在用户请求间共享状态

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

高级指南在“Request-scoped services”下只执行一次 `root.Scope("request")` 并向其中注册服务,没有展示为每个请求新建和销毁作用域。随附评测却明确要求每个请求创建新作用域,说明正文示例与预期隔离模型不一致。

为什么需要注意

如果应用照抄并跨请求复用该作用域,延迟创建的请求上下文、当前用户或其他有状态服务可能被多个请求共享,造成身份混淆或一个用户的数据进入另一个用户的处理流程。

正文把一个只创建一次的 `root.Scope("request")` 标为“请求级”,却没有说明必须为每个请求创建独立作用域或在请求结束时清理。若用户照此在启动阶段创建并复用该作用域,其中的当前用户、请求上下文等可变服务可能被并发请求共享,造成跨用户数据混淆。评测文件虽不属于运行代码,但也明确记录了预期应“每个请求”新建作用域。用户可要求作者补充逐请求创建与释放的完整处理器示例。

references/advanced.md:49来自说明文档打开原文件
```goroot := do.New()// Global/stateless services in rootdo.Provide(root, NewConfig)do.Provide(root, NewLogger)// Request-scoped servicesrequestScope := root.Scope("request")do.Provide(requestScope, NewRequestContext)```
查看另外 1 个位置
evals/evals.json:61来自说明文档打开原文件
    "description": "Tests whether the model uses scopes to organize services by lifecycle and visibility",    "prompt": "In my Go web app using samber/do, I have global services (config, logger) and per-request services (request context, current user). How do I prevent per-request services from being shared across requests?",    "trap": "Without the skill, the model registers everything in the root container, leading to shared per-request state across concurrent requests",    "assertions": [      {"id": "5.1", "text": "Uses do.Scope to create child scopes for per-request services"},      {"id": "5.2", "text": "Registers global/stateless services (config, logger) in the root container"},      {"id": "5.3", "text": "Creates a new scope per request for request-scoped services"},      {"id": "5.4", "text": "Child scope services can access parent (root) services"},      {"id": "5.5", "text": "Does NOT register request-scoped services in the root container"}    ]
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。发现 1 项风险
中风险

无版本固定的 `go get -u` 会扩大依赖更新和项目文件改动

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

安装步骤明确使用 `-u` 且没有固定版本。该命令不仅取得目标包,还允许 Go 更新所选模块依赖,并改写项目的 `go.mod`、`go.sum`;实际变化取决于当前模块图。

为什么需要注意

用户可能在只想添加 DI 库时意外引入额外版本变化、新的传递代码或兼容性回归,增加供应链与构建风险。

这是面向用户的主动安装指令,使用了未固定版本的 `go get -u`。用户执行后,Go 可能升级目标模块及模块图中的相关依赖,并改写当前项目的 `go.mod` 和 `go.sum`,变化范围取决于项目现状。依赖注入库安装符合 Skill 目的,但 `-u` 扩大了修改面。用户可要求固定已审查版本、去掉 `-u`,并先查看模块文件差异。

SKILL.md:41来自说明文档打开原文件
Install v2 — v1 is superseded and lacks the generics-based container, scopes, and lifecycle hooks documented below, so v1-era guidance misleads on every API in this skill:```bashgo get -u github.com/samber/do/v2```
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 1 项风险
低风险

Skill 获得任意 git 子命令和代理启动权限,范围大于所展示的 DI 工作流

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

权限声明包含 `Bash(git:*)`、`Agent`、`WebFetch` 以及文件写入。编辑 Go 文件和查询文档符合目的,但正文展示的工作流不需要任意 git 操作或启动其他代理。

为什么需要注意

如果代理被错误指令或随后读取的不可信内容影响,这些权限可扩大影响范围,包括改变仓库历史或远端状态、读取联网内容以及把任务交给更多代理;现有证据没有显示这些动作已经发生。

权限声明是活跃的 Skill 元数据,允许读写文件、任意 `git` 子命令、启动代理及网络取文档。编辑 Go 文件和查库文档与依赖注入任务有关,但所示流程没有证明需要任意 Git 操作或代理权限。若宿主按此字段授予能力,受诱导或误操作时可能改动仓库、读取并发送项目内容,或扩大代理执行范围。用户可要求最小权限版本,并在宿主中禁用 Git、代理或网络能力,除非当前任务明确需要。

SKILL.md:18来自说明文档打开原文件
    skill-library-version: "2.0.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 Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*paths:  - "**/*.go"---
查看另外 2 个位置
SKILL.md:2来自说明文档打开原文件
---name: golang-samber-dodescription: "Dependency injection in Golang using samber/do — service containers, lifecycle management, scopes, health checks, graceful shutdown, and module organization. Apply when using or adopting samber/do, when the codebase imports github.com/samber/do or github.com/samber/do/v2, or when refactoring manual constructor injection into a DI container."user-invocable: truelicense: MITcompatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang.metadata:
SKILL.md:35来自说明文档打开原文件
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.
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

7 个说明模块

该 Skill 指导代理把 samber/do v2 加入 Go 项目,并在组合根注册、解析和关闭服务;安装命令会访问网络并改动项目的 Go 模块文件。

查看原文
SKILL.md:41来自说明文档打开原文件
Install v2 — v1 is superseded and lacks the generics-based container, scopes, and lifecycle hooks documented below, so v1-era guidance misleads on every API in this skill:```bashgo get -u github.com/samber/do/v2```
SKILL.md:177来自说明文档打开原文件
```gofunc main() {    injector := do.New(        infrastructure.Package,        repository.Package,        service.Package,        transport.Package,    )    server := do.MustInvoke[*http.Server](injector)    go server.ListenAndServe()    _ = injector.ShutdownOnSignalsWithContext(context.Background(), os.Interrupt)}

它还提供子作用域、生命周期、健康检查、结构体注入以及克隆容器并替换测试依赖的示例。

查看原文
references/advanced.md:21来自说明文档打开原文件
## Scopes (Module Tree)Scopes SHOULD be used to organize services by module:```goroot := do.New()// Register shared services in rootdo.Provide(root, func(i do.Injector) (Database, error) {    return &Database{}, nil})// Create child scopeapiScope := root.Scope("api")// Services in apiScope can access root servicesdo.Provide(apiScope, func(i do.Injector) (UserService, error) {    db := do.MustInvoke[Database](i) // from root    return &userService{db: db}, nil
references/testing.md:8来自说明文档打开原文件
```gofunc TestUserService(t *testing.T) {    // Create test container by cloning main container    testInjector := mainInjector.Clone()    // Override with mocks    mockDB := &MockDatabase{}    do.OverrideValue(testInjector, mockDB)    // Test with mocked dependencies    service := do.MustInvoke[UserService](testInjector)    // ... test code

清单授予读写文件、任意 git 子命令、受限 Go 命令、联网取文档和启动其他代理等能力;正文没有要求执行具体 git 操作。

查看原文
SKILL.md:18来自说明文档打开原文件
    skill-library-version: "2.0.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 Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*paths:  - "**/*.go"---
从这里开始 · 工作说明SKILL.md
golang-samber-do
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。

文件引用关系图

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

检查范围与遗漏

逐文件查看涉及的内容

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

  • SKILL.md已纳入全文
  • references/advanced.md已纳入全文
  • references/testing.md已纳入全文
  • evals/evals.json已纳入全文

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

  • SKILL.md工作说明
  • evals/evals.json配套文件
  • references/advanced.md配套文件
  • references/testing.md配套文件

代码和说明中提到的操作

连接外部网站
SKILL.md:12来自说明文档打开原文件
    emoji: "💉"    homepage: https://github.com/samber/cc-skills-golang    requires:
SKILL.md:31来自说明文档打开原文件
- [pkg.go.dev/github.com/samber/do/v2](https://pkg.go.dev/github.com/samber/do/v2)- [do.samber.dev](https://do.samber.dev)
SKILL.md:32来自说明文档打开原文件
- [pkg.go.dev/github.com/samber/do/v2](https://pkg.go.dev/github.com/samber/do/v2)- [do.samber.dev](https://do.samber.dev)- [github.com/samber/do/v2](https://github.com/samber/do)
运行命令
SKILL.md:18来自说明文档打开原文件
    skill-library-version: "2.0.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 Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*paths:
SKILL.md:43来自说明文档打开原文件
```bashgo get -u github.com/samber/do/v2
读取了多少行
667
文件校验值(用于核对版本)
b02f906d1703ceff0b63a68ea19c30e62c411adc03389bc5b2a4351df239a667