@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.
Files changed (136) hide show
  1. package/CHANGELOG.md +149 -1
  2. package/LICENSE +21 -21
  3. package/LIMITATIONS.md +36 -2
  4. package/LIMITATIONS.tr.md +25 -2
  5. package/SECURITY.md +1 -0
  6. package/bin/conarium-coverage.mjs +89 -6
  7. package/bin/conarium-doctor.mjs +62 -0
  8. package/bin/conarium-verify.mjs +110 -51
  9. package/dist/anchor.d.ts +11 -0
  10. package/dist/anchor.d.ts.map +1 -1
  11. package/dist/anchor.js +27 -0
  12. package/dist/anchor.js.map +1 -1
  13. package/dist/audit.d.ts +4 -0
  14. package/dist/audit.d.ts.map +1 -1
  15. package/dist/audit.js +136 -33
  16. package/dist/audit.js.map +1 -1
  17. package/dist/config.d.ts +28 -8
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/config.js +51 -1
  20. package/dist/config.js.map +1 -1
  21. package/dist/connectors/custom-sql.d.ts +22 -0
  22. package/dist/connectors/custom-sql.d.ts.map +1 -0
  23. package/dist/connectors/custom-sql.js +67 -0
  24. package/dist/connectors/custom-sql.js.map +1 -0
  25. package/dist/connectors/index.d.ts +1 -0
  26. package/dist/connectors/index.d.ts.map +1 -1
  27. package/dist/connectors/index.js +5 -1
  28. package/dist/connectors/index.js.map +1 -1
  29. package/dist/connectors/openapi.d.ts +14 -1
  30. package/dist/connectors/openapi.d.ts.map +1 -1
  31. package/dist/connectors/openapi.js +78 -6
  32. package/dist/connectors/openapi.js.map +1 -1
  33. package/dist/connectors/postgres.js +8 -8
  34. package/dist/connectors/supabase_rest.d.ts.map +1 -1
  35. package/dist/connectors/supabase_rest.js +0 -1
  36. package/dist/connectors/supabase_rest.js.map +1 -1
  37. package/dist/console-receipts.d.ts +12 -1
  38. package/dist/console-receipts.d.ts.map +1 -1
  39. package/dist/console-receipts.js +14 -2
  40. package/dist/console-receipts.js.map +1 -1
  41. package/dist/console.d.ts.map +1 -1
  42. package/dist/console.js +15 -4
  43. package/dist/console.js.map +1 -1
  44. package/dist/coverage.d.ts +17 -1
  45. package/dist/coverage.d.ts.map +1 -1
  46. package/dist/coverage.js +30 -3
  47. package/dist/coverage.js.map +1 -1
  48. package/dist/digit_pii.d.ts.map +1 -1
  49. package/dist/digit_pii.js +24 -5
  50. package/dist/digit_pii.js.map +1 -1
  51. package/dist/executor.d.ts.map +1 -1
  52. package/dist/executor.js +0 -1
  53. package/dist/executor.js.map +1 -1
  54. package/dist/governance.d.ts +2 -0
  55. package/dist/governance.d.ts.map +1 -1
  56. package/dist/governance.js +23 -8
  57. package/dist/governance.js.map +1 -1
  58. package/dist/http.d.ts +11 -1
  59. package/dist/http.d.ts.map +1 -1
  60. package/dist/http.js +87 -7
  61. package/dist/http.js.map +1 -1
  62. package/dist/iban.d.ts.map +1 -1
  63. package/dist/iban.js +6 -3
  64. package/dist/iban.js.map +1 -1
  65. package/dist/index.js +1 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/keys.d.ts +5 -0
  68. package/dist/keys.d.ts.map +1 -1
  69. package/dist/keys.js +22 -7
  70. package/dist/keys.js.map +1 -1
  71. package/dist/mask-text.d.ts +11 -0
  72. package/dist/mask-text.d.ts.map +1 -0
  73. package/dist/mask-text.js +42 -0
  74. package/dist/mask-text.js.map +1 -0
  75. package/dist/receipt-view.d.ts +13 -0
  76. package/dist/receipt-view.d.ts.map +1 -1
  77. package/dist/receipt-view.js +28 -5
  78. package/dist/receipt-view.js.map +1 -1
  79. package/dist/search_policy.d.ts.map +1 -1
  80. package/dist/search_policy.js +8 -4
  81. package/dist/search_policy.js.map +1 -1
  82. package/dist/server.d.ts.map +1 -1
  83. package/dist/server.js +111 -20
  84. package/dist/server.js.map +1 -1
  85. package/dist/sql-executor.d.ts +14 -0
  86. package/dist/sql-executor.d.ts.map +1 -0
  87. package/dist/sql-executor.js +75 -0
  88. package/dist/sql-executor.js.map +1 -0
  89. package/dist/sql-gate/mssql.d.ts.map +1 -1
  90. package/dist/sql-gate/mssql.js +36 -2
  91. package/dist/sql-gate/mssql.js.map +1 -1
  92. package/dist/sql-gate/oracle.d.ts.map +1 -1
  93. package/dist/sql-gate/oracle.js +24 -3
  94. package/dist/sql-gate/oracle.js.map +1 -1
  95. package/dist/sql-gate/rules.d.ts +19 -1
  96. package/dist/sql-gate/rules.d.ts.map +1 -1
  97. package/dist/sql-gate/rules.js +116 -7
  98. package/dist/sql-gate/rules.js.map +1 -1
  99. package/dist/table-unavailable.d.ts +12 -0
  100. package/dist/table-unavailable.d.ts.map +1 -0
  101. package/dist/table-unavailable.js +32 -0
  102. package/dist/table-unavailable.js.map +1 -0
  103. package/dist/types.d.ts +10 -3
  104. package/dist/types.d.ts.map +1 -1
  105. package/docs/API-STABILITY.md +4 -4
  106. package/docs/ARCHITECTURE.md +42 -42
  107. package/docs/BENCHMARK.md +20 -0
  108. package/docs/RECEIPT-SPEC.md +17 -11
  109. package/docs/benchmarks/concurrency-20260814.json +38 -0
  110. package/docs/plans/2026-07-02-redteam-harness.md +416 -416
  111. package/docs/security/NPM-PROVENANCE.md +64 -0
  112. package/docs/security/THREAT-MODEL.md +18 -0
  113. package/docs/specs/2026-07-02-redteam-harness-design.md +90 -90
  114. package/docs/superpowers/TODO-gate1-f4.md +23 -23
  115. package/docs/superpowers/plans/2026-07-29-conarium-receipt-plan.md +200 -200
  116. package/docs/superpowers/specs/2026-07-29-conarium-receipt-design.md +202 -202
  117. package/examples/claude-desktop-config.json +9 -9
  118. package/examples/cursor-mcp-settings.json +10 -10
  119. package/examples/custom-sql/README.md +50 -0
  120. package/examples/custom-sql/conarium.config.json +22 -0
  121. package/examples/custom-sql/memory-executor.mjs +16 -0
  122. package/package.json +8 -4
  123. package/public/app.js +378 -378
  124. package/public/index.html +160 -160
  125. package/public/style.css +504 -504
  126. package/scripts/benchmark-concurrency.mjs +133 -0
  127. package/scripts/conarium_sabah_brief.mjs +107 -107
  128. package/scripts/start-mcp-c1.mjs +93 -93
  129. package/test-vectors/sql-gate/LAST-RUN.json +1 -1
  130. package/test-vectors/sql-gate/vectors.json +28 -0
  131. package/dist/openapi_connector.d.ts +0 -6
  132. package/dist/openapi_connector.d.ts.map +0 -1
  133. package/dist/openapi_connector.js +0 -145
  134. package/dist/openapi_connector.js.map +0 -1
  135. package/docs/audit/2026-08-14-security-scan.md +0 -48
  136. package/docs/audit/2026-08-14-surface-sync.md +0 -34
