跳转到正文
报告库
用途分类 / 数据分析

Supabase Postgres Best Practices Skill 安全审计

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

Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and schedule

第三方安全检查结论

先别安装或运行

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

全局超时示例会持久修改服务器并终止会话或事务

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

推荐方案使用 `ALTER SYSTEM` 设置 30 秒的空闲事务超时和 10 分钟的空闲会话超时,再重新加载配置。这是服务器级持久变更,不是仅针对被诊断连接的临时设置;30 秒后被终止的空闲事务会回滚。

为什么需要注意

长时间交互式事务、迁移、管理工具或合法池化会话可能突然断开或回滚,造成服务错误、部分工作失败和停机。

推荐代码使用 `ALTER SYSTEM` 写入服务器级配置并重新加载,而非仅调整当前诊断会话。启用后,空闲事务连接在 30 秒、完全空闲连接在 10 分钟后会被终止;前者未提交事务将回滚,并可能影响所有使用该实例的应用。用户可要求作者先评估工作负载和连接池行为,优先给出会话/角色级方案,并要求生产变更审批与回滚计划。

references/conn-idle-timeout.md:25来自说明文档打开原文件
**Correct (automatic cleanup of idle connections):**```sql-- Terminate connections idle in transaction after 30 secondsalter system set idle_in_transaction_session_timeout = '30s';-- Terminate completely idle connections after 10 minutesalter system set idle_session_timeout = '10min';-- Reload configurationselect pg_reload_conf();```
中风险

对任意慢查询推广 EXPLAIN ANALYZE 可能实际执行写入或昂贵操作

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

指南明确说明 `EXPLAIN ANALYZE` 会执行查询,同时 Skill 的触发范围涵盖一般慢查询诊断。示例恰好是 SELECT,但没有警告代理:把同一做法用于 INSERT、UPDATE、DELETE、函数调用或极慢查询会产生真实副作用或负载。

为什么需要注意

诊断动作可能修改或删除生产数据、触发外部副作用,或再次运行昂贵查询并加重数据库过载。

指南明确称 `EXPLAIN ANALYZE` 会执行查询,并把它作为慢查询诊断的“正确”做法;Skill 的触发说明也覆盖一般慢查询。展示的命令仅为 SELECT,未警告将该模式套到 INSERT、UPDATE、DELETE、带副作用函数或极昂贵查询时会真实修改数据或增加生产负载。用户可限制只对只读语句使用,要求写语句在可回滚事务或副本中分析,并设置超时。

