sinapse-ai 7.7.5 → 7.7.7

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/.claude/CLAUDE.md CHANGED
@@ -24,6 +24,7 @@ O SINAPSE possui uma **Constitution formal** com princípios inegociáveis e gat
24
24
  | VII | Ecosystem Metrics Accuracy | NON-NEGOTIABLE |
25
25
  | VIII | Mandatory Delegation | NON-NEGOTIABLE |
26
26
  | IX | Safe Collaboration | NON-NEGOTIABLE |
27
+ | X | Security & Data Protection | NON-NEGOTIABLE |
27
28
 
28
29
  **Gates automáticos bloqueiam violações.** Consulte a Constitution para detalhes completos.
29
30
 
@@ -0,0 +1,233 @@
1
+ # Security & Data Protection (NON-NEGOTIABLE)
2
+
3
+ > **Constitution Article X — NON-NEGOTIABLE**
4
+ > Applies to ALL agents, ALL projects handling user data.
5
+ > Sources: OWASP Top 10, NIST CSF 2.0, CIS Controls v8, Zero Trust (SP 800-207),
6
+ > LGPD/ANPD, Supabase Security, Claude API Security, CRIABR Guide #0023,
7
+ > Historical breach analysis (Change Healthcare 192.7M, Ticketmaster 560M, 23andMe 6.9M)
8
+
9
+ ## Rule
10
+
11
+ Every project that handles user data MUST follow these security practices from the first commit. No shortcuts, no "we'll add security later." Security is NOT a feature — it is the foundation.
12
+
13
+ ## Pre-Deploy Gate — 25 Deployment Blockers
14
+
15
+ NENHUM projeto pode ir para producao sem passar por TODOS estes checks.
16
+ Os agentes DEVEM verificar e BLOQUEAR deploy se qualquer item falhar.
17
+
18
+ ### TIER 1: ABSOLUTE BLOCKERS (deploy = impossivel)
19
+
20
+ | # | Blocker | Source | Check |
21
+ |---|---------|--------|-------|
22
+ | 1 | Tabela sem RLS ativado | Supabase, OWASP A01 | `SELECT tablename FROM pg_tables WHERE NOT rowsecurity` |
23
+ | 2 | API keys hardcoded no codigo | Claude API, CIS C3 | Hook: secret-scanning.cjs |
24
+ | 3 | service_role no frontend | Supabase | Grep: `service_role` em `src/`, `app/`, `pages/` |
25
+ | 4 | Sem MFA em contas admin/cloud/prod | Breach lessons, CIS C5-6 | Manual: verificar dashboard |
26
+ | 5 | APIs sem autenticacao | OWASP A01 | Review: todo endpoint precisa de auth middleware |
27
+ | 6 | SQL com string concatenation | OWASP A05 | Hook: sql-governance.py |
28
+ | 7 | Vulnerabilidades critical/high em deps | OWASP A03, CIS C7 | `npm audit --audit-level=high` |
29
+ | 8 | Secrets detectados no codebase | CIS C3 | `npx gitleaks detect` ou hook |
30
+ | 9 | Credenciais default em producao | OWASP A02 | Review: nenhum admin/admin, test/test |
31
+ | 10 | Sem TLS (dados em transito nao encriptados) | NIST CSF, Zero Trust | Verificar HTTPS forced |
32
+
33
+ ### TIER 2: COMPLIANCE BLOCKERS (deploy = ilegal no Brasil)
34
+
35
+ | # | Blocker | Source |
36
+ |---|---------|--------|
37
+ | 11 | Sem DPO/Encarregado designado | LGPD Art. 41 |
38
+ | 12 | Sem capacidade de notificacao de breach (<3 dias) | LGPD Resolucao 15 |
39
+ | 13 | Sem mecanismo de consentimento | LGPD Art. 7-8 |
40
+ | 14 | Sem portal de direitos do titular | LGPD Art. 18 |
41
+ | 15 | Transferencia internacional sem SCCs | LGPD Art. 33 |
42
+ | 16 | Dados de criancas sem consentimento dos pais | LGPD Art. 14 |
43
+ | 17 | Sem politica de privacidade publicada | LGPD Art. 9 |
44
+
45
+ ### TIER 3: OPERATIONAL BLOCKERS (deploy = irresponsavel)
46
+
47
+ | # | Blocker | Source |
48
+ |---|---------|--------|
49
+ | 18 | Sem inventario de ativos | CIS C1-2, NIST IDENTIFY |
50
+ | 19 | Sem logging centralizado | CIS C8, OWASP A09 |
51
+ | 20 | Sem plano de resposta a incidentes | CIS C17, NIST RESPOND |
52
+ | 21 | Sem verificacao de backup nos ultimos 90 dias | CIS C11 |
53
+ | 22 | Sem processo de vulnerability scanning | CIS C7, OWASP A03 |
54
+ | 23 | Sem segmentacao de rede | Zero Trust, breach lessons |
55
+ | 24 | Sem avaliacao de seguranca de vendors | NIST GOVERN, CIS C15 |
56
+ | 25 | Sem SSL enforcement no database | Supabase, NIST CSF |
57
+
58
+ **Licao #1 dos maiores vazamentos historicos:** A AUSENCIA DE MFA foi a causa raiz das maiores breaches de 2023-2025. MFA obrigatorio e o controle de maior ROI.
59
+
60
+ ## Database Security
61
+
62
+ ### RLS (Row Level Security) — MANDATORY
63
+ ```sql
64
+ -- EVERY table with user data must have RLS enabled
65
+ ALTER TABLE {table_name} ENABLE ROW LEVEL SECURITY;
66
+
67
+ -- Policy: users only see their own data
68
+ CREATE POLICY "users_own_data"
69
+ ON {table_name}
70
+ FOR ALL
71
+ USING (auth.uid() = user_id);
72
+ ```
73
+
74
+ ### service_role — NEVER in frontend
75
+ | Key | Where | What |
76
+ |-----|-------|------|
77
+ | `anon` | Frontend/client | Respects RLS policies |
78
+ | `service_role` | Server ONLY | Bypasses RLS — full access |
79
+
80
+ ### SQL Injection — ALWAYS parameterize
81
+ ```javascript
82
+ // FORBIDDEN: string interpolation
83
+ db.query(`SELECT * FROM users WHERE name = '${input}'`);
84
+
85
+ // REQUIRED: parameterized queries
86
+ db.query('SELECT * FROM users WHERE name = $1', [input]);
87
+
88
+ // Supabase: already parameterized
89
+ supabase.from('users').select('*').eq('name', input);
90
+ ```
91
+
92
+ ### Least Privilege
93
+ - Each service uses a dedicated role with minimal permissions
94
+ - Read-only services get SELECT only
95
+ - Never connect with postgres superuser from application code
96
+
97
+ ## API Security
98
+
99
+ ### Rate Limiting — MANDATORY
100
+ ```javascript
101
+ // Every public API must have rate limiting
102
+ const limiter = rateLimit({
103
+ windowMs: 15 * 60 * 1000, // 15 minutes
104
+ max: 100, // 100 requests per window
105
+ standardHeaders: true,
106
+ });
107
+
108
+ // Stricter for auth endpoints
109
+ const authLimiter = rateLimit({
110
+ windowMs: 15 * 60 * 1000,
111
+ max: 5, // Only 5 login attempts per window
112
+ });
113
+ ```
114
+
115
+ ### Input Validation — MANDATORY
116
+ ```javascript
117
+ // Use Zod or equivalent for ALL inputs
118
+ const schema = z.object({
119
+ email: z.string().email(),
120
+ name: z.string().min(2).max(100),
121
+ });
122
+
123
+ const result = schema.safeParse(input);
124
+ if (!result.success) return res.status(400).json(result.error);
125
+ ```
126
+
127
+ ### CORS — RESTRICT origins
128
+ ```javascript
129
+ // FORBIDDEN in production
130
+ app.use(cors({ origin: '*' }));
131
+
132
+ // REQUIRED: explicit origins
133
+ app.use(cors({
134
+ origin: ['https://myapp.com', 'https://api.myapp.com'],
135
+ credentials: true,
136
+ }));
137
+ ```
138
+
139
+ ### Security Headers — helmet
140
+ ```javascript
141
+ app.use(helmet()); // Sets X-Frame-Options, CSP, HSTS, etc.
142
+ ```
143
+
144
+ ## Secrets Management
145
+
146
+ ### .env rules
147
+ - `.env` files MUST be in `.gitignore` — NEVER committed
148
+ - `.env.example` MUST exist with placeholder values
149
+ - `NEXT_PUBLIC_*` variables are PUBLIC — never put secrets in them
150
+ - Rotate keys immediately on any suspected leak
151
+
152
+ ### Platform secrets
153
+ | Platform | Where to store |
154
+ |----------|---------------|
155
+ | Vercel | Environment Variables in dashboard |
156
+ | Supabase | Vault or Edge Function secrets |
157
+ | AWS | Secrets Manager or Parameter Store |
158
+ | GitHub | Repository Secrets (Settings > Secrets) |
159
+
160
+ ## LGPD Compliance
161
+
162
+ ### Required for ALL projects with Brazilian user data
163
+ - Consent collection before processing personal data (Art. 7)
164
+ - User rights: access, correct, delete their data (Art. 18)
165
+ - DPO/Encarregado designation (Art. 37)
166
+ - Technical security measures (Art. 46)
167
+ - Breach notification to ANPD + data subjects (Art. 48)
168
+ - Data retention period defined and documented
169
+ - Audit logging for all personal data access
170
+
171
+ ## Security Checklist (verify before EVERY deploy)
172
+
173
+ ### Database
174
+ - [ ] RLS enabled on ALL tables with user data
175
+ - [ ] service_role NOT exposed in frontend code
176
+ - [ ] All queries parameterized (no string interpolation)
177
+ - [ ] Sensitive data encrypted at rest (pgcrypto or equivalent)
178
+ - [ ] Database roles follow least privilege principle
179
+
180
+ ### APIs
181
+ - [ ] Rate limiting on all public endpoints
182
+ - [ ] Auth endpoints have stricter rate limits
183
+ - [ ] Input validation with schema (Zod/Joi)
184
+ - [ ] CORS restricted to known origins
185
+ - [ ] Security headers active (helmet)
186
+
187
+ ### Secrets
188
+ - [ ] .env in .gitignore
189
+ - [ ] .env.example exists with placeholders
190
+ - [ ] No NEXT_PUBLIC_ with secrets
191
+ - [ ] No hardcoded keys in source code
192
+ - [ ] git-secrets or truffleHog scan ran
193
+
194
+ ### GitHub
195
+ - [ ] Repository is private (for production code)
196
+ - [ ] Branch protection active on main
197
+ - [ ] GitHub Secret Scanning enabled
198
+ - [ ] Dependabot configured
199
+ - [ ] CODEOWNERS protects critical files
200
+ - [ ] CI/CD uses GitHub Secrets (not hardcoded)
201
+
202
+ ### LGPD
203
+ - [ ] Consent form with explicit opt-in
204
+ - [ ] Data deletion endpoint/mechanism exists
205
+ - [ ] DPO/Encarregado designated
206
+ - [ ] Privacy policy published and accessible
207
+ - [ ] Breach notification procedure documented
208
+ - [ ] Data retention periods defined
209
+
210
+ ## Delegation
211
+
212
+ Security work MUST be delegated to the appropriate specialist:
213
+
214
+ | Request | Delegate To |
215
+ |---------|-------------|
216
+ | Threat modeling | @cyber-orqx → Shield |
217
+ | Penetration testing | @cyber-orqx → Breach |
218
+ | Incident response | @cyber-orqx → Rapid |
219
+ | LGPD/compliance | @cyber-orqx → Govern |
220
+ | Cloud security | @cyber-orqx → Nimbus |
221
+ | Database security/RLS | @data-engineer (Dara) |
222
+ | Application security | @developer (Dex) |
223
+
224
+ ## Anti-Patterns (FORBIDDEN)
225
+
226
+ - Using superuser credentials in application code
227
+ - Disabling RLS "temporarily" (it never gets re-enabled)
228
+ - Hardcoding API keys "just for testing"
229
+ - Using `origin: '*'` in CORS
230
+ - Skipping input validation on "internal" APIs
231
+ - Storing passwords in plain text
232
+ - Logging personal data (PII) without masking
233
+ - "We'll add security later" — security is from day one