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

Golang Database Skill 安全审计

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

Comprehensive guide for Go database access — parameterized queries, struct scanning, NULLable columns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context propagation, and migration tooling. Use when writing, reviewing, or debugging Golang code that interacts with PostgreSQL, MariaDB, MySQL, or SQLite; for database testing; or for questions about database/

第三方安全检查结论

发现安全风险

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

宽泛的 `EXPLAIN ANALYZE` 指令可能实际执行写入语句

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

Skill 要求优化前使用 `EXPLAIN ANALYZE`,但没有把它限制为只读 SELECT。在 PostgreSQL 中,ANALYZE 会真正执行被分析的语句,而不只是显示计划。

为什么需要注意

若代理对 INSERT、UPDATE、DELETE 或带副作用的语句使用它,连接到的数据库可能被修改,也可能产生锁、触发器副作用或高负载。

这是主动的性能建议,要求优化前使用 `EXPLAIN ANALYZE`,却没有把目标限制为只读查询。PostgreSQL 会实际执行被分析的语句;若代理把该建议用于 UPDATE、DELETE 或 INSERT,可能真实修改用户数据。文档同时说性能改动只应建议并经人工审核,但这没有明确禁止执行分析命令。用户可要求作者限定为 SELECT,或改用不执行语句的 `EXPLAIN`。

references/performance.md:220来自说明文档打开原文件
- **`EXPLAIN ANALYZE`** before optimizing — measure, don't guess- **List columns explicitly** — avoid `SELECT *`, it fetches unnecessary data and breaks struct scanning when schema changes
查看另外 1 个位置
references/performance.md:225来自说明文档打开原文件
- **Avoid N+1 queries** — use `JOIN` or batch `WHERE id IN (...)` instead of querying in a loop- **Suggest improvements, never execute them** — performance changes (indexes, query rewrites, configuration) need human review in context of production data and workload patterns
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 1 项风险
中风险

测试模板可在未经环境校验的任意数据库上连接并运行迁移

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

模板直接信任 `TEST_DATABASE_URL`,连接后建议在事务测试开始前运行迁移。虽然文档禁止测试生产库,但示例没有检查数据库名称、主机或显式测试标记。

为什么需要注意

如果环境变量误指向共享、预发布或生产数据库,测试初始化可能造成持久的模式或数据变化;后续每个测试的回滚无法撤销初始化阶段已运行的迁移。

这段证据能说明什么

示例确实直接使用 `TEST_DATABASE_URL` 连接数据库,且迁移注释出现在事务隔离建立之前,因此错误配置可能指向不应使用的数据库。不过“Run migrations”只是示例注释,并非实际迁移代码;文档还明确禁止生产库测试。来源不足以证明技能会自动运行迁移,但模板缺少对测试环境的强制校验。用户可限制数据库凭据,并要求连接前验证专用测试库标记。