SKILL.md:3来自说明文档打开原文件
name: supabase-postgres-best-practicesdescription: "Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pg_cron, pgmq), vector/semantic search (pgvector), and restoring dumps (pg_restore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query."license: MIT
查看另外 2 个位置
references/monitor-explain-analyze.md:8来自说明文档打开原文件
## Use EXPLAIN ANALYZE to Diagnose Slow QueriesEXPLAIN ANALYZE executes the query and shows actual timings, revealing the true performance bottlenecks.
references/monitor-explain-analyze.md:20来自说明文档打开原文件
**Correct (use EXPLAIN ANALYZE):**```sqlexplain (analyze, buffers, format text)select * from orders where customer_id = 123 and status = 'pending';
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 2 项风险
高风险

可由客户端设置的会话变量被当作租户身份,可能导致跨租户读取

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

推荐的 RLS 策略直接信任 `app.current_user_id`,随后又演示用普通 `SET` 指定该值。自定义 PostgreSQL 会话参数本身不验证登录者身份;如果应用角色或用户能执行任意 SQL 或影响该会话设置,就可能把它改成另一用户的 ID。

为什么需要注意

攻击者可能读取或修改其他用户的订单。`FORCE ROW LEVEL SECURITY` 不会修复不可信身份来源,因为策略仍会接受被伪造的值。

该“正确”示例把可由 `SET` 写入的自定义会话参数直接用于 RLS 身份判断。源码没有展示该值与已认证身份的可信绑定;若应用角色能够执行任意 SQL、复用被污染的连接或影响该设置,就可能改成其他用户 ID 并读取其订单。用户可要求作者改用不可伪造的认证声明,并限制应用角色设置身份参数及验证连接池重置。

references/security-rls-basics.md:28来自说明文档打开原文件
-- Create policy for users to see only their orderscreate policy orders_user_policy on orders  for all  using (user_id = current_setting('app.current_user_id')::bigint);-- Force RLS even for table ownersalter table orders force row level security;-- Set user context and queryset app.current_user_id = '123';select * from orders;  -- Only returns orders for user 123```
查看另外 2 个位置
references/security-rls-basics.md:41来自说明文档打开原文件
Policy for authenticated role:```sqlcreate policy orders_user_policy on orders  for all  to authenticated  using (user_id = auth.uid());```
references/security-rls-basics.md:36来自说明文档打开原文件
-- Set user context and queryset app.current_user_id = '123';select * from orders;  -- Only returns orders for user 123```
高风险

“正确”分区示例直接删除整张分区表及其中数据

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

该指南把 `drop table events_2023_01` 作为快速清理旧数据的推荐操作。此操作删除分区及其全部数据,而示例没有要求确认保留期限、先解绑或归档分区、检查依赖或验证备份。

为什么需要注意

代理在迁移或优化任务中套用示例时,可能永久删除仍需保留的历史事件,并破坏依赖该分区的对象或审计记录。

分区指南把 `DROP TABLE` 作为快速删除旧数据的推荐示例;执行时会删除该分区及其中全部数据。虽然条件被描述为“旧数据”,源码没有要求在执行前确认保留策略、归档、备份或依赖,因此代理套用示例时存在不可恢复数据丢失风险。用户可要求作者加入明确确认、备份验证和依赖检查,并禁止代理未经批准执行 DROP。

SKILL.md:3来自说明文档打开原文件
name: supabase-postgres-best-practicesdescription: "Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pg_cron, pgmq), vector/semantic search (pgvector), and restoring dumps (pg_restore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query."license: MIT
查看另外 2 个位置
references/schema-partitioning.md:42来自说明文档打开原文件
-- Queries only scan relevant partitionsselect * from events where created_at > '2024-01-15';  -- Only scans events_2024_01+-- Drop old data instantlydrop table events_2023_01;  -- Instant vs DELETE taking hours```When to partition:- Tables > 100M rows- Time-series data with date-based queries- Need to efficiently drop old data
references/schema-partitioning.md:49来自说明文档打开原文件
When to partition:- Tables > 100M rows- Time-series data with date-based queries- Need to efficiently drop old data
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 1 项风险
中风险

部分“幂等”约束检查只按名称查询,可能静默跳过必要约束

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

“所有约束类型”的推荐示例只用 `conname` 查找约束,没有限定目标表或模式。PostgreSQL 中另一个表若已有同名约束,条件会误判为已存在,从而不在目标表添加 CHECK 或外键。

为什么需要注意

迁移可能表面成功但缺少数据完整性保护,允许无效年龄、孤立外键或其他不符合业务规则的数据进入数据库。

“所有约束类型”的 CHECK 和外键示例都仅按 `conname` 检查,没有限定 `conrelid` 或目标模式。若数据库内另一张表已有同名约束,`if not exists` 会为假,迁移不会报错却会跳过目标表所需约束,可能削弱数据完整性。用户可要求作者像前一个 profiles 示例一样同时匹配目标表,并在迁移后验证约束定义。