package/CHANGELOG.md CHANGED
@@ -1,6 +1,154 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.2.13 — 2026-08-15
4
+
5
+ Security hardening release. Two independent external reviews and one code
6
+ audit produced the findings below; each was reproduced against running code
7
+ before it was fixed. Several defaults change — the entries marked
8
+ **Behavior change** are the ones to read before upgrading.
9
+
10
+ - **Dialect scalar functions.** The function allow-list carries Postgres
11
+ names, so routing the MSSQL and Oracle gates through it denied ordinary
12
+ calls (`GETDATE`, `ISNULL`, `DATEADD`, `NVL`, `TO_CHAR`). Safe scalars are
13
+ now listed per dialect and consulted only for an unqualified name, so
14
+ `app.pkg.nvl` stays a user package. One dialect's list never applies to
15
+ another's gate, and row-collapsing, `DBMS_*` and `UTL_*` families remain
16
+ denied.
17
+
18
+ - **npm Trusted Publishing (OIDC).** The publish workflow no longer expects a
19
+ long-lived `NPM_TOKEN`; npmjs.com recognises the repository and workflow as
20
+ the authorised publisher and provenance is attached to the release. No
21
+ publish token lives in the repository. See `docs/security/NPM-PROVENANCE.md`.
22
+
23
+ - **G20:** Write-token scan ignores SQL string literals
24
+ (`SELECT 'DELETE ' FROM t` is a read). OpenAPI fetch caps the body at
25
+ 50KB before `JSON.parse`. Audit sink hash stays `JSON.stringify`
26
+ (JCS would break existing files — LIMITATIONS).
27
+
28
+ - **G12:** `conarium-doctor` warns when HTTP is on and
29
+ `CONARIUM_MCP_RATE_PER_MIN` is 0; a positive limit is an info line.
30
+ The default remains 0 (production profile fills 60).
31
+
32
+ - **G11:** Unpinned `conarium-verify` still exits 0, but stderr says the
33
+ tail was not seen and `--json` carries `tailPinned`. `--strict` requires
34
+ a tail pin (exit 11) and pins seq from 1. The console verify command
35
+ embeds `--expect-count` and `--expect-last-hash` for the current chain.
36
+
37
+ - **Behavior change (G10):** OpenAPI fetch uses `redirect: manual` and
38
+ re-checks every hop (max 5). The approved DNS address is pinned via
39
+ an undici Agent lookup; TLS SNI stays the original hostname. undici
40
+ is not added to package.json.
41
+
42
+ - **Behavior change (G9):** Private key files that are not 0600 fail
43
+ boot. Escape hatch `CONARIUM_ALLOW_LOOSE_KEY_PERMS=1` restores the
44
+ old warning. win32 skips the check (POSIX mode is meaningless).
45
+
46
+ - **Behavior change (G6):** HTTP sessions idle out after
47
+ `CONARIUM_SESSION_IDLE_MS` (default 30 minutes; 0 = off). Owner-binding
48
+ is unchanged. Sweeper uses `unref()`.
49
+
50
+ - **Behavior change (G7):** `CONARIUM_MAX_SESSIONS` defaults to 100
51
+ (0 = unlimited). A new initialize at the cap is JSON-RPC rejected.
52
+
53
+ - **G8:** Token file reloads on mtime change. Broken JSON keeps the
54
+ previous store and logs; it does not fall back to an empty map.
55
+
56
+ - **G5:** Audit sink takes an advisory `<sink>.lock` (`wx`, PID + start).
57
+ A second OS process is rejected; a stale lock (dead PID) is stolen.
58
+ Same-process re-entry stays allowed (console / validateChain boot).
59
+ The lock does not stop a writer outside Conarium.
60
+
61
+ - **G4:** `profile: "production"` (or `CONARIUM_PROFILE=production`) refuses
62
+ boot without Ed25519 AND HMAC, turns G3 strict signatures and OpenTimestamps
63
+ anchoring on, and defaults HTTP rate-limit to 60/min unless explicitly 0.
64
+ `conarium-doctor` reports the profile as one block.
65
+
66
+ - **Behavior change (G21):** `conarium-coverage --receipts` re-verifies each
67
+ receipt Ed25519 signature; a broken sig is not COMPLETE and names the
68
+ receipt. The declaration carries `windowStartPinned` — an unpinned
69
+ prefix-truncated window is no longer a silent complete. Output says
70
+ "access NOT RECORDED", never "no access occurred". `--expect-seq-from`
71
+ pins the window start.
72
+
73
+ - **Behavior change (G17):** Receipt HTML never prints raw `anchor.state`
74
+ as a trust signal — forged `state: bitcoin` renders as `doğrulanmadı`
75
+ until the OTS sidecar verifies. `--anchor-check` skips `anchor:null`
76
+ (periodic anchoring) and fails only on a claimed-but-unverified
77
+ anchor; the run ends with `N/M anchored, head anchored: yes/no`.
78
+ `--require-head-anchor` exits 14 when the chain head is unanchored.
79
+
80
+ - **G3:** `CONARIUM_AUDIT_REQUIRE_SIG=1` is opt-in strict boot — any
81
+ unsigned line is rejected when a signing key is configured. Default
82
+ unchanged (legacy unsigned chains still open).
83
+
84
+ - **Behavior change (G18):** Flat query rows apply the same column-name
85
+ secret/PII heuristic as nested JSON (`api_key` / `password` →
86
+ `[MASKED_SECRET]`). One function, two call sites.
87
+
88
+ - **Behavior change (G19):** Console `/api/config` redacts `key`,
89
+ `anonKey`, `headers`, and `authorization`, and also redacts JWT /
90
+ `sk-` / `AKIA` shaped values under innocent names.
91
+
92
+ - **Behavior change (G16):** Audit `reason`, `target`, and `governance`
93
+ go through the same mask pipeline as `args`. A DB error that carries
94
+ a cell value can no longer land unmasked on the signed sink.
95
+
96
+ - **Audit chain atomicity (G1):** `lastHash` and `sinkSize` advance
97
+ only after a successful sink append — same order as `writeReceipt()`.
98
+ A failed write no longer orphans the in-memory chain.
99
+
100
+ - **Audit self-heal (G2):** After a failed append, the next successful
101
+ `log()` chains from the last hash that is actually on disk. A fresh
102
+ `Audit({sink})` boot `validateChain` stays clean. `failClosed=true`
103
+ also leaves state unmoved.
104
+
105
+ - **Behavior change (G15):** Content detectors treat `.` / `/` as group
106
+ separators and use token boundaries (a glued letter or `_` no longer
107
+ hides a card/phone/IBAN). Zero-padded `&#064;` emails are masked.
108
+ Hyphenated US SSN is masked; bare 9-digit SSN stays a documented
109
+ limitation.
110
+
111
+ - **Behavior change (G14):** MSSQL and Oracle gates use the same function
112
+ allow-list as Postgres (`isSafeBuiltinFunction` / `isBlockedDumpFunction`).
113
+ `STRING_AGG` / `LISTAGG` and user/package functions are denied. MSSQL
114
+ locking hints (`WITH (UPDLOCK)` and kin) are denied. Oracle row-cap
115
+ wrapper strips comments so a trailing `--` cannot swallow `FETCH FIRST`.
116
+
117
+ - **Behavior change (G13):** Connector/DB error text is masked before it
118
+ reaches the model. Failed `query` / `search` / `describe_table` paths
119
+ that previously skipped the audit trail now write a `denied` line.
120
+ Already-logged denies (policy, missing table, 50KB) are not written twice.
121
+
122
+ ## 0.2.8 – 0.2.12 — 2026-08-14
123
+
124
+ These shipped across 0.2.8, 0.2.9, 0.2.10, 0.2.11 and 0.2.12 and were kept in
125
+ one list at the time; the tags are the authority on which release carries which.
126
+
127
+ - **Table existence oracle closed.** Assistant `describe_table` / `search` /
128
+ `query` errors no longer distinguish denied from missing. The audit log
129
+ keeps the real reason. Denied tables still never reach the connector.
130
+ `describe_table` now has the same 50KB payload cap as `query` / `search`.
131
+ - **Dropped `js-yaml` and `node-fetch`.** Zero remaining imports. HTTP uses
132
+ Node's built-in `fetch` (engines already `>=18`).
133
+ - **npm provenance workflow** prepared (`publish.yml`, dispatch-only). Does
134
+ not publish on push. See `docs/security/NPM-PROVENANCE.md`.
135
+ - **Two-process audit sink** stated in LIMITATIONS and the threat model.
136
+ No lock in this release.
137
+
138
+ - **Operator is inside the boundary.** Threat model and LIMITATIONS state
139
+ it in the open: importing the library can skip the gate the same way
140
+ opening the database with the operator's credential can. Not a vulnerability.
141
+ - **HMAC compare uses `timingSafeEqual`.** Audit-sink HMAC was `!==` on the
142
+ hex digest. Ed25519 verify stays on Node `crypto.verify`.
143
+ - **Doctor names `custom-sql`** and fails when that connector is present
144
+ without a declared `policy.dialect`. `list_tables` on an executor-only
145
+ install says schema discovery is not implemented (not a silent empty list).
146
+
147
+ - **Operator SQL executor (`custom-sql`).** No MSSQL/Oracle driver is
148
+ shipped. The operator registers a function or a local `config.module`;
149
+ it receives only gated SQL. `policy.dialect` is required on that path.
150
+ Row cap and masking still apply on the return. See
151
+ `examples/custom-sql/`.
4
152
 
