@conarium-ai/core 0.2.10 → 0.2.12
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 +43 -2
- package/LIMITATIONS.md +39 -5
- package/LIMITATIONS.tr.md +38 -5
- package/README.md +11 -8
- package/SECURITY.md +1 -0
- package/bin/conarium-doctor.mjs +226 -7
- package/bin/doctor-sql.mjs +47 -0
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +12 -3
- package/dist/audit.js.map +1 -1
- package/dist/config.d.ts +22 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +22 -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.map +1 -1
- package/dist/connectors/openapi.js +0 -1
- package/dist/connectors/openapi.js.map +1 -1
- 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.d.ts.map +1 -1
- package/dist/console.js +14 -3
- package/dist/console.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 +8 -0
- package/dist/governance.d.ts.map +1 -1
- package/dist/governance.js +29 -78
- package/dist/governance.js.map +1 -1
- package/dist/masking-cost.d.ts +16 -0
- package/dist/masking-cost.d.ts.map +1 -0
- package/dist/masking-cost.js +31 -0
- package/dist/masking-cost.js.map +1 -0
- 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 +90 -13
- 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/dispatch.d.ts +17 -0
- package/dist/sql-gate/dispatch.d.ts.map +1 -0
- package/dist/sql-gate/dispatch.js +30 -0
- package/dist/sql-gate/dispatch.js.map +1 -0
- package/dist/sql-gate/mssql.d.ts +11 -0
- package/dist/sql-gate/mssql.d.ts.map +1 -0
- package/dist/sql-gate/mssql.js +287 -0
- package/dist/sql-gate/mssql.js.map +1 -0
- package/dist/sql-gate/oracle.d.ts +11 -0
- package/dist/sql-gate/oracle.d.ts.map +1 -0
- package/dist/sql-gate/oracle.js +227 -0
- package/dist/sql-gate/oracle.js.map +1 -0
- package/dist/sql-gate/postgres.d.ts +12 -0
- package/dist/sql-gate/postgres.d.ts.map +1 -0
- package/dist/sql-gate/postgres.js +64 -0
- package/dist/sql-gate/postgres.js.map +1 -0
- package/dist/sql-gate/rules.d.ts +14 -0
- package/dist/sql-gate/rules.d.ts.map +1 -0
- package/dist/sql-gate/rules.js +73 -0
- package/dist/sql-gate/rules.js.map +1 -0
- package/dist/sql-gate/types.d.ts +31 -0
- package/dist/sql-gate/types.d.ts.map +1 -0
- package/dist/sql-gate/types.js +9 -0
- package/dist/sql-gate/types.js.map +1 -0
- 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 +8 -1
- package/dist/types.d.ts.map +1 -1
- package/docs/API-STABILITY.md +174 -0
- package/docs/BENCHMARK.md +144 -0
- package/docs/audit/2026-08-14-e2e-health.md +69 -0
- package/docs/audit/2026-08-14-security-scan.md +48 -0
- package/docs/audit/2026-08-14-surface-sync.md +34 -0
- package/docs/benchmarks/concurrency-20260814.json +38 -0
- package/docs/benchmarks/latest.json +2310 -0
- package/docs/benchmarks/masking-cost-threshold.json +6 -0
- package/docs/benchmarks/overhead-20260814T1238Z-win32.json +402 -0
- package/docs/benchmarks/overhead-20260814T1346Z-linux.json +2310 -0
- package/docs/benchmarks/overhead-20260814T1644Z-win32.json +2310 -0
- package/docs/releases/v0.2.10.md +24 -0
- package/docs/releases/v0.2.8.md +23 -0
- package/docs/releases/v0.2.9.md +26 -0
- package/docs/security/NPM-PROVENANCE.md +64 -0
- package/docs/security/PENTEST-SCOPE.md +1 -1
- package/docs/security/THREAT-MODEL.md +25 -5
- package/docs/specs/2026-08-14-mssql-bypass-inventory.md +37 -0
- package/docs/specs/2026-08-14-oracle-bypass-inventory.md +28 -0
- 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 +5 -5
- package/scripts/benchmark-concurrency.mjs +133 -0
- package/scripts/benchmark-overhead.mjs +492 -0
- package/test-vectors/README.md +3 -0
- package/test-vectors/sql-gate/LAST-RUN.json +11 -0
- package/test-vectors/sql-gate/README.md +19 -0
- package/test-vectors/sql-gate/vectors.json +331 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Conarium overhead vs direct Postgres.
|
|
4
|
+
*
|
|
5
|
+
* CONARIUM_BENCH_DSN=postgres://… node scripts/benchmark-overhead.mjs
|
|
6
|
+
*
|
|
7
|
+
* Without a DSN this does not invent a comparison. It writes koşulamadı
|
|
8
|
+
* for (a) vs (b) and still records in-process gate timings (CPU of
|
|
9
|
+
* guardQuery + redact — not a substitute for the Postgres delta).
|
|
10
|
+
*
|
|
11
|
+
* No extra packages. Node builtins + the `postgres` dependency already
|
|
12
|
+
* in the product, plus `dist/governance.js`.
|
|
13
|
+
*
|
|
14
|
+
* --out <path> JSON destination (default: docs/benchmarks/<stamp>.json)
|
|
15
|
+
* --help
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
18
|
+
import { cpus, totalmem, platform, release, arch } from 'node:os'
|
|
19
|
+
import { dirname, join } from 'node:path'
|
|
20
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
21
|
+
import { performance } from 'node:perf_hooks'
|
|
22
|
+
|
|
23
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
24
|
+
const ARGS = process.argv.slice(2)
|
|
25
|
+
|
|
26
|
+
function has(flag) {
|
|
27
|
+
return ARGS.includes(flag)
|
|
28
|
+
}
|
|
29
|
+
function valueOf(flag, fallback) {
|
|
30
|
+
const i = ARGS.indexOf(flag)
|
|
31
|
+
if (i < 0) return fallback
|
|
32
|
+
return ARGS[i + 1] ?? fallback
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (has('--help') || has('-h')) {
|
|
36
|
+
console.log(`Usage: node scripts/benchmark-overhead.mjs [--out <path>]
|
|
37
|
+
|
|
38
|
+
Measures Conarium's added cost, not absolute speed.
|
|
39
|
+
|
|
40
|
+
(a) the same SELECT against Postgres
|
|
41
|
+
(b) guardQuery → that SELECT (rewritten) → redact
|
|
42
|
+
|
|
43
|
+
Scenarios: allow (unmasked) · partial (email masked) · deny (query must not run).
|
|
44
|
+
Caps: 100 (code default) · 500 · 5 000. Dataset is 5 000 rows.
|
|
45
|
+
|
|
46
|
+
Needs CONARIUM_BENCH_DSN for (a) vs (b). Without it: koşulamadı.`)
|
|
47
|
+
process.exit(0)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const govJs = join(root, 'dist', 'governance.js')
|
|
51
|
+
if (!existsSync(govJs)) {
|
|
52
|
+
console.error('dist/governance.js missing — run npm run build first')
|
|
53
|
+
process.exit(2)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { Governance, PolicyError } = await import(pathToFileURL(govJs).href)
|
|
57
|
+
|
|
58
|
+
const DEFAULT_MAX_ROWS = 100
|
|
59
|
+
const CAPS = [DEFAULT_MAX_ROWS, 500, 5_000]
|
|
60
|
+
const DATASET_ROWS = 5_000
|
|
61
|
+
const IN_PROCESS_SIZES = [50, 100, 500, 1_000, 5_000]
|
|
62
|
+
const WARMUP_SMALL = 15
|
|
63
|
+
const REPEAT_SMALL = 50
|
|
64
|
+
const WARMUP_LARGE = 2
|
|
65
|
+
const REPEAT_LARGE = 8
|
|
66
|
+
const LARGE_AT = 5_000
|
|
67
|
+
const QUERY = 'SELECT id, name, email, note FROM public.bench_customers ORDER BY id'
|
|
68
|
+
const DENY_QUERY = 'SELECT id, name, email, note FROM public.bench_secrets ORDER BY id'
|
|
69
|
+
const SECRET_EMAIL = 'bench-secret-user@example.com'
|
|
70
|
+
|
|
71
|
+
function budget(n, series) {
|
|
72
|
+
if (series === 'same-sql' || n >= LARGE_AT) {
|
|
73
|
+
return { warmup: 5, repeats: 15 }
|
|
74
|
+
}
|
|
75
|
+
return { warmup: WARMUP_SMALL, repeats: REPEAT_SMALL }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function percentile(sorted, p) {
|
|
79
|
+
if (sorted.length === 0) return null
|
|
80
|
+
const idx = Math.min(sorted.length - 1, Math.max(0, Math.ceil((p / 100) * sorted.length) - 1))
|
|
81
|
+
return sorted[idx]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function summarize(samples) {
|
|
85
|
+
const sorted = [...samples].sort((a, b) => a - b)
|
|
86
|
+
return {
|
|
87
|
+
n: sorted.length,
|
|
88
|
+
p50: percentile(sorted, 50),
|
|
89
|
+
p95: percentile(sorted, 95),
|
|
90
|
+
p99: percentile(sorted, 99),
|
|
91
|
+
min: sorted[0] ?? null,
|
|
92
|
+
max: sorted[sorted.length - 1] ?? null,
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function hardware() {
|
|
97
|
+
const list = cpus()
|
|
98
|
+
return {
|
|
99
|
+
platform: platform(),
|
|
100
|
+
release: release(),
|
|
101
|
+
arch: arch(),
|
|
102
|
+
cpu: list[0]?.model ?? 'unknown',
|
|
103
|
+
cores: list.length,
|
|
104
|
+
ramBytes: totalmem(),
|
|
105
|
+
node: process.version,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function stampName() {
|
|
110
|
+
const d = new Date()
|
|
111
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
112
|
+
return `${d.getUTCFullYear()}${pad(d.getUTCMonth() + 1)}${pad(d.getUTCDate())}T${pad(d.getUTCHours())}${pad(d.getUTCMinutes())}Z`
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function policyFor(kind, maxRows = DEFAULT_MAX_ROWS) {
|
|
116
|
+
if (kind === 'allow') {
|
|
117
|
+
return { allowTables: ['public.bench_customers'], maxRows }
|
|
118
|
+
}
|
|
119
|
+
if (kind === 'partial') {
|
|
120
|
+
return {
|
|
121
|
+
allowTables: ['public.bench_customers'],
|
|
122
|
+
maskColumns: ['*.email'],
|
|
123
|
+
maxRows,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
allowTables: ['public.bench_customers'],
|
|
128
|
+
denyTables: ['public.bench_secrets'],
|
|
129
|
+
maskColumns: ['*.email'],
|
|
130
|
+
maxRows,
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function syntheticRows(n, { uniqueEmails = true } = {}) {
|
|
135
|
+
const rows = new Array(n)
|
|
136
|
+
for (let i = 1; i <= n; i++) {
|
|
137
|
+
rows[i - 1] = {
|
|
138
|
+
id: i,
|
|
139
|
+
name: `user-${i}`,
|
|
140
|
+
email: uniqueEmails
|
|
141
|
+
? (i === 1 ? SECRET_EMAIL : `user-${i}@example.com`)
|
|
142
|
+
: SECRET_EMAIL,
|
|
143
|
+
note: `note ${i}`,
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return rows
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function timeSync(fn, warmup, repeats, label = '') {
|
|
150
|
+
if (label) process.stderr.write(` ${label} warmup=${warmup} n=${repeats}\n`)
|
|
151
|
+
for (let i = 0; i < warmup; i++) fn()
|
|
152
|
+
const samples = new Array(repeats)
|
|
153
|
+
for (let i = 0; i < repeats; i++) {
|
|
154
|
+
const t0 = performance.now()
|
|
155
|
+
fn()
|
|
156
|
+
samples[i] = performance.now() - t0
|
|
157
|
+
if (label && (i === 0 || i === repeats - 1)) {
|
|
158
|
+
process.stderr.write(` ${label} sample ${i + 1}/${repeats} ${samples[i].toFixed(1)}ms\n`)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return samples
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function timeAsync(fn, warmup, repeats, label = '') {
|
|
165
|
+
if (label) process.stderr.write(` ${label} warmup=${warmup} n=${repeats}\n`)
|
|
166
|
+
for (let i = 0; i < warmup; i++) await fn()
|
|
167
|
+
const samples = new Array(repeats)
|
|
168
|
+
for (let i = 0; i < repeats; i++) {
|
|
169
|
+
const t0 = performance.now()
|
|
170
|
+
await fn()
|
|
171
|
+
samples[i] = performance.now() - t0
|
|
172
|
+
if (label && (i === 0 || i === repeats - 1)) {
|
|
173
|
+
process.stderr.write(` ${label} sample ${i + 1}/${repeats} ${samples[i].toFixed(1)}ms\n`)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return samples
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function runInProcess() {
|
|
180
|
+
const out = { guard: {}, redact: {}, samples: { guard: {}, redact: {} } }
|
|
181
|
+
for (const kind of ['allow', 'partial', 'deny']) {
|
|
182
|
+
const gov = new Governance(policyFor(kind, DEFAULT_MAX_ROWS))
|
|
183
|
+
const sql = kind === 'deny' ? DENY_QUERY : QUERY
|
|
184
|
+
const { warmup, repeats } = budget(10)
|
|
185
|
+
const samples = timeSync(() => {
|
|
186
|
+
try {
|
|
187
|
+
gov.guardQuery(sql)
|
|
188
|
+
} catch (err) {
|
|
189
|
+
if (kind !== 'deny') throw err
|
|
190
|
+
if (!(err instanceof PolicyError)) throw err
|
|
191
|
+
}
|
|
192
|
+
}, warmup, repeats, `guard ${kind}`)
|
|
193
|
+
out.samples.guard[kind] = samples
|
|
194
|
+
out.guard[kind] = { ...summarize(samples), warmup, repeats, unit: 'ms' }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const sizes = process.env.CONARIUM_BENCH_DSN
|
|
198
|
+
? IN_PROCESS_SIZES.filter((n) => n <= 500)
|
|
199
|
+
: IN_PROCESS_SIZES
|
|
200
|
+
for (const n of sizes) {
|
|
201
|
+
const gov = new Governance(policyFor('partial', Math.max(n, DEFAULT_MAX_ROWS)))
|
|
202
|
+
const guarded = gov.guardQuery(QUERY)
|
|
203
|
+
const { warmup, repeats } = budget(n)
|
|
204
|
+
|
|
205
|
+
const uniqueRows = syntheticRows(n, { uniqueEmails: true })
|
|
206
|
+
const uniquePayload = {
|
|
207
|
+
rows: uniqueRows,
|
|
208
|
+
rowCount: n,
|
|
209
|
+
fields: ['id', 'name', 'email', 'note'],
|
|
210
|
+
sql: guarded.sql,
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const samples = timeSync(() => {
|
|
214
|
+
gov.redact(uniquePayload, guarded.aliases, guarded.metadata)
|
|
215
|
+
}, warmup, repeats, `redact ${n} unique-email`)
|
|
216
|
+
out.samples.redact[String(n)] = samples
|
|
217
|
+
out.redact[String(n)] = {
|
|
218
|
+
...summarize(samples),
|
|
219
|
+
warmup,
|
|
220
|
+
repeats,
|
|
221
|
+
unit: 'ms',
|
|
222
|
+
rows: n,
|
|
223
|
+
uniqueEmails: true,
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return out
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function ensureBenchTables(sql) {
|
|
230
|
+
await sql.unsafe(`
|
|
231
|
+
CREATE TABLE IF NOT EXISTS public.bench_customers (
|
|
232
|
+
id integer PRIMARY KEY,
|
|
233
|
+
name text NOT NULL,
|
|
234
|
+
email text NOT NULL,
|
|
235
|
+
note text NOT NULL
|
|
236
|
+
)
|
|
237
|
+
`)
|
|
238
|
+
await sql.unsafe(`
|
|
239
|
+
CREATE TABLE IF NOT EXISTS public.bench_secrets (
|
|
240
|
+
id integer PRIMARY KEY,
|
|
241
|
+
name text NOT NULL,
|
|
242
|
+
email text NOT NULL,
|
|
243
|
+
note text NOT NULL
|
|
244
|
+
)
|
|
245
|
+
`)
|
|
246
|
+
const [{ n }] = await sql.unsafe('SELECT count(*)::int AS n FROM public.bench_customers')
|
|
247
|
+
if (n < DATASET_ROWS) {
|
|
248
|
+
await sql.unsafe('TRUNCATE public.bench_customers')
|
|
249
|
+
const batch = 1_000
|
|
250
|
+
for (let start = 1; start <= DATASET_ROWS; start += batch) {
|
|
251
|
+
const end = Math.min(DATASET_ROWS, start + batch - 1)
|
|
252
|
+
const values = []
|
|
253
|
+
for (let i = start; i <= end; i++) {
|
|
254
|
+
const email = i === 1 ? SECRET_EMAIL : `user-${i}@example.com`
|
|
255
|
+
values.push(`(${i}, 'user-${i}', '${email}', 'note ${i}')`)
|
|
256
|
+
}
|
|
257
|
+
await sql.unsafe(
|
|
258
|
+
`INSERT INTO public.bench_customers (id, name, email, note) VALUES ${values.join(',')}`,
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const [{ s }] = await sql.unsafe('SELECT count(*)::int AS s FROM public.bench_secrets')
|
|
263
|
+
if (s < 1) {
|
|
264
|
+
await sql.unsafe(
|
|
265
|
+
`INSERT INTO public.bench_secrets (id, name, email, note) VALUES (1, 'hidden', '${SECRET_EMAIL}', 'secret')`,
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function runPostgresComparison(dsn) {
|
|
271
|
+
const postgres = (await import('postgres')).default
|
|
272
|
+
const sql = postgres(dsn, { max: 1, idle_timeout: 5 })
|
|
273
|
+
let queryRuns = 0
|
|
274
|
+
const tracked = async (text) => {
|
|
275
|
+
queryRuns += 1
|
|
276
|
+
return sql.unsafe(text)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
try {
|
|
280
|
+
const [{ version }] = await sql.unsafe('SELECT version()')
|
|
281
|
+
await ensureBenchTables(sql)
|
|
282
|
+
|
|
283
|
+
const comparison = {}
|
|
284
|
+
const samples = {}
|
|
285
|
+
|
|
286
|
+
for (const series of ['same-sql', 'same-limit']) {
|
|
287
|
+
comparison[series] = {}
|
|
288
|
+
samples[series] = {}
|
|
289
|
+
for (const kind of ['allow', 'partial', 'deny']) {
|
|
290
|
+
comparison[series][kind] = {}
|
|
291
|
+
samples[series][kind] = {}
|
|
292
|
+
for (const cap of CAPS) {
|
|
293
|
+
const gov = new Governance(policyFor(kind, cap))
|
|
294
|
+
const base = kind === 'deny' ? DENY_QUERY : QUERY
|
|
295
|
+
const text = series === 'same-limit' ? `${base} LIMIT ${cap}` : base
|
|
296
|
+
const { warmup, repeats } = budget(cap, series)
|
|
297
|
+
const cellLabel = `${series} ${kind} maxRows=${cap}`
|
|
298
|
+
|
|
299
|
+
if (kind === 'deny') {
|
|
300
|
+
const before = queryRuns
|
|
301
|
+
const denySamples = await timeAsync(async () => {
|
|
302
|
+
try {
|
|
303
|
+
gov.guardQuery(text)
|
|
304
|
+
throw new Error('deny scenario allowed the query — not measured as deny')
|
|
305
|
+
} catch (err) {
|
|
306
|
+
if (!(err instanceof PolicyError)) throw err
|
|
307
|
+
}
|
|
308
|
+
}, warmup, repeats, cellLabel)
|
|
309
|
+
if (queryRuns !== before) {
|
|
310
|
+
throw new Error(`deny ran the query ${queryRuns - before} time(s) — gate failed`)
|
|
311
|
+
}
|
|
312
|
+
comparison[series][kind][String(cap)] = {
|
|
313
|
+
direct: null,
|
|
314
|
+
conarium: { ...summarize(denySamples), warmup, repeats, unit: 'ms' },
|
|
315
|
+
overhead: null,
|
|
316
|
+
note: 'deny must not hit Postgres; overhead vs direct is not defined',
|
|
317
|
+
queryRan: false,
|
|
318
|
+
maxRows: cap,
|
|
319
|
+
}
|
|
320
|
+
samples[series][kind][String(cap)] = { conarium: denySamples }
|
|
321
|
+
continue
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const directSamples = await timeAsync(async () => {
|
|
325
|
+
await tracked(text)
|
|
326
|
+
}, warmup, repeats, `${cellLabel} direct`)
|
|
327
|
+
|
|
328
|
+
const conariumSamples = []
|
|
329
|
+
const deltas = []
|
|
330
|
+
let lastDirectRows = 0
|
|
331
|
+
let lastConariumRows = 0
|
|
332
|
+
for (let i = 0; i < warmup; i++) {
|
|
333
|
+
const guarded = gov.guardQuery(text)
|
|
334
|
+
const rows = await tracked(guarded.sql)
|
|
335
|
+
gov.redact(
|
|
336
|
+
{ rows, rowCount: rows.length, fields: ['id', 'name', 'email', 'note'], sql: guarded.sql },
|
|
337
|
+
guarded.aliases,
|
|
338
|
+
guarded.metadata,
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
for (let i = 0; i < repeats; i++) {
|
|
342
|
+
const d0 = performance.now()
|
|
343
|
+
const directRows = await tracked(text)
|
|
344
|
+
const directMs = performance.now() - d0
|
|
345
|
+
lastDirectRows = directRows.length
|
|
346
|
+
|
|
347
|
+
const c0 = performance.now()
|
|
348
|
+
const guarded = gov.guardQuery(text)
|
|
349
|
+
const rows = await tracked(guarded.sql)
|
|
350
|
+
const redacted = gov.redact(
|
|
351
|
+
{ rows, rowCount: rows.length, fields: ['id', 'name', 'email', 'note'], sql: guarded.sql },
|
|
352
|
+
guarded.aliases,
|
|
353
|
+
guarded.metadata,
|
|
354
|
+
)
|
|
355
|
+
const conariumMs = performance.now() - c0
|
|
356
|
+
lastConariumRows = redacted.rows.length
|
|
357
|
+
if (kind === 'partial') {
|
|
358
|
+
const leaked = redacted.rows.some((row) =>
|
|
359
|
+
Object.values(row).some((v) => typeof v === 'string' && v.includes(SECRET_EMAIL)),
|
|
360
|
+
)
|
|
361
|
+
if (leaked) throw new Error('partial scenario leaked the secret email — numbers discarded')
|
|
362
|
+
}
|
|
363
|
+
conariumSamples.push(conariumMs)
|
|
364
|
+
deltas.push(conariumMs - directMs)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
comparison[series][kind][String(cap)] = {
|
|
368
|
+
direct: { ...summarize(directSamples), warmup, repeats, unit: 'ms', rows: lastDirectRows },
|
|
369
|
+
conarium: { ...summarize(conariumSamples), warmup, repeats, unit: 'ms', rows: lastConariumRows },
|
|
370
|
+
overhead: { ...summarize(deltas), warmup, repeats, unit: 'ms' },
|
|
371
|
+
queryRan: true,
|
|
372
|
+
maxRows: cap,
|
|
373
|
+
userSql: text,
|
|
374
|
+
}
|
|
375
|
+
samples[series][kind][String(cap)] = {
|
|
376
|
+
direct: directSamples,
|
|
377
|
+
conarium: conariumSamples,
|
|
378
|
+
overhead: deltas,
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return { status: 'ran', version, datasetRows: DATASET_ROWS, caps: CAPS, comparison, samples }
|
|
385
|
+
} finally {
|
|
386
|
+
await sql.end({ timeout: 5 })
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const dsn = process.env.CONARIUM_BENCH_DSN || ''
|
|
391
|
+
const hw = hardware()
|
|
392
|
+
const inProcess = runInProcess()
|
|
393
|
+
|
|
394
|
+
let postgresResult
|
|
395
|
+
if (!dsn) {
|
|
396
|
+
postgresResult = {
|
|
397
|
+
status: 'kosulanmadi',
|
|
398
|
+
reason: 'CONARIUM_BENCH_DSN unset; this machine has no local Postgres in PATH and no Docker',
|
|
399
|
+
version: null,
|
|
400
|
+
comparison: null,
|
|
401
|
+
samples: null,
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
postgresResult = await runPostgresComparison(dsn)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const report = {
|
|
408
|
+
measuredAt: new Date().toISOString(),
|
|
409
|
+
hardware: hw,
|
|
410
|
+
method: {
|
|
411
|
+
defaultMaxRows: DEFAULT_MAX_ROWS,
|
|
412
|
+
caps: CAPS,
|
|
413
|
+
datasetRows: DATASET_ROWS,
|
|
414
|
+
inProcessSizes: IN_PROCESS_SIZES,
|
|
415
|
+
warmupSmall: WARMUP_SMALL,
|
|
416
|
+
repeatsSmall: REPEAT_SMALL,
|
|
417
|
+
warmupLarge: WARMUP_LARGE,
|
|
418
|
+
repeatsLarge: REPEAT_LARGE,
|
|
419
|
+
query: QUERY,
|
|
420
|
+
denyQuery: DENY_QUERY,
|
|
421
|
+
headline: 'p50 / p95 / p99 — mean is not reported',
|
|
422
|
+
whatOverheadMeans:
|
|
423
|
+
'overhead = paired (guardQuery + Postgres + redact) minus the same SELECT sent straight to Postgres. same-sql: user SQL has no LIMIT (Conarium adds maxRows). same-limit: user SQL already has LIMIT = maxRows (same row count).',
|
|
424
|
+
},
|
|
425
|
+
postgres: {
|
|
426
|
+
status: postgresResult.status,
|
|
427
|
+
reason: postgresResult.reason ?? null,
|
|
428
|
+
version: postgresResult.version ?? null,
|
|
429
|
+
datasetRows: postgresResult.datasetRows ?? null,
|
|
430
|
+
caps: postgresResult.caps ?? null,
|
|
431
|
+
comparison: postgresResult.comparison,
|
|
432
|
+
},
|
|
433
|
+
inProcess: {
|
|
434
|
+
note: 'Gate CPU only. Not a substitute for the Postgres comparison.',
|
|
435
|
+
guard: inProcess.guard,
|
|
436
|
+
redact: inProcess.redact,
|
|
437
|
+
},
|
|
438
|
+
samples: {
|
|
439
|
+
postgres: postgresResult.samples,
|
|
440
|
+
inProcess: inProcess.samples,
|
|
441
|
+
},
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const outDir = join(root, 'docs', 'benchmarks')
|
|
445
|
+
mkdirSync(outDir, { recursive: true })
|
|
446
|
+
const defaultOut = join(outDir, `overhead-${stampName()}-${platform()}.json`)
|
|
447
|
+
const outPath = valueOf('--out', defaultOut)
|
|
448
|
+
writeFileSync(outPath, JSON.stringify(report, null, 2) + '\n')
|
|
449
|
+
writeFileSync(join(outDir, 'latest.json'), JSON.stringify(report, null, 2) + '\n')
|
|
450
|
+
|
|
451
|
+
function line(label, stats) {
|
|
452
|
+
if (!stats || stats.p50 == null) return `${label}: (yok)`
|
|
453
|
+
const f = (x) => (typeof x === 'number' ? x.toFixed(3) : String(x))
|
|
454
|
+
return `${label}: p50=${f(stats.p50)} p95=${f(stats.p95)} p99=${f(stats.p99)} ms (n=${stats.n})`
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
console.log(`hardware ${hw.cpu} × ${hw.cores} RAM=${Math.round(hw.ramBytes / 1e9)}GB ${hw.platform} ${hw.release} node ${hw.node}`)
|
|
458
|
+
console.log(`postgres ${postgresResult.status}${postgresResult.reason ? ` — ${postgresResult.reason}` : ''}`)
|
|
459
|
+
if (postgresResult.version) console.log(`pg ${postgresResult.version}`)
|
|
460
|
+
console.log('')
|
|
461
|
+
if (postgresResult.comparison) {
|
|
462
|
+
for (const series of Object.keys(postgresResult.comparison)) {
|
|
463
|
+
for (const kind of Object.keys(postgresResult.comparison[series])) {
|
|
464
|
+
for (const cap of Object.keys(postgresResult.comparison[series][kind])) {
|
|
465
|
+
const cell = postgresResult.comparison[series][kind][cap]
|
|
466
|
+
const rows = cell.direct?.rows != null ? ` directRows=${cell.direct.rows} conariumRows=${cell.conarium?.rows}` : ''
|
|
467
|
+
console.log(`[${series} ${kind} maxRows=${cap}${rows}]`)
|
|
468
|
+
console.log(' ' + line('direct ', cell.direct))
|
|
469
|
+
console.log(' ' + line('conarium ', cell.conarium))
|
|
470
|
+
console.log(' ' + line('overhead ', cell.overhead))
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
console.log('Postgres comparison: koşulamadı')
|
|
476
|
+
}
|
|
477
|
+
console.log('')
|
|
478
|
+
console.log('in-process (not vs Postgres)')
|
|
479
|
+
for (const kind of Object.keys(inProcess.guard)) {
|
|
480
|
+
console.log(' ' + line(`guard ${kind.padEnd(8)}`, inProcess.guard[kind]))
|
|
481
|
+
}
|
|
482
|
+
for (const n of Object.keys(inProcess.redact)) {
|
|
483
|
+
const cell = inProcess.redact[n]
|
|
484
|
+
if (cell.status === 'kosulanmadi') {
|
|
485
|
+
console.log(` redact ${n}: koşulamadı — ${cell.reason}`)
|
|
486
|
+
} else {
|
|
487
|
+
console.log(' ' + line(`redact ${String(n).padStart(6)}`, cell))
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
console.log('')
|
|
491
|
+
console.log(`wrote ${outPath}`)
|
|
492
|
+
process.exit(postgresResult.status === 'ran' || postgresResult.status === 'kosulanmadi' ? 0 : 1)
|
package/test-vectors/README.md
CHANGED
|
@@ -90,3 +90,6 @@ change the specification and the version string with it.
|
|
|
90
90
|
|
|
91
91
|
The frozen hash of case 001 is asserted separately in `test/vectors_run.mjs`
|
|
92
92
|
for exactly this reason.
|
|
93
|
+
|
|
94
|
+
SQL-gate attack leftovers (not receipts) live in [`sql-gate/`](sql-gate/).
|
|
95
|
+
They are produced only when `test/property_sql_gate.mjs` finds a bypass.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# SQL-gate attack vectors
|
|
2
|
+
|
|
3
|
+
Not receipt conformance.
|
|
4
|
+
|
|
5
|
+
`vectors.json` is the shared named set. The same file is run per dialect
|
|
6
|
+
(`src/sql-gate/vectors.test.ts`). A dialect with no `sql.<name>` is skipped,
|
|
7
|
+
not marked supported.
|
|
8
|
+
|
|
9
|
+
Postgres policy uses `public.*`. MSSQL overlay uses `dbo.*`. Oracle overlay
|
|
10
|
+
uses `app.*`. All three have a live engine run. Oracle synonyms and
|
|
11
|
+
database links are not resolved — that is a documented limit, not a skip.
|
|
12
|
+
|
|
13
|
+
`test/property_sql_gate.mjs` is the generated-attack leftover. A **real
|
|
14
|
+
bypass** is written here as one JSON file and that check stays red.
|
|
15
|
+
|
|
16
|
+
`LAST-RUN.json` is the last green generator run (seed + counts). It is not
|
|
17
|
+
a claim that no bypass exists.
|
|
18
|
+
|
|
19
|
+
Receipt vectors stay in the parent folder and are unchanged.
|