@conarium-ai/core 0.2.12 → 0.2.14
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 +170 -1
- package/LICENSE +21 -21
- package/LIMITATIONS.md +23 -2
- package/LIMITATIONS.tr.md +13 -2
- package/bin/conarium-coverage.mjs +89 -6
- package/bin/conarium-doctor.mjs +44 -0
- package/bin/conarium-verify.mjs +110 -51
- package/dist/anchor.d.ts +11 -0
- package/dist/anchor.d.ts.map +1 -1
- package/dist/anchor.js +27 -0
- package/dist/anchor.js.map +1 -1
- package/dist/audit.d.ts +4 -0
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +126 -30
- package/dist/audit.js.map +1 -1
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -0
- package/dist/config.js.map +1 -1
- package/dist/connectors/openapi.d.ts +14 -1
- package/dist/connectors/openapi.d.ts.map +1 -1
- package/dist/connectors/openapi.js +78 -5
- package/dist/connectors/openapi.js.map +1 -1
- package/dist/connectors/postgres.js +8 -8
- package/dist/console-receipts.d.ts +12 -1
- package/dist/console-receipts.d.ts.map +1 -1
- package/dist/console-receipts.js +14 -2
- package/dist/console-receipts.js.map +1 -1
- package/dist/console-shortcut.d.ts.map +1 -1
- package/dist/console-shortcut.js +5 -1
- package/dist/console-shortcut.js.map +1 -1
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +15 -4
- package/dist/console.js.map +1 -1
- package/dist/coverage.d.ts +17 -1
- package/dist/coverage.d.ts.map +1 -1
- package/dist/coverage.js +30 -3
- package/dist/coverage.js.map +1 -1
- package/dist/digit_pii.d.ts.map +1 -1
- package/dist/digit_pii.js +64 -12
- package/dist/digit_pii.js.map +1 -1
- package/dist/governance.d.ts +2 -0
- package/dist/governance.d.ts.map +1 -1
- package/dist/governance.js +23 -8
- package/dist/governance.js.map +1 -1
- package/dist/http.d.ts +11 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +87 -7
- package/dist/http.js.map +1 -1
- package/dist/iban.d.ts.map +1 -1
- package/dist/iban.js +6 -3
- package/dist/iban.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +5 -0
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +22 -7
- package/dist/keys.js.map +1 -1
- package/dist/mask-text.d.ts +11 -0
- package/dist/mask-text.d.ts.map +1 -0
- package/dist/mask-text.js +42 -0
- package/dist/mask-text.js.map +1 -0
- package/dist/receipt-view.d.ts +13 -0
- package/dist/receipt-view.d.ts.map +1 -1
- package/dist/receipt-view.js +28 -5
- package/dist/receipt-view.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +31 -15
- package/dist/server.js.map +1 -1
- package/dist/sql-gate/mssql.d.ts.map +1 -1
- package/dist/sql-gate/mssql.js +36 -2
- package/dist/sql-gate/mssql.js.map +1 -1
- package/dist/sql-gate/oracle.d.ts.map +1 -1
- package/dist/sql-gate/oracle.js +24 -3
- package/dist/sql-gate/oracle.js.map +1 -1
- package/dist/sql-gate/rules.d.ts +19 -1
- package/dist/sql-gate/rules.d.ts.map +1 -1
- package/dist/sql-gate/rules.js +116 -7
- package/dist/sql-gate/rules.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/API-STABILITY.md +2 -2
- package/docs/ARCHITECTURE.md +42 -42
- package/docs/RECEIPT-SPEC.md +17 -11
- package/docs/plans/2026-07-02-redteam-harness.md +416 -416
- package/docs/specs/2026-07-02-redteam-harness-design.md +90 -90
- package/docs/superpowers/TODO-gate1-f4.md +23 -23
- package/docs/superpowers/plans/2026-07-29-conarium-receipt-plan.md +200 -200
- package/docs/superpowers/specs/2026-07-29-conarium-receipt-design.md +202 -202
- package/examples/claude-desktop-config.json +9 -9
- package/examples/cursor-mcp-settings.json +10 -10
- package/examples/proof-service/README.md +50 -0
- package/package.json +9 -2
- package/public/app.js +378 -378
- package/public/index.html +160 -160
- package/public/style.css +504 -504
- package/scripts/conarium_sabah_brief.mjs +107 -107
- package/scripts/start-mcp-c1.mjs +93 -93
- package/test-vectors/sql-gate/LAST-RUN.json +1 -2
- package/test-vectors/sql-gate/README.md +3 -1
- package/test-vectors/sql-gate/vectors.json +28 -0
- package/dist/openapi_connector.d.ts +0 -6
- package/dist/openapi_connector.d.ts.map +0 -1
- package/dist/openapi_connector.js +0 -145
- package/dist/openapi_connector.js.map +0 -1
- package/docs/audit/2026-08-14-security-scan.md +0 -48
- package/docs/audit/2026-08-14-surface-sync.md +0 -34
package/public/app.js
CHANGED
|
@@ -1,378 +1,378 @@
|
|
|
1
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
2
|
-
|
|
3
|
-
// Tab Switching Logic
|
|
4
|
-
const tabs = document.querySelectorAll('.nav-item');
|
|
5
|
-
const contents = document.querySelectorAll('.tab-content');
|
|
6
|
-
|
|
7
|
-
function receiptUi() {
|
|
8
|
-
return {
|
|
9
|
-
chain: document.getElementById('receipt-chain'),
|
|
10
|
-
empty: document.getElementById('receipt-empty'),
|
|
11
|
-
table: document.getElementById('receipt-table'),
|
|
12
|
-
tbody: document.getElementById('receipt-body'),
|
|
13
|
-
detail: document.getElementById('receipt-detail'),
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function activateTab(name) {
|
|
18
|
-
tabs.forEach(t => t.classList.toggle('active', t.dataset.tab === name))
|
|
19
|
-
contents.forEach(c => c.classList.toggle('active', c.id === 'tab-' + name))
|
|
20
|
-
const panel = document.getElementById('tab-' + name)
|
|
21
|
-
if (!panel) {
|
|
22
|
-
const empty = document.getElementById('receipt-empty')
|
|
23
|
-
if (empty && name === 'receipts') {
|
|
24
|
-
empty.hidden = false
|
|
25
|
-
empty.textContent = 'Makbuzlar alanı bulunamadı.'
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
tabs.forEach(tab => {
|
|
31
|
-
tab.addEventListener('click', (e) => {
|
|
32
|
-
e.preventDefault();
|
|
33
|
-
const name = tab.dataset.tab
|
|
34
|
-
activateTab(name)
|
|
35
|
-
if (name === 'receipts') {
|
|
36
|
-
ConariumReceiptsPanel.showLoading(receiptUi())
|
|
37
|
-
loadReceipts()
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
function csrfFromCookie() {
|
|
43
|
-
const m = document.cookie.match(/(?:^|; )conarium_console_csrf=([^;]*)/)
|
|
44
|
-
return m ? decodeURIComponent(m[1]) : ''
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function authHeaders(extra) {
|
|
48
|
-
const params = new URLSearchParams(location.search)
|
|
49
|
-
let token = params.get('token') || sessionStorage.getItem('conarium-console-token') || ''
|
|
50
|
-
if (token) sessionStorage.setItem('conarium-console-token', token)
|
|
51
|
-
const headers = { ...(extra || {}) }
|
|
52
|
-
if (token) {
|
|
53
|
-
headers['Authorization'] = 'Bearer ' + token
|
|
54
|
-
headers['x-csrf-token'] = token
|
|
55
|
-
} else {
|
|
56
|
-
const csrf = csrfFromCookie()
|
|
57
|
-
if (csrf) headers['x-csrf-token'] = csrf
|
|
58
|
-
}
|
|
59
|
-
return headers
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function apiFetch(url, init) {
|
|
63
|
-
return fetch(url, { credentials: 'same-origin', ...init, headers: { ...authHeaders(init && init.headers) } })
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function policyOf(data) {
|
|
67
|
-
if (data && typeof data.policy === 'object' && data.policy) return data.policy
|
|
68
|
-
return data || {}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function parseList(raw) {
|
|
72
|
-
return String(raw || '')
|
|
73
|
-
.split(/[\n,]+/)
|
|
74
|
-
.map(s => s.trim())
|
|
75
|
-
.filter(Boolean)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function fillList(id, arr) {
|
|
79
|
-
const el = document.getElementById(id)
|
|
80
|
-
el.value = Array.isArray(arr) ? arr.join('\n') : ''
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function setAllowTablesWarn(empty) {
|
|
84
|
-
const w = document.getElementById('allowTables-warn')
|
|
85
|
-
if (!w) return
|
|
86
|
-
w.hidden = !empty
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Load Config
|
|
90
|
-
async function loadConfig() {
|
|
91
|
-
try {
|
|
92
|
-
const res = await apiFetch('/api/config')
|
|
93
|
-
if (!res.ok) {
|
|
94
|
-
showToast('Could not load policy (' + res.status + '). Pass ?token=…')
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
const data = await res.json()
|
|
98
|
-
const pol = policyOf(data)
|
|
99
|
-
const maxEl = document.getElementById('maxRows')
|
|
100
|
-
maxEl.value = pol.maxRows == null ? '' : String(pol.maxRows)
|
|
101
|
-
fillList('allowTables', pol.allowTables)
|
|
102
|
-
fillList('denyTables', pol.denyTables)
|
|
103
|
-
fillList('maskColumns', pol.maskColumns)
|
|
104
|
-
document.getElementById('allowTools').value = Array.isArray(pol.allowTools) ? pol.allowTools.join(', ') : ''
|
|
105
|
-
document.getElementById('denyTools').value = Array.isArray(pol.denyTools) ? pol.denyTools.join(', ') : ''
|
|
106
|
-
setAllowTablesWarn(!Array.isArray(pol.allowTables) || pol.allowTables.length === 0)
|
|
107
|
-
} catch (e) {
|
|
108
|
-
console.error('Failed to load config', e)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Save Config — only the fields this form edits. connectors/audit/profiles stay on the server.
|
|
113
|
-
document.getElementById('config-form').addEventListener('submit', async (e) => {
|
|
114
|
-
e.preventDefault()
|
|
115
|
-
|
|
116
|
-
const maxRaw = document.getElementById('maxRows').value
|
|
117
|
-
const body = {
|
|
118
|
-
allowTables: parseList(document.getElementById('allowTables').value),
|
|
119
|
-
denyTables: parseList(document.getElementById('denyTables').value),
|
|
120
|
-
maskColumns: parseList(document.getElementById('maskColumns').value),
|
|
121
|
-
allowTools: parseList(document.getElementById('allowTools').value),
|
|
122
|
-
denyTools: parseList(document.getElementById('denyTools').value),
|
|
123
|
-
}
|
|
124
|
-
if (maxRaw !== '') body.maxRows = parseInt(maxRaw, 10)
|
|
125
|
-
|
|
126
|
-
setAllowTablesWarn(body.allowTables.length === 0)
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
const res = await apiFetch('/api/config', {
|
|
130
|
-
method: 'POST',
|
|
131
|
-
headers: { 'Content-Type': 'application/json' },
|
|
132
|
-
body: JSON.stringify(body)
|
|
133
|
-
})
|
|
134
|
-
if (res.ok) {
|
|
135
|
-
const out = await res.json().catch(() => ({}))
|
|
136
|
-
if (out.allowTablesEmpty) setAllowTablesWarn(true)
|
|
137
|
-
showToast('Governance Policy Saved')
|
|
138
|
-
} else {
|
|
139
|
-
showToast('Save failed (' + res.status + ')')
|
|
140
|
-
}
|
|
141
|
-
} catch (e) {
|
|
142
|
-
console.error('Failed to save config', e)
|
|
143
|
-
}
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
// Load Audit Logs
|
|
147
|
-
async function loadAudit() {
|
|
148
|
-
try {
|
|
149
|
-
const res = await apiFetch('/api/audit');
|
|
150
|
-
const data = await res.json();
|
|
151
|
-
|
|
152
|
-
const tbody = document.getElementById('audit-body');
|
|
153
|
-
tbody.innerHTML = '';
|
|
154
|
-
|
|
155
|
-
if (data.length === 0) {
|
|
156
|
-
tbody.innerHTML = `<tr><td colspan="8" class="text-center">No audit logs found.</td></tr>`;
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
data.forEach(log => {
|
|
161
|
-
const tr = document.createElement('tr');
|
|
162
|
-
const isDenied = Boolean(log.denied);
|
|
163
|
-
const statusClass = isDenied ? 'status-rejected' : 'status-success';
|
|
164
|
-
const statusText = isDenied ? 'Denied' : 'Allowed';
|
|
165
|
-
const sqlText = String(log.args && log.args.sql ? log.args.sql : (log.query || '-'));
|
|
166
|
-
const hashValue = String(log.hash || '');
|
|
167
|
-
const hashText = hashValue ? hashValue.substring(0, 8) + '...' : '-';
|
|
168
|
-
|
|
169
|
-
function tdText(value) {
|
|
170
|
-
const td = document.createElement('td');
|
|
171
|
-
td.textContent = String(value);
|
|
172
|
-
return td;
|
|
173
|
-
}
|
|
174
|
-
function tdCode(value) {
|
|
175
|
-
const td = document.createElement('td');
|
|
176
|
-
const code = document.createElement('code');
|
|
177
|
-
code.textContent = String(value);
|
|
178
|
-
td.appendChild(code);
|
|
179
|
-
return td;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
tr.appendChild(tdText(new Date(log.timestamp).toLocaleString()));
|
|
183
|
-
tr.appendChild(tdText(log.actor || 'unknown'));
|
|
184
|
-
tr.appendChild(tdCode(log.tool || '-'));
|
|
185
|
-
|
|
186
|
-
const sqlTd = document.createElement('td');
|
|
187
|
-
sqlTd.title = sqlText;
|
|
188
|
-
const sqlCode = document.createElement('code');
|
|
189
|
-
sqlCode.textContent = sqlText.length > 40 ? sqlText.substring(0, 40) + '...' : sqlText;
|
|
190
|
-
sqlTd.appendChild(sqlCode);
|
|
191
|
-
tr.appendChild(sqlTd);
|
|
192
|
-
|
|
193
|
-
tr.appendChild(tdText(log.rowsReturned || 0));
|
|
194
|
-
tr.appendChild(tdText(`${log.maskedCount || 0} PII`));
|
|
195
|
-
|
|
196
|
-
const statusTd = document.createElement('td');
|
|
197
|
-
const status = document.createElement('span');
|
|
198
|
-
status.className = `status-badge-sm ${statusClass}`;
|
|
199
|
-
status.textContent = statusText;
|
|
200
|
-
statusTd.appendChild(status);
|
|
201
|
-
tr.appendChild(statusTd);
|
|
202
|
-
|
|
203
|
-
const hashTd = document.createElement('td');
|
|
204
|
-
hashTd.title = hashValue;
|
|
205
|
-
const hashCode = document.createElement('code');
|
|
206
|
-
hashCode.style.fontSize = '0.75rem';
|
|
207
|
-
hashCode.style.color = 'var(--text-secondary)';
|
|
208
|
-
hashCode.textContent = hashText;
|
|
209
|
-
hashTd.appendChild(hashCode);
|
|
210
|
-
tr.appendChild(hashTd);
|
|
211
|
-
|
|
212
|
-
tbody.appendChild(tr);
|
|
213
|
-
});
|
|
214
|
-
} catch (e) {
|
|
215
|
-
console.error('Failed to load audit logs', e);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
document.getElementById('refresh-audit').addEventListener('click', loadAudit);
|
|
220
|
-
|
|
221
|
-
async function loadReceipts() {
|
|
222
|
-
const ui = receiptUi()
|
|
223
|
-
try {
|
|
224
|
-
const res = await apiFetch('/api/receipts')
|
|
225
|
-
if (!res.ok) {
|
|
226
|
-
ConariumReceiptsPanel.showError(ui, 'Makbuz listesi alınamadı (' + res.status + ').')
|
|
227
|
-
return
|
|
228
|
-
}
|
|
229
|
-
const data = await res.json()
|
|
230
|
-
ConariumReceiptsPanel.render(ui, data, {
|
|
231
|
-
tr: function () { return document.createElement('tr') },
|
|
232
|
-
td: function () { return document.createElement('td') },
|
|
233
|
-
span: function () { return document.createElement('span') },
|
|
234
|
-
formatTime: function (ts) { return new Date(ts).toLocaleString() },
|
|
235
|
-
onRow: function (tr, row) {
|
|
236
|
-
tr.addEventListener('click', function () { openReceipt(row.id, tr) })
|
|
237
|
-
},
|
|
238
|
-
})
|
|
239
|
-
} catch (e) {
|
|
240
|
-
ConariumReceiptsPanel.showError(ui, 'Makbuz listesi alınamadı.')
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async function openReceipt(id, rowEl) {
|
|
245
|
-
const detail = document.getElementById('receipt-detail')
|
|
246
|
-
document.querySelectorAll('.receipt-table-row').forEach(function (r) { r.classList.remove('selected') })
|
|
247
|
-
if (rowEl) rowEl.classList.add('selected')
|
|
248
|
-
try {
|
|
249
|
-
const res = await apiFetch('/api/receipts/' + encodeURIComponent(id))
|
|
250
|
-
if (!res.ok) {
|
|
251
|
-
detail.hidden = false
|
|
252
|
-
detail.textContent = 'Makbuz okunamadı (' + res.status + ').'
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
const data = await res.json()
|
|
256
|
-
detail.hidden = false
|
|
257
|
-
detail.innerHTML = data.html || ''
|
|
258
|
-
if (data.html && /BEGIN PRIVATE KEY|BEGIN.*PRIVATE/.test(data.html)) {
|
|
259
|
-
detail.textContent = 'özel anahtar panele düştü — gösterilmedi'
|
|
260
|
-
}
|
|
261
|
-
} catch (e) {
|
|
262
|
-
detail.hidden = false
|
|
263
|
-
detail.textContent = 'Makbuz okunamadı.'
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const refreshReceipts = document.getElementById('refresh-receipts')
|
|
268
|
-
if (refreshReceipts) refreshReceipts.addEventListener('click', function () {
|
|
269
|
-
ConariumReceiptsPanel.showLoading(receiptUi())
|
|
270
|
-
loadReceipts()
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
// Load Connectors
|
|
274
|
-
async function loadConnectors() {
|
|
275
|
-
try {
|
|
276
|
-
const res = await apiFetch('/api/connectors');
|
|
277
|
-
const data = await res.json();
|
|
278
|
-
|
|
279
|
-
const list = document.getElementById('connector-list');
|
|
280
|
-
list.innerHTML = '';
|
|
281
|
-
|
|
282
|
-
data.forEach(conn => {
|
|
283
|
-
const statusColor = conn.status === 'connected' ? 'var(--success)' : 'var(--danger)';
|
|
284
|
-
const el = document.createElement('div');
|
|
285
|
-
el.className = 'connector-item';
|
|
286
|
-
el.innerHTML = `
|
|
287
|
-
<div class="connector-info">
|
|
288
|
-
<h4>${conn.id}</h4>
|
|
289
|
-
<span>${conn.type}</span>
|
|
290
|
-
</div>
|
|
291
|
-
<div style="text-align: right">
|
|
292
|
-
<div style="color: ${statusColor}; font-weight: 600; font-size: 0.875rem;">
|
|
293
|
-
● ${conn.status}
|
|
294
|
-
</div>
|
|
295
|
-
<span style="font-size: 0.75rem; color: var(--text-secondary)">${conn.latency}</span>
|
|
296
|
-
</div>
|
|
297
|
-
`;
|
|
298
|
-
list.appendChild(el);
|
|
299
|
-
});
|
|
300
|
-
} catch (e) {
|
|
301
|
-
console.error('Failed to load connectors', e);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// --- Live Playground ---
|
|
306
|
-
const pgQuery = document.getElementById('pg-query');
|
|
307
|
-
document.querySelectorAll('.pg-samples .chip').forEach(chip => {
|
|
308
|
-
chip.addEventListener('click', () => { pgQuery.value = chip.dataset.q; });
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
function renderRows(rows) {
|
|
312
|
-
return rows.map(r => {
|
|
313
|
-
const lines = Object.entries(r).map(([k, v]) => {
|
|
314
|
-
const masked = v === '[MASKED_PII]';
|
|
315
|
-
return ` <span class="jk">"${k}"</span>: <span class="${masked ? 'jmask' : 'jv'}">${JSON.stringify(v)}</span>`;
|
|
316
|
-
}).join(',\n');
|
|
317
|
-
return `{\n${lines}\n}`;
|
|
318
|
-
}).join(',\n');
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const pgRun = document.getElementById('pg-run');
|
|
322
|
-
if (pgRun) pgRun.addEventListener('click', async () => {
|
|
323
|
-
const query = pgQuery.value.trim();
|
|
324
|
-
const out = document.getElementById('pg-result');
|
|
325
|
-
out.innerHTML = '<div class="loader">Running through Conarium…</div>';
|
|
326
|
-
try {
|
|
327
|
-
const res = await apiFetch('/api/playground', {
|
|
328
|
-
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
329
|
-
body: JSON.stringify({ query })
|
|
330
|
-
});
|
|
331
|
-
const d = await res.json();
|
|
332
|
-
if (d.decision === 'deny') {
|
|
333
|
-
out.innerHTML = `
|
|
334
|
-
<div class="pg-blocked">
|
|
335
|
-
<div class="pg-blocked-icon">🛑</div>
|
|
336
|
-
<div>
|
|
337
|
-
<h4>BLOCKED by Conarium</h4>
|
|
338
|
-
<p>${d.reason}</p>
|
|
339
|
-
<span class="pg-logged">✓ Logged to audit · decision: <code>deny</code></span>
|
|
340
|
-
</div>
|
|
341
|
-
</div>`;
|
|
342
|
-
} else {
|
|
343
|
-
out.innerHTML = `
|
|
344
|
-
<div class="pg-compare">
|
|
345
|
-
<div class="pg-col pg-raw">
|
|
346
|
-
<div class="pg-col-head">🔴 RAW — direct DB access</div>
|
|
347
|
-
<pre>${renderRows(d.raw)}</pre>
|
|
348
|
-
</div>
|
|
349
|
-
<div class="pg-arrow">▸</div>
|
|
350
|
-
<div class="pg-col pg-gov">
|
|
351
|
-
<div class="pg-col-head">🟢 GOVERNED — through Conarium</div>
|
|
352
|
-
<pre>${renderRows(d.governed)}</pre>
|
|
353
|
-
</div>
|
|
354
|
-
</div>
|
|
355
|
-
<div class="pg-logged">✓ <strong>${d.maskedCount}</strong> PII field(s) masked · ${d.governed.length} row(s) · logged to audit</div>`;
|
|
356
|
-
}
|
|
357
|
-
loadAudit();
|
|
358
|
-
} catch (e) {
|
|
359
|
-
out.innerHTML = `<div class="pg-blocked"><p>Error: ${e.message}</p></div>`;
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
// Toast Utility
|
|
364
|
-
function showToast(msg) {
|
|
365
|
-
const toast = document.getElementById('toast');
|
|
366
|
-
toast.textContent = msg;
|
|
367
|
-
toast.classList.add('show');
|
|
368
|
-
setTimeout(() => toast.classList.remove('show'), 3000);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// Initialize
|
|
372
|
-
loadConfig();
|
|
373
|
-
loadAudit();
|
|
374
|
-
loadConnectors();
|
|
375
|
-
loadReceipts();
|
|
376
|
-
setInterval(() => { apiFetch('/api/presence').catch(() => {}) }, 2000)
|
|
377
|
-
window.addEventListener('pagehide', () => { apiFetch('/api/presence').catch(() => {}) })
|
|
378
|
-
});
|
|
1
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
2
|
+
|
|
3
|
+
// Tab Switching Logic
|
|
4
|
+
const tabs = document.querySelectorAll('.nav-item');
|
|
5
|
+
const contents = document.querySelectorAll('.tab-content');
|
|
6
|
+
|
|
7
|
+
function receiptUi() {
|
|
8
|
+
return {
|
|
9
|
+
chain: document.getElementById('receipt-chain'),
|
|
10
|
+
empty: document.getElementById('receipt-empty'),
|
|
11
|
+
table: document.getElementById('receipt-table'),
|
|
12
|
+
tbody: document.getElementById('receipt-body'),
|
|
13
|
+
detail: document.getElementById('receipt-detail'),
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function activateTab(name) {
|
|
18
|
+
tabs.forEach(t => t.classList.toggle('active', t.dataset.tab === name))
|
|
19
|
+
contents.forEach(c => c.classList.toggle('active', c.id === 'tab-' + name))
|
|
20
|
+
const panel = document.getElementById('tab-' + name)
|
|
21
|
+
if (!panel) {
|
|
22
|
+
const empty = document.getElementById('receipt-empty')
|
|
23
|
+
if (empty && name === 'receipts') {
|
|
24
|
+
empty.hidden = false
|
|
25
|
+
empty.textContent = 'Makbuzlar alanı bulunamadı.'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
tabs.forEach(tab => {
|
|
31
|
+
tab.addEventListener('click', (e) => {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
const name = tab.dataset.tab
|
|
34
|
+
activateTab(name)
|
|
35
|
+
if (name === 'receipts') {
|
|
36
|
+
ConariumReceiptsPanel.showLoading(receiptUi())
|
|
37
|
+
loadReceipts()
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function csrfFromCookie() {
|
|
43
|
+
const m = document.cookie.match(/(?:^|; )conarium_console_csrf=([^;]*)/)
|
|
44
|
+
return m ? decodeURIComponent(m[1]) : ''
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function authHeaders(extra) {
|
|
48
|
+
const params = new URLSearchParams(location.search)
|
|
49
|
+
let token = params.get('token') || sessionStorage.getItem('conarium-console-token') || ''
|
|
50
|
+
if (token) sessionStorage.setItem('conarium-console-token', token)
|
|
51
|
+
const headers = { ...(extra || {}) }
|
|
52
|
+
if (token) {
|
|
53
|
+
headers['Authorization'] = 'Bearer ' + token
|
|
54
|
+
headers['x-csrf-token'] = token
|
|
55
|
+
} else {
|
|
56
|
+
const csrf = csrfFromCookie()
|
|
57
|
+
if (csrf) headers['x-csrf-token'] = csrf
|
|
58
|
+
}
|
|
59
|
+
return headers
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function apiFetch(url, init) {
|
|
63
|
+
return fetch(url, { credentials: 'same-origin', ...init, headers: { ...authHeaders(init && init.headers) } })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function policyOf(data) {
|
|
67
|
+
if (data && typeof data.policy === 'object' && data.policy) return data.policy
|
|
68
|
+
return data || {}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function parseList(raw) {
|
|
72
|
+
return String(raw || '')
|
|
73
|
+
.split(/[\n,]+/)
|
|
74
|
+
.map(s => s.trim())
|
|
75
|
+
.filter(Boolean)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function fillList(id, arr) {
|
|
79
|
+
const el = document.getElementById(id)
|
|
80
|
+
el.value = Array.isArray(arr) ? arr.join('\n') : ''
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function setAllowTablesWarn(empty) {
|
|
84
|
+
const w = document.getElementById('allowTables-warn')
|
|
85
|
+
if (!w) return
|
|
86
|
+
w.hidden = !empty
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Load Config
|
|
90
|
+
async function loadConfig() {
|
|
91
|
+
try {
|
|
92
|
+
const res = await apiFetch('/api/config')
|
|
93
|
+
if (!res.ok) {
|
|
94
|
+
showToast('Could not load policy (' + res.status + '). Pass ?token=…')
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
const data = await res.json()
|
|
98
|
+
const pol = policyOf(data)
|
|
99
|
+
const maxEl = document.getElementById('maxRows')
|
|
100
|
+
maxEl.value = pol.maxRows == null ? '' : String(pol.maxRows)
|
|
101
|
+
fillList('allowTables', pol.allowTables)
|
|
102
|
+
fillList('denyTables', pol.denyTables)
|
|
103
|
+
fillList('maskColumns', pol.maskColumns)
|
|
104
|
+
document.getElementById('allowTools').value = Array.isArray(pol.allowTools) ? pol.allowTools.join(', ') : ''
|
|
105
|
+
document.getElementById('denyTools').value = Array.isArray(pol.denyTools) ? pol.denyTools.join(', ') : ''
|
|
106
|
+
setAllowTablesWarn(!Array.isArray(pol.allowTables) || pol.allowTables.length === 0)
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error('Failed to load config', e)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Save Config — only the fields this form edits. connectors/audit/profiles stay on the server.
|
|
113
|
+
document.getElementById('config-form').addEventListener('submit', async (e) => {
|
|
114
|
+
e.preventDefault()
|
|
115
|
+
|
|
116
|
+
const maxRaw = document.getElementById('maxRows').value
|
|
117
|
+
const body = {
|
|
118
|
+
allowTables: parseList(document.getElementById('allowTables').value),
|
|
119
|
+
denyTables: parseList(document.getElementById('denyTables').value),
|
|
120
|
+
maskColumns: parseList(document.getElementById('maskColumns').value),
|
|
121
|
+
allowTools: parseList(document.getElementById('allowTools').value),
|
|
122
|
+
denyTools: parseList(document.getElementById('denyTools').value),
|
|
123
|
+
}
|
|
124
|
+
if (maxRaw !== '') body.maxRows = parseInt(maxRaw, 10)
|
|
125
|
+
|
|
126
|
+
setAllowTablesWarn(body.allowTables.length === 0)
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const res = await apiFetch('/api/config', {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
headers: { 'Content-Type': 'application/json' },
|
|
132
|
+
body: JSON.stringify(body)
|
|
133
|
+
})
|
|
134
|
+
if (res.ok) {
|
|
135
|
+
const out = await res.json().catch(() => ({}))
|
|
136
|
+
if (out.allowTablesEmpty) setAllowTablesWarn(true)
|
|
137
|
+
showToast('Governance Policy Saved')
|
|
138
|
+
} else {
|
|
139
|
+
showToast('Save failed (' + res.status + ')')
|
|
140
|
+
}
|
|
141
|
+
} catch (e) {
|
|
142
|
+
console.error('Failed to save config', e)
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// Load Audit Logs
|
|
147
|
+
async function loadAudit() {
|
|
148
|
+
try {
|
|
149
|
+
const res = await apiFetch('/api/audit');
|
|
150
|
+
const data = await res.json();
|
|
151
|
+
|
|
152
|
+
const tbody = document.getElementById('audit-body');
|
|
153
|
+
tbody.innerHTML = '';
|
|
154
|
+
|
|
155
|
+
if (data.length === 0) {
|
|
156
|
+
tbody.innerHTML = `<tr><td colspan="8" class="text-center">No audit logs found.</td></tr>`;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
data.forEach(log => {
|
|
161
|
+
const tr = document.createElement('tr');
|
|
162
|
+
const isDenied = Boolean(log.denied);
|
|
163
|
+
const statusClass = isDenied ? 'status-rejected' : 'status-success';
|
|
164
|
+
const statusText = isDenied ? 'Denied' : 'Allowed';
|
|
165
|
+
const sqlText = String(log.args && log.args.sql ? log.args.sql : (log.query || '-'));
|
|
166
|
+
const hashValue = String(log.hash || '');
|
|
167
|
+
const hashText = hashValue ? hashValue.substring(0, 8) + '...' : '-';
|
|
168
|
+
|
|
169
|
+
function tdText(value) {
|
|
170
|
+
const td = document.createElement('td');
|
|
171
|
+
td.textContent = String(value);
|
|
172
|
+
return td;
|
|
173
|
+
}
|
|
174
|
+
function tdCode(value) {
|
|
175
|
+
const td = document.createElement('td');
|
|
176
|
+
const code = document.createElement('code');
|
|
177
|
+
code.textContent = String(value);
|
|
178
|
+
td.appendChild(code);
|
|
179
|
+
return td;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
tr.appendChild(tdText(new Date(log.timestamp).toLocaleString()));
|
|
183
|
+
tr.appendChild(tdText(log.actor || 'unknown'));
|
|
184
|
+
tr.appendChild(tdCode(log.tool || '-'));
|
|
185
|
+
|
|
186
|
+
const sqlTd = document.createElement('td');
|
|
187
|
+
sqlTd.title = sqlText;
|
|
188
|
+
const sqlCode = document.createElement('code');
|
|
189
|
+
sqlCode.textContent = sqlText.length > 40 ? sqlText.substring(0, 40) + '...' : sqlText;
|
|
190
|
+
sqlTd.appendChild(sqlCode);
|
|
191
|
+
tr.appendChild(sqlTd);
|
|
192
|
+
|
|
193
|
+
tr.appendChild(tdText(log.rowsReturned || 0));
|
|
194
|
+
tr.appendChild(tdText(`${log.maskedCount || 0} PII`));
|
|
195
|
+
|
|
196
|
+
const statusTd = document.createElement('td');
|
|
197
|
+
const status = document.createElement('span');
|
|
198
|
+
status.className = `status-badge-sm ${statusClass}`;
|
|
199
|
+
status.textContent = statusText;
|
|
200
|
+
statusTd.appendChild(status);
|
|
201
|
+
tr.appendChild(statusTd);
|
|
202
|
+
|
|
203
|
+
const hashTd = document.createElement('td');
|
|
204
|
+
hashTd.title = hashValue;
|
|
205
|
+
const hashCode = document.createElement('code');
|
|
206
|
+
hashCode.style.fontSize = '0.75rem';
|
|
207
|
+
hashCode.style.color = 'var(--text-secondary)';
|
|
208
|
+
hashCode.textContent = hashText;
|
|
209
|
+
hashTd.appendChild(hashCode);
|
|
210
|
+
tr.appendChild(hashTd);
|
|
211
|
+
|
|
212
|
+
tbody.appendChild(tr);
|
|
213
|
+
});
|
|
214
|
+
} catch (e) {
|
|
215
|
+
console.error('Failed to load audit logs', e);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
document.getElementById('refresh-audit').addEventListener('click', loadAudit);
|
|
220
|
+
|
|
221
|
+
async function loadReceipts() {
|
|
222
|
+
const ui = receiptUi()
|
|
223
|
+
try {
|
|
224
|
+
const res = await apiFetch('/api/receipts')
|
|
225
|
+
if (!res.ok) {
|
|
226
|
+
ConariumReceiptsPanel.showError(ui, 'Makbuz listesi alınamadı (' + res.status + ').')
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
const data = await res.json()
|
|
230
|
+
ConariumReceiptsPanel.render(ui, data, {
|
|
231
|
+
tr: function () { return document.createElement('tr') },
|
|
232
|
+
td: function () { return document.createElement('td') },
|
|
233
|
+
span: function () { return document.createElement('span') },
|
|
234
|
+
formatTime: function (ts) { return new Date(ts).toLocaleString() },
|
|
235
|
+
onRow: function (tr, row) {
|
|
236
|
+
tr.addEventListener('click', function () { openReceipt(row.id, tr) })
|
|
237
|
+
},
|
|
238
|
+
})
|
|
239
|
+
} catch (e) {
|
|
240
|
+
ConariumReceiptsPanel.showError(ui, 'Makbuz listesi alınamadı.')
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async function openReceipt(id, rowEl) {
|
|
245
|
+
const detail = document.getElementById('receipt-detail')
|
|
246
|
+
document.querySelectorAll('.receipt-table-row').forEach(function (r) { r.classList.remove('selected') })
|
|
247
|
+
if (rowEl) rowEl.classList.add('selected')
|
|
248
|
+
try {
|
|
249
|
+
const res = await apiFetch('/api/receipts/' + encodeURIComponent(id))
|
|
250
|
+
if (!res.ok) {
|
|
251
|
+
detail.hidden = false
|
|
252
|
+
detail.textContent = 'Makbuz okunamadı (' + res.status + ').'
|
|
253
|
+
return
|
|
254
|
+
}
|
|
255
|
+
const data = await res.json()
|
|
256
|
+
detail.hidden = false
|
|
257
|
+
detail.innerHTML = data.html || ''
|
|
258
|
+
if (data.html && /BEGIN PRIVATE KEY|BEGIN.*PRIVATE/.test(data.html)) {
|
|
259
|
+
detail.textContent = 'özel anahtar panele düştü — gösterilmedi'
|
|
260
|
+
}
|
|
261
|
+
} catch (e) {
|
|
262
|
+
detail.hidden = false
|
|
263
|
+
detail.textContent = 'Makbuz okunamadı.'
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const refreshReceipts = document.getElementById('refresh-receipts')
|
|
268
|
+
if (refreshReceipts) refreshReceipts.addEventListener('click', function () {
|
|
269
|
+
ConariumReceiptsPanel.showLoading(receiptUi())
|
|
270
|
+
loadReceipts()
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
// Load Connectors
|
|
274
|
+
async function loadConnectors() {
|
|
275
|
+
try {
|
|
276
|
+
const res = await apiFetch('/api/connectors');
|
|
277
|
+
const data = await res.json();
|
|
278
|
+
|
|
279
|
+
const list = document.getElementById('connector-list');
|
|
280
|
+
list.innerHTML = '';
|
|
281
|
+
|
|
282
|
+
data.forEach(conn => {
|
|
283
|
+
const statusColor = conn.status === 'connected' ? 'var(--success)' : 'var(--danger)';
|
|
284
|
+
const el = document.createElement('div');
|
|
285
|
+
el.className = 'connector-item';
|
|
286
|
+
el.innerHTML = `
|
|
287
|
+
<div class="connector-info">
|
|
288
|
+
<h4>${conn.id}</h4>
|
|
289
|
+
<span>${conn.type}</span>
|
|
290
|
+
</div>
|
|
291
|
+
<div style="text-align: right">
|
|
292
|
+
<div style="color: ${statusColor}; font-weight: 600; font-size: 0.875rem;">
|
|
293
|
+
● ${conn.status}
|
|
294
|
+
</div>
|
|
295
|
+
<span style="font-size: 0.75rem; color: var(--text-secondary)">${conn.latency}</span>
|
|
296
|
+
</div>
|
|
297
|
+
`;
|
|
298
|
+
list.appendChild(el);
|
|
299
|
+
});
|
|
300
|
+
} catch (e) {
|
|
301
|
+
console.error('Failed to load connectors', e);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// --- Live Playground ---
|
|
306
|
+
const pgQuery = document.getElementById('pg-query');
|
|
307
|
+
document.querySelectorAll('.pg-samples .chip').forEach(chip => {
|
|
308
|
+
chip.addEventListener('click', () => { pgQuery.value = chip.dataset.q; });
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
function renderRows(rows) {
|
|
312
|
+
return rows.map(r => {
|
|
313
|
+
const lines = Object.entries(r).map(([k, v]) => {
|
|
314
|
+
const masked = v === '[MASKED_PII]';
|
|
315
|
+
return ` <span class="jk">"${k}"</span>: <span class="${masked ? 'jmask' : 'jv'}">${JSON.stringify(v)}</span>`;
|
|
316
|
+
}).join(',\n');
|
|
317
|
+
return `{\n${lines}\n}`;
|
|
318
|
+
}).join(',\n');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const pgRun = document.getElementById('pg-run');
|
|
322
|
+
if (pgRun) pgRun.addEventListener('click', async () => {
|
|
323
|
+
const query = pgQuery.value.trim();
|
|
324
|
+
const out = document.getElementById('pg-result');
|
|
325
|
+
out.innerHTML = '<div class="loader">Running through Conarium…</div>';
|
|
326
|
+
try {
|
|
327
|
+
const res = await apiFetch('/api/playground', {
|
|
328
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
329
|
+
body: JSON.stringify({ query })
|
|
330
|
+
});
|
|
331
|
+
const d = await res.json();
|
|
332
|
+
if (d.decision === 'deny') {
|
|
333
|
+
out.innerHTML = `
|
|
334
|
+
<div class="pg-blocked">
|
|
335
|
+
<div class="pg-blocked-icon">🛑</div>
|
|
336
|
+
<div>
|
|
337
|
+
<h4>BLOCKED by Conarium</h4>
|
|
338
|
+
<p>${d.reason}</p>
|
|
339
|
+
<span class="pg-logged">✓ Logged to audit · decision: <code>deny</code></span>
|
|
340
|
+
</div>
|
|
341
|
+
</div>`;
|
|
342
|
+
} else {
|
|
343
|
+
out.innerHTML = `
|
|
344
|
+
<div class="pg-compare">
|
|
345
|
+
<div class="pg-col pg-raw">
|
|
346
|
+
<div class="pg-col-head">🔴 RAW — direct DB access</div>
|
|
347
|
+
<pre>${renderRows(d.raw)}</pre>
|
|
348
|
+
</div>
|
|
349
|
+
<div class="pg-arrow">▸</div>
|
|
350
|
+
<div class="pg-col pg-gov">
|
|
351
|
+
<div class="pg-col-head">🟢 GOVERNED — through Conarium</div>
|
|
352
|
+
<pre>${renderRows(d.governed)}</pre>
|
|
353
|
+
</div>
|
|
354
|
+
</div>
|
|
355
|
+
<div class="pg-logged">✓ <strong>${d.maskedCount}</strong> PII field(s) masked · ${d.governed.length} row(s) · logged to audit</div>`;
|
|
356
|
+
}
|
|
357
|
+
loadAudit();
|
|
358
|
+
} catch (e) {
|
|
359
|
+
out.innerHTML = `<div class="pg-blocked"><p>Error: ${e.message}</p></div>`;
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// Toast Utility
|
|
364
|
+
function showToast(msg) {
|
|
365
|
+
const toast = document.getElementById('toast');
|
|
366
|
+
toast.textContent = msg;
|
|
367
|
+
toast.classList.add('show');
|
|
368
|
+
setTimeout(() => toast.classList.remove('show'), 3000);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Initialize
|
|
372
|
+
loadConfig();
|
|
373
|
+
loadAudit();
|
|
374
|
+
loadConnectors();
|
|
375
|
+
loadReceipts();
|
|
376
|
+
setInterval(() => { apiFetch('/api/presence').catch(() => {}) }, 2000)
|
|
377
|
+
window.addEventListener('pagehide', () => { apiFetch('/api/presence').catch(() => {}) })
|
|
378
|
+
});
|