5
153
  - **Postgres overhead measured.** Same SELECT, default `maxRows` 100: about
6
154
  5 ms added when email is masked. 500 → ~87 ms. 5 000 → ~22 s. Cost
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Emek Can Doğru (Conarium)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emek Can Doğru (Conarium)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/LIMITATIONS.md CHANGED
@@ -14,11 +14,17 @@ Version is 0.2.x. The API can break.
14
14
 
15
15
  MySQL is not implemented.
16
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 connector. 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.
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
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. The gate rewrites SQL; a connector that can speak that engine is still the operator's.
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
20
  Parsers: Postgres `pgsql-ast-parser` · MSSQL `node-sql-parser` (transactsql) · Oracle `@guanmingchiu/sqlparser-ts`.
21
21
 
22
+ ## Bare 9-digit US SSN is not a content detector
23
+
24
+ `XXX-XX-XXXX` (hyphenated) is masked. A bare 9-digit run is not: it
25
+ collides with order IDs and other identifiers. This is a measured
26
+ limitation, not an oversight.
27
+
22
28
  ## Names in free text are not guaranteed
23
29
 
24
30
  Structured columns: deterministic (`maskColumns`).
@@ -39,6 +45,34 @@ Bus factor 1.
39
45
 
40
46
  An OpenTimestamps stamp can take hours to confirm on Bitcoin. Receipts already show `pending`.
