@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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- **Table existence oracle closed.** Assistant `describe_table` / `search` /
|
|
6
|
+
`query` errors no longer distinguish denied from missing. The audit log
|
|
7
|
+
keeps the real reason. Denied tables still never reach the connector.
|
|
8
|
+
`describe_table` now has the same 50KB payload cap as `query` / `search`.
|
|
9
|
+
- **Dropped `js-yaml` and `node-fetch`.** Zero remaining imports. HTTP uses
|
|
10
|
+
Node's built-in `fetch` (engines already `>=18`).
|
|
11
|
+
- **npm provenance workflow** prepared (`publish.yml`, dispatch-only). Does
|
|
12
|
+
not publish on push. See `docs/security/NPM-PROVENANCE.md`.
|
|
13
|
+
- **Two-process audit sink** stated in LIMITATIONS and the threat model.
|
|
14
|
+
No lock in this release.
|
|
15
|
+
|
|
16
|
+
- **Operator is inside the boundary.** Threat model and LIMITATIONS state
|
|
17
|
+
it in the open: importing the library can skip the gate the same way
|
|
18
|
+
opening the database with the operator's credential can. Not a vulnerability.
|
|
19
|
+
- **HMAC compare uses `timingSafeEqual`.** Audit-sink HMAC was `!==` on the
|
|
20
|
+
hex digest. Ed25519 verify stays on Node `crypto.verify`.
|
|
21
|
+
- **Doctor names `custom-sql`** and fails when that connector is present
|
|
22
|
+
without a declared `policy.dialect`. `list_tables` on an executor-only
|
|
23
|
+
install says schema discovery is not implemented (not a silent empty list).
|
|
24
|
+
|
|
25
|
+
- **Operator SQL executor (`custom-sql`).** No MSSQL/Oracle driver is
|
|
26
|
+
shipped. The operator registers a function or a local `config.module`;
|
|
27
|
+
it receives only gated SQL. `policy.dialect` is required on that path.
|
|
28
|
+
Row cap and masking still apply on the return. See
|
|
29
|
+
`examples/custom-sql/`.
|
|
30
|
+
|
|
31
|
+
- **Postgres overhead measured.** Same SELECT, default `maxRows` 100: about
|
|
32
|
+
5 ms added when email is masked. 500 → ~87 ms. 5 000 → ~22 s. Cost
|
|
33
|
+
follows distinct masked values. Doctor and boot warn above 100; they
|
|
34
|
+
do not reject the query. See `docs/BENCHMARK.md`.
|
|
35
|
+
- **Carry-over corpus lock.** `src/governance.carryover-diff.test.ts`.
|
|
36
|
+
A single-pass rewrite disagreed on sequential longest-first overlap
|
|
37
|
+
and was reverted.
|
|
38
|
+
|
|
39
|
+
- **Overhead benchmark script.** `scripts/benchmark-overhead.mjs` measures
|
|
40
|
+
the same SELECT direct vs through the gate (p50/p95/p99). Without a DSN
|
|
41
|
+
the comparison is recorded as koşulamadı — no invented numbers.
|
|
42
|
+
See `docs/BENCHMARK.md`.
|
|
43
|
+
- **Generated SQL-gate attacks.** `test/property_sql_gate.mjs` (property +
|
|
44
|
+
fuzz). A real bypass stays red and is written under
|
|
45
|
+
`test-vectors/sql-gate/`.
|
|
46
|
+
- **API stability inventory** (draft, not a 1.0): `docs/API-STABILITY.md`.
|
|
47
|
+
|
|
5
48
|
- **Built-in OpenTimestamps client.** Stamp / upgrade / verify no longer
|
|
6
49
|
load `javascript-opentimestamps`. The `web3` / `request` / `bitcore` tree
|
|
7
50
|
is not installed. Old proofs still verify (pending fixture + dogfood
|
|
@@ -14,8 +57,6 @@
|
|
|
14
57
|
- **`test:checks` runs every check even if one fails.** The old `&&` chain
|
|
15
58
|
went silent after the first failure. `test/init.mjs` resolves temp paths
|
|
16
59
|
with `fs.realpathSync` (`/var` vs `/private/var` on macOS).
|
|
17
|
-
- **OpenTimestamps opt-in warning.** Enabling the feature pulls a tree with
|
|
18
|
-
7 critical and 3 high known advisories. Default install still does not.
|
|
19
60
|
|
|
20
61
|
- **c1 launcher sets `CONARIUM_AUDIT_SIGNING_KEY`** from
|
|
21
62
|
`~/.conarium/audit-ed25519.pem` when `receiptSink` is set. Cursor MCP env
|
package/LIMITATIONS.md
CHANGED
|
@@ -10,12 +10,14 @@ No SOC 2. No ISO. No independent penetration test. On the roadmap.
|
|
|
10
10
|
|
|
11
11
|
Version is 0.2.x. The API can break.
|
|
12
12
|
|
|
13
|
-
## SQL is Postgres
|
|
13
|
+
## SQL is Postgres, Microsoft SQL Server, and Oracle
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
A
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
MySQL is not implemented.
|
|
16
|
+
A dialect is listed here only when the shared SQL-gate vector set is green against that dialect, unparseable input is denied, and a live engine run applied the row cap.
|
|
17
|
+
This is a second parser layer, not a shipped database client. The shipped `query` tool selects the gate from `policy.dialect` (`postgres` when omitted, or `mssql`, or `oracle`). The dialect is the operator's declaration — it is not inferred from the SQL. An unknown dialect rejects the config; it does not fall back to postgres.
|
|
18
|
+
Oracle does not resolve synonyms: an allow-listed name is the name the parser sees, not the base table. Database links (`table@dblink`) are denied. `ROWNUM` is denied (it is not a row cap).
|
|
19
|
+
There is no MSSQL or Oracle connector. An operator can attach their own executor (`connectors[].type: custom-sql`) that receives only gated SQL. That path requires an explicit `policy.dialect` — the omitted-dialect postgres default does not apply. The gate speaks three dialects; the connection is the operator's.
|
|
20
|
+
Parsers: Postgres `pgsql-ast-parser` · MSSQL `node-sql-parser` (transactsql) · Oracle `@guanmingchiu/sqlparser-ts`.
|
|
19
21
|
|
|
20
22
|
## Names in free text are not guaranteed
|
|
21
23
|
|
|
@@ -37,10 +39,42 @@ Bus factor 1.
|
|
|
37
39
|
|
|
38
40
|
An OpenTimestamps stamp can take hours to confirm on Bitcoin. Receipts already show `pending`.
|
|
39
41
|
|
|
42
|
+
## The operator is inside the boundary
|
|
43
|
+
|
|
44
|
+
The product defends the assistant-to-gateway path. Code that imports the
|
|
45
|
+
library can skip the gate the same way it can open the database with the
|
|
46
|
+
operator's credential. The operator's own process is not an audit subject
|
|
47
|
+
of this gateway.
|
|
48
|
+
|
|
49
|
+
## Two processes, one audit file
|
|
50
|
+
|
|
51
|
+
`Audit.log()` is synchronous. One process can write many concurrent queries
|
|
52
|
+
without breaking `prevHash`. Two OS processes appending the same sink have
|
|
53
|
+
no lock. That install is unsupported until a lock is an explicit decision.
|
|
54
|
+
|
|
40
55
|
## Cryptography is not independently audited
|
|
41
56
|
|
|
42
57
|
The Ed25519 implementation has not had a formal audit.
|
|
43
58
|
|
|
59
|
+
## Masking cost grows with distinct masked values
|
|
60
|
+
|
|
61
|
+
Carry-over builds one matcher per unique value this policy already
|
|
62
|
+
masked. `maxRows` bounds that set. When the policy leaves it unset the code falls
|
|
63
|
+
back to 100; the `conarium.config.json` shipped with the package sets 50, so a
|
|
64
|
+
fresh install runs at 50. The figures below use 100 as the conservative case.
|
|
65
|
+
|
|
66
|
+
Measured (same SELECT, same row count, Postgres 16.14, WSL2, see
|
|
67
|
+
[`docs/BENCHMARK.md`](docs/BENCHMARK.md)):
|
|
68
|
+
|
|
69
|
+
| maxRows | overhead p50 (masked) |
|
|
70
|
+
|---|---|
|
|
71
|
+
| 100 (default) | 5.0 ms |
|
|
72
|
+
| 500 | 87 ms |
|
|
73
|
+
| 5 000 | 22 s |
|
|
74
|
+
|
|
75
|
+
Raising the cap is allowed. The doctor and boot log warn above 100.
|
|
76
|
+
The query is not rejected.
|
|
77
|
+
|
|
44
78
|
## OpenTimestamps client
|
|
45
79
|
|
|
46
80
|
Stamping uses a built-in calendar client (Node `crypto` + HTTPS to the public calendars).
|
package/LIMITATIONS.tr.md
CHANGED
|
@@ -10,12 +10,14 @@ SOC 2 yok. ISO yok. Bağımsız sızma testi yok. Yol haritasında.
|
|
|
10
10
|
|
|
11
11
|
Sürüm 0.2.x. API kırılabilir.
|
|
12
12
|
|
|
13
|
-
## SQL
|
|
13
|
+
## SQL: Postgres, Microsoft SQL Server ve Oracle
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
MySQL yok.
|
|
16
|
+
Bir lehçe ancak paylaşılan SQL-kapısı vektör seti o lehçede yeşilse, ayrıştırılamayan girdi reddediliyorsa ve canlı motorda satır tavanı uygulanıyorsa burada yazılır.
|
|
17
|
+
Bu bir dağıtılan veritabanı istemcisi değil, ikinci ayrıştırıcı katmanı. Dağıtılan `query` aracı kapıyı `policy.dialect` ile seçer (yoksa `postgres`; `mssql`; `oracle`). Lehçe operatörün beyanıdır — SQL’den tahmin edilmez. Bilinmeyen lehçe yapılandırmayı reddeder; sessizce postgres’e düşmez.
|
|
18
|
+
Oracle synonym hedefini çözmez: allow-list’teki ad, parser’ın gördüğü addır, taban tablo değil. Veritabanı bağlantısı (`table@dblink`) reddedilir. `ROWNUM` reddedilir (satır tavanı değildir).
|
|
19
|
+
MSSQL veya Oracle konnektörü yok. Operatör kendi çalıştırıcısını takabilir (`connectors[].type: custom-sql`); çalıştırıcıya yalnız kapıdan geçmiş SQL gider. Bu yolda `policy.dialect` zorunludur — yoksa postgres varsayılanı uygulanmaz. Kapı üç lehçeyi yönetir; bağlantıyı operatör getirir.
|
|
20
|
+
Ayrıştırıcılar: Postgres `pgsql-ast-parser` · MSSQL `node-sql-parser` (transactsql) · Oracle `@guanmingchiu/sqlparser-ts`.
|
|
19
21
|
|
|
20
22
|
## Serbest metinde isim garantisi yok
|
|
21
23
|
|
|
@@ -37,10 +39,41 @@ Bus factor 1.
|
|
|
37
39
|
|
|
38
40
|
OpenTimestamps damgasının Bitcoin'de onaylanması saatler sürebilir. Makbuzda `pending` zaten görünür.
|
|
39
41
|
|
|
42
|
+
## Operatör sınırın içindedir
|
|
43
|
+
|
|
44
|
+
Ürün asistan ↔ kapı yolunu korur. Kütüphaneyi import eden kod kapıyı,
|
|
45
|
+
operatörün kimlik bilgisiyle veritabanına bağlanmakla aynı yetkiyle
|
|
46
|
+
atlayabilir. Operatörün kendi süreci bu kapının denetim konusu değildir.
|
|
47
|
+
|
|
48
|
+
## İki süreç, tek denetim dosyası
|
|
49
|
+
|
|
50
|
+
`Audit.log()` senkrondur. Tek süreçte eşzamanlı sorgular `prevHash` kırmadan
|
|
51
|
+
yazar. İki OS süreci aynı sink’e kilit olmadan ekler. Kilit ayrı karar;
|
|
52
|
+
o kurulum desteklenmez.
|
|
53
|
+
|
|
40
54
|
## Denetlenmemiş kriptografi
|
|
41
55
|
|
|
42
56
|
Ed25519 uygulaması resmî denetimden geçmedi.
|
|
43
57
|
|
|
58
|
+
## Maskeleme maliyeti satırla değil, benzersiz değerle büyür
|
|
59
|
+
|
|
60
|
+
Taşıma eşleştiricisi, politikanın maskelediği her benzersiz değer için
|
|
61
|
+
bir tarama kurar. `maxRows` o kümeyi sınırlar. Politika boş bırakırsa kod 100'e
|
|
62
|
+
düşer; pakette gelen `conarium.config.json` 50 yazar. Taze kurulum 50'de çalışır.
|
|
63
|
+
Aşağıdaki ölçüm ihtiyatlı olsun diye 100 üzerinden.
|
|
64
|
+
|
|
65
|
+
Ölçülmüş (aynı SELECT, aynı satır sayısı, Postgres 16.14, WSL2, bakınız
|
|
66
|
+
[`docs/BENCHMARK.md`](docs/BENCHMARK.md)):
|
|
67
|
+
|
|
68
|
+
| maxRows | ek yük p50 (maskeli) |
|
|
69
|
+
|---|---|
|
|
70
|
+
| 100 (varsayılan) | 5,0 ms |
|
|
71
|
+
| 500 | 87 ms |
|
|
72
|
+
| 5 000 | 22 s |
|
|
73
|
+
|
|
74
|
+
Tavanı yükseltmek serbest. 100'ün üstünde doctor ve boot uyarır.
|
|
75
|
+
Sorgu reddedilmez.
|
|
76
|
+
|
|
44
77
|
## OpenTimestamps istemcisi
|
|
45
78
|
|
|
46
79
|
Damgalama yerleşik takvim istemcisiyle yapılır (Node `crypto` + herkese açık takvimlere HTTPS).
|
package/README.md
CHANGED
|
@@ -329,7 +329,7 @@ Conarium operates on a strict tripartite architecture, balancing power between t
|
|
|
329
329
|
graph LR
|
|
330
330
|
A([AI Assistant\nCursor / Copilot]) -- "MCP Query" --> B{The Gateway\nConarium Proxy};
|
|
331
331
|
B -- "Intercept & Parse" --> C[The Engine\nGovernance & Regex];
|
|
332
|
-
C -- "Execute Query" --> D[(Your Database\nPostgres)];
|
|
332
|
+
C -- "Execute Query" --> D[(Your Database\nPostgres / SQL Server / Oracle)];
|
|
333
333
|
D -- "Raw Data" --> C;
|
|
334
334
|
C -- "Mask & Cap" --> B;
|
|
335
335
|
B -- "Sanitized Data" --> A;
|
|
@@ -472,6 +472,8 @@ Control access using a simple `conarium.json` policy file:
|
|
|
472
472
|
|
|
473
473
|
Anything not in `allowTables` is denied by default; matched `maskColumns` are redacted to `[MASKED_PII]` before the data ever reaches the model.
|
|
474
474
|
|
|
475
|
+
`policy.dialect` selects the SQL gate the `query` tool uses: `postgres` (omitted default), `mssql`, or `oracle`. It is the operator's declaration — Conarium does not guess the dialect from the statement. A typo or `mysql` rejects the config.
|
|
476
|
+
|
|
475
477
|
> **Connectors are fail-closed.** `allowConnectors` is a strict allow-list:
|
|
476
478
|
> if it is missing or empty, **no** connector is permitted (previously an empty
|
|
477
479
|
> list meant "allow all"). If you configure connectors, you must list them here —
|
|
@@ -538,14 +540,13 @@ including labelled names in free text · allow/deny + row caps · per-person mas
|
|
|
538
540
|
profiles · immutable hash-chained audit ledger · Ed25519-signed receipt per access
|
|
539
541
|
with an offline verifier · signed coverage declarations · two-sided reconciliation
|
|
540
542
|
against the database's own counters · OpenTimestamps anchoring and an optional
|
|
541
|
-
anchoring service · conformance vectors · Postgres,
|
|
542
|
-
and
|
|
543
|
-
|
|
543
|
+
anchoring service · conformance vectors · SQL gate: Postgres, Microsoft SQL Server, Oracle
|
|
544
|
+
(MySQL is not implemented; Oracle synonyms and database links are not resolved — see LIMITATIONS) · Postgres, Supabase, docs, OpenAPI, Jira
|
|
545
|
+
and Slack connectors · `conarium-init` / `conarium-doctor` via `npx` (`@conarium-ai/core`).
|
|
544
546
|
|
|
545
547
|
**Next:** consent binding ([spec published](docs/CONSENT-BINDING-SPEC.md), no code —
|
|
546
548
|
patent review first) · a second independent implementation of the receipt format ·
|
|
547
|
-
per-user identity bound to an identity provider rather than an operator token map
|
|
548
|
-
publishing `@conarium-ai/core` to npm so `npx conarium-init` works without a clone.
|
|
549
|
+
per-user identity bound to an identity provider rather than an operator token map.
|
|
549
550
|
|
|
550
551
|
**Deliberately not planned**, so nobody waits for it:
|
|
551
552
|
|
|
@@ -556,8 +557,10 @@ publishing `@conarium-ai/core` to npm so `npx conarium-init` works without a clo
|
|
|
556
557
|
- **SOC 2.** It audits organisations that hold customer data. We never receive
|
|
557
558
|
yours. If that ever stops being true, this line changes first.
|
|
558
559
|
|
|
559
|
-
Known gaps: [LIMITATIONS.md](LIMITATIONS.md), the README above,
|
|
560
|
-
[`docs/RECEIPT-SPEC.md`](docs/RECEIPT-SPEC.md)
|
|
560
|
+
Known gaps: [LIMITATIONS.md](LIMITATIONS.md), the README above,
|
|
561
|
+
[`docs/RECEIPT-SPEC.md`](docs/RECEIPT-SPEC.md),
|
|
562
|
+
[`docs/BENCHMARK.md`](docs/BENCHMARK.md), and
|
|
563
|
+
[`docs/API-STABILITY.md`](docs/API-STABILITY.md).
|
|
561
564
|
|
|
562
565
|
## 📜 License
|
|
563
566
|
|
package/SECURITY.md
CHANGED
|
@@ -41,6 +41,7 @@ Bitcoin-block checks use `blockstream.info`. Unreachable explorer → exit 15
|
|
|
41
41
|
|
|
42
42
|
The tester pack is [`docs/security/THREAT-MODEL.md`](docs/security/THREAT-MODEL.md)
|
|
43
43
|
and [`docs/security/PENTEST-SCOPE.md`](docs/security/PENTEST-SCOPE.md).
|
|
44
|
+
npm provenance (after a dispatch publish): [`docs/security/NPM-PROVENANCE.md`](docs/security/NPM-PROVENANCE.md).
|
|
44
45
|
Those documents are not an audit.
|
|
45
46
|
|
|
46
47
|
## Threat model
|
package/bin/conarium-doctor.mjs
CHANGED
|
@@ -30,9 +30,16 @@
|
|
|
30
30
|
*/
|
|
31
31
|
import { existsSync, readFileSync, statSync, accessSync, constants } from 'node:fs'
|
|
32
32
|
import { resolve, dirname, join } from 'node:path'
|
|
33
|
-
import { fileURLToPath } from 'node:url'
|
|
33
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
34
34
|
import net from 'node:net'
|
|
35
35
|
import { createPublicKey, createPrivateKey } from 'node:crypto'
|
|
36
|
+
import {
|
|
37
|
+
dialectAgrees,
|
|
38
|
+
dialectLine,
|
|
39
|
+
familyFromBanner,
|
|
40
|
+
familyFromScheme,
|
|
41
|
+
resolveDoctorDialect,
|
|
42
|
+
} from './doctor-sql.mjs'
|
|
36
43
|
|
|
37
44
|
const ARGS = process.argv.slice(2)
|
|
38
45
|
const has = (f) => ARGS.includes(f)
|
|
@@ -60,6 +67,8 @@ const results = []
|
|
|
60
67
|
const ok = (label, detail) => results.push({ level: 'ok', label, detail })
|
|
61
68
|
const warn = (label, detail, fix) => results.push({ level: 'warn', label, detail, fix })
|
|
62
69
|
const fail = (label, detail, fix) => results.push({ level: 'fail', label, detail, fix })
|
|
70
|
+
/** Could not complete the check. Not a pass. Not a silent skip. */
|
|
71
|
+
const unseen = (label, detail, fix) => results.push({ level: 'unseen', label, detail, fix })
|
|
63
72
|
|
|
64
73
|
/* ---------------------------------------------------------------- helpers */
|
|
65
74
|
|
|
@@ -108,6 +117,28 @@ function tcpProbe(host, port, timeoutMs = 4000) {
|
|
|
108
117
|
})
|
|
109
118
|
}
|
|
110
119
|
|
|
120
|
+
/** Ask a reachable engine who it is. Never log the DSN. */
|
|
121
|
+
async function identifyEngine(t) {
|
|
122
|
+
const schemeFamily = familyFromScheme(t.scheme)
|
|
123
|
+
const looksPostgres = schemeFamily === 'postgres' || t.type === 'postgres' || t.type === 'supabase'
|
|
124
|
+
if (!looksPostgres) return null
|
|
125
|
+
try {
|
|
126
|
+
const postgres = (await import('postgres')).default
|
|
127
|
+
const sql = postgres(t.raw, { max: 1, connect_timeout: 3, idle_timeout: 1 })
|
|
128
|
+
try {
|
|
129
|
+
const rows = await sql`select version() as v`
|
|
130
|
+
const banner = String(rows?.[0]?.v || '')
|
|
131
|
+
const family = familyFromBanner(banner)
|
|
132
|
+
if (!family) return null
|
|
133
|
+
return { family, summary: banner.split(',')[0].replace(/\s+/g, ' ').slice(0, 72) }
|
|
134
|
+
} finally {
|
|
135
|
+
await sql.end({ timeout: 2 })
|
|
136
|
+
}
|
|
137
|
+
} catch {
|
|
138
|
+
return null
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
111
142
|
function envSet(name) {
|
|
112
143
|
const v = process.env[name]
|
|
113
144
|
return typeof v === 'string' && v.trim() !== '' ? v : null
|
|
@@ -254,6 +285,123 @@ if (config) {
|
|
|
254
285
|
ok('Policy surface', [hasAllowTables && 'allowTables', hasDeny && 'denyTables', hasMask && 'maskColumns'].filter(Boolean).join(' + '))
|
|
255
286
|
}
|
|
256
287
|
|
|
288
|
+
// 4b. Raised maxRows — performance warning, not a deny.
|
|
289
|
+
// Threshold is measured (docs/benchmarks/masking-cost-threshold.json).
|
|
290
|
+
// Doctor does not import dist/; the number is read from that file, or 100.
|
|
291
|
+
const thresholdPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'docs', 'benchmarks', 'masking-cost-threshold.json')
|
|
292
|
+
let warnAbove = 100
|
|
293
|
+
try {
|
|
294
|
+
if (existsSync(thresholdPath)) {
|
|
295
|
+
const t = JSON.parse(readFileSync(thresholdPath, 'utf8'))
|
|
296
|
+
if (Number.isFinite(t.warnAbove)) warnAbove = t.warnAbove
|
|
297
|
+
}
|
|
298
|
+
} catch { /* keep 100 */ }
|
|
299
|
+
const maxRows = pol.maxRows
|
|
300
|
+
if (typeof maxRows === 'number' && maxRows > warnAbove) {
|
|
301
|
+
warn(
|
|
302
|
+
'policy.maxRows',
|
|
303
|
+
`maxRows is ${maxRows} (measured warning above ${warnAbove}). Masking cost grows with the number of distinct values this policy already masked, not with table size. The row cap bounds that set. The query is not rejected.`,
|
|
304
|
+
'Leave the default if you do not need more rows. If you raise it, expect carry-over cost to grow with unique masked values.',
|
|
305
|
+
)
|
|
306
|
+
} else if (typeof maxRows === 'number') {
|
|
307
|
+
ok('policy.maxRows', `maxRows is ${maxRows} (at or below the measured threshold ${warnAbove})`)
|
|
308
|
+
} else {
|
|
309
|
+
ok('policy.maxRows', `maxRows is 100 (default — policy.maxRows omitted; threshold ${warnAbove})`)
|
|
310
|
+
}
|
|
311
|
+
for (const [name, profile] of Object.entries(pol.profiles || {})) {
|
|
312
|
+
const pMax = profile && typeof profile === 'object' ? profile.maxRows : undefined
|
|
313
|
+
if (typeof pMax === 'number' && pMax > warnAbove) {
|
|
314
|
+
warn(
|
|
315
|
+
`policy.profiles.${name}.maxRows`,
|
|
316
|
+
`profile maxRows is ${pMax} (measured warning above ${warnAbove}). Same cost: distinct masked values, not table size. Not rejected.`,
|
|
317
|
+
'A profile can only raise the cap for one identified person. The cost still grows with unique masked values.',
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// D2 — which SQL gate the query tool will use. Silence here was the bug.
|
|
323
|
+
const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
324
|
+
let dialectInfo = null
|
|
325
|
+
try {
|
|
326
|
+
dialectInfo = resolveDoctorDialect(pol.dialect)
|
|
327
|
+
ok('SQL dialect', dialectLine(dialectInfo.dialect, dialectInfo.source))
|
|
328
|
+
} catch (e) {
|
|
329
|
+
fail('SQL dialect', e.message, 'Set policy.dialect to postgres, mssql, or oracle. A typo does not become postgres.')
|
|
330
|
+
}
|
|
331
|
+
if (dialectInfo) {
|
|
332
|
+
if (dialectInfo.dialect === 'postgres') {
|
|
333
|
+
ok('SQL gate', 'postgres gate is built-in (Governance.guardQuery)')
|
|
334
|
+
} else {
|
|
335
|
+
const gateFile = join(pkgRoot, 'dist', 'sql-gate', `${dialectInfo.dialect}.js`)
|
|
336
|
+
if (!existsSync(gateFile)) {
|
|
337
|
+
fail(
|
|
338
|
+
'SQL gate',
|
|
339
|
+
`${dialectInfo.dialect} gate file is missing (dist/sql-gate/${dialectInfo.dialect}.js)`,
|
|
340
|
+
'Run npm run build in the install. The query tool cannot load this dialect without that file.',
|
|
341
|
+
)
|
|
342
|
+
} else {
|
|
343
|
+
try {
|
|
344
|
+
await import(pathToFileURL(gateFile).href)
|
|
345
|
+
ok('SQL gate', `${dialectInfo.dialect} gate loaded from dist/sql-gate/${dialectInfo.dialect}.js`)
|
|
346
|
+
} catch (e) {
|
|
347
|
+
fail(
|
|
348
|
+
'SQL gate',
|
|
349
|
+
`${dialectInfo.dialect} gate failed to load: ${e.name}`,
|
|
350
|
+
'Rebuild the package. The query tool will fail closed on this dialect until the gate loads.',
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// K6 — operator executor is not a silent empty schema.
|
|
358
|
+
const customSql = connectors.filter((c) => c && c.type === 'custom-sql')
|
|
359
|
+
if (customSql.length) {
|
|
360
|
+
ok(
|
|
361
|
+
'custom-sql',
|
|
362
|
+
`${customSql.length} operator executor(s): ${customSql.map((c) => c.name).join(', ')}. Schema discovery is not implemented.`,
|
|
363
|
+
)
|
|
364
|
+
if (!pol.dialect) {
|
|
365
|
+
fail(
|
|
366
|
+
'custom-sql dialect',
|
|
367
|
+
'custom-sql is configured but policy.dialect is omitted',
|
|
368
|
+
'Declare policy.dialect (postgres, mssql, or oracle). The omitted-dialect postgres default does not apply.',
|
|
369
|
+
)
|
|
370
|
+
} else {
|
|
371
|
+
ok('custom-sql dialect', `declared ${String(pol.dialect)}`)
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// D3 — custom PII: names only. Pattern text must never reach stdout.
|
|
376
|
+
const patterns = Array.isArray(pol.customPatterns) ? pol.customPatterns : []
|
|
377
|
+
const patternNames = patterns
|
|
378
|
+
.map((p) => (p && typeof p.name === 'string' ? p.name : null))
|
|
379
|
+
.filter(Boolean)
|
|
380
|
+
if (patterns.length === 0) {
|
|
381
|
+
ok('policy.customPatterns', '0 custom patterns')
|
|
382
|
+
} else {
|
|
383
|
+
const compilerPath = join(pkgRoot, 'dist', 'custom_patterns.js')
|
|
384
|
+
if (!existsSync(compilerPath)) {
|
|
385
|
+
unseen(
|
|
386
|
+
'policy.customPatterns',
|
|
387
|
+
`${patterns.length} named: ${patternNames.join(', ') || '(unnamed)'} — compile not checked (dist/custom_patterns.js missing)`,
|
|
388
|
+
'Run npm run build. The gateway rejects a broken pattern at load; the doctor could not confirm that here.',
|
|
389
|
+
)
|
|
390
|
+
} else {
|
|
391
|
+
try {
|
|
392
|
+
const { compileCustomPatterns } = await import(pathToFileURL(compilerPath).href)
|
|
393
|
+
compileCustomPatterns(patterns)
|
|
394
|
+
ok('policy.customPatterns', `${patterns.length} compiled: ${patternNames.join(', ')}`)
|
|
395
|
+
} catch (e) {
|
|
396
|
+
fail(
|
|
397
|
+
'policy.customPatterns',
|
|
398
|
+
`${patterns.length} named: ${patternNames.join(', ') || '(unnamed)'} — compile failed (${e.name})`,
|
|
399
|
+
'The gateway will refuse this config. Fix or remove the broken rule. Pattern text is not printed.',
|
|
400
|
+
)
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
257
405
|
// 5. Per-person profiles need per-user credentials
|
|
258
406
|
const profiles = pol.profiles || pol.actorProfiles
|
|
259
407
|
if (profiles && Object.keys(profiles).length > 0) {
|
|
@@ -414,18 +562,87 @@ if (config) {
|
|
|
414
562
|
} else {
|
|
415
563
|
ok('Connector DSN', `${c.name}: ${d.text}${d.hasPassword ? ' (password set, not shown)' : ''}`)
|
|
416
564
|
}
|
|
417
|
-
if (d.host && d.port) targets.push({ name: c.name, ...d })
|
|
565
|
+
if (d.host && d.port) targets.push({ name: c.name, type: c.type, raw, ...d })
|
|
418
566
|
}
|
|
567
|
+
const reachable = []
|
|
419
568
|
for (const t of SKIP_NET ? [] : targets) {
|
|
420
569
|
const r = await tcpProbe(t.host, t.port)
|
|
421
|
-
if (r.reachable)
|
|
422
|
-
|
|
570
|
+
if (r.reachable) {
|
|
571
|
+
ok('Reachability', `${t.name}: ${t.host}:${t.port} answers`)
|
|
572
|
+
reachable.push(t)
|
|
573
|
+
} else
|
|
423
574
|
fail(
|
|
424
575
|
'Reachability',
|
|
425
576
|
`${t.name}: ${t.host}:${t.port} unreachable (${r.why})`,
|
|
426
577
|
'The gateway logs connector failures and keeps running with zero connectors — it will look healthy and serve nothing.',
|
|
427
578
|
)
|
|
428
579
|
}
|
|
580
|
+
|
|
581
|
+
// D1 — declared dialect vs the engine that actually answers.
|
|
582
|
+
// Silence here meant Oracle rules on a Postgres DSN. Mismatch is FAIL.
|
|
583
|
+
// Cannot ask → unseen. Never "probably matches".
|
|
584
|
+
let dialectForEngine = null
|
|
585
|
+
try {
|
|
586
|
+
dialectForEngine = resolveDoctorDialect(config.policy?.dialect).dialect
|
|
587
|
+
} catch {
|
|
588
|
+
dialectForEngine = null
|
|
589
|
+
}
|
|
590
|
+
if (dialectForEngine) {
|
|
591
|
+
let schemeConflict = false
|
|
592
|
+
for (const t of targets) {
|
|
593
|
+
const fromScheme = familyFromScheme(t.scheme)
|
|
594
|
+
if (fromScheme && !dialectAgrees(dialectForEngine, fromScheme)) {
|
|
595
|
+
schemeConflict = true
|
|
596
|
+
fail(
|
|
597
|
+
'Engine identity',
|
|
598
|
+
`${t.name}: policy.dialect is ${dialectForEngine} but the DSN scheme is ${t.scheme} (${fromScheme})`,
|
|
599
|
+
'The query tool will parse with one grammar and send the SQL to another engine. Point the DSN at the declared dialect, or change policy.dialect.',
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (schemeConflict) {
|
|
604
|
+
// Already FAIL. Do not add a "not checked" line that reads like a second opinion.
|
|
605
|
+
} else if (SKIP_NET) {
|
|
606
|
+
unseen(
|
|
607
|
+
'Engine identity',
|
|
608
|
+
`not checked (--no-net). Declared dialect ${dialectForEngine} was not compared to a live engine.`,
|
|
609
|
+
'Rerun without --no-net when the database is reachable. Do not assume the dialect matches.',
|
|
610
|
+
)
|
|
611
|
+
} else if (targets.length === 0) {
|
|
612
|
+
unseen(
|
|
613
|
+
'Engine identity',
|
|
614
|
+
`not checked (no SQL DSN). Declared dialect ${dialectForEngine}.`,
|
|
615
|
+
'Add a postgres / SQL connector URL, or ignore this if this install has no SQL engine.',
|
|
616
|
+
)
|
|
617
|
+
} else if (reachable.length === 0) {
|
|
618
|
+
unseen(
|
|
619
|
+
'Engine identity',
|
|
620
|
+
`not checked (host unreachable). Declared dialect ${dialectForEngine}.`,
|
|
621
|
+
'Bring the engine up, then rerun. Unreachable is not a match.',
|
|
622
|
+
)
|
|
623
|
+
} else {
|
|
624
|
+
for (const t of reachable) {
|
|
625
|
+
const id = await identifyEngine(t)
|
|
626
|
+
if (!id) {
|
|
627
|
+
unseen(
|
|
628
|
+
'Engine identity',
|
|
629
|
+
`${t.name}: ${t.host}:${t.port} answers TCP but the engine family could not be read. Declared ${dialectForEngine}.`,
|
|
630
|
+
'Doctor asked the engine and got no version banner. Not a pass.',
|
|
631
|
+
)
|
|
632
|
+
continue
|
|
633
|
+
}
|
|
634
|
+
if (!dialectAgrees(dialectForEngine, id.family)) {
|
|
635
|
+
fail(
|
|
636
|
+
'Engine identity',
|
|
637
|
+
`${t.name}: policy.dialect is ${dialectForEngine} but the engine identified as ${id.family} (${id.summary})`,
|
|
638
|
+
'The query tool will enforce the wrong grammar against this engine. Fix policy.dialect or the DSN.',
|
|
639
|
+
)
|
|
640
|
+
} else {
|
|
641
|
+
ok('Engine identity', `${t.name}: engine is ${id.family} — matches policy.dialect ${dialectForEngine}`)
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
429
646
|
}
|
|
430
647
|
|
|
431
648
|
// 12. License pack — offline, never fail-closed. A broken license file must
|
|
@@ -466,7 +683,7 @@ if (config) {
|
|
|
466
683
|
|
|
467
684
|
/* ------------------------------------------------------------------ report */
|
|
468
685
|
|
|
469
|
-
const ICON = { ok: ' ok ', warn: ' warn ', fail: ' FAIL ' }
|
|
686
|
+
const ICON = { ok: ' ok ', warn: ' warn ', fail: ' FAIL ', unseen: 'unseen' }
|
|
470
687
|
console.log('')
|
|
471
688
|
console.log('conarium doctor')
|
|
472
689
|
console.log('─'.repeat(66))
|
|
@@ -476,9 +693,11 @@ for (const r of results) {
|
|
|
476
693
|
}
|
|
477
694
|
const fails = results.filter((r) => r.level === 'fail').length
|
|
478
695
|
const warns = results.filter((r) => r.level === 'warn').length
|
|
696
|
+
const unseenN = results.filter((r) => r.level === 'unseen').length
|
|
479
697
|
console.log('─'.repeat(66))
|
|
480
|
-
console.log(`${results.length} checks · ${fails} failed · ${warns} warning(s)`)
|
|
481
|
-
if (fails === 0 && warns === 0) console.log('This install is ready.')
|
|
698
|
+
console.log(`${results.length} checks · ${fails} failed · ${warns} warning(s) · ${unseenN} unseen`)
|
|
699
|
+
if (fails === 0 && warns === 0 && unseenN === 0) console.log('This install is ready.')
|
|
700
|
+
if (fails === 0 && unseenN > 0) console.log('No failures. Unseen lines were not verified — not a pass.')
|
|
482
701
|
if (fails > 0) console.log('Fix the FAIL lines above; the gateway will not govern correctly until you do.')
|
|
483
702
|
console.log('')
|
|
484
703
|
// Set the code and let the loop drain. process.exit() here raced the closing
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure dialect / engine helpers for conarium-doctor.
|
|
3
|
+
* Kept out of src/ so the doctor still runs when the build is broken.
|
|
4
|
+
* No DSN, no pattern text, no secrets.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const DOCTOR_DIALECTS = ['postgres', 'mssql', 'oracle']
|
|
8
|
+
|
|
9
|
+
/** Missing → postgres (today's path). Typo / mysql → throw. No silent fallback. */
|
|
10
|
+
export function resolveDoctorDialect(value) {
|
|
11
|
+
if (value === undefined) return { dialect: 'postgres', source: 'default' }
|
|
12
|
+
if (value === 'postgres' || value === 'mssql' || value === 'oracle') {
|
|
13
|
+
return { dialect: value, source: 'declared' }
|
|
14
|
+
}
|
|
15
|
+
const shown = typeof value === 'string' ? value : typeof value
|
|
16
|
+
throw new Error(`policy.dialect "${shown}" is not allowed. Use postgres, mssql, or oracle.`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function familyFromScheme(scheme) {
|
|
20
|
+
const s = String(scheme || '').toLowerCase().replace(/:$/, '')
|
|
21
|
+
if (s === 'postgres' || s === 'postgresql') return 'postgres'
|
|
22
|
+
if (s === 'mssql' || s === 'sqlserver' || s === 'microsoft-sql-server') return 'mssql'
|
|
23
|
+
if (s === 'oracle' || s === 'oracledb') return 'oracle'
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Banner / version() text → family. Unknown stays unknown — never guessed into a match. */
|
|
28
|
+
export function familyFromBanner(text) {
|
|
29
|
+
const t = String(text || '')
|
|
30
|
+
if (/postgresql/i.test(t) || /\bpostgres\b/i.test(t)) return 'postgres'
|
|
31
|
+
if (/microsoft sql server/i.test(t) || /\bsql server\b/i.test(t)) return 'mssql'
|
|
32
|
+
if (/\boracle\b/i.test(t)) return 'oracle'
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function dialectAgrees(dialect, family) {
|
|
37
|
+
if (!family) return false
|
|
38
|
+
return dialect === family
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** One line the operator can paste. Never include a DSN or password. */
|
|
42
|
+
export function dialectLine(dialect, source) {
|
|
43
|
+
if (source === 'default') {
|
|
44
|
+
return `${dialect} (default — policy.dialect omitted)`
|
|
45
|
+
}
|
|
46
|
+
return `${dialect} (declared in policy.dialect)`
|
|
47
|
+
}
|
package/dist/audit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAejD,OAAO,EAIL,KAAK,UAAU,EAIhB,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOnE,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,iFAAiF;IACjF,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;OAGG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|
2
|
+
import { createHmac, timingSafeEqual } from 'crypto';
|
|
3
3
|
import { computeEntryHash, GENESIS_HASH } from './audit-hash.js';
|
|
4
4
|
import { loadSigningKey, loadTrustStore, signHash, verifyHash, } from './keys.js';
|
|
5
5
|
import { maskIbansInText, prepareIbanPass } from './iban.js';
|
|
@@ -73,6 +73,14 @@ function entryToReceiptInput(entry, meta) {
|
|
|
73
73
|
outcome: { status: entry.denied ? 'denied' : 'complete', denied: entry.denied },
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
+
/** HMAC hex compare. `!==` on the digest leaks via timing; Node's primitive does not. */
|
|
77
|
+
function hmacDigestEqual(presented, expected) {
|
|
78
|
+
const a = Buffer.from(presented, 'utf8');
|
|
79
|
+
const b = Buffer.from(expected, 'utf8');
|
|
80
|
+
if (a.length !== b.length)
|
|
81
|
+
return false;
|
|
82
|
+
return timingSafeEqual(a, b);
|
|
83
|
+
}
|
|
76
84
|
let unsignedWarned = false;
|
|
77
85
|
function warnUnsignedOnce() {
|
|
78
86
|
if (unsignedWarned)
|
|
@@ -369,13 +377,14 @@ export class Audit {
|
|
|
369
377
|
// imza YOK + henüz imzalı satır görülmedi → eski kayıt, kabul
|
|
370
378
|
// imza YOK + daha önce imzalı satır var → strip girişimi, reddet
|
|
371
379
|
// imza VAR ama eşleşmiyor → kurcalama, her zaman reddet
|
|
372
|
-
const
|
|
380
|
+
const presentedSig = typeof entry.signature === 'string' ? entry.signature : '';
|
|
381
|
+
const hasSignature = presentedSig.length > 0;
|
|
373
382
|
if (hasSignature) {
|
|
374
383
|
// Doğrulama yalnızca anahtar varken yapılabilir; anahtarsızken imzanın VARLIĞI
|
|
375
384
|
// yine de bitişiklik için sayılır, yoksa "anahtarı kaldır + imzaları sil" açık kalırdı.
|
|
376
385
|
if (this.hmacKey) {
|
|
377
386
|
const expectedSignature = createHmac('sha256', this.hmacKey).update(entry.hash).digest('hex');
|
|
378
|
-
if (
|
|
387
|
+
if (!hmacDigestEqual(presentedSig, expectedSignature)) {
|
|
379
388
|
throw new Error('Audit sink is corrupt: entry signature mismatch.');
|
|
380
389
|
}
|
|
381
390
|
}
|