这项判断针对展示的代码和适用条件,不表示风险已经实际发生。
references/testing.md:131来自说明文档打开原文件
func (s *UserRepoSuite) SetupSuite() {    dsn := os.Getenv("TEST_DATABASE_URL") // e.g., postgres://test:test@localhost:5432/testdb?sslmode=disable    db, err := sqlx.Connect("postgres", dsn)    s.Require().NoError(err)    s.db = db    // Run migrations here if needed}
查看另外 2 个位置
references/testing.md:143来自说明文档打开原文件
func (s *UserRepoSuite) SetupTest() {    tx, err := s.db.Beginx()    s.Require().NoError(err)    s.tx = tx}func (s *UserRepoSuite) TearDownTest() {    s.tx.Rollback() // rolls back all changes — each test starts clean}
references/testing.md:219来自说明文档打开原文件
- Integration tests SHOULD use testcontainers-go for reproducible database environments in CI.- NEVER test against production databases.
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 1 项风险
中风险

声明的 git 权限覆盖全部子命令,超出数据库代码指导所需范围

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

`Bash(git:*)` 没有限制为只读检查,而 Skill 的主要用途是生成和审查 Go 数据库代码。该权限范围可让支持此语法的执行环境接受具有远程或持久仓库副作用的 git 操作,即使正文没有要求这些操作。

为什么需要注意

若代理被项目内容或后续提示误导,可能改变仓库配置、引用或远程状态;具体影响取决于运行环境授予的仓库和凭据权限。

清单授予 `git:*`,没有限定为 status、diff 等只读子命令;在执行环境认可该权限语法时,它可能允许 push、提交、分支删除或其他会影响本地及远程仓库的操作。正文要求搜索既有代码模式,但没有说明为何需要全部 Git 子命令,因此能力范围明显宽于所述任务。权限本身不证明任何命令已执行。用户可要求只开放必要的只读 Git 操作并阻止远程或破坏性子命令。

SKILL.md:17来自说明文档打开原文件
    install: []allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestionpaths:
查看另外 2 个位置
SKILL.md:3来自说明文档打开原文件
name: golang-databasedescription: "Comprehensive guide for Go database access — parameterized queries, struct scanning, NULLable columns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context propagation, and migration tooling. Use when writing, reviewing, or debugging Golang code that interacts with PostgreSQL, MariaDB, MySQL, or SQLite; for database testing; or for questions about database/sql, sqlx, or pgx. Does NOT generate database schemas or migration SQL."user-invocable: true
SKILL.md:26来自说明文档打开原文件
- **Write mode** — generating new repository functions, query helpers, or transaction wrappers: follow the skill's sequential instructions; launch a background agent to grep for existing query patterns and naming conventions in the codebase before generating new code.- **Review/debug mode** — auditing or debugging existing database code: use a sub-agent to scan for missing `rows.Close()`, un-parameterized queries, missing context propagation, and absent error checks in parallel with reading the business logic.
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

8 个说明模块

这是一个指导代理编写和审查 Go 数据库代码的文档型 Skill;未提供安装命令或可执行脚本,但声明了代码读写、Go、git 和子代理权限。

查看原文
SKILL.md:16来自说明文档打开原文件
        - go    install: []allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestionpaths:

Skill 要求在写入或审查模式中启动子代理扫描仓库中的查询模式及常见数据库缺陷,因此使用时可能让额外代理读取项目的 Go 源码。

查看原文
SKILL.md:26来自说明文档打开原文件
- **Write mode** — generating new repository functions, query helpers, or transaction wrappers: follow the skill's sequential instructions; launch a background agent to grep for existing query patterns and naming conventions in the codebase before generating new code.- **Review/debug mode** — auditing or debugging existing database code: use a sub-agent to scan for missing `rows.Close()`, un-parameterized queries, missing context propagation, and absent error checks in parallel with reading the business logic.
SKILL.md:18来自说明文档打开原文件
allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestionpaths:  - "**/*.go"---

数据库建议总体强调参数化查询、上下文传播、关闭结果集、事务和人工审查,并明确禁止自行创建或删除索引。

查看原文
SKILL.md:40来自说明文档打开原文件
1. **Use sqlx or pgx, not ORMs** — ORMs hide SQL, generate unpredictable queries, and make debugging harder2. Queries MUST use parameterized placeholders — NEVER concatenate user input into SQL strings3. Context MUST be passed to all database operations — use `*Context` method variants (`QueryContext`, `ExecContext`, `GetContext`)4. `sql.ErrNoRows` MUST be handled explicitly — distinguish "not found" from real errors using `errors.Is`5. Rows MUST be closed after iteration — `defer rows.Close()` immediately after `QueryContext` calls6. NEVER use `db.Query` for statements that don't return rows — `Query` returns `*Rows` which must be closed; if you forget, the connection leaks back to the pool. Use `db.Exec` instead7. **Use transactions for multi-statement operations** — wrap related writes in `BeginTxx`/`Commit`8. **Use `SELECT ... FOR UPDATE`** when reading data you intend to modify — prevents race conditions
references/performance.md:183来自说明文档打开原文件
**Never create or drop indexes yourself.** Index changes affect production query performance and write throughput. Always suggest to the developer and let them decide.

集成测试模板从环境变量取得数据库地址,也提供会拉取并启动 PostgreSQL 容器的 testcontainers 示例;这些操作只在用户运行生成的集成测试时发生。

查看原文
references/testing.md:131来自说明文档打开原文件
func (s *UserRepoSuite) SetupSuite() {    dsn := os.Getenv("TEST_DATABASE_URL") // e.g., postgres://test:test@localhost:5432/testdb?sslmode=disable    db, err := sqlx.Connect("postgres", dsn)    s.Require().NoError(err)    s.db = db    // Run migrations here if needed}
references/testing.md:182来自说明文档打开原文件
```gofunc (s *UserRepoSuite) SetupSuite() {    ctx := context.Background()    container, err := postgres.Run(ctx, "postgres:16-alpine",        postgres.WithDatabase("testdb"),        postgres.WithUsername("test"),        postgres.WithPassword("test"),        testcontainers.WithWaitStrategy(            wait.ForLog("database system is ready to accept connections").
从这里开始 · 工作说明SKILL.md
golang-database
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。 另有 6 个章节,可在原文件中查看。

文件引用关系图

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

检查范围与遗漏

逐文件查看涉及的内容

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

  • SKILL.md已纳入全文
  • references/performance.md已纳入全文
  • references/scanning.md已纳入全文
  • references/testing.md已纳入全文
  • references/transactions.md已纳入全文
  • evals/evals.json已纳入全文

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

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

代码和说明中提到的操作

连接外部网站
SKILL.md:12来自说明文档打开原文件
    emoji: "🗄"    homepage: https://github.com/samber/cc-skills-golang    requires:
SKILL.md:212来自说明文档打开原文件
- [golang-migrate](https://github.com/golang-migrate/migrate) — CLI + Go library, supports all major databases- [Flyway](https://flywaydb.org/) — JVM-based, widely used in enterprise environments
SKILL.md:213来自说明文档打开原文件
- [golang-migrate](https://github.com/golang-migrate/migrate) — CLI + Go library, supports all major databases- [Flyway](https://flywaydb.org/) — JVM-based, widely used in enterprise environments- [Atlas](https://atlasgo.io/) — modern, declarative schema management
运行命令
SKILL.md:17来自说明文档打开原文件
    install: []allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestionpaths:
references/testing.md:173来自说明文档打开原文件
```bashgo test -tags=integration -v ./internal/repository/...
读取密钥或账号配置
references/testing.md:132来自说明文档打开原文件
func (s *UserRepoSuite) SetupSuite() {    dsn := os.Getenv("TEST_DATABASE_URL") // e.g., postgres://test:test@localhost:5432/testdb?sslmode=disable    db, err := sqlx.Connect("postgres", dsn)
读取了多少行
1,045
文件校验值(用于核对版本)
1332b042886e935f47078d043d93fe64a66c02867d5ace934f689087957f8b88