41
47
 
48
+ ## The operator is inside the boundary
49
+
50
+ The product defends the assistant-to-gateway path. Code that imports the
51
+ library can skip the gate the same way it can open the database with the
52
+ operator's credential. The operator's own process is not an audit subject
53
+ of this gateway.
54
+
55
+ ## Two processes, one audit file
56
+
57
+ `Audit.log()` is synchronous. One process can write many concurrent queries
58
+ without breaking `prevHash`. A second OS process that opens the same sink
59
+ is rejected (`<sink>.lock`, advisory `wx`). The lock does not stop a writer
60
+ outside Conarium that ignores the lock file.
61
+
62
+ ## Strict signature mode is opt-in
63
+
64
+ `CONARIUM_AUDIT_REQUIRE_SIG=1` refuses boot if a signing key is set and
65
+ any audit line is unsigned. The default still accepts a fully unsigned
66
+ legacy chain when an HMAC key is later added (08-05 compatibility).
67
+
68
+ ## Audit sink hash is not JCS
69
+
70
+ Receipts hash with RFC 8785 JCS (`canonicalize`). The audit JSONL hasher
71
+ (`src/audit-hash.ts`) uses `JSON.stringify` of insertion order. The two
72
+ disagree when keys are unsorted (`{"b":1,"a":2}` vs `{"a":2,"b":1}`).
73
+ Switching the sink to JCS would invalidate every existing audit file.
74
+ Independent re-hash of an old sink must use `JSON.stringify`, not JCS.
75
+
42
76
  ## Cryptography is not independently audited
