@conarium-ai/core 0.2.11 → 0.2.13
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/CHANGELOG.md +149 -1
- package/LICENSE +21 -21
- package/LIMITATIONS.md +36 -2
- package/LIMITATIONS.tr.md +25 -2
- package/SECURITY.md +1 -0
- package/bin/conarium-coverage.mjs +89 -6
- package/bin/conarium-doctor.mjs +62 -0
- package/bin/conarium-verify.mjs +110 -51
- package/dist/anchor.d.ts +11 -0
- package/dist/anchor.d.ts.map +1 -1
- package/dist/anchor.js +27 -0
- package/dist/anchor.js.map +1 -1
- package/dist/audit.d.ts +4 -0
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +136 -33
- package/dist/audit.js.map +1 -1
- package/dist/config.d.ts +28 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +51 -1
- package/dist/config.js.map +1 -1
- package/dist/connectors/custom-sql.d.ts +22 -0
- package/dist/connectors/custom-sql.d.ts.map +1 -0
- package/dist/connectors/custom-sql.js +67 -0
- package/dist/connectors/custom-sql.js.map +1 -0
- package/dist/connectors/index.d.ts +1 -0
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +5 -1
- package/dist/connectors/index.js.map +1 -1
- package/dist/connectors/openapi.d.ts +14 -1
- package/dist/connectors/openapi.d.ts.map +1 -1
- package/dist/connectors/openapi.js +78 -6
- package/dist/connectors/openapi.js.map +1 -1
- package/dist/connectors/postgres.js +8 -8
- package/dist/connectors/supabase_rest.d.ts.map +1 -1
- package/dist/connectors/supabase_rest.js +0 -1
- package/dist/connectors/supabase_rest.js.map +1 -1
- package/dist/console-receipts.d.ts +12 -1
- package/dist/console-receipts.d.ts.map +1 -1
- package/dist/console-receipts.js +14 -2
- package/dist/console-receipts.js.map +1 -1
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +15 -4
- package/dist/console.js.map +1 -1
- package/dist/coverage.d.ts +17 -1
- package/dist/coverage.d.ts.map +1 -1
- package/dist/coverage.js +30 -3
- package/dist/coverage.js.map +1 -1
- package/dist/digit_pii.d.ts.map +1 -1
- package/dist/digit_pii.js +24 -5
- package/dist/digit_pii.js.map +1 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +0 -1
- package/dist/executor.js.map +1 -1
- package/dist/governance.d.ts +2 -0
- package/dist/governance.d.ts.map +1 -1
- package/dist/governance.js +23 -8
- package/dist/governance.js.map +1 -1
- package/dist/http.d.ts +11 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +87 -7
- package/dist/http.js.map +1 -1
- package/dist/iban.d.ts.map +1 -1
- package/dist/iban.js +6 -3
- package/dist/iban.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +5 -0
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +22 -7
- package/dist/keys.js.map +1 -1
- package/dist/mask-text.d.ts +11 -0
- package/dist/mask-text.d.ts.map +1 -0
- package/dist/mask-text.js +42 -0
- package/dist/mask-text.js.map +1 -0
- package/dist/receipt-view.d.ts +13 -0
- package/dist/receipt-view.d.ts.map +1 -1
- package/dist/receipt-view.js +28 -5
- package/dist/receipt-view.js.map +1 -1
- package/dist/search_policy.d.ts.map +1 -1
- package/dist/search_policy.js +8 -4
- package/dist/search_policy.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +111 -20
- package/dist/server.js.map +1 -1
- package/dist/sql-executor.d.ts +14 -0
- package/dist/sql-executor.d.ts.map +1 -0
- package/dist/sql-executor.js +75 -0
- package/dist/sql-executor.js.map +1 -0
- package/dist/sql-gate/mssql.d.ts.map +1 -1
- package/dist/sql-gate/mssql.js +36 -2
- package/dist/sql-gate/mssql.js.map +1 -1
- package/dist/sql-gate/oracle.d.ts.map +1 -1
- package/dist/sql-gate/oracle.js +24 -3
- package/dist/sql-gate/oracle.js.map +1 -1
- package/dist/sql-gate/rules.d.ts +19 -1
- package/dist/sql-gate/rules.d.ts.map +1 -1
- package/dist/sql-gate/rules.js +116 -7
- package/dist/sql-gate/rules.js.map +1 -1
- package/dist/table-unavailable.d.ts +12 -0
- package/dist/table-unavailable.d.ts.map +1 -0
- package/dist/table-unavailable.js +32 -0
- package/dist/table-unavailable.js.map +1 -0
- package/dist/types.d.ts +10 -3
- package/dist/types.d.ts.map +1 -1
- package/docs/API-STABILITY.md +4 -4
- package/docs/ARCHITECTURE.md +42 -42
- package/docs/BENCHMARK.md +20 -0
- package/docs/RECEIPT-SPEC.md +17 -11
- package/docs/benchmarks/concurrency-20260814.json +38 -0
- package/docs/plans/2026-07-02-redteam-harness.md +416 -416
- package/docs/security/NPM-PROVENANCE.md +64 -0
- package/docs/security/THREAT-MODEL.md +18 -0
- package/docs/specs/2026-07-02-redteam-harness-design.md +90 -90
- package/docs/superpowers/TODO-gate1-f4.md +23 -23
- package/docs/superpowers/plans/2026-07-29-conarium-receipt-plan.md +200 -200
- package/docs/superpowers/specs/2026-07-29-conarium-receipt-design.md +202 -202
- package/examples/claude-desktop-config.json +9 -9
- package/examples/cursor-mcp-settings.json +10 -10
- package/examples/custom-sql/README.md +50 -0
- package/examples/custom-sql/conarium.config.json +22 -0
- package/examples/custom-sql/memory-executor.mjs +16 -0
- package/package.json +8 -4
- package/public/app.js +378 -378
- package/public/index.html +160 -160
- package/public/style.css +504 -504
- package/scripts/benchmark-concurrency.mjs +133 -0
- package/scripts/conarium_sabah_brief.mjs +107 -107
- package/scripts/start-mcp-c1.mjs +93 -93
- package/test-vectors/sql-gate/LAST-RUN.json +1 -1
- package/test-vectors/sql-gate/vectors.json +28 -0
- package/dist/openapi_connector.d.ts +0 -6
- package/dist/openapi_connector.d.ts.map +0 -1
- package/dist/openapi_connector.js +0 -145
- package/dist/openapi_connector.js.map +0 -1
- package/docs/audit/2026-08-14-security-scan.md +0 -48
- package/docs/audit/2026-08-14-surface-sync.md +0 -34
|
@@ -1,416 +1,416 @@
|
|
|
1
|
-
# Conarium Red-Team Harness v1 — Implementation Plan
|
|
2
|
-
|
|
3
|
-
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
|
4
|
-
|
|
5
|
-
**Goal:** NEO'nun Conarium'un `Governance` motoruna saldırıp savunmayı ölçen, DEFENDED/BYPASSED raporu üreten red-team harness'i.
|
|
6
|
-
|
|
7
|
-
**Architecture:** `nexus/redteam/` altında izole modüller. Saldırı case'leri (`AttackCase`) doğrudan `Governance` sınıfını çağırır: sorgu-zamanı `guardQuery` (PolicyError=blok), sonuç-zamanı `redact` (PII maske). Runner sınıflar, report üretir.
|
|
8
|
-
|
|
9
|
-
**Tech Stack:** TypeScript (ESM/NodeNext), tsx, vitest.
|
|
10
|
-
|
|
11
|
-
## Global Constraints
|
|
12
|
-
|
|
13
|
-
- ESM/NodeNext: **tüm importlar `.js` uzantısı kullanır** (repo konvansiyonu; örn. `import { Governance } from '../src/governance.js'`).
|
|
14
|
-
- `Governance` API (kanıtlı): `new Governance(policy: GovernancePolicy)`; `guardQuery(sql): GuardedQuery` — bloklarsa `PolicyError` fırlatır; `redact(result: QueryResult): GovernedQueryResult` — `QueryResult = { rows, rowCount, fields, sql? }`.
|
|
15
|
-
- Harness Conarium'u DEĞİŞTİRMEZ; sadece dışarıdan çağırır (salt-okunur saldırı).
|
|
16
|
-
- Test runner: `vitest run` (`npm test`).
|
|
17
|
-
- Dürüstlük: encode-base64 PII-exfil case'i **BYPASSED beklenir** (gerçek delik); harness bunu doğru tespit etmeli.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
### Task 0: Test altyapısı + redteam/types.ts
|
|
22
|
-
|
|
23
|
-
**Files:**
|
|
24
|
-
- Modify: `package.json` (devDep vitest, script test)
|
|
25
|
-
- Create: `redteam/types.ts`
|
|
26
|
-
|
|
27
|
-
- [ ] **Step 1:** `package.json` → `devDependencies`'e `"vitest": "^2.0.0"`, `scripts`'e `"test": "vitest run"` ekle, sonra `npm install`.
|
|
28
|
-
|
|
29
|
-
- [ ] **Step 2:** `redteam/types.ts` oluştur:
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
import type { Governance } from '../src/governance.js';
|
|
33
|
-
|
|
34
|
-
export type AttackCategory = 'write_smuggle' | 'unauthorized_table' | 'multi_statement' | 'pii_exfil';
|
|
35
|
-
export type Severity = 'CRITICAL' | 'HIGH' | 'MEDIUM';
|
|
36
|
-
|
|
37
|
-
export interface AttackCase {
|
|
38
|
-
id: string;
|
|
39
|
-
category: AttackCategory;
|
|
40
|
-
severity: Severity;
|
|
41
|
-
description: string;
|
|
42
|
-
run(gov: Governance): { defended: boolean; detail: string };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface AttackResult {
|
|
46
|
-
id: string;
|
|
47
|
-
category: AttackCategory;
|
|
48
|
-
severity: Severity;
|
|
49
|
-
description: string;
|
|
50
|
-
defended: boolean;
|
|
51
|
-
detail: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface RedTeamReport {
|
|
55
|
-
ranAt: string;
|
|
56
|
-
total: number;
|
|
57
|
-
defended: number;
|
|
58
|
-
bypassed: number;
|
|
59
|
-
results: AttackResult[];
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
- [ ] **Step 3:** Doğrula: `npx tsx -e "import('./redteam/types.js').then(()=>console.log('types OK'))"` → "types OK"
|
|
64
|
-
- [ ] **Step 4:** Commit: `git add package.json redteam/types.ts && git commit -m "chore(redteam): test altyapısı + tipler"`
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
### Task 1: attacks/queryTime.ts (sorgu-zamanı saldırılar)
|
|
69
|
-
|
|
70
|
-
**Files:**
|
|
71
|
-
- Create: `redteam/attacks/queryTime.ts`
|
|
72
|
-
- Test: `redteam/attacks/queryTime.test.ts`
|
|
73
|
-
|
|
74
|
-
**Interfaces:**
|
|
75
|
-
- Produces: `queryTimeAttacks: AttackCase[]`
|
|
76
|
-
|
|
77
|
-
- [ ] **Step 1: Testi yaz:**
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
import { describe, it, expect } from 'vitest';
|
|
81
|
-
import { Governance } from '../../src/governance.js';
|
|
82
|
-
import { queryTimeAttacks } from './queryTime.js';
|
|
83
|
-
|
|
84
|
-
const gov = new Governance({ allowTables: ['public.customers'], maxRows: 100 });
|
|
85
|
-
|
|
86
|
-
describe('queryTimeAttacks', () => {
|
|
87
|
-
it('tüm write/multi-statement/yetkisiz-tablo saldırıları DEFENDED (bloklanır)', () => {
|
|
88
|
-
for (const atk of queryTimeAttacks) {
|
|
89
|
-
const r = atk.run(gov);
|
|
90
|
-
expect(r.defended, `${atk.id} savunulmalıydı: ${r.detail}`).toBe(true);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
- [ ] **Step 2:** `npx vitest run redteam/attacks/queryTime.test.ts` → FAIL
|
|
97
|
-
- [ ] **Step 3: Uygula:**
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
import type { AttackCase } from '../types.js';
|
|
101
|
-
import type { Governance } from '../../src/governance.js';
|
|
102
|
-
|
|
103
|
-
function shouldBlock(gov: Governance, sql: string): { defended: boolean; detail: string } {
|
|
104
|
-
try {
|
|
105
|
-
gov.guardQuery(sql);
|
|
106
|
-
return { defended: false, detail: `BYPASS — guardQuery izin verdi: ${sql}` };
|
|
107
|
-
} catch (e: any) {
|
|
108
|
-
return { defended: true, detail: `DEFENDED — ${e.message}` };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export const queryTimeAttacks: AttackCase[] = [
|
|
113
|
-
{ id: 'wr-delete', category: 'write_smuggle', severity: 'CRITICAL', description: 'Düz DELETE',
|
|
114
|
-
run: g => shouldBlock(g, 'DELETE FROM customers') },
|
|
115
|
-
{ id: 'wr-drop', category: 'write_smuggle', severity: 'CRITICAL', description: 'DROP TABLE',
|
|
116
|
-
run: g => shouldBlock(g, 'DROP TABLE customers') },
|
|
117
|
-
{ id: 'wr-stacked', category: 'multi_statement', severity: 'CRITICAL', description: 'Stacked query ile gizli write',
|
|
118
|
-
run: g => shouldBlock(g, 'SELECT 1; DROP TABLE customers') },
|
|
119
|
-
{ id: 'wr-update-comment', category: 'write_smuggle', severity: 'HIGH', description: 'Yorumla gizlenmiş UPDATE',
|
|
120
|
-
run: g => shouldBlock(g, 'UPDATE customers SET name=1 -- SELECT') },
|
|
121
|
-
{ id: 'tbl-unauth', category: 'unauthorized_table', severity: 'HIGH', description: 'İzin listesi dışı tabloya erişim',
|
|
122
|
-
run: g => shouldBlock(g, 'SELECT * FROM secret.admin_users') },
|
|
123
|
-
];
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
- [ ] **Step 4:** `npx vitest run redteam/attacks/queryTime.test.ts` → PASS
|
|
127
|
-
- [ ] **Step 5:** Commit: `git add redteam/attacks/queryTime.* && git commit -m "feat(redteam): sorgu-zamanı saldırılar"`
|
|
128
|
-
|
|
129
|
-
---
|
|
130
|
-
|
|
131
|
-
### Task 2: attacks/resultTime.ts (PII exfil — encode bypass'ı yakalar)
|
|
132
|
-
|
|
133
|
-
**Files:**
|
|
134
|
-
- Create: `redteam/attacks/resultTime.ts`
|
|
135
|
-
- Test: `redteam/attacks/resultTime.test.ts`
|
|
136
|
-
|
|
137
|
-
**Interfaces:**
|
|
138
|
-
- Produces: `resultTimeAttacks: AttackCase[]`
|
|
139
|
-
|
|
140
|
-
- [ ] **Step 1: Testi yaz:**
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
import { describe, it, expect } from 'vitest';
|
|
144
|
-
import { Governance } from '../../src/governance.js';
|
|
145
|
-
import { resultTimeAttacks } from './resultTime.js';
|
|
146
|
-
|
|
147
|
-
const gov = new Governance({ maskColumns: ['*.email'], maxRows: 100 });
|
|
148
|
-
|
|
149
|
-
describe('resultTimeAttacks', () => {
|
|
150
|
-
it('düz-metin PII DEFENDED (maskelenir)', () => {
|
|
151
|
-
const plain = resultTimeAttacks.find(a => a.id === 'pii-plaintext')!;
|
|
152
|
-
expect(plain.run(gov).defended).toBe(true);
|
|
153
|
-
});
|
|
154
|
-
it('base64-encode PII BYPASSED (harness gerçek deliği yakalar)', () => {
|
|
155
|
-
const enc = resultTimeAttacks.find(a => a.id === 'pii-base64')!;
|
|
156
|
-
expect(enc.run(gov).defended).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
- [ ] **Step 2:** `npx vitest run redteam/attacks/resultTime.test.ts` → FAIL
|
|
162
|
-
- [ ] **Step 3: Uygula:**
|
|
163
|
-
|
|
164
|
-
```ts
|
|
165
|
-
import type { AttackCase } from '../types.js';
|
|
166
|
-
import type { Governance } from '../../src/governance.js';
|
|
167
|
-
import type { QueryResult, GovernedQueryResult } from '../../src/types.js';
|
|
168
|
-
|
|
169
|
-
const PII_EMAIL = 'ahmet@wearu.app';
|
|
170
|
-
const PII_RE = /@[a-z0-9.-]+\.[a-z]{2,}|\b[1-9][0-9]{10}\b/i;
|
|
171
|
-
|
|
172
|
-
function containsRecoverablePII(governed: GovernedQueryResult): boolean {
|
|
173
|
-
const flat = JSON.stringify(governed.rows);
|
|
174
|
-
if (PII_RE.test(flat)) return true; // düz PII sağ kaldı
|
|
175
|
-
for (const row of governed.rows) {
|
|
176
|
-
for (const v of Object.values(row)) {
|
|
177
|
-
if (typeof v === 'string' && /^[A-Za-z0-9+/]{8,}={0,2}$/.test(v)) {
|
|
178
|
-
try {
|
|
179
|
-
const dec = Buffer.from(v, 'base64').toString('utf8');
|
|
180
|
-
if (PII_RE.test(dec)) return true; // encode ile kaçırılmış PII
|
|
181
|
-
} catch { /* base64 değil */ }
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function tryRedact(gov: Governance, rows: Record<string, unknown>[]): { defended: boolean; detail: string } {
|
|
189
|
-
const result: QueryResult = { rows, rowCount: rows.length, fields: Object.keys(rows[0] ?? {}) };
|
|
190
|
-
const governed = gov.redact(result);
|
|
191
|
-
const leaked = containsRecoverablePII(governed);
|
|
192
|
-
return {
|
|
193
|
-
defended: !leaked,
|
|
194
|
-
detail: leaked
|
|
195
|
-
? `BYPASS — PII geri-kazanılabilir: ${JSON.stringify(governed.rows)}`
|
|
196
|
-
: `DEFENDED — maskelendi: ${JSON.stringify(governed.rows)}`,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export const resultTimeAttacks: AttackCase[] = [
|
|
201
|
-
{ id: 'pii-plaintext', category: 'pii_exfil', severity: 'HIGH', description: 'Düz-metin e-posta çıktısı',
|
|
202
|
-
run: g => tryRedact(g, [{ email: PII_EMAIL }]) },
|
|
203
|
-
{ id: 'pii-base64', category: 'pii_exfil', severity: 'CRITICAL', description: 'encode(email,base64) ile maske atlatma',
|
|
204
|
-
run: g => tryRedact(g, [{ leak: Buffer.from(PII_EMAIL).toString('base64') }]) },
|
|
205
|
-
];
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
- [ ] **Step 4:** `npx vitest run redteam/attacks/resultTime.test.ts` → PASS
|
|
209
|
-
- [ ] **Step 5:** Commit: `git add redteam/attacks/resultTime.* && git commit -m "feat(redteam): sonuç-zamanı PII-exfil (encode bypass tespiti)"`
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
### Task 3: runner.ts
|
|
214
|
-
|
|
215
|
-
**Files:**
|
|
216
|
-
- Create: `redteam/runner.ts`
|
|
217
|
-
- Test: `redteam/runner.test.ts`
|
|
218
|
-
|
|
219
|
-
**Interfaces:**
|
|
220
|
-
- Consumes: `AttackCase`, `RedTeamReport`, `Governance`
|
|
221
|
-
- Produces: `runRedTeam(gov: Governance, attacks: AttackCase[], now?: Date): RedTeamReport`
|
|
222
|
-
|
|
223
|
-
- [ ] **Step 1: Testi yaz:**
|
|
224
|
-
|
|
225
|
-
```ts
|
|
226
|
-
import { describe, it, expect } from 'vitest';
|
|
227
|
-
import { Governance } from '../src/governance.js';
|
|
228
|
-
import { runRedTeam } from './runner.js';
|
|
229
|
-
import type { AttackCase } from './types.js';
|
|
230
|
-
|
|
231
|
-
const fake: AttackCase[] = [
|
|
232
|
-
{ id: 'a', category: 'write_smuggle', severity: 'CRITICAL', description: 'x', run: () => ({ defended: true, detail: 'ok' }) },
|
|
233
|
-
{ id: 'b', category: 'pii_exfil', severity: 'CRITICAL', description: 'y', run: () => ({ defended: false, detail: 'leak' }) },
|
|
234
|
-
];
|
|
235
|
-
|
|
236
|
-
describe('runRedTeam', () => {
|
|
237
|
-
it('defended/bypassed sayar', () => {
|
|
238
|
-
const rep = runRedTeam(new Governance({}), fake, new Date('2026-07-02T00:00:00Z'));
|
|
239
|
-
expect(rep.total).toBe(2);
|
|
240
|
-
expect(rep.defended).toBe(1);
|
|
241
|
-
expect(rep.bypassed).toBe(1);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
- [ ] **Step 2:** `npx vitest run redteam/runner.test.ts` → FAIL
|
|
247
|
-
- [ ] **Step 3: Uygula:**
|
|
248
|
-
|
|
249
|
-
```ts
|
|
250
|
-
import type { Governance } from '../src/governance.js';
|
|
251
|
-
import type { AttackCase, AttackResult, RedTeamReport } from './types.js';
|
|
252
|
-
|
|
253
|
-
export function runRedTeam(gov: Governance, attacks: AttackCase[], now: Date = new Date()): RedTeamReport {
|
|
254
|
-
const results: AttackResult[] = attacks.map(atk => {
|
|
255
|
-
const { defended, detail } = atk.run(gov);
|
|
256
|
-
return { id: atk.id, category: atk.category, severity: atk.severity, description: atk.description, defended, detail };
|
|
257
|
-
});
|
|
258
|
-
return {
|
|
259
|
-
ranAt: now.toISOString(),
|
|
260
|
-
total: results.length,
|
|
261
|
-
defended: results.filter(r => r.defended).length,
|
|
262
|
-
bypassed: results.filter(r => !r.defended).length,
|
|
263
|
-
results,
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
- [ ] **Step 4:** `npx vitest run redteam/runner.test.ts` → PASS
|
|
269
|
-
- [ ] **Step 5:** Commit: `git add redteam/runner.* && git commit -m "feat(redteam): runner + sınıflandırma"`
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
### Task 4: report.ts
|
|
274
|
-
|
|
275
|
-
**Files:**
|
|
276
|
-
- Create: `redteam/report.ts`
|
|
277
|
-
- Test: `redteam/report.test.ts`
|
|
278
|
-
|
|
279
|
-
**Interfaces:**
|
|
280
|
-
- Consumes: `RedTeamReport`
|
|
281
|
-
- Produces: `renderMarkdown(report: RedTeamReport): string`
|
|
282
|
-
|
|
283
|
-
- [ ] **Step 1: Testi yaz:**
|
|
284
|
-
|
|
285
|
-
```ts
|
|
286
|
-
import { describe, it, expect } from 'vitest';
|
|
287
|
-
import { renderMarkdown } from './report.js';
|
|
288
|
-
import type { RedTeamReport } from './types.js';
|
|
289
|
-
|
|
290
|
-
const rep: RedTeamReport = {
|
|
291
|
-
ranAt: '2026-07-02T00:00:00.000Z', total: 2, defended: 1, bypassed: 1,
|
|
292
|
-
results: [
|
|
293
|
-
{ id: 'a', category: 'write_smuggle', severity: 'CRITICAL', description: 'x', defended: true, detail: 'ok' },
|
|
294
|
-
{ id: 'b', category: 'pii_exfil', severity: 'CRITICAL', description: 'y', defended: false, detail: 'leak' },
|
|
295
|
-
],
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
describe('renderMarkdown', () => {
|
|
299
|
-
it('savunma karnesi + BYPASSED bulgularını listeler', () => {
|
|
300
|
-
const md = renderMarkdown(rep);
|
|
301
|
-
expect(md).toContain('1/2 savundu');
|
|
302
|
-
expect(md).toContain('BYPASS');
|
|
303
|
-
expect(md).toContain('b');
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
- [ ] **Step 2:** `npx vitest run redteam/report.test.ts` → FAIL
|
|
309
|
-
- [ ] **Step 3: Uygula:**
|
|
310
|
-
|
|
311
|
-
```ts
|
|
312
|
-
import type { RedTeamReport } from './types.js';
|
|
313
|
-
|
|
314
|
-
export function renderMarkdown(r: RedTeamReport): string {
|
|
315
|
-
const l: string[] = [];
|
|
316
|
-
l.push(`# Conarium Savunma Karnesi (NEO Red-Team)`);
|
|
317
|
-
l.push(`Tarih: ${r.ranAt}`, '');
|
|
318
|
-
l.push(`**Sonuç: ${r.defended}/${r.total} savundu, ${r.bypassed} bypass.**`, '');
|
|
319
|
-
const bypassed = r.results.filter(x => !x.defended);
|
|
320
|
-
if (bypassed.length) {
|
|
321
|
-
l.push(`## 🚨 Sertleştirilecekler (BYPASS)`);
|
|
322
|
-
for (const b of bypassed) l.push(`- [${b.severity}] ${b.id} — ${b.description}\n - ${b.detail}`);
|
|
323
|
-
l.push('');
|
|
324
|
-
}
|
|
325
|
-
l.push(`## ✅ Savunulanlar (DEFENDED)`);
|
|
326
|
-
for (const d of r.results.filter(x => x.defended)) l.push(`- [${d.severity}] ${d.id} — ${d.description}`);
|
|
327
|
-
return l.join('\n');
|
|
328
|
-
}
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
- [ ] **Step 4:** `npx vitest run redteam/report.test.ts` → PASS
|
|
332
|
-
- [ ] **Step 5:** Commit: `git add redteam/report.* && git commit -m "feat(redteam): savunma karnesi render"`
|
|
333
|
-
|
|
334
|
-
---
|
|
335
|
-
|
|
336
|
-
### Task 5: index.ts (orkestratör + CLI)
|
|
337
|
-
|
|
338
|
-
**Files:**
|
|
339
|
-
- Create: `redteam/index.ts`
|
|
340
|
-
- Test: `redteam/index.test.ts`
|
|
341
|
-
|
|
342
|
-
**Interfaces:**
|
|
343
|
-
- Consumes: `runRedTeam`, `queryTimeAttacks`, `resultTimeAttacks`, `Governance`
|
|
344
|
-
- Produces: `allAttacks: AttackCase[]`, `redTeamConarium(policy): RedTeamReport`
|
|
345
|
-
|
|
346
|
-
- [ ] **Step 1: Testi yaz:**
|
|
347
|
-
|
|
348
|
-
```ts
|
|
349
|
-
import { describe, it, expect } from 'vitest';
|
|
350
|
-
import { redTeamConarium, allAttacks } from './index.js';
|
|
351
|
-
|
|
352
|
-
describe('redTeamConarium', () => {
|
|
353
|
-
it('gerçek Governance ile çalışır: write DEFENDED + base64 PII BYPASS', () => {
|
|
354
|
-
const rep = redTeamConarium({ allowTables: ['public.customers'], maskColumns: ['*.email'] });
|
|
355
|
-
expect(rep.total).toBe(allAttacks.length);
|
|
356
|
-
expect(rep.results.find(r => r.id === 'wr-delete')!.defended).toBe(true);
|
|
357
|
-
expect(rep.results.find(r => r.id === 'pii-base64')!.defended).toBe(false);
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
- [ ] **Step 2:** `npx vitest run redteam/index.test.ts` → FAIL
|
|
363
|
-
- [ ] **Step 3: Uygula:**
|
|
364
|
-
|
|
365
|
-
```ts
|
|
366
|
-
import { Governance } from '../src/governance.js';
|
|
367
|
-
import type { GovernancePolicy } from '../src/types.js';
|
|
368
|
-
import type { AttackCase, RedTeamReport } from './types.js';
|
|
369
|
-
import { queryTimeAttacks } from './attacks/queryTime.js';
|
|
370
|
-
import { resultTimeAttacks } from './attacks/resultTime.js';
|
|
371
|
-
import { runRedTeam } from './runner.js';
|
|
372
|
-
import { renderMarkdown } from './report.js';
|
|
373
|
-
|
|
374
|
-
export const allAttacks: AttackCase[] = [...queryTimeAttacks, ...resultTimeAttacks];
|
|
375
|
-
|
|
376
|
-
export function redTeamConarium(policy: GovernancePolicy): RedTeamReport {
|
|
377
|
-
return runRedTeam(new Governance(policy), allAttacks);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// CLI: npx tsx redteam/index.ts
|
|
381
|
-
const isMain = import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('index.ts');
|
|
382
|
-
if (isMain) {
|
|
383
|
-
const rep = redTeamConarium({ allowTables: ['public.customers'], maskColumns: ['*.email'], maxRows: 100 });
|
|
384
|
-
console.log(renderMarkdown(rep));
|
|
385
|
-
}
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
- [ ] **Step 4:** `npx vitest run redteam/index.test.ts` → PASS. Sonra tüm suite: `npm test` → hepsi PASS.
|
|
389
|
-
- [ ] **Step 5:** Commit: `git add redteam/index.* && git commit -m "feat(redteam): orkestratör + CLI"`
|
|
390
|
-
|
|
391
|
-
---
|
|
392
|
-
|
|
393
|
-
### Task 6: Canlı çalıştırma (demo materyali)
|
|
394
|
-
|
|
395
|
-
**Files:**
|
|
396
|
-
- (kod yok — canlı doğrulama)
|
|
397
|
-
|
|
398
|
-
- [ ] **Step 1: Harness'i gerçek Conarium'a karşı çalıştır:**
|
|
399
|
-
|
|
400
|
-
Run: `npx tsx redteam/index.ts`
|
|
401
|
-
|
|
402
|
-
Beklenen: Markdown "Savunma Karnesi" — write/unauthorized saldırıları DEFENDED, `pii-base64` BYPASS olarak listelenir (Conarium'un gerçek deliği = Faz 1 demosunun ham materyali + Faz 2 sertleştirme girdisi).
|
|
403
|
-
|
|
404
|
-
- [ ] **Step 2:** Raporu kaydet: `npx tsx redteam/index.ts > redteam/last-report.md` (gitignore'a `redteam/last-report.md` ekle).
|
|
405
|
-
|
|
406
|
-
---
|
|
407
|
-
|
|
408
|
-
## Self-Review
|
|
409
|
-
|
|
410
|
-
**Spec coverage:** ✅ query-time saldırılar (T1), result-time PII-exfil + encode bypass (T2), runner sınıflandırma (T3), savunma karnesi (T4), orkestratör+CLI (T5), canlı demo (T6). Test stratejisi her task'ta.
|
|
411
|
-
|
|
412
|
-
**Placeholder scan:** Tüm adımlarda gerçek kod; TODO/TBD yok.
|
|
413
|
-
|
|
414
|
-
**Type consistency:** `AttackCase.run(gov): {defended, detail}` T0'da tanımlı, T1/T2/T5 aynı kullanıyor. `runRedTeam(gov, attacks, now?)` T3↔T5 tutarlı. `QueryResult` `{rows,rowCount,fields}` gerçek tiple (types.ts:63) uyumlu. Importlar `.js` uzantılı (repo konvansiyonu).
|
|
415
|
-
|
|
416
|
-
**Not:** encode-base64 case'i bilerek BYPASS beklenir — bu Conarium'un gerçek deliği; harness'in görevi onu doğru yakalamak (Conarium'u kusursuz göstermek değil).
|
|
1
|
+
# Conarium Red-Team Harness v1 — Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
|
4
|
+
|
|
5
|
+
**Goal:** NEO'nun Conarium'un `Governance` motoruna saldırıp savunmayı ölçen, DEFENDED/BYPASSED raporu üreten red-team harness'i.
|
|
6
|
+
|
|
7
|
+
**Architecture:** `nexus/redteam/` altında izole modüller. Saldırı case'leri (`AttackCase`) doğrudan `Governance` sınıfını çağırır: sorgu-zamanı `guardQuery` (PolicyError=blok), sonuç-zamanı `redact` (PII maske). Runner sınıflar, report üretir.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** TypeScript (ESM/NodeNext), tsx, vitest.
|
|
10
|
+
|
|
11
|
+
## Global Constraints
|
|
12
|
+
|
|
13
|
+
- ESM/NodeNext: **tüm importlar `.js` uzantısı kullanır** (repo konvansiyonu; örn. `import { Governance } from '../src/governance.js'`).
|
|
14
|
+
- `Governance` API (kanıtlı): `new Governance(policy: GovernancePolicy)`; `guardQuery(sql): GuardedQuery` — bloklarsa `PolicyError` fırlatır; `redact(result: QueryResult): GovernedQueryResult` — `QueryResult = { rows, rowCount, fields, sql? }`.
|
|
15
|
+
- Harness Conarium'u DEĞİŞTİRMEZ; sadece dışarıdan çağırır (salt-okunur saldırı).
|
|
16
|
+
- Test runner: `vitest run` (`npm test`).
|
|
17
|
+
- Dürüstlük: encode-base64 PII-exfil case'i **BYPASSED beklenir** (gerçek delik); harness bunu doğru tespit etmeli.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
### Task 0: Test altyapısı + redteam/types.ts
|
|
22
|
+
|
|
23
|
+
**Files:**
|
|
24
|
+
- Modify: `package.json` (devDep vitest, script test)
|
|
25
|
+
- Create: `redteam/types.ts`
|
|
26
|
+
|
|
27
|
+
- [ ] **Step 1:** `package.json` → `devDependencies`'e `"vitest": "^2.0.0"`, `scripts`'e `"test": "vitest run"` ekle, sonra `npm install`.
|
|
28
|
+
|
|
29
|
+
- [ ] **Step 2:** `redteam/types.ts` oluştur:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import type { Governance } from '../src/governance.js';
|
|
33
|
+
|
|
34
|
+
export type AttackCategory = 'write_smuggle' | 'unauthorized_table' | 'multi_statement' | 'pii_exfil';
|
|
35
|
+
export type Severity = 'CRITICAL' | 'HIGH' | 'MEDIUM';
|
|
36
|
+
|
|
37
|
+
export interface AttackCase {
|
|
38
|
+
id: string;
|
|
39
|
+
category: AttackCategory;
|
|
40
|
+
severity: Severity;
|
|
41
|
+
description: string;
|
|
42
|
+
run(gov: Governance): { defended: boolean; detail: string };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface AttackResult {
|
|
46
|
+
id: string;
|
|
47
|
+
category: AttackCategory;
|
|
48
|
+
severity: Severity;
|
|
49
|
+
description: string;
|
|
50
|
+
defended: boolean;
|
|
51
|
+
detail: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface RedTeamReport {
|
|
55
|
+
ranAt: string;
|
|
56
|
+
total: number;
|
|
57
|
+
defended: number;
|
|
58
|
+
bypassed: number;
|
|
59
|
+
results: AttackResult[];
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- [ ] **Step 3:** Doğrula: `npx tsx -e "import('./redteam/types.js').then(()=>console.log('types OK'))"` → "types OK"
|
|
64
|
+
- [ ] **Step 4:** Commit: `git add package.json redteam/types.ts && git commit -m "chore(redteam): test altyapısı + tipler"`
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### Task 1: attacks/queryTime.ts (sorgu-zamanı saldırılar)
|
|
69
|
+
|
|
70
|
+
**Files:**
|
|
71
|
+
- Create: `redteam/attacks/queryTime.ts`
|
|
72
|
+
- Test: `redteam/attacks/queryTime.test.ts`
|
|
73
|
+
|
|
74
|
+
**Interfaces:**
|
|
75
|
+
- Produces: `queryTimeAttacks: AttackCase[]`
|
|
76
|
+
|
|
77
|
+
- [ ] **Step 1: Testi yaz:**
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { describe, it, expect } from 'vitest';
|
|
81
|
+
import { Governance } from '../../src/governance.js';
|
|
82
|
+
import { queryTimeAttacks } from './queryTime.js';
|
|
83
|
+
|
|
84
|
+
const gov = new Governance({ allowTables: ['public.customers'], maxRows: 100 });
|
|
85
|
+
|
|
86
|
+
describe('queryTimeAttacks', () => {
|
|
87
|
+
it('tüm write/multi-statement/yetkisiz-tablo saldırıları DEFENDED (bloklanır)', () => {
|
|
88
|
+
for (const atk of queryTimeAttacks) {
|
|
89
|
+
const r = atk.run(gov);
|
|
90
|
+
expect(r.defended, `${atk.id} savunulmalıydı: ${r.detail}`).toBe(true);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- [ ] **Step 2:** `npx vitest run redteam/attacks/queryTime.test.ts` → FAIL
|
|
97
|
+
- [ ] **Step 3: Uygula:**
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import type { AttackCase } from '../types.js';
|
|
101
|
+
import type { Governance } from '../../src/governance.js';
|
|
102
|
+
|
|
103
|
+
function shouldBlock(gov: Governance, sql: string): { defended: boolean; detail: string } {
|
|
104
|
+
try {
|
|
105
|
+
gov.guardQuery(sql);
|
|
106
|
+
return { defended: false, detail: `BYPASS — guardQuery izin verdi: ${sql}` };
|
|
107
|
+
} catch (e: any) {
|
|
108
|
+
return { defended: true, detail: `DEFENDED — ${e.message}` };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const queryTimeAttacks: AttackCase[] = [
|
|
113
|
+
{ id: 'wr-delete', category: 'write_smuggle', severity: 'CRITICAL', description: 'Düz DELETE',
|
|
114
|
+
run: g => shouldBlock(g, 'DELETE FROM customers') },
|
|
115
|
+
{ id: 'wr-drop', category: 'write_smuggle', severity: 'CRITICAL', description: 'DROP TABLE',
|
|
116
|
+
run: g => shouldBlock(g, 'DROP TABLE customers') },
|
|
117
|
+
{ id: 'wr-stacked', category: 'multi_statement', severity: 'CRITICAL', description: 'Stacked query ile gizli write',
|
|
118
|
+
run: g => shouldBlock(g, 'SELECT 1; DROP TABLE customers') },
|
|
119
|
+
{ id: 'wr-update-comment', category: 'write_smuggle', severity: 'HIGH', description: 'Yorumla gizlenmiş UPDATE',
|
|
120
|
+
run: g => shouldBlock(g, 'UPDATE customers SET name=1 -- SELECT') },
|
|
121
|
+
{ id: 'tbl-unauth', category: 'unauthorized_table', severity: 'HIGH', description: 'İzin listesi dışı tabloya erişim',
|
|
122
|
+
run: g => shouldBlock(g, 'SELECT * FROM secret.admin_users') },
|
|
123
|
+
];
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- [ ] **Step 4:** `npx vitest run redteam/attacks/queryTime.test.ts` → PASS
|
|
127
|
+
- [ ] **Step 5:** Commit: `git add redteam/attacks/queryTime.* && git commit -m "feat(redteam): sorgu-zamanı saldırılar"`
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
### Task 2: attacks/resultTime.ts (PII exfil — encode bypass'ı yakalar)
|
|
132
|
+
|
|
133
|
+
**Files:**
|
|
134
|
+
- Create: `redteam/attacks/resultTime.ts`
|
|
135
|
+
- Test: `redteam/attacks/resultTime.test.ts`
|
|
136
|
+
|
|
137
|
+
**Interfaces:**
|
|
138
|
+
- Produces: `resultTimeAttacks: AttackCase[]`
|
|
139
|
+
|
|
140
|
+
- [ ] **Step 1: Testi yaz:**
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { describe, it, expect } from 'vitest';
|
|
144
|
+
import { Governance } from '../../src/governance.js';
|
|
145
|
+
import { resultTimeAttacks } from './resultTime.js';
|
|
146
|
+
|
|
147
|
+
const gov = new Governance({ maskColumns: ['*.email'], maxRows: 100 });
|
|
148
|
+
|
|
149
|
+
describe('resultTimeAttacks', () => {
|
|
150
|
+
it('düz-metin PII DEFENDED (maskelenir)', () => {
|
|
151
|
+
const plain = resultTimeAttacks.find(a => a.id === 'pii-plaintext')!;
|
|
152
|
+
expect(plain.run(gov).defended).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
it('base64-encode PII BYPASSED (harness gerçek deliği yakalar)', () => {
|
|
155
|
+
const enc = resultTimeAttacks.find(a => a.id === 'pii-base64')!;
|
|
156
|
+
expect(enc.run(gov).defended).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
- [ ] **Step 2:** `npx vitest run redteam/attacks/resultTime.test.ts` → FAIL
|
|
162
|
+
- [ ] **Step 3: Uygula:**
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import type { AttackCase } from '../types.js';
|
|
166
|
+
import type { Governance } from '../../src/governance.js';
|
|
167
|
+
import type { QueryResult, GovernedQueryResult } from '../../src/types.js';
|
|
168
|
+
|
|
169
|
+
const PII_EMAIL = 'ahmet@wearu.app';
|
|
170
|
+
const PII_RE = /@[a-z0-9.-]+\.[a-z]{2,}|\b[1-9][0-9]{10}\b/i;
|
|
171
|
+
|
|
172
|
+
function containsRecoverablePII(governed: GovernedQueryResult): boolean {
|
|
173
|
+
const flat = JSON.stringify(governed.rows);
|
|
174
|
+
if (PII_RE.test(flat)) return true; // düz PII sağ kaldı
|
|
175
|
+
for (const row of governed.rows) {
|
|
176
|
+
for (const v of Object.values(row)) {
|
|
177
|
+
if (typeof v === 'string' && /^[A-Za-z0-9+/]{8,}={0,2}$/.test(v)) {
|
|
178
|
+
try {
|
|
179
|
+
const dec = Buffer.from(v, 'base64').toString('utf8');
|
|
180
|
+
if (PII_RE.test(dec)) return true; // encode ile kaçırılmış PII
|
|
181
|
+
} catch { /* base64 değil */ }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function tryRedact(gov: Governance, rows: Record<string, unknown>[]): { defended: boolean; detail: string } {
|
|
189
|
+
const result: QueryResult = { rows, rowCount: rows.length, fields: Object.keys(rows[0] ?? {}) };
|
|
190
|
+
const governed = gov.redact(result);
|
|
191
|
+
const leaked = containsRecoverablePII(governed);
|
|
192
|
+
return {
|
|
193
|
+
defended: !leaked,
|
|
194
|
+
detail: leaked
|
|
195
|
+
? `BYPASS — PII geri-kazanılabilir: ${JSON.stringify(governed.rows)}`
|
|
196
|
+
: `DEFENDED — maskelendi: ${JSON.stringify(governed.rows)}`,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const resultTimeAttacks: AttackCase[] = [
|
|
201
|
+
{ id: 'pii-plaintext', category: 'pii_exfil', severity: 'HIGH', description: 'Düz-metin e-posta çıktısı',
|
|
202
|
+
run: g => tryRedact(g, [{ email: PII_EMAIL }]) },
|
|
203
|
+
{ id: 'pii-base64', category: 'pii_exfil', severity: 'CRITICAL', description: 'encode(email,base64) ile maske atlatma',
|
|
204
|
+
run: g => tryRedact(g, [{ leak: Buffer.from(PII_EMAIL).toString('base64') }]) },
|
|
205
|
+
];
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
- [ ] **Step 4:** `npx vitest run redteam/attacks/resultTime.test.ts` → PASS
|
|
209
|
+
- [ ] **Step 5:** Commit: `git add redteam/attacks/resultTime.* && git commit -m "feat(redteam): sonuç-zamanı PII-exfil (encode bypass tespiti)"`
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
### Task 3: runner.ts
|
|
214
|
+
|
|
215
|
+
**Files:**
|
|
216
|
+
- Create: `redteam/runner.ts`
|
|
217
|
+
- Test: `redteam/runner.test.ts`
|
|
218
|
+
|
|
219
|
+
**Interfaces:**
|
|
220
|
+
- Consumes: `AttackCase`, `RedTeamReport`, `Governance`
|
|
221
|
+
- Produces: `runRedTeam(gov: Governance, attacks: AttackCase[], now?: Date): RedTeamReport`
|
|
222
|
+
|
|
223
|
+
- [ ] **Step 1: Testi yaz:**
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import { describe, it, expect } from 'vitest';
|
|
227
|
+
import { Governance } from '../src/governance.js';
|
|
228
|
+
import { runRedTeam } from './runner.js';
|
|
229
|
+
import type { AttackCase } from './types.js';
|
|
230
|
+
|
|
231
|
+
const fake: AttackCase[] = [
|
|
232
|
+
{ id: 'a', category: 'write_smuggle', severity: 'CRITICAL', description: 'x', run: () => ({ defended: true, detail: 'ok' }) },
|
|
233
|
+
{ id: 'b', category: 'pii_exfil', severity: 'CRITICAL', description: 'y', run: () => ({ defended: false, detail: 'leak' }) },
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
describe('runRedTeam', () => {
|
|
237
|
+
it('defended/bypassed sayar', () => {
|
|
238
|
+
const rep = runRedTeam(new Governance({}), fake, new Date('2026-07-02T00:00:00Z'));
|
|
239
|
+
expect(rep.total).toBe(2);
|
|
240
|
+
expect(rep.defended).toBe(1);
|
|
241
|
+
expect(rep.bypassed).toBe(1);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
- [ ] **Step 2:** `npx vitest run redteam/runner.test.ts` → FAIL
|
|
247
|
+
- [ ] **Step 3: Uygula:**
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
import type { Governance } from '../src/governance.js';
|
|
251
|
+
import type { AttackCase, AttackResult, RedTeamReport } from './types.js';
|
|
252
|
+
|
|
253
|
+
export function runRedTeam(gov: Governance, attacks: AttackCase[], now: Date = new Date()): RedTeamReport {
|
|
254
|
+
const results: AttackResult[] = attacks.map(atk => {
|
|
255
|
+
const { defended, detail } = atk.run(gov);
|
|
256
|
+
return { id: atk.id, category: atk.category, severity: atk.severity, description: atk.description, defended, detail };
|
|
257
|
+
});
|
|
258
|
+
return {
|
|
259
|
+
ranAt: now.toISOString(),
|
|
260
|
+
total: results.length,
|
|
261
|
+
defended: results.filter(r => r.defended).length,
|
|
262
|
+
bypassed: results.filter(r => !r.defended).length,
|
|
263
|
+
results,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
- [ ] **Step 4:** `npx vitest run redteam/runner.test.ts` → PASS
|
|
269
|
+
- [ ] **Step 5:** Commit: `git add redteam/runner.* && git commit -m "feat(redteam): runner + sınıflandırma"`
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
### Task 4: report.ts
|
|
274
|
+
|
|
275
|
+
**Files:**
|
|
276
|
+
- Create: `redteam/report.ts`
|
|
277
|
+
- Test: `redteam/report.test.ts`
|
|
278
|
+
|
|
279
|
+
**Interfaces:**
|
|
280
|
+
- Consumes: `RedTeamReport`
|
|
281
|
+
- Produces: `renderMarkdown(report: RedTeamReport): string`
|
|
282
|
+
|
|
283
|
+
- [ ] **Step 1: Testi yaz:**
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
import { describe, it, expect } from 'vitest';
|
|
287
|
+
import { renderMarkdown } from './report.js';
|
|
288
|
+
import type { RedTeamReport } from './types.js';
|
|
289
|
+
|
|
290
|
+
const rep: RedTeamReport = {
|
|
291
|
+
ranAt: '2026-07-02T00:00:00.000Z', total: 2, defended: 1, bypassed: 1,
|
|
292
|
+
results: [
|
|
293
|
+
{ id: 'a', category: 'write_smuggle', severity: 'CRITICAL', description: 'x', defended: true, detail: 'ok' },
|
|
294
|
+
{ id: 'b', category: 'pii_exfil', severity: 'CRITICAL', description: 'y', defended: false, detail: 'leak' },
|
|
295
|
+
],
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
describe('renderMarkdown', () => {
|
|
299
|
+
it('savunma karnesi + BYPASSED bulgularını listeler', () => {
|
|
300
|
+
const md = renderMarkdown(rep);
|
|
301
|
+
expect(md).toContain('1/2 savundu');
|
|
302
|
+
expect(md).toContain('BYPASS');
|
|
303
|
+
expect(md).toContain('b');
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
- [ ] **Step 2:** `npx vitest run redteam/report.test.ts` → FAIL
|
|
309
|
+
- [ ] **Step 3: Uygula:**
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import type { RedTeamReport } from './types.js';
|
|
313
|
+
|
|
314
|
+
export function renderMarkdown(r: RedTeamReport): string {
|
|
315
|
+
const l: string[] = [];
|
|
316
|
+
l.push(`# Conarium Savunma Karnesi (NEO Red-Team)`);
|
|
317
|
+
l.push(`Tarih: ${r.ranAt}`, '');
|
|
318
|
+
l.push(`**Sonuç: ${r.defended}/${r.total} savundu, ${r.bypassed} bypass.**`, '');
|
|
319
|
+
const bypassed = r.results.filter(x => !x.defended);
|
|
320
|
+
if (bypassed.length) {
|
|
321
|
+
l.push(`## 🚨 Sertleştirilecekler (BYPASS)`);
|
|
322
|
+
for (const b of bypassed) l.push(`- [${b.severity}] ${b.id} — ${b.description}\n - ${b.detail}`);
|
|
323
|
+
l.push('');
|
|
324
|
+
}
|
|
325
|
+
l.push(`## ✅ Savunulanlar (DEFENDED)`);
|
|
326
|
+
for (const d of r.results.filter(x => x.defended)) l.push(`- [${d.severity}] ${d.id} — ${d.description}`);
|
|
327
|
+
return l.join('\n');
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
- [ ] **Step 4:** `npx vitest run redteam/report.test.ts` → PASS
|
|
332
|
+
- [ ] **Step 5:** Commit: `git add redteam/report.* && git commit -m "feat(redteam): savunma karnesi render"`
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
### Task 5: index.ts (orkestratör + CLI)
|
|
337
|
+
|
|
338
|
+
**Files:**
|
|
339
|
+
- Create: `redteam/index.ts`
|
|
340
|
+
- Test: `redteam/index.test.ts`
|
|
341
|
+
|
|
342
|
+
**Interfaces:**
|
|
343
|
+
- Consumes: `runRedTeam`, `queryTimeAttacks`, `resultTimeAttacks`, `Governance`
|
|
344
|
+
- Produces: `allAttacks: AttackCase[]`, `redTeamConarium(policy): RedTeamReport`
|
|
345
|
+
|
|
346
|
+
- [ ] **Step 1: Testi yaz:**
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { describe, it, expect } from 'vitest';
|
|
350
|
+
import { redTeamConarium, allAttacks } from './index.js';
|
|
351
|
+
|
|
352
|
+
describe('redTeamConarium', () => {
|
|
353
|
+
it('gerçek Governance ile çalışır: write DEFENDED + base64 PII BYPASS', () => {
|
|
354
|
+
const rep = redTeamConarium({ allowTables: ['public.customers'], maskColumns: ['*.email'] });
|
|
355
|
+
expect(rep.total).toBe(allAttacks.length);
|
|
356
|
+
expect(rep.results.find(r => r.id === 'wr-delete')!.defended).toBe(true);
|
|
357
|
+
expect(rep.results.find(r => r.id === 'pii-base64')!.defended).toBe(false);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
- [ ] **Step 2:** `npx vitest run redteam/index.test.ts` → FAIL
|
|
363
|
+
- [ ] **Step 3: Uygula:**
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
import { Governance } from '../src/governance.js';
|
|
367
|
+
import type { GovernancePolicy } from '../src/types.js';
|
|
368
|
+
import type { AttackCase, RedTeamReport } from './types.js';
|
|
369
|
+
import { queryTimeAttacks } from './attacks/queryTime.js';
|
|
370
|
+
import { resultTimeAttacks } from './attacks/resultTime.js';
|
|
371
|
+
import { runRedTeam } from './runner.js';
|
|
372
|
+
import { renderMarkdown } from './report.js';
|
|
373
|
+
|
|
374
|
+
export const allAttacks: AttackCase[] = [...queryTimeAttacks, ...resultTimeAttacks];
|
|
375
|
+
|
|
376
|
+
export function redTeamConarium(policy: GovernancePolicy): RedTeamReport {
|
|
377
|
+
return runRedTeam(new Governance(policy), allAttacks);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// CLI: npx tsx redteam/index.ts
|
|
381
|
+
const isMain = import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('index.ts');
|
|
382
|
+
if (isMain) {
|
|
383
|
+
const rep = redTeamConarium({ allowTables: ['public.customers'], maskColumns: ['*.email'], maxRows: 100 });
|
|
384
|
+
console.log(renderMarkdown(rep));
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
- [ ] **Step 4:** `npx vitest run redteam/index.test.ts` → PASS. Sonra tüm suite: `npm test` → hepsi PASS.
|
|
389
|
+
- [ ] **Step 5:** Commit: `git add redteam/index.* && git commit -m "feat(redteam): orkestratör + CLI"`
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
### Task 6: Canlı çalıştırma (demo materyali)
|
|
394
|
+
|
|
395
|
+
**Files:**
|
|
396
|
+
- (kod yok — canlı doğrulama)
|
|
397
|
+
|
|
398
|
+
- [ ] **Step 1: Harness'i gerçek Conarium'a karşı çalıştır:**
|
|
399
|
+
|
|
400
|
+
Run: `npx tsx redteam/index.ts`
|
|
401
|
+
|
|
402
|
+
Beklenen: Markdown "Savunma Karnesi" — write/unauthorized saldırıları DEFENDED, `pii-base64` BYPASS olarak listelenir (Conarium'un gerçek deliği = Faz 1 demosunun ham materyali + Faz 2 sertleştirme girdisi).
|
|
403
|
+
|
|
404
|
+
- [ ] **Step 2:** Raporu kaydet: `npx tsx redteam/index.ts > redteam/last-report.md` (gitignore'a `redteam/last-report.md` ekle).
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
## Self-Review
|
|
409
|
+
|
|
410
|
+
**Spec coverage:** ✅ query-time saldırılar (T1), result-time PII-exfil + encode bypass (T2), runner sınıflandırma (T3), savunma karnesi (T4), orkestratör+CLI (T5), canlı demo (T6). Test stratejisi her task'ta.
|
|
411
|
+
|
|
412
|
+
**Placeholder scan:** Tüm adımlarda gerçek kod; TODO/TBD yok.
|
|
413
|
+
|
|
414
|
+
**Type consistency:** `AttackCase.run(gov): {defended, detail}` T0'da tanımlı, T1/T2/T5 aynı kullanıyor. `runRedTeam(gov, attacks, now?)` T3↔T5 tutarlı. `QueryResult` `{rows,rowCount,fields}` gerçek tiple (types.ts:63) uyumlu. Importlar `.js` uzantılı (repo konvansiyonu).
|
|
415
|
+
|
|
416
|
+
**Not:** encode-base64 case'i bilerek BYPASS beklenir — bu Conarium'un gerçek deliği; harness'in görevi onu doğru yakalamak (Conarium'u kusursuz göstermek değil).
|