references/schema-constraints.md:37来自说明文档打开原文件
For all constraint types:```sql-- Check constraintsdo $$begin  if not exists (    select 1 from pg_constraint    where conname = 'check_age_positive'  ) then    alter table users add constraint check_age_positive check (age > 0);  end if;end $$;-- Foreign keysdo $$begin  if not exists (    select 1 from pg_constraint    where conname = 'profiles_birthchart_id_fkey'  ) then    alter table profiles    add constraint profiles_birthchart_id_fkey    foreign key (birthchart_id) references birthcharts(id);  end if;end $$;```
查看另外 2 个位置
references/schema-constraints.md:40来自说明文档打开原文件
```sql-- Check constraintsdo $$begin  if not exists (    select 1 from pg_constraint    where conname = 'check_age_positive'  ) then    alter table users add constraint check_age_positive check (age > 0);  end if;end $$;
references/schema-constraints.md:51来自说明文档打开原文件
-- Foreign keysdo $$begin  if not exists (    select 1 from pg_constraint    where conname = 'profiles_birthchart_id_fkey'  ) then    alter table profiles    add constraint profiles_birthchart_id_fkey    foreign key (birthchart_id) references birthcharts(id);  end if;
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

4 个说明模块

该 Skill 是供代理在编写 SQL、设计架构、处理连接和 RLS 时查阅的规则集;入口要求读取独立参考文件,而不是直接执行安装程序。示例中的 SQL 仍可能被代理复制到真实数据库。

查看原文
SKILL.md:19来自说明文档打开原文件
Reference these guidelines when:- Writing SQL queries or designing schemas- Implementing indexes or query optimization- Reviewing database performance issues- Configuring connection pooling or scaling- Optimizing for Postgres-specific features- Working with Row-Level Security (RLS)
SKILL.md:40来自说明文档打开原文件
## How to UseRead individual rule files for detailed explanations and SQL examples:```references/query-missing-indexes.mdreferences/query-partial-indexes.mdreferences/_sections.md```

资料刻意先展示错误示例、再展示正确示例。代理若忽略标签或只复制局部片段,可能采用本来用于反例的 SQL;这些反例本身不应被视为 Skill 要求执行的行为。

查看原文
references/_contributing.md:15来自说明文档打开原文件
### 2. Error-First StructureAlways show the problematic pattern first, then the solution. This trains agentsto recognize anti-patterns.```markdown**Incorrect (sequential queries):** [bad example]**Correct (batched query):** [good example]```

版本信息不一致:入口元数据显示 1.1.1,而变更日志顶部显示 1.6.0。用户无法仅凭这些文件明确判断实际包含哪个发布版本及安全修复状态。

查看原文
SKILL.md:7来自说明文档打开原文件
  author: supabase  version: "1.1.1"  organization: Supabase  date: January 2026  abstract: Comprehensive Postgres performance optimization guide for developers using Supabase and Postgres. Contains performance rules across 8 categories, prioritized by impact from critical (query performance, connection management) to incremental (advanced features). Each rule includes detailed explanations, incorrect vs. correct SQL examples, query plan analysis, and specific performance metrics to guide automated optimization and code generation.
CHANGELOG.md:3来自说明文档打开原文件
## [1.6.0](https://github.com/supabase/agent-skills/compare/supabase-postgres-best-practices-v1.5.0...supabase-postgres-best-practices-v1.6.0) (2026-07-30)
从这里开始 · 工作说明SKILL.md
supabase-postgres-best-practices
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。

文件引用关系图

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

检查范围与遗漏

逐文件查看涉及的内容

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

  • SKILL.md已纳入全文
  • references/_sections.md已纳入全文
  • references/query-missing-indexes.md已纳入全文
  • references/query-partial-indexes.md已纳入全文
  • CHANGELOG.md已纳入全文
  • references/_contributing.md已纳入全文
  • references/_template.md已纳入全文
  • references/advanced-full-text-search.md已纳入全文
  • references/advanced-jsonb-indexing.md已纳入全文
  • references/conn-idle-timeout.md已纳入全文
  • references/conn-limits.md已纳入全文
  • references/conn-pooling.md已纳入全文
  • references/conn-prepared-statements.md已纳入全文
  • references/data-batch-inserts.md已纳入全文
  • references/data-n-plus-one.md已纳入全文
  • references/data-pagination.md已纳入全文
  • references/data-upsert.md已纳入全文
  • references/lock-advisory.md已纳入全文
  • references/lock-deadlock-prevention.md已纳入全文
  • references/lock-short-transactions.md已纳入全文
  • references/lock-skip-locked.md已纳入全文
  • references/monitor-explain-analyze.md已纳入全文
  • references/monitor-pg-stat-statements.md已纳入全文
  • references/monitor-vacuum-analyze.md已纳入全文
  • references/query-composite-indexes.md已纳入全文
  • references/query-covering-indexes.md已纳入全文
  • references/query-index-types.md已纳入全文
  • references/schema-constraints.md已纳入全文
  • references/schema-data-types.md已纳入全文
  • references/schema-foreign-key-indexes.md已纳入全文
  • references/schema-lowercase-identifiers.md已纳入全文
  • references/schema-partitioning.md已纳入全文
  • references/schema-primary-keys.md已纳入全文
  • references/security-privileges.md已纳入全文
  • references/security-rls-basics.md已纳入全文
  • references/security-rls-performance.md已纳入全文

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

  • CHANGELOG.md配套文件
  • SKILL.md工作说明
  • references/_contributing.md配套文件
  • references/_sections.md配套文件
  • references/_template.md配套文件
  • references/advanced-full-text-search.md配套文件
  • references/advanced-jsonb-indexing.md配套文件
  • references/conn-idle-timeout.md配套文件
  • references/conn-limits.md配套文件
  • references/conn-pooling.md配套文件
  • references/conn-prepared-statements.md配套文件
  • references/data-batch-inserts.md配套文件
  • references/data-n-plus-one.md配套文件
  • references/data-pagination.md配套文件
  • references/data-upsert.md配套文件
  • references/lock-advisory.md配套文件
  • references/lock-deadlock-prevention.md配套文件
  • references/lock-short-transactions.md配套文件
  • references/lock-skip-locked.md配套文件
  • references/monitor-explain-analyze.md配套文件
  • references/monitor-pg-stat-statements.md配套文件
  • references/monitor-vacuum-analyze.md配套文件
  • references/query-composite-indexes.md配套文件
  • references/query-covering-indexes.md配套文件
  • references/query-index-types.md配套文件
  • references/query-missing-indexes.md配套文件
  • references/query-partial-indexes.md配套文件
  • references/schema-constraints.md配套文件
  • references/schema-data-types.md配套文件
  • references/schema-foreign-key-indexes.md配套文件
  • references/schema-lowercase-identifiers.md配套文件
  • references/schema-partitioning.md配套文件
  • references/schema-primary-keys.md配套文件
  • references/security-privileges.md配套文件
  • references/security-rls-basics.md配套文件
  • references/security-rls-performance.md配套文件

代码和说明中提到的操作

连接外部网站
CHANGELOG.md:3来自说明文档打开原文件
## [1.6.0](https://github.com/supabase/agent-skills/compare/supabase-postgres-best-practices-v1.5.0...supabase-postgres-best-practices-v1.6.0) (2026-07-30)
CHANGELOG.md:8来自说明文档打开原文件
* add schema-constraints reference for safe migration patterns ([#30](https://github.com/supabase/agent-skills/issues/30)) ([9b236f3](https://github.com/supabase/agent-skills/commit/9b236f3ebd65d76a2c570f19931353da9c858d5a))* using Supabase agent skills ([#12](https://github.com/supabase/agent-skills/issues/12)) ([7c2e389](https://github.com/supabase/agent-skills/commit/7c2e3894fddfde8eb6c77d2a8921904543b9be7a))
CHANGELOG.md:9来自说明文档打开原文件
* add schema-constraints reference for safe migration patterns ([#30](https://github.com/supabase/agent-skills/issues/30)) ([9b236f3](https://github.com/supabase/agent-skills/commit/9b236f3ebd65d76a2c570f19931353da9c858d5a))* using Supabase agent skills ([#12](https://github.com/supabase/agent-skills/issues/12)) ([7c2e389](https://github.com/supabase/agent-skills/commit/7c2e3894fddfde8eb6c77d2a8921904543b9be7a))
读取了多少行
2,030
文件校验值(用于核对版本)
8bf87a81fc598f58400cea081a2ff143a8faae7a08ce7afeae09cb41568cc6ef