43
77
 
44
78
  The Ed25519 implementation has not had a formal audit.
package/LIMITATIONS.tr.md CHANGED
@@ -14,11 +14,16 @@ Sürüm 0.2.x. API kırılabilir.
14
14
 
15
15
  MySQL yok.
16
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 konnektör 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.
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
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. Kapı SQL’i yeniden yazar; o motora konuşan konnektör hâlâ operatörün.
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
20
  Ayrıştırıcılar: Postgres `pgsql-ast-parser` · MSSQL `node-sql-parser` (transactsql) · Oracle `@guanmingchiu/sqlparser-ts`.
21
21
 
22
+ ## Çıplak 9 haneli ABD SSN içerik dedektörü değil
23
+
24
+ `XXX-XX-XXXX` (tireli) maskelenir. Çıplak 9 haneli koşu maskelenmez:
25
+ sipariş numarası ve benzeri kimliklerle çakışır. Ölçülmüş sınır, unutkanlık değil.
26
+
22
27
  ## Serbest metinde isim garantisi yok
23
28
 
24
29
  Yapılandırılmış kolonlar: deterministik (`maskColumns`).
@@ -39,6 +44,24 @@ Bus factor 1.
39
44
 
40
45
  OpenTimestamps damgasının Bitcoin'de onaylanması saatler sürebilir. Makbuzda `pending` zaten görünür.
