codebyplan 1.13.39 → 1.13.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +24631 -354
- package/package.json +4 -2
- package/templates/agents/cbp-cc-executor.md +4 -4
- package/templates/agents/cbp-database-agent.md +15 -4
- package/templates/agents/cbp-round-executor.md +2 -10
- package/templates/agents/cbp-task-check.md +2 -0
- package/templates/agents/cbp-task-planner.md +2 -5
- package/templates/hooks/README.md +14 -2
- package/templates/hooks/cbp-session-start-hook.sh +32 -0
- package/templates/hooks/cbp-test-coverage-gate.sh +20 -6
- package/templates/hooks/cbp-test-hooks.sh +72 -0
- package/templates/hooks/hooks.json +11 -0
- package/templates/hooks/validate-structure-patterns.sh +5 -3
- package/templates/hooks/validate-structure.sh +3 -2
- package/templates/settings.project.base.json +12 -0
- package/templates/skills/cbp-checkpoint-check/SKILL.md +10 -10
- package/templates/skills/cbp-checkpoint-complete/SKILL.md +7 -7
- package/templates/skills/cbp-checkpoint-create/SKILL.md +11 -9
- package/templates/skills/cbp-checkpoint-end/SKILL.md +7 -10
- package/templates/skills/cbp-checkpoint-plan/SKILL.md +10 -10
- package/templates/skills/cbp-checkpoint-start/SKILL.md +6 -6
- package/templates/skills/cbp-checkpoint-update/SKILL.md +9 -9
- package/templates/skills/cbp-git-commit/SKILL.md +8 -4
- package/templates/skills/cbp-merge-main/SKILL.md +2 -5
- package/templates/skills/cbp-round-check/SKILL.md +12 -8
- package/templates/skills/cbp-round-complete/SKILL.md +16 -10
- package/templates/skills/cbp-round-end/SKILL.md +9 -10
- package/templates/skills/cbp-round-execute/SKILL.md +7 -6
- package/templates/skills/cbp-round-input/SKILL.md +24 -12
- package/templates/skills/cbp-round-start/SKILL.md +36 -16
- package/templates/skills/cbp-round-update/SKILL.md +14 -10
- package/templates/skills/cbp-session-end/SKILL.md +22 -12
- package/templates/skills/cbp-session-start/SKILL.md +20 -47
- package/templates/skills/cbp-ship/SKILL.md +4 -4
- package/templates/skills/cbp-ship-main/SKILL.md +4 -5
- package/templates/skills/cbp-supabase-branch-check/SKILL.md +1 -0
- package/templates/skills/cbp-supabase-migrate/SKILL.md +14 -9
- package/templates/skills/cbp-supabase-setup/SKILL.md +1 -0
- package/templates/skills/cbp-task-check/SKILL.md +10 -10
- package/templates/skills/cbp-task-complete/SKILL.md +11 -9
- package/templates/skills/cbp-task-create/SKILL.md +7 -5
- package/templates/skills/cbp-task-start/SKILL.md +15 -17
- package/templates/skills/cbp-task-testing/SKILL.md +18 -18
- package/templates/skills/cbp-todo/SKILL.md +21 -21
- package/templates/skills/supabase/CHANGELOG.md +35 -0
- package/templates/skills/supabase/PROVENANCE.md +50 -0
- package/templates/skills/supabase/SKILL.md +136 -0
- package/templates/skills/supabase/assets/feedback-issue-template.md +17 -0
- package/templates/skills/supabase/references/skill-feedback.md +17 -0
- package/templates/skills/supabase-postgres-best-practices/CHANGELOG.md +29 -0
- package/templates/skills/supabase-postgres-best-practices/PROVENANCE.md +52 -0
- package/templates/skills/supabase-postgres-best-practices/SKILL.md +65 -0
- package/templates/skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
- package/templates/skills/supabase-postgres-best-practices/references/_sections.md +39 -0
- package/templates/skills/supabase-postgres-best-practices/references/_template.md +34 -0
- package/templates/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
- package/templates/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
- package/templates/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
- package/templates/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
- package/templates/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
- package/templates/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
- package/templates/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
- package/templates/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
- package/templates/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
- package/templates/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
- package/templates/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
- package/templates/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
- package/templates/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
- package/templates/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
- package/templates/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
- package/templates/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
- package/templates/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
- package/templates/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
- package/templates/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
- package/templates/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
- package/templates/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
- package/templates/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
- package/templates/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
- package/templates/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
- package/templates/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
- package/templates/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
- package/templates/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
- package/templates/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
- package/templates/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
- package/templates/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
- package/templates/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Apply Principle of Least Privilege
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: Reduced attack surface, better audit trail
|
|
5
|
+
tags: privileges, security, roles, permissions
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Apply Principle of Least Privilege
|
|
9
|
+
|
|
10
|
+
Grant only the minimum permissions required. Never use superuser for application queries.
|
|
11
|
+
|
|
12
|
+
**Incorrect (overly broad permissions):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
-- Application uses superuser connection
|
|
16
|
+
-- Or grants ALL to application role
|
|
17
|
+
grant all privileges on all tables in schema public to app_user;
|
|
18
|
+
grant all privileges on all sequences in schema public to app_user;
|
|
19
|
+
|
|
20
|
+
-- Any SQL injection becomes catastrophic
|
|
21
|
+
-- drop table users; cascades to everything
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Correct (minimal, specific grants):**
|
|
25
|
+
|
|
26
|
+
```sql
|
|
27
|
+
-- Create role with no default privileges
|
|
28
|
+
create role app_readonly nologin;
|
|
29
|
+
|
|
30
|
+
-- Grant only SELECT on specific tables
|
|
31
|
+
grant usage on schema public to app_readonly;
|
|
32
|
+
grant select on public.products, public.categories to app_readonly;
|
|
33
|
+
|
|
34
|
+
-- Create role for writes with limited scope
|
|
35
|
+
create role app_writer nologin;
|
|
36
|
+
grant usage on schema public to app_writer;
|
|
37
|
+
grant select, insert, update on public.orders to app_writer;
|
|
38
|
+
grant usage on sequence orders_id_seq to app_writer;
|
|
39
|
+
-- No DELETE permission
|
|
40
|
+
|
|
41
|
+
-- Login role inherits from these
|
|
42
|
+
create role app_user login password 'xxx';
|
|
43
|
+
grant app_writer to app_user;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Revoke public defaults:
|
|
47
|
+
|
|
48
|
+
```sql
|
|
49
|
+
-- Revoke default public access
|
|
50
|
+
revoke all on schema public from public;
|
|
51
|
+
revoke all on all tables in schema public from public;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Reference: [Roles and Privileges](https://supabase.com/blog/postgres-roles-and-privileges)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Enable Row Level Security for Multi-Tenant Data
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: Database-enforced tenant isolation, prevent data leaks
|
|
5
|
+
tags: rls, row-level-security, multi-tenant, security
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Enable Row Level Security for Multi-Tenant Data
|
|
9
|
+
|
|
10
|
+
Row Level Security (RLS) enforces data access at the database level, ensuring users only see their own data.
|
|
11
|
+
|
|
12
|
+
**Incorrect (application-level filtering only):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
-- Relying only on application to filter
|
|
16
|
+
select * from orders where user_id = $current_user_id;
|
|
17
|
+
|
|
18
|
+
-- Bug or bypass means all data is exposed!
|
|
19
|
+
select * from orders; -- Returns ALL orders
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (database-enforced RLS):**
|
|
23
|
+
|
|
24
|
+
```sql
|
|
25
|
+
-- Enable RLS on the table
|
|
26
|
+
alter table orders enable row level security;
|
|
27
|
+
|
|
28
|
+
-- Create policy for users to see only their orders
|
|
29
|
+
create policy orders_user_policy on orders
|
|
30
|
+
for all
|
|
31
|
+
using (user_id = current_setting('app.current_user_id')::bigint);
|
|
32
|
+
|
|
33
|
+
-- Force RLS even for table owners
|
|
34
|
+
alter table orders force row level security;
|
|
35
|
+
|
|
36
|
+
-- Set user context and query
|
|
37
|
+
set app.current_user_id = '123';
|
|
38
|
+
select * from orders; -- Only returns orders for user 123
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Policy for authenticated role:
|
|
42
|
+
|
|
43
|
+
```sql
|
|
44
|
+
create policy orders_user_policy on orders
|
|
45
|
+
for all
|
|
46
|
+
to authenticated
|
|
47
|
+
using (user_id = auth.uid());
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Reference: [Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)
|
package/templates/skills/supabase-postgres-best-practices/references/security-rls-performance.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Optimize RLS Policies for Performance
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: 5-10x faster RLS queries with proper patterns
|
|
5
|
+
tags: rls, performance, security, optimization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Optimize RLS Policies for Performance
|
|
9
|
+
|
|
10
|
+
Poorly written RLS policies can cause severe performance issues. Use subqueries and indexes strategically.
|
|
11
|
+
|
|
12
|
+
**Incorrect (function called for every row):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
create policy orders_policy on orders
|
|
16
|
+
using (auth.uid() = user_id); -- auth.uid() called per row!
|
|
17
|
+
|
|
18
|
+
-- With 1M rows, auth.uid() is called 1M times
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Correct (wrap functions in SELECT):**
|
|
22
|
+
|
|
23
|
+
```sql
|
|
24
|
+
create policy orders_policy on orders
|
|
25
|
+
using ((select auth.uid()) = user_id); -- Called once, cached
|
|
26
|
+
|
|
27
|
+
-- 100x+ faster on large tables
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Use security definer functions for complex checks:
|
|
31
|
+
|
|
32
|
+
`SECURITY DEFINER` functions run with the creator's privileges and bypass RLS on any tables they touch — which is what makes them useful for internal lookups, but also what makes them dangerous if misused. Always include an explicit `auth.uid()` check inside the function body, keep them in a non-exposed schema, and revoke `EXECUTE` from any role that shouldn't call them directly.
|
|
33
|
+
|
|
34
|
+
```sql
|
|
35
|
+
-- Create helper function in a private schema
|
|
36
|
+
create or replace function private.is_team_member(team_id bigint)
|
|
37
|
+
returns boolean
|
|
38
|
+
language sql
|
|
39
|
+
security definer
|
|
40
|
+
set search_path = ''
|
|
41
|
+
as $$
|
|
42
|
+
select exists (
|
|
43
|
+
select 1 from public.team_members
|
|
44
|
+
-- always check the calling user's identity inside the function
|
|
45
|
+
where team_id = $1 and user_id = (select auth.uid())
|
|
46
|
+
);
|
|
47
|
+
$$;
|
|
48
|
+
|
|
49
|
+
-- Revoke direct execution from public roles
|
|
50
|
+
revoke execute on function private.is_team_member(bigint) from PUBLIC, anon, authenticated, service_role;
|
|
51
|
+
|
|
52
|
+
-- Use in policy (indexed lookup, not per-row check)
|
|
53
|
+
create policy team_orders_policy on orders
|
|
54
|
+
using ((select private.is_team_member(team_id)));
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Always add indexes on columns used in RLS policies:
|
|
58
|
+
|
|
59
|
+
```sql
|
|
60
|
+
create index orders_user_id_idx on orders (user_id);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Reference: [RLS Performance](https://supabase.com/docs/guides/database/postgres/row-level-security#rls-performance-recommendations)
|