41
46
 
47
+ ## Operatör sınırın içindedir
48
+
49
+ Ürün asistan ↔ kapı yolunu korur. Kütüphaneyi import eden kod kapıyı,
50
+ operatörün kimlik bilgisiyle veritabanına bağlanmakla aynı yetkiyle
51
+ atlayabilir. Operatörün kendi süreci bu kapının denetim konusu değildir.
52
+
53
+ ## İki süreç, tek denetim dosyası
54
+
55
+ `Audit.log()` senkrondur. Tek süreçte eşzamanlı sorgular `prevHash` kırmadan
56
+ yazar. Aynı sink’i açan ikinci OS süreci reddedilir (`<sink>.lock`,
57
+ advisory `wx`). Kilit, Conarium dışından dosyaya yazan süreci durdurmaz.
58
+
59
+ ## Sıkı imza kipi opt-in
60
+
61
+ `CONARIUM_AUDIT_REQUIRE_SIG=1` imza anahtarı varken imzasız tek satırda
62
+ boot'u reddeder. Varsayılan, HMAC sonradan eklenince tamamen imzasız
63
+ eski zinciri hâlâ açar (08-05 uyumu).
64
+
42
65
  ## Denetlenmemiş kriptografi
43
66
 
44
67
  Ed25519 uygulaması resmî denetimden geçmedi.
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
@@ -64,6 +64,20 @@ function coverageHash(d) {
64
64
  return `sha256:${digest}`
65
65
  }
66
66
 
67
+ function receiptHash(r) {
68
+ const copy = { ...r }
69
+ delete copy.hash
70
+ delete copy.sig
71
+ delete copy.anchor
72
+ if (copy.chain && typeof copy.chain === 'object') {
73
+ const chain = { ...copy.chain }
74
+ delete chain.hash
75
+ copy.chain = chain
76
+ }
77
+ const digest = createHash('sha256').update(canonicalize(copy)).digest('hex')
78
+ return `sha256:${digest}`
79
+ }
80
+
67
81
  // Exported for cross-check tests (dynamic import of this file).
68
82
  export { canonicalize, coverageHash }
69
83
 
@@ -72,12 +86,12 @@ export { canonicalize, coverageHash }
72
86
  function usage(msg) {
73
87
  if (msg) console.error(msg)
74
88
  console.error(
75
- 'Usage: conarium-coverage <declaration.json> --pubkey <path> [--receipts <receipts.jsonl>] [--allow-gaps] [--json]',
89
+ 'Usage: conarium-coverage <declaration.json> --pubkey <path> [--receipts <receipts.jsonl>] [--expect-seq-from N] [--allow-gaps] [--json]',
76
90
  )
77
91
  }
78
92
 
79
93
  function parseArgs(argv) {
80
- const out = { target: null, pubkeys: [], receiptsPath: null, json: false, allowGaps: false }
94
+ const out = { target: null, pubkeys: [], receiptsPath: null, json: false, allowGaps: false, expectSeqFrom: null }
81
95
  const args = [...argv]
82
96
  while (args.length) {
83
97
  const a = args.shift()
@@ -93,6 +107,10 @@ function parseArgs(argv) {
93
107
  out.json = true
94
108
  } else if (a === '--allow-gaps') {
95
109
  out.allowGaps = true
110
+ } else if (a === '--expect-seq-from') {
111
+ const n = args.shift()
112
+ if (n === undefined || !/^\d+$/.test(n)) throw new Error('--expect-seq-from requires an integer')
113
+ out.expectSeqFrom = Number(n)
96
114
  } else if (a === '--help' || a === '-h') {
97
115
  usage()
98
116
  process.exit(0)
@@ -206,6 +224,30 @@ function schemaOk(d) {
206
224
  return null
207
225
  }
208
226
 
227
+ function verifyReceiptSig(keys, receipt) {
228
+ const id = receipt.id || `seq:${receipt.chain?.seq}`
229
+ if (!receipt.sig || typeof receipt.sig !== 'object') {
230
+ return { id, error: 'missing sig' }
231
+ }
232
+ if (receipt.sig.alg !== 'Ed25519') return { id, error: `unsupported sig.alg ${receipt.sig.alg}` }
233
+ const pk = keys.get(receipt.sig.keyId)
234
+ if (!pk) return { id, error: `unknown keyId ${receipt.sig.keyId}` }
235
+ try {
236
+ if (receipt.chain?.hash && receiptHash(receipt) !== receipt.chain.hash) {
237
+ return { id, error: 'hash mismatch' }
238
+ }
239
+ const ok = cryptoVerify(
240
+ null,
241
+ Buffer.from(receipt.chain.hash, 'utf-8'),
242
+ pk,
243
+ Buffer.from(receipt.sig.value, 'base64'),
244
+ )
245
+ return ok ? null : { id, error: 'signature cryptographically invalid' }
246
+ } catch (err) {
247
+ return { id, error: `signature verify error: ${err.message}` }
248
+ }
249
+ }
250
+
209
251
  function verifySig(keys, d) {
210
252
  const pk = keys.get(d.sig.keyId)
211
253
  if (!pk) return `unknown keyId ${d.sig.keyId}`
@@ -370,10 +412,32 @@ async function main(argv = process.argv.slice(2)) {
370
412
  if (recResult.error) {
371
413
  fail(recResult.code, recResult.error, opts.json)
372
414
  }
415
+ for (const receipt of recResult.receipts) {
416
+ const sigFail = verifyReceiptSig(keys, receipt)
417
+ if (sigFail) {
418
+ fail(
419
+ 13,
420
+ `receipt signature invalid at ${sigFail.id}: ${sigFail.error} — coverage is not COMPLETE`,
421
+ opts.json,
422
+ { receiptId: sigFail.id },
423
+ )
424
+ }
425
+ }
373
426
  const crossErr = crossCheck(d, recResult.receipts)
374
427
  if (crossErr) {
375
428
  fail(30, `inconsistent with receipts: ${crossErr}`, opts.json)
376
429
  }
430
+ if (opts.expectSeqFrom !== null && recResult.receipts.length) {
431
+ const seqs = recResult.receipts.map((r) => r.chain.seq).sort((a, b) => a - b)
432
+ if (seqs[0] !== opts.expectSeqFrom) {
433
+ fail(
434
+ 12,
435
+ `window start mismatch: expected seq ${opts.expectSeqFrom}, receipts start at ${seqs[0]} — coverage is not COMPLETE`,
436
+ opts.json,
437
+ { expectedFirstSeq: opts.expectSeqFrom, firstSeq: seqs[0] },
438
+ )
439
+ }
440
+ }
377
441
  }
378
442
 
379
443
  // Zincir kesintisizliği: CI'da sorulan soru "kapsamam eksiksiz mi?" (b).
@@ -391,20 +455,39 @@ async function main(argv = process.argv.slice(2)) {
391
455
  fail(12, msg, opts.json, { gaps: d.chain.gaps })
392
456
  }
393
457
 
458
+ const windowStartPinned = d.chain.windowStartPinned === true || opts.expectSeqFrom !== null
459
+ const complete = d.chain.contiguous === true && windowStartPinned
460
+ const pinNote = windowStartPinned
461
+ ? 'window start pinned'
462
+ : 'window start not pinned (başlangıç sabitlenmedi)'
463
+
394
464
  if (opts.json) {
395
- console.log(JSON.stringify({ ok: true, code: 0, declaration: d.id, version: d.v }))
465
+ console.log(JSON.stringify({
466
+ ok: true,
467
+ code: 0,
468
+ declaration: d.id,
469
+ version: d.v,
470
+ complete,
471
+ windowStartPinned,
472
+ pinNote,
473
+ }))
396
474
  } else {
397
475
  const unassigned = d.v === COVERAGE_V ? d.coverage.unassignedReceiptCount : 0
398
476
  console.log(
399
477
  `ok: coverage declaration ${d.id} verified (version ${d.v}, ${d.chain.count} receipts, ` +
400
- `contiguous=${d.chain.contiguous}, accessed=${d.coverage.accessed}, ` +
401
- `notRecorded=${d.coverage.notRecorded})`,
478
+ `contiguous=${d.chain.contiguous}, ${pinNote}, accessed=${d.coverage.accessed}, ` +
479
+ `notRecorded=${d.coverage.notRecorded} (access NOT RECORDED))`,
402
480
  )
481
+ if (!windowStartPinned) {
482
+ console.warn(
483
+ 'warning: window start not pinned — prefix truncation is invisible; pass --expect-seq-from N',
484
+ )
485
+ }
403
486
  // Belirsizlik uyarısı: notRecorded listesi ancak unassigned=0 iken "kesin" sayılabilir.
404
487
  // "erişilmedi"/"not accessed" ifadesi YASAK — kaydın yokluğu belirsizdir, erişim yokluğu değil.
405
488
  if (unassigned > 0) {
406
489
  console.warn(
407
- `warning: notRecorded=${d.coverage.notRecorded} (${unassigned} receipt(s) could not be attributed ` +
490
+ `warning: notRecorded=${d.coverage.notRecorded} (access NOT RECORDED; ${unassigned} receipt(s) could not be attributed ` +
408
491
  `to a specific object; this list is NOT definitive)`,
409
492
  )
410
493
  }
@@ -354,6 +354,24 @@ if (config) {
354
354
  }
355
355
  }
356
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
+
357
375
  // D3 — custom PII: names only. Pattern text must never reach stdout.
358
376
  const patterns = Array.isArray(pol.customPatterns) ? pol.customPatterns : []
359
377
  const patternNames = patterns
@@ -428,6 +446,50 @@ if (config) {
428
446
  }
429
447
  }
430
448
 
449
+ // 7b. Production proof profile — one block
450
+ {
451
+ const production =
452
+ (process.env.CONARIUM_PROFILE || '').toLowerCase() === 'production' ||
453
+ config?.profile === 'production'
454
+ if (production) {
455
+ const missing = []
456
+ if (!envSet('CONARIUM_AUDIT_SIGNING_KEY')) missing.push('Ed25519 (CONARIUM_AUDIT_SIGNING_KEY)')
457
+ if (!envSet('CONARIUM_AUDIT_HMAC_KEY')) missing.push('HMAC (CONARIUM_AUDIT_HMAC_KEY)')
458
+ const rateRaw = process.env.CONARIUM_MCP_RATE_PER_MIN
459
+ const rate = rateRaw === undefined || rateRaw === '' ? 60 : Number(rateRaw)
460
+ if (missing.length) {
461
+ fail(
462
+ 'Production profile',
463
+ `refuses boot without ${missing.join(' and ')}`,
464
+ 'Production requires Ed25519 AND HMAC, G3 strict signatures, and an anchor sink. Rate limit defaults to 60/min unless CONARIUM_MCP_RATE_PER_MIN=0.',
465
+ )
466
+ } else {
467
+ ok(
468
+ 'Production profile',
469
+ `Ed25519 + HMAC required; G3 on; anchor on; rate ${Number.isFinite(rate) ? rate : 60}/min`,
470
+ )
471
+ }
472
+ }
473
+ }
474
+
475
+ // 7c. HTTP rate limit — default 0 is intentional; say so when HTTP is on
476
+ {
477
+ const httpMode = Boolean(envSet('CONARIUM_MCP_TOKEN'))
478
+ if (httpMode) {
479
+ const rateRaw = process.env.CONARIUM_MCP_RATE_PER_MIN
480
+ const rate = rateRaw === undefined || rateRaw === '' ? 0 : Number(rateRaw)
481
+ if (!Number.isFinite(rate) || rate === 0) {
482
+ warn(
483
+ 'HTTP rate limit',
484
+ 'CONARIUM_MCP_RATE_PER_MIN is 0 (off)',
485
+ 'Public HTTP should set a limit. Production profile defaults to 60/min unless explicitly 0.',
486
+ )
487
+ } else {
488
+ ok('HTTP rate limit', `${rate}/min`)
489
+ }
490
+ }
491
+ }
492
+
431
493
  // 8. Signing key material — never printed, only described
432
494
  {
433
495
  const keyPath = envSet('CONARIUM_AUDIT_SIGNING_KEY')