@sanctuary-framework/mcp-server 0.3.1 → 0.4.0
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/dist/cli.cjs +2072 -51
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2073 -53
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +2043 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +262 -1
- package/dist/index.d.ts +262 -1
- package/dist/index.js +2036 -88
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
5
5
|
import { mkdir, readFile, writeFile, stat, unlink, readdir, chmod, access } from 'fs/promises';
|
|
6
6
|
import { join } from 'path';
|
|
7
7
|
import { homedir } from 'os';
|
|
8
|
+
import { createRequire } from 'module';
|
|
8
9
|
import { randomBytes as randomBytes$1, createHmac } from 'crypto';
|
|
9
10
|
import { gcm } from '@noble/ciphers/aes.js';
|
|
10
11
|
import { RistrettoPoint, ed25519 } from '@noble/curves/ed25519';
|
|
@@ -13,8 +14,9 @@ import { hkdf } from '@noble/hashes/hkdf';
|
|
|
13
14
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
14
15
|
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
15
16
|
import { createServer as createServer$2 } from 'http';
|
|
16
|
-
import { createServer as createServer$1 } from 'https';
|
|
17
|
-
import { readFileSync } from 'fs';
|
|
17
|
+
import { createServer as createServer$1, get } from 'https';
|
|
18
|
+
import { readFileSync, statSync } from 'fs';
|
|
19
|
+
import { execSync } from 'child_process';
|
|
18
20
|
|
|
19
21
|
var __defProp = Object.defineProperty;
|
|
20
22
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -204,9 +206,11 @@ var init_hashing = __esm({
|
|
|
204
206
|
init_encoding();
|
|
205
207
|
}
|
|
206
208
|
});
|
|
209
|
+
var require2 = createRequire(import.meta.url);
|
|
210
|
+
var { version: PKG_VERSION } = require2("../package.json");
|
|
207
211
|
function defaultConfig() {
|
|
208
212
|
return {
|
|
209
|
-
version:
|
|
213
|
+
version: PKG_VERSION,
|
|
210
214
|
storage_path: join(homedir(), ".sanctuary"),
|
|
211
215
|
state: {
|
|
212
216
|
encryption: "aes-256-gcm",
|
|
@@ -332,6 +336,18 @@ function validateConfig(config) {
|
|
|
332
336
|
`Unimplemented config value: disclosure.proof_system = "${config.disclosure.proof_system}". Only ${[...implementedProofSystem].map((v) => `"${v}"`).join(", ")} is currently implemented. Using an unimplemented proof system would silently degrade security.`
|
|
333
337
|
);
|
|
334
338
|
}
|
|
339
|
+
const implementedDisclosurePolicy = /* @__PURE__ */ new Set(["minimum-necessary"]);
|
|
340
|
+
if (!implementedDisclosurePolicy.has(config.disclosure.default_policy)) {
|
|
341
|
+
errors.push(
|
|
342
|
+
`Unimplemented config value: disclosure.default_policy = "${config.disclosure.default_policy}". Only ${[...implementedDisclosurePolicy].map((v) => `"${v}"`).join(", ")} is currently implemented. Using an unimplemented disclosure policy would silently skip disclosure controls.`
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
const implementedReputationMode = /* @__PURE__ */ new Set(["self-custodied"]);
|
|
346
|
+
if (!implementedReputationMode.has(config.reputation.mode)) {
|
|
347
|
+
errors.push(
|
|
348
|
+
`Unimplemented config value: reputation.mode = "${config.reputation.mode}". Only ${[...implementedReputationMode].map((v) => `"${v}"`).join(", ")} is currently implemented. Using an unimplemented reputation mode would silently skip reputation verification.`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
335
351
|
if (errors.length > 0) {
|
|
336
352
|
throw new Error(
|
|
337
353
|
`Sanctuary configuration references unimplemented features:
|
|
@@ -1037,6 +1053,8 @@ var StateStore = class {
|
|
|
1037
1053
|
};
|
|
1038
1054
|
}
|
|
1039
1055
|
};
|
|
1056
|
+
var require3 = createRequire(import.meta.url);
|
|
1057
|
+
var { version: PKG_VERSION2 } = require3("../package.json");
|
|
1040
1058
|
var MAX_STRING_BYTES = 1048576;
|
|
1041
1059
|
var MAX_BUNDLE_BYTES = 5242880;
|
|
1042
1060
|
var BUNDLE_FIELDS = /* @__PURE__ */ new Set(["bundle"]);
|
|
@@ -1119,7 +1137,7 @@ function createServer(tools, options) {
|
|
|
1119
1137
|
const server = new Server(
|
|
1120
1138
|
{
|
|
1121
1139
|
name: "sanctuary-mcp-server",
|
|
1122
|
-
version:
|
|
1140
|
+
version: PKG_VERSION2
|
|
1123
1141
|
},
|
|
1124
1142
|
{
|
|
1125
1143
|
capabilities: {
|
|
@@ -3573,7 +3591,9 @@ var DEFAULT_POLICY = {
|
|
|
3573
3591
|
"state_delete",
|
|
3574
3592
|
"identity_rotate",
|
|
3575
3593
|
"reputation_import",
|
|
3576
|
-
"
|
|
3594
|
+
"reputation_export",
|
|
3595
|
+
"bootstrap_provide_guarantee",
|
|
3596
|
+
"decommission_certificate"
|
|
3577
3597
|
],
|
|
3578
3598
|
tier2_anomaly: DEFAULT_TIER2,
|
|
3579
3599
|
tier3_always_allow: [
|
|
@@ -3590,7 +3610,6 @@ var DEFAULT_POLICY = {
|
|
|
3590
3610
|
"disclosure_evaluate",
|
|
3591
3611
|
"reputation_record",
|
|
3592
3612
|
"reputation_query",
|
|
3593
|
-
"reputation_export",
|
|
3594
3613
|
"bootstrap_create_escrow",
|
|
3595
3614
|
"exec_attest",
|
|
3596
3615
|
"monitor_health",
|
|
@@ -3612,7 +3631,14 @@ var DEFAULT_POLICY = {
|
|
|
3612
3631
|
"zk_prove",
|
|
3613
3632
|
"zk_verify",
|
|
3614
3633
|
"zk_range_prove",
|
|
3615
|
-
"zk_range_verify"
|
|
3634
|
+
"zk_range_verify",
|
|
3635
|
+
"context_gate_set_policy",
|
|
3636
|
+
"context_gate_apply_template",
|
|
3637
|
+
"context_gate_recommend",
|
|
3638
|
+
"context_gate_filter",
|
|
3639
|
+
"context_gate_list_policies",
|
|
3640
|
+
"l2_hardening_status",
|
|
3641
|
+
"l2_verify_isolation"
|
|
3616
3642
|
],
|
|
3617
3643
|
approval_channel: DEFAULT_CHANNEL
|
|
3618
3644
|
};
|
|
@@ -3714,6 +3740,7 @@ tier1_always_approve:
|
|
|
3714
3740
|
- state_delete
|
|
3715
3741
|
- identity_rotate
|
|
3716
3742
|
- reputation_import
|
|
3743
|
+
- reputation_export
|
|
3717
3744
|
- bootstrap_provide_guarantee
|
|
3718
3745
|
|
|
3719
3746
|
# \u2500\u2500\u2500 Tier 2: Behavioral Anomaly Detection \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
@@ -3743,7 +3770,6 @@ tier3_always_allow:
|
|
|
3743
3770
|
- disclosure_evaluate
|
|
3744
3771
|
- reputation_record
|
|
3745
3772
|
- reputation_query
|
|
3746
|
-
- reputation_export
|
|
3747
3773
|
- bootstrap_create_escrow
|
|
3748
3774
|
- exec_attest
|
|
3749
3775
|
- monitor_health
|
|
@@ -3766,6 +3792,11 @@ tier3_always_allow:
|
|
|
3766
3792
|
- zk_verify
|
|
3767
3793
|
- zk_range_prove
|
|
3768
3794
|
- zk_range_verify
|
|
3795
|
+
- context_gate_set_policy
|
|
3796
|
+
- context_gate_apply_template
|
|
3797
|
+
- context_gate_recommend
|
|
3798
|
+
- context_gate_filter
|
|
3799
|
+
- context_gate_list_policies
|
|
3769
3800
|
|
|
3770
3801
|
# \u2500\u2500\u2500 Approval Channel \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3771
3802
|
# How Sanctuary reaches you when approval is needed.
|
|
@@ -4542,8 +4573,14 @@ function generateDashboardHTML(options) {
|
|
|
4542
4573
|
}
|
|
4543
4574
|
|
|
4544
4575
|
// src/principal-policy/dashboard.ts
|
|
4576
|
+
var require4 = createRequire(import.meta.url);
|
|
4577
|
+
var { version: PKG_VERSION3 } = require4("../../package.json");
|
|
4545
4578
|
var SESSION_TTL_MS = 5 * 60 * 1e3;
|
|
4546
4579
|
var MAX_SESSIONS = 1e3;
|
|
4580
|
+
var RATE_LIMIT_WINDOW_MS = 6e4;
|
|
4581
|
+
var RATE_LIMIT_GENERAL = 120;
|
|
4582
|
+
var RATE_LIMIT_DECISIONS = 20;
|
|
4583
|
+
var MAX_RATE_LIMIT_ENTRIES = 1e4;
|
|
4547
4584
|
var DashboardApprovalChannel = class {
|
|
4548
4585
|
config;
|
|
4549
4586
|
pending = /* @__PURE__ */ new Map();
|
|
@@ -4558,13 +4595,15 @@ var DashboardApprovalChannel = class {
|
|
|
4558
4595
|
/** SEC-012: Short-lived session store. Sessions replace URL query tokens. */
|
|
4559
4596
|
sessions = /* @__PURE__ */ new Map();
|
|
4560
4597
|
sessionCleanupTimer = null;
|
|
4598
|
+
/** Rate limiting: per-IP request tracking */
|
|
4599
|
+
rateLimits = /* @__PURE__ */ new Map();
|
|
4561
4600
|
constructor(config) {
|
|
4562
4601
|
this.config = config;
|
|
4563
4602
|
this.authToken = config.auth_token;
|
|
4564
4603
|
this.useTLS = !!(config.tls?.cert_path && config.tls?.key_path);
|
|
4565
4604
|
this.dashboardHTML = generateDashboardHTML({
|
|
4566
4605
|
timeoutSeconds: config.timeout_seconds,
|
|
4567
|
-
serverVersion:
|
|
4606
|
+
serverVersion: PKG_VERSION3,
|
|
4568
4607
|
authToken: this.authToken
|
|
4569
4608
|
});
|
|
4570
4609
|
this.sessionCleanupTimer = setInterval(() => this.cleanupSessions(), 6e4);
|
|
@@ -4643,6 +4682,7 @@ var DashboardApprovalChannel = class {
|
|
|
4643
4682
|
clearInterval(this.sessionCleanupTimer);
|
|
4644
4683
|
this.sessionCleanupTimer = null;
|
|
4645
4684
|
}
|
|
4685
|
+
this.rateLimits.clear();
|
|
4646
4686
|
if (this.httpServer) {
|
|
4647
4687
|
return new Promise((resolve) => {
|
|
4648
4688
|
this.httpServer.close(() => resolve());
|
|
@@ -4768,6 +4808,61 @@ var DashboardApprovalChannel = class {
|
|
|
4768
4808
|
}
|
|
4769
4809
|
}
|
|
4770
4810
|
}
|
|
4811
|
+
// ── Rate Limiting ─────────────────────────────────────────────────
|
|
4812
|
+
/**
|
|
4813
|
+
* Get the remote address from a request, normalizing IPv6-mapped IPv4.
|
|
4814
|
+
*/
|
|
4815
|
+
getRemoteAddr(req) {
|
|
4816
|
+
const addr = req.socket.remoteAddress ?? "unknown";
|
|
4817
|
+
return addr.startsWith("::ffff:") ? addr.slice(7) : addr;
|
|
4818
|
+
}
|
|
4819
|
+
/**
|
|
4820
|
+
* Check rate limit for a request. Returns true if allowed, false if rate-limited.
|
|
4821
|
+
* When rate-limited, sends a 429 response.
|
|
4822
|
+
*/
|
|
4823
|
+
checkRateLimit(req, res, type) {
|
|
4824
|
+
const addr = this.getRemoteAddr(req);
|
|
4825
|
+
const now = Date.now();
|
|
4826
|
+
const windowStart = now - RATE_LIMIT_WINDOW_MS;
|
|
4827
|
+
let entry = this.rateLimits.get(addr);
|
|
4828
|
+
if (!entry) {
|
|
4829
|
+
if (this.rateLimits.size >= MAX_RATE_LIMIT_ENTRIES) {
|
|
4830
|
+
this.pruneRateLimits(now);
|
|
4831
|
+
}
|
|
4832
|
+
entry = { general: [], decisions: [] };
|
|
4833
|
+
this.rateLimits.set(addr, entry);
|
|
4834
|
+
}
|
|
4835
|
+
entry.general = entry.general.filter((t) => t > windowStart);
|
|
4836
|
+
entry.decisions = entry.decisions.filter((t) => t > windowStart);
|
|
4837
|
+
const limit = type === "decisions" ? RATE_LIMIT_DECISIONS : RATE_LIMIT_GENERAL;
|
|
4838
|
+
const timestamps = entry[type];
|
|
4839
|
+
if (timestamps.length >= limit) {
|
|
4840
|
+
const retryAfter = Math.ceil((timestamps[0] + RATE_LIMIT_WINDOW_MS - now) / 1e3);
|
|
4841
|
+
res.writeHead(429, {
|
|
4842
|
+
"Content-Type": "application/json",
|
|
4843
|
+
"Retry-After": String(Math.max(1, retryAfter))
|
|
4844
|
+
});
|
|
4845
|
+
res.end(JSON.stringify({
|
|
4846
|
+
error: "Rate limit exceeded",
|
|
4847
|
+
retry_after_seconds: Math.max(1, retryAfter)
|
|
4848
|
+
}));
|
|
4849
|
+
return false;
|
|
4850
|
+
}
|
|
4851
|
+
timestamps.push(now);
|
|
4852
|
+
return true;
|
|
4853
|
+
}
|
|
4854
|
+
/**
|
|
4855
|
+
* Remove stale entries from the rate limit map.
|
|
4856
|
+
*/
|
|
4857
|
+
pruneRateLimits(now) {
|
|
4858
|
+
const windowStart = now - RATE_LIMIT_WINDOW_MS;
|
|
4859
|
+
for (const [addr, entry] of this.rateLimits) {
|
|
4860
|
+
const hasRecent = entry.general.some((t) => t > windowStart) || entry.decisions.some((t) => t > windowStart);
|
|
4861
|
+
if (!hasRecent) {
|
|
4862
|
+
this.rateLimits.delete(addr);
|
|
4863
|
+
}
|
|
4864
|
+
}
|
|
4865
|
+
}
|
|
4771
4866
|
// ── HTTP Request Handler ────────────────────────────────────────────
|
|
4772
4867
|
handleRequest(req, res) {
|
|
4773
4868
|
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
|
|
@@ -4786,6 +4881,7 @@ var DashboardApprovalChannel = class {
|
|
|
4786
4881
|
return;
|
|
4787
4882
|
}
|
|
4788
4883
|
if (!this.checkAuth(req, url, res)) return;
|
|
4884
|
+
if (!this.checkRateLimit(req, res, "general")) return;
|
|
4789
4885
|
try {
|
|
4790
4886
|
if (method === "POST" && url.pathname === "/auth/session") {
|
|
4791
4887
|
this.handleSessionExchange(req, res);
|
|
@@ -4802,9 +4898,11 @@ var DashboardApprovalChannel = class {
|
|
|
4802
4898
|
} else if (method === "GET" && url.pathname === "/api/audit-log") {
|
|
4803
4899
|
this.handleAuditLog(url, res);
|
|
4804
4900
|
} else if (method === "POST" && url.pathname.startsWith("/api/approve/")) {
|
|
4901
|
+
if (!this.checkRateLimit(req, res, "decisions")) return;
|
|
4805
4902
|
const id = url.pathname.slice("/api/approve/".length);
|
|
4806
4903
|
this.handleDecision(id, "approve", res);
|
|
4807
4904
|
} else if (method === "POST" && url.pathname.startsWith("/api/deny/")) {
|
|
4905
|
+
if (!this.checkRateLimit(req, res, "decisions")) return;
|
|
4808
4906
|
const id = url.pathname.slice("/api/deny/".length);
|
|
4809
4907
|
this.handleDecision(id, "deny", res);
|
|
4810
4908
|
} else {
|
|
@@ -5547,14 +5645,14 @@ function generateSHR(identityId, opts) {
|
|
|
5547
5645
|
code: "PROCESS_ISOLATION_ONLY",
|
|
5548
5646
|
severity: "warning",
|
|
5549
5647
|
description: "Process-level isolation only (no TEE)",
|
|
5550
|
-
mitigation: "TEE support planned for
|
|
5648
|
+
mitigation: "TEE support planned for a future release"
|
|
5551
5649
|
});
|
|
5552
5650
|
degradations.push({
|
|
5553
5651
|
layer: "l2",
|
|
5554
5652
|
code: "SELF_REPORTED_ATTESTATION",
|
|
5555
5653
|
severity: "warning",
|
|
5556
5654
|
description: "Attestation is self-reported (no hardware root of trust)",
|
|
5557
|
-
mitigation: "TEE attestation planned for
|
|
5655
|
+
mitigation: "TEE attestation planned for a future release"
|
|
5558
5656
|
});
|
|
5559
5657
|
}
|
|
5560
5658
|
if (config.disclosure.proof_system === "commitment-only") {
|
|
@@ -5698,6 +5796,245 @@ function assessSovereigntyLevel(body) {
|
|
|
5698
5796
|
return "minimal";
|
|
5699
5797
|
}
|
|
5700
5798
|
|
|
5799
|
+
// src/shr/gateway-adapter.ts
|
|
5800
|
+
var LAYER_WEIGHTS = {
|
|
5801
|
+
l1: 100,
|
|
5802
|
+
l2: 100,
|
|
5803
|
+
l3: 100,
|
|
5804
|
+
l4: 100
|
|
5805
|
+
};
|
|
5806
|
+
var DEGRADATION_IMPACT = {
|
|
5807
|
+
critical: 40,
|
|
5808
|
+
warning: 25,
|
|
5809
|
+
info: 10
|
|
5810
|
+
};
|
|
5811
|
+
function transformSHRForGateway(shr) {
|
|
5812
|
+
const { body, signed_by, signature } = shr;
|
|
5813
|
+
const layerScores = calculateLayerScores(body);
|
|
5814
|
+
const overallScore = calculateOverallScore(layerScores);
|
|
5815
|
+
const trustLevel = determineTrustLevel(overallScore);
|
|
5816
|
+
const signals = extractAuthorizationSignals(body);
|
|
5817
|
+
const degradations = transformDegradations(body.degradations);
|
|
5818
|
+
const constraints = generateAuthorizationConstraints(body);
|
|
5819
|
+
return {
|
|
5820
|
+
shr_version: body.shr_version,
|
|
5821
|
+
agent_identity: signed_by,
|
|
5822
|
+
generated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5823
|
+
context_expires_at: body.expires_at,
|
|
5824
|
+
overall_score: overallScore,
|
|
5825
|
+
recommended_trust_level: trustLevel,
|
|
5826
|
+
layer_scores: {
|
|
5827
|
+
l1_cognitive: layerScores.l1,
|
|
5828
|
+
l2_operational: layerScores.l2,
|
|
5829
|
+
l3_disclosure: layerScores.l3,
|
|
5830
|
+
l4_reputation: layerScores.l4
|
|
5831
|
+
},
|
|
5832
|
+
layer_status: {
|
|
5833
|
+
l1_cognitive: body.layers.l1.status,
|
|
5834
|
+
l2_operational: body.layers.l2.status,
|
|
5835
|
+
l3_disclosure: body.layers.l3.status,
|
|
5836
|
+
l4_reputation: body.layers.l4.status
|
|
5837
|
+
},
|
|
5838
|
+
authorization_signals: signals,
|
|
5839
|
+
degradations,
|
|
5840
|
+
recommended_constraints: constraints,
|
|
5841
|
+
shr_signature: signature,
|
|
5842
|
+
shr_signed_by: signed_by
|
|
5843
|
+
};
|
|
5844
|
+
}
|
|
5845
|
+
function calculateLayerScores(body) {
|
|
5846
|
+
const layers = body.layers;
|
|
5847
|
+
const degradations = body.degradations;
|
|
5848
|
+
let l1Score = LAYER_WEIGHTS.l1;
|
|
5849
|
+
let l2Score = LAYER_WEIGHTS.l2;
|
|
5850
|
+
let l3Score = LAYER_WEIGHTS.l3;
|
|
5851
|
+
let l4Score = LAYER_WEIGHTS.l4;
|
|
5852
|
+
for (const deg of degradations) {
|
|
5853
|
+
const impact = DEGRADATION_IMPACT[deg.severity] || 10;
|
|
5854
|
+
if (deg.layer === "l1") {
|
|
5855
|
+
l1Score = Math.max(0, l1Score - impact);
|
|
5856
|
+
} else if (deg.layer === "l2") {
|
|
5857
|
+
l2Score = Math.max(0, l2Score - impact);
|
|
5858
|
+
} else if (deg.layer === "l3") {
|
|
5859
|
+
l3Score = Math.max(0, l3Score - impact);
|
|
5860
|
+
} else if (deg.layer === "l4") {
|
|
5861
|
+
l4Score = Math.max(0, l4Score - impact);
|
|
5862
|
+
}
|
|
5863
|
+
}
|
|
5864
|
+
if (layers.l1.status === "active" && l1Score > 50) l1Score = Math.min(100, l1Score + 5);
|
|
5865
|
+
if (layers.l2.status === "active" && l2Score > 50) l2Score = Math.min(100, l2Score + 5);
|
|
5866
|
+
if (layers.l3.status === "active" && l3Score > 50) l3Score = Math.min(100, l3Score + 5);
|
|
5867
|
+
if (layers.l4.status === "active" && l4Score > 50) l4Score = Math.min(100, l4Score + 5);
|
|
5868
|
+
if (layers.l1.status === "inactive") l1Score = 0;
|
|
5869
|
+
if (layers.l2.status === "inactive") l2Score = 0;
|
|
5870
|
+
if (layers.l3.status === "inactive") l3Score = 0;
|
|
5871
|
+
if (layers.l4.status === "inactive") l4Score = 0;
|
|
5872
|
+
return {
|
|
5873
|
+
l1: Math.round(l1Score),
|
|
5874
|
+
l2: Math.round(l2Score),
|
|
5875
|
+
l3: Math.round(l3Score),
|
|
5876
|
+
l4: Math.round(l4Score)
|
|
5877
|
+
};
|
|
5878
|
+
}
|
|
5879
|
+
function calculateOverallScore(layerScores) {
|
|
5880
|
+
const average = (layerScores.l1 + layerScores.l2 + layerScores.l3 + layerScores.l4) / 4;
|
|
5881
|
+
return Math.round(average);
|
|
5882
|
+
}
|
|
5883
|
+
function determineTrustLevel(score) {
|
|
5884
|
+
if (score >= 80) return "full";
|
|
5885
|
+
if (score >= 60) return "elevated";
|
|
5886
|
+
if (score >= 40) return "standard";
|
|
5887
|
+
return "restricted";
|
|
5888
|
+
}
|
|
5889
|
+
function extractAuthorizationSignals(body) {
|
|
5890
|
+
const l1 = body.layers.l1;
|
|
5891
|
+
const l3 = body.layers.l3;
|
|
5892
|
+
const l4 = body.layers.l4;
|
|
5893
|
+
return {
|
|
5894
|
+
approval_gate_active: body.capabilities.handshake,
|
|
5895
|
+
// Handshake implies human loop capability
|
|
5896
|
+
context_gating_active: body.capabilities.encrypted_channel,
|
|
5897
|
+
// Proxy for gating capability
|
|
5898
|
+
encryption_at_rest: l1.encryption !== "none" && l1.encryption !== "unencrypted",
|
|
5899
|
+
behavioral_baseline_active: false,
|
|
5900
|
+
// Would need explicit field in SHR v1.1
|
|
5901
|
+
identity_verified: l1.identity_type === "ed25519" || l1.identity_type !== "none",
|
|
5902
|
+
zero_knowledge_capable: l3.status === "active" && l3.proof_system !== "commitment-only",
|
|
5903
|
+
selective_disclosure_active: l3.selective_disclosure,
|
|
5904
|
+
reputation_portable: l4.reputation_portable,
|
|
5905
|
+
handshake_capable: body.capabilities.handshake
|
|
5906
|
+
};
|
|
5907
|
+
}
|
|
5908
|
+
function transformDegradations(degradations) {
|
|
5909
|
+
return degradations.map((deg) => {
|
|
5910
|
+
let authzImpact = "";
|
|
5911
|
+
if (deg.code === "NO_TEE") {
|
|
5912
|
+
authzImpact = "Restricted to read-only operations until TEE available";
|
|
5913
|
+
} else if (deg.code === "PROCESS_ISOLATION_ONLY") {
|
|
5914
|
+
authzImpact = "Requires additional identity verification";
|
|
5915
|
+
} else if (deg.code === "COMMITMENT_ONLY") {
|
|
5916
|
+
authzImpact = "Limited data sharing scope \u2014 no zero-knowledge proofs";
|
|
5917
|
+
} else if (deg.code === "NO_ZK_PROOFS") {
|
|
5918
|
+
authzImpact = "Cannot perform confidential disclosures";
|
|
5919
|
+
} else if (deg.code === "SELF_REPORTED_ATTESTATION") {
|
|
5920
|
+
authzImpact = "Attestation trust degraded \u2014 human verification recommended";
|
|
5921
|
+
} else if (deg.code === "NO_SELECTIVE_DISCLOSURE") {
|
|
5922
|
+
authzImpact = "Must share entire data context, cannot redact";
|
|
5923
|
+
} else if (deg.code === "BASIC_SYBIL_ONLY") {
|
|
5924
|
+
authzImpact = "Restrict to interactions with known agents only";
|
|
5925
|
+
} else {
|
|
5926
|
+
authzImpact = "Unknown authorization impact";
|
|
5927
|
+
}
|
|
5928
|
+
return {
|
|
5929
|
+
layer: deg.layer,
|
|
5930
|
+
code: deg.code,
|
|
5931
|
+
severity: deg.severity,
|
|
5932
|
+
description: deg.description,
|
|
5933
|
+
authorization_impact: authzImpact
|
|
5934
|
+
};
|
|
5935
|
+
});
|
|
5936
|
+
}
|
|
5937
|
+
function generateAuthorizationConstraints(body, _degradations) {
|
|
5938
|
+
const constraints = [];
|
|
5939
|
+
const layers = body.layers;
|
|
5940
|
+
if (layers.l1.status === "degraded" || layers.l1.key_custody !== "self") {
|
|
5941
|
+
constraints.push({
|
|
5942
|
+
type: "identity_verification_required",
|
|
5943
|
+
description: "Additional identity verification required for sensitive operations",
|
|
5944
|
+
rationale: "L1 is degraded or key custody is not self-managed",
|
|
5945
|
+
priority: "high"
|
|
5946
|
+
});
|
|
5947
|
+
}
|
|
5948
|
+
if (!layers.l1.state_portable) {
|
|
5949
|
+
constraints.push({
|
|
5950
|
+
type: "location_bound",
|
|
5951
|
+
description: "Agent state is not portable \u2014 restrict to home environment",
|
|
5952
|
+
rationale: "State cannot be safely migrated across boundaries",
|
|
5953
|
+
priority: "medium"
|
|
5954
|
+
});
|
|
5955
|
+
}
|
|
5956
|
+
if (layers.l2.status === "degraded" || layers.l2.isolation_type === "local-process") {
|
|
5957
|
+
constraints.push({
|
|
5958
|
+
type: "read_only",
|
|
5959
|
+
description: "Restrict to read-only operations until operational isolation improves",
|
|
5960
|
+
rationale: "L2 isolation is process-level only (no TEE)",
|
|
5961
|
+
priority: "high"
|
|
5962
|
+
});
|
|
5963
|
+
}
|
|
5964
|
+
if (!layers.l2.attestation_available) {
|
|
5965
|
+
constraints.push({
|
|
5966
|
+
type: "requires_approval",
|
|
5967
|
+
description: "Human approval required for writes and sensitive reads",
|
|
5968
|
+
rationale: "No attestation available \u2014 self-reported integrity only",
|
|
5969
|
+
priority: "high"
|
|
5970
|
+
});
|
|
5971
|
+
}
|
|
5972
|
+
if (layers.l3.status === "degraded" || !layers.l3.selective_disclosure) {
|
|
5973
|
+
constraints.push({
|
|
5974
|
+
type: "restricted_scope",
|
|
5975
|
+
description: "Limit data sharing to minimal required scope \u2014 no selective disclosure",
|
|
5976
|
+
rationale: "Agent cannot redact data or prove predicates without revealing all context",
|
|
5977
|
+
priority: "high"
|
|
5978
|
+
});
|
|
5979
|
+
}
|
|
5980
|
+
if (layers.l3.proof_system === "commitment-only") {
|
|
5981
|
+
constraints.push({
|
|
5982
|
+
type: "restricted_scope",
|
|
5983
|
+
description: "No zero-knowledge proofs available \u2014 entire state context may be visible",
|
|
5984
|
+
rationale: "Proof system is commitment-only (no ZK)",
|
|
5985
|
+
priority: "medium"
|
|
5986
|
+
});
|
|
5987
|
+
}
|
|
5988
|
+
if (layers.l4.status === "degraded") {
|
|
5989
|
+
constraints.push({
|
|
5990
|
+
type: "known_agents_only",
|
|
5991
|
+
description: "Restrict interactions to known, pre-approved agents",
|
|
5992
|
+
rationale: "Reputation layer is degraded",
|
|
5993
|
+
priority: "medium"
|
|
5994
|
+
});
|
|
5995
|
+
}
|
|
5996
|
+
if (!layers.l4.reputation_portable) {
|
|
5997
|
+
constraints.push({
|
|
5998
|
+
type: "location_bound",
|
|
5999
|
+
description: "Reputation is not portable \u2014 restrict to home environment",
|
|
6000
|
+
rationale: "Cannot present reputation to external parties",
|
|
6001
|
+
priority: "low"
|
|
6002
|
+
});
|
|
6003
|
+
}
|
|
6004
|
+
const layerScores = calculateLayerScores(body);
|
|
6005
|
+
const overallScore = calculateOverallScore(layerScores);
|
|
6006
|
+
if (overallScore < 40) {
|
|
6007
|
+
constraints.push({
|
|
6008
|
+
type: "restricted_scope",
|
|
6009
|
+
description: "Overall sovereignty score below threshold \u2014 restrict to non-sensitive operations",
|
|
6010
|
+
rationale: `Overall sovereignty score is ${overallScore}/100`,
|
|
6011
|
+
priority: "high"
|
|
6012
|
+
});
|
|
6013
|
+
}
|
|
6014
|
+
return constraints;
|
|
6015
|
+
}
|
|
6016
|
+
function transformSHRGeneric(shr) {
|
|
6017
|
+
const context = transformSHRForGateway(shr);
|
|
6018
|
+
return {
|
|
6019
|
+
agent_id: context.agent_identity,
|
|
6020
|
+
sovereignty_score: context.overall_score,
|
|
6021
|
+
trust_level: context.recommended_trust_level,
|
|
6022
|
+
layer_scores: {
|
|
6023
|
+
l1: context.layer_scores.l1_cognitive,
|
|
6024
|
+
l2: context.layer_scores.l2_operational,
|
|
6025
|
+
l3: context.layer_scores.l3_disclosure,
|
|
6026
|
+
l4: context.layer_scores.l4_reputation
|
|
6027
|
+
},
|
|
6028
|
+
capabilities: context.authorization_signals,
|
|
6029
|
+
constraints: context.recommended_constraints.map((c) => ({
|
|
6030
|
+
type: c.type,
|
|
6031
|
+
description: c.description
|
|
6032
|
+
})),
|
|
6033
|
+
expires_at: context.context_expires_at,
|
|
6034
|
+
signature: context.shr_signature
|
|
6035
|
+
};
|
|
6036
|
+
}
|
|
6037
|
+
|
|
5701
6038
|
// src/shr/tools.ts
|
|
5702
6039
|
function createSHRTools(config, identityManager, masterKey, auditLog) {
|
|
5703
6040
|
const generatorOpts = {
|
|
@@ -5760,6 +6097,53 @@ function createSHRTools(config, identityManager, masterKey, auditLog) {
|
|
|
5760
6097
|
);
|
|
5761
6098
|
return toolResult(result);
|
|
5762
6099
|
}
|
|
6100
|
+
},
|
|
6101
|
+
{
|
|
6102
|
+
name: "sanctuary/shr_gateway_export",
|
|
6103
|
+
description: "Export this instance's Sovereignty Health Report formatted for Ping Identity's Agent Gateway or other identity providers. Transforms the SHR into an authorization context with sovereignty scores, capability flags, and recommended access constraints.",
|
|
6104
|
+
inputSchema: {
|
|
6105
|
+
type: "object",
|
|
6106
|
+
properties: {
|
|
6107
|
+
format: {
|
|
6108
|
+
type: "string",
|
|
6109
|
+
enum: ["ping", "generic"],
|
|
6110
|
+
description: "Output format: 'ping' (Ping Identity Gateway format) or 'generic' (format-agnostic). Default: 'ping'."
|
|
6111
|
+
},
|
|
6112
|
+
identity_id: {
|
|
6113
|
+
type: "string",
|
|
6114
|
+
description: "Identity to sign the SHR with. Defaults to primary identity."
|
|
6115
|
+
},
|
|
6116
|
+
validity_minutes: {
|
|
6117
|
+
type: "number",
|
|
6118
|
+
description: "How long the SHR is valid (minutes). Default: 60."
|
|
6119
|
+
}
|
|
6120
|
+
}
|
|
6121
|
+
},
|
|
6122
|
+
handler: async (args) => {
|
|
6123
|
+
const format = args.format || "ping";
|
|
6124
|
+
const validityMs = args.validity_minutes ? args.validity_minutes * 60 * 1e3 : void 0;
|
|
6125
|
+
const shrResult = generateSHR(args.identity_id, {
|
|
6126
|
+
...generatorOpts,
|
|
6127
|
+
validityMs
|
|
6128
|
+
});
|
|
6129
|
+
if (typeof shrResult === "string") {
|
|
6130
|
+
return toolResult({ error: shrResult });
|
|
6131
|
+
}
|
|
6132
|
+
let context;
|
|
6133
|
+
if (format === "generic") {
|
|
6134
|
+
context = transformSHRGeneric(shrResult);
|
|
6135
|
+
} else {
|
|
6136
|
+
context = transformSHRForGateway(shrResult);
|
|
6137
|
+
}
|
|
6138
|
+
auditLog.append(
|
|
6139
|
+
"l2",
|
|
6140
|
+
"shr_gateway_export",
|
|
6141
|
+
shrResult.body.instance_id,
|
|
6142
|
+
void 0,
|
|
6143
|
+
"success"
|
|
6144
|
+
);
|
|
6145
|
+
return toolResult(context);
|
|
6146
|
+
}
|
|
5763
6147
|
}
|
|
5764
6148
|
];
|
|
5765
6149
|
return { tools };
|
|
@@ -7038,9 +7422,11 @@ var L1_INTEGRITY_VERIFICATION = 8;
|
|
|
7038
7422
|
var L1_STATE_PORTABLE = 7;
|
|
7039
7423
|
var L2_THREE_TIER_GATE = 10;
|
|
7040
7424
|
var L2_BINARY_GATE = 3;
|
|
7041
|
-
var L2_ANOMALY_DETECTION =
|
|
7042
|
-
var L2_ENCRYPTED_AUDIT =
|
|
7043
|
-
var L2_TOOL_SANDBOXING =
|
|
7425
|
+
var L2_ANOMALY_DETECTION = 5;
|
|
7426
|
+
var L2_ENCRYPTED_AUDIT = 4;
|
|
7427
|
+
var L2_TOOL_SANDBOXING = 2;
|
|
7428
|
+
var L2_CONTEXT_GATING = 4;
|
|
7429
|
+
var L2_PROCESS_HARDENING = 5;
|
|
7044
7430
|
var L3_COMMITMENT_SCHEME = 8;
|
|
7045
7431
|
var L3_ZK_PROOFS = 7;
|
|
7046
7432
|
var L3_DISCLOSURE_POLICIES = 5;
|
|
@@ -7054,6 +7440,35 @@ var SEVERITY_ORDER = {
|
|
|
7054
7440
|
medium: 2,
|
|
7055
7441
|
low: 3
|
|
7056
7442
|
};
|
|
7443
|
+
var INCIDENT_META_SEV1 = {
|
|
7444
|
+
id: "META-SEV1-2026",
|
|
7445
|
+
name: "Meta Sev 1: Unauthorized autonomous data exposure",
|
|
7446
|
+
date: "2026-03-18",
|
|
7447
|
+
description: "AI agent autonomously posted proprietary code, business strategies, and user datasets to an internal forum without human approval. Two-hour exposure window."
|
|
7448
|
+
};
|
|
7449
|
+
var INCIDENT_OPENCLAW_SANDBOX = {
|
|
7450
|
+
id: "OPENCLAW-CVE-2026",
|
|
7451
|
+
name: "OpenClaw sandbox escape via privilege inheritance",
|
|
7452
|
+
date: "2026-03-18",
|
|
7453
|
+
description: "Nine CVEs in four days. Child processes inherited sandbox.mode=off from parent, bypassing runtime confinement. 42,900+ internet-exposed instances, 15,200 vulnerable to RCE.",
|
|
7454
|
+
cves: [
|
|
7455
|
+
"CVE-2026-32048",
|
|
7456
|
+
"CVE-2026-32915",
|
|
7457
|
+
"CVE-2026-32918"
|
|
7458
|
+
]
|
|
7459
|
+
};
|
|
7460
|
+
var INCIDENT_CONTEXT_LEAKAGE = {
|
|
7461
|
+
id: "CONTEXT-LEAK-CLASS",
|
|
7462
|
+
name: "Context leakage: Full state exposure to inference providers",
|
|
7463
|
+
date: "2026-03",
|
|
7464
|
+
description: "Agents send full context \u2014 conversation history, memory, secrets, internal reasoning \u2014 to remote LLM providers on every inference call with no filtering mechanism."
|
|
7465
|
+
};
|
|
7466
|
+
var INCIDENT_CLAUDE_CODE_LEAK = {
|
|
7467
|
+
id: "CLAUDE-CODE-LEAK-2026",
|
|
7468
|
+
name: "Claude Code source leak: 512K lines exposed via npm source map",
|
|
7469
|
+
date: "2026-03-31",
|
|
7470
|
+
description: "Anthropic accidentally shipped a 59.8 MB source map in npm package v2.1.88, exposing the full Claude Code TypeScript source \u2014 1,900 files, internal model codenames, unreleased features, OAuth flows, and multi-agent coordination logic."
|
|
7471
|
+
};
|
|
7057
7472
|
function analyzeSovereignty(env, config) {
|
|
7058
7473
|
const l1 = assessL1(env, config);
|
|
7059
7474
|
const l2 = assessL2(env);
|
|
@@ -7126,14 +7541,18 @@ function assessL2(env, _config) {
|
|
|
7126
7541
|
let auditTrailEncrypted = false;
|
|
7127
7542
|
let auditTrailExists = false;
|
|
7128
7543
|
let toolSandboxing = "none";
|
|
7544
|
+
let contextGating = false;
|
|
7545
|
+
let processIsolationHardening = "none";
|
|
7129
7546
|
if (sanctuaryActive) {
|
|
7130
7547
|
approvalGate = "three-tier";
|
|
7131
7548
|
behavioralAnomalyDetection = true;
|
|
7132
7549
|
auditTrailEncrypted = true;
|
|
7133
7550
|
auditTrailExists = true;
|
|
7551
|
+
contextGating = true;
|
|
7134
7552
|
findings.push("Three-tier Principal Policy gate active");
|
|
7135
7553
|
findings.push("Behavioral anomaly detection (BaselineTracker) enabled");
|
|
7136
7554
|
findings.push("Encrypted audit trail active");
|
|
7555
|
+
findings.push("Context gating available (sanctuary/context_gate_set_policy)");
|
|
7137
7556
|
}
|
|
7138
7557
|
if (env.openclaw_detected && env.openclaw_config) {
|
|
7139
7558
|
if (env.openclaw_config.require_approval_enabled) {
|
|
@@ -7151,6 +7570,7 @@ function assessL2(env, _config) {
|
|
|
7151
7570
|
);
|
|
7152
7571
|
}
|
|
7153
7572
|
}
|
|
7573
|
+
processIsolationHardening = "none";
|
|
7154
7574
|
const status = approvalGate === "three-tier" && auditTrailEncrypted ? "active" : approvalGate !== "none" || auditTrailExists ? "partial" : "inactive";
|
|
7155
7575
|
return {
|
|
7156
7576
|
status,
|
|
@@ -7159,6 +7579,8 @@ function assessL2(env, _config) {
|
|
|
7159
7579
|
audit_trail_encrypted: auditTrailEncrypted,
|
|
7160
7580
|
audit_trail_exists: auditTrailExists,
|
|
7161
7581
|
tool_sandboxing: sanctuaryActive ? "policy-enforced" : toolSandboxing,
|
|
7582
|
+
context_gating: contextGating,
|
|
7583
|
+
process_isolation_hardening: processIsolationHardening,
|
|
7162
7584
|
findings
|
|
7163
7585
|
};
|
|
7164
7586
|
}
|
|
@@ -7173,8 +7595,10 @@ function assessL3(env, _config) {
|
|
|
7173
7595
|
zkProofs = true;
|
|
7174
7596
|
selectiveDisclosurePolicy = true;
|
|
7175
7597
|
findings.push("SHA-256 + Pedersen commitment schemes active");
|
|
7176
|
-
findings.push("Schnorr
|
|
7598
|
+
findings.push("Schnorr zero-knowledge proofs (Fiat-Shamir) enabled \u2014 genuine ZK proofs");
|
|
7599
|
+
findings.push("Range proofs (bit-decomposition + OR-proofs) enabled \u2014 genuine ZK proofs");
|
|
7177
7600
|
findings.push("Selective disclosure policies configurable");
|
|
7601
|
+
findings.push("Non-interactive proofs with replay-resistant domain separation");
|
|
7178
7602
|
}
|
|
7179
7603
|
const status = commitmentScheme === "pedersen+sha256" && zkProofs ? "active" : commitmentScheme !== "none" ? "partial" : "inactive";
|
|
7180
7604
|
return {
|
|
@@ -7226,6 +7650,9 @@ function scoreL2(l2) {
|
|
|
7226
7650
|
if (l2.audit_trail_encrypted) score += L2_ENCRYPTED_AUDIT;
|
|
7227
7651
|
if (l2.tool_sandboxing === "policy-enforced") score += L2_TOOL_SANDBOXING;
|
|
7228
7652
|
else if (l2.tool_sandboxing === "basic") score += 1;
|
|
7653
|
+
if (l2.context_gating) score += L2_CONTEXT_GATING;
|
|
7654
|
+
if (l2.process_isolation_hardening === "hardened") score += L2_PROCESS_HARDENING;
|
|
7655
|
+
else if (l2.process_isolation_hardening === "basic") score += 2;
|
|
7229
7656
|
return score;
|
|
7230
7657
|
}
|
|
7231
7658
|
function scoreL3(l3) {
|
|
@@ -7255,7 +7682,8 @@ function generateGaps(env, l1, l2, l3, l4) {
|
|
|
7255
7682
|
title: "Agent memory stored in plaintext",
|
|
7256
7683
|
description: "Your agent's memory (MEMORY.md, daily notes, SQLite index) is stored in plaintext at ~/.openclaw/workspace/. Any process with file access can read your agent's full context \u2014 preferences, decisions, conversation history.",
|
|
7257
7684
|
openclaw_relevance: "Stock OpenClaw stores all agent memory in plaintext files. There is no built-in encryption for agent state.",
|
|
7258
|
-
sanctuary_solution: "Sanctuary encrypts all state at rest with AES-256-GCM using a key derived from Argon2id, making state opaque to any process that doesn't hold the master key. Use sanctuary/state_write to migrate sensitive state to the encrypted store."
|
|
7685
|
+
sanctuary_solution: "Sanctuary encrypts all state at rest with AES-256-GCM using a key derived from Argon2id, making state opaque to any process that doesn't hold the master key. Use sanctuary/state_write to migrate sensitive state to the encrypted store.",
|
|
7686
|
+
incident_class: INCIDENT_META_SEV1
|
|
7259
7687
|
});
|
|
7260
7688
|
}
|
|
7261
7689
|
if (oc && oc.env_file_exposed) {
|
|
@@ -7288,7 +7716,8 @@ function generateGaps(env, l1, l2, l3, l4) {
|
|
|
7288
7716
|
title: "Binary approval gate (no anomaly detection)",
|
|
7289
7717
|
description: "Your approval gate provides binary approve/deny gating without behavioral anomaly detection. Routine operations require the same manual approval as sensitive ones.",
|
|
7290
7718
|
openclaw_relevance: env.openclaw_detected ? "OpenClaw's requireApproval hook provides binary approve/deny gating. Sanctuary's three-tier Principal Policy adds behavioral anomaly detection (auto-escalation when agent behavior deviates from baseline), encrypted audit trails, and graduated approval tiers \u2014 so routine operations auto-proceed while sensitive operations require explicit consent." : null,
|
|
7291
|
-
sanctuary_solution: "Sanctuary's three-tier Principal Policy gate auto-allows routine operations (Tier 3), escalates anomalous behavior (Tier 2), and always requires human approval for irreversible operations (Tier 1). Use sanctuary/principal_policy_view to inspect."
|
|
7719
|
+
sanctuary_solution: "Sanctuary's three-tier Principal Policy gate auto-allows routine operations (Tier 3), escalates anomalous behavior (Tier 2), and always requires human approval for irreversible operations (Tier 1). Use sanctuary/principal_policy_view to inspect.",
|
|
7720
|
+
incident_class: INCIDENT_META_SEV1
|
|
7292
7721
|
});
|
|
7293
7722
|
} else if (l2.approval_gate === "none") {
|
|
7294
7723
|
gaps.push({
|
|
@@ -7298,7 +7727,8 @@ function generateGaps(env, l1, l2, l3, l4) {
|
|
|
7298
7727
|
title: "No approval gate",
|
|
7299
7728
|
description: "No approval gate is configured. All tool calls execute without oversight.",
|
|
7300
7729
|
openclaw_relevance: null,
|
|
7301
|
-
sanctuary_solution: "Sanctuary's Principal Policy evaluates every tool call before execution. Enable it to get three-tier approval gating with behavioral anomaly detection."
|
|
7730
|
+
sanctuary_solution: "Sanctuary's Principal Policy evaluates every tool call before execution. Enable it to get three-tier approval gating with behavioral anomaly detection.",
|
|
7731
|
+
incident_class: INCIDENT_META_SEV1
|
|
7302
7732
|
});
|
|
7303
7733
|
}
|
|
7304
7734
|
if (l2.tool_sandboxing === "basic") {
|
|
@@ -7309,18 +7739,32 @@ function generateGaps(env, l1, l2, l3, l4) {
|
|
|
7309
7739
|
title: "Basic tool sandboxing (no cryptographic attestation)",
|
|
7310
7740
|
description: "Your tool sandbox enforces allow/deny lists but provides no cryptographic attestation of execution context.",
|
|
7311
7741
|
openclaw_relevance: env.openclaw_detected ? "OpenClaw's sandbox tool policy (tools.sandbox.tools) enforces allow/deny lists. Sanctuary adds cryptographic attestation of execution context \u2014 a verifiable proof that an operation ran within policy, not just that a policy was configured." : null,
|
|
7312
|
-
sanctuary_solution: "Sanctuary provides cryptographic execution attestation via sanctuary/exec_attest and policy-enforced sandboxing with encrypted audit trails."
|
|
7742
|
+
sanctuary_solution: "Sanctuary provides cryptographic execution attestation via sanctuary/exec_attest and policy-enforced sandboxing with encrypted audit trails.",
|
|
7743
|
+
incident_class: INCIDENT_OPENCLAW_SANDBOX
|
|
7313
7744
|
});
|
|
7314
7745
|
}
|
|
7315
|
-
if (!l2.
|
|
7746
|
+
if (!l2.context_gating) {
|
|
7316
7747
|
gaps.push({
|
|
7317
7748
|
id: "GAP-L2-003",
|
|
7318
7749
|
layer: "L2",
|
|
7319
7750
|
severity: "high",
|
|
7751
|
+
title: "No context gating for outbound inference calls",
|
|
7752
|
+
description: "Your agent sends its full context \u2014 conversation history, memory, preferences, internal reasoning \u2014 to remote LLM providers on every inference call. There is no mechanism to filter what leaves the sovereignty boundary. The provider sees everything the agent knows.",
|
|
7753
|
+
openclaw_relevance: env.openclaw_detected ? "OpenClaw sends full agent context (including MEMORY.md, tool results, and conversation history) to the configured LLM provider with every API call. There is no built-in context filtering." : null,
|
|
7754
|
+
sanctuary_solution: "Sanctuary's context gating (sanctuary/context_gate_set_policy + sanctuary/context_gate_filter) lets you define per-provider policies that control exactly what context flows outbound. Redact secrets, hash identifiers, and send only minimum-necessary context for each call.",
|
|
7755
|
+
incident_class: INCIDENT_CONTEXT_LEAKAGE
|
|
7756
|
+
});
|
|
7757
|
+
}
|
|
7758
|
+
if (!l2.audit_trail_exists) {
|
|
7759
|
+
gaps.push({
|
|
7760
|
+
id: "GAP-L2-004",
|
|
7761
|
+
layer: "L2",
|
|
7762
|
+
severity: "high",
|
|
7320
7763
|
title: "No audit trail",
|
|
7321
7764
|
description: "No audit trail exists for tool call history. There is no record of what operations were executed, when, or by whom.",
|
|
7322
7765
|
openclaw_relevance: null,
|
|
7323
|
-
sanctuary_solution: "Sanctuary maintains an encrypted audit log of all operations, queryable via sanctuary/monitor_audit_log."
|
|
7766
|
+
sanctuary_solution: "Sanctuary maintains an encrypted audit log of all operations, queryable via sanctuary/monitor_audit_log.",
|
|
7767
|
+
incident_class: INCIDENT_CLAUDE_CODE_LEAK
|
|
7324
7768
|
});
|
|
7325
7769
|
}
|
|
7326
7770
|
if (l3.commitment_scheme === "none") {
|
|
@@ -7329,9 +7773,10 @@ function generateGaps(env, l1, l2, l3, l4) {
|
|
|
7329
7773
|
layer: "L3",
|
|
7330
7774
|
severity: "high",
|
|
7331
7775
|
title: "No selective disclosure capability",
|
|
7332
|
-
description: "Your agent has no
|
|
7776
|
+
description: "Your agent has no cryptographic mechanism to prove facts about its state without revealing the state itself. Every disclosure is all-or-nothing: no commitments, no zero-knowledge proofs, no selective disclosure policies.",
|
|
7333
7777
|
openclaw_relevance: env.openclaw_detected ? "OpenClaw has no selective disclosure mechanism. When your agent shares information, it shares everything or nothing \u2014 there is no way to prove a claim without revealing the underlying data." : null,
|
|
7334
|
-
sanctuary_solution: "Sanctuary's L3 provides SHA-256 + Pedersen commitments
|
|
7778
|
+
sanctuary_solution: "Sanctuary's L3 provides SHA-256 + Pedersen commitments with genuine zero-knowledge proofs (Schnorr + range proofs via Fiat-Shamir transform). Your agent can prove it has a valid credential, sufficient reputation, or a completed transaction without exposing the underlying data. Use sanctuary/zk_commit and sanctuary/zk_prove.",
|
|
7779
|
+
incident_class: INCIDENT_META_SEV1
|
|
7335
7780
|
});
|
|
7336
7781
|
}
|
|
7337
7782
|
if (!l4.reputation_portable) {
|
|
@@ -7383,9 +7828,18 @@ function generateRecommendations(env, l1, l2, l3, l4) {
|
|
|
7383
7828
|
impact: "high"
|
|
7384
7829
|
});
|
|
7385
7830
|
}
|
|
7386
|
-
if (!
|
|
7831
|
+
if (!l2.context_gating) {
|
|
7387
7832
|
recs.push({
|
|
7388
7833
|
priority: 5,
|
|
7834
|
+
action: "Configure context gating to control what flows to LLM providers",
|
|
7835
|
+
tool: "sanctuary/context_gate_set_policy",
|
|
7836
|
+
effort: "minutes",
|
|
7837
|
+
impact: "high"
|
|
7838
|
+
});
|
|
7839
|
+
}
|
|
7840
|
+
if (!l4.reputation_signed) {
|
|
7841
|
+
recs.push({
|
|
7842
|
+
priority: 6,
|
|
7389
7843
|
action: "Start recording reputation attestations from completed interactions",
|
|
7390
7844
|
tool: "sanctuary/reputation_record",
|
|
7391
7845
|
effort: "minutes",
|
|
@@ -7394,7 +7848,7 @@ function generateRecommendations(env, l1, l2, l3, l4) {
|
|
|
7394
7848
|
}
|
|
7395
7849
|
if (!l3.selective_disclosure_policy) {
|
|
7396
7850
|
recs.push({
|
|
7397
|
-
priority:
|
|
7851
|
+
priority: 7,
|
|
7398
7852
|
action: "Configure selective disclosure policies for data sharing",
|
|
7399
7853
|
tool: "sanctuary/disclosure_set_policy",
|
|
7400
7854
|
effort: "hours",
|
|
@@ -7443,6 +7897,10 @@ function formatAuditReport(result) {
|
|
|
7443
7897
|
`;
|
|
7444
7898
|
report += ` \u2502 L2 Operational Isolation \u2502 ${padStatus(layers.l2_operational.status)} \u2502 ${padScore(l2Score, 25)} \u2502
|
|
7445
7899
|
`;
|
|
7900
|
+
if (layers.l2_operational.context_gating) {
|
|
7901
|
+
report += ` \u2502 \u2514 Context Gating \u2502 ACTIVE \u2502 \u2502
|
|
7902
|
+
`;
|
|
7903
|
+
}
|
|
7446
7904
|
report += ` \u2502 L3 Selective Disclosure \u2502 ${padStatus(layers.l3_selective_disclosure.status)} \u2502 ${padScore(l3Score, 20)} \u2502
|
|
7447
7905
|
`;
|
|
7448
7906
|
report += ` \u2502 L4 Verifiable Reputation \u2502 ${padStatus(layers.l4_reputation.status)} \u2502 ${padScore(l4Score, 20)} \u2502
|
|
@@ -7460,6 +7918,12 @@ function formatAuditReport(result) {
|
|
|
7460
7918
|
const descLines = wordWrap(gap.description, 66);
|
|
7461
7919
|
for (const line of descLines) {
|
|
7462
7920
|
report += ` ${line}
|
|
7921
|
+
`;
|
|
7922
|
+
}
|
|
7923
|
+
if (gap.incident_class) {
|
|
7924
|
+
const ic = gap.incident_class;
|
|
7925
|
+
const cveStr = ic.cves?.length ? ` (${ic.cves.join(", ")})` : "";
|
|
7926
|
+
report += ` \u2192 Incident precedent: ${ic.name}${cveStr} [${ic.date}]
|
|
7463
7927
|
`;
|
|
7464
7928
|
}
|
|
7465
7929
|
report += ` \u2192 Fix: ${gap.sanctuary_solution.split(".")[0]}.
|
|
@@ -7554,33 +8018,1509 @@ function createAuditTools(config) {
|
|
|
7554
8018
|
return { tools };
|
|
7555
8019
|
}
|
|
7556
8020
|
|
|
7557
|
-
// src/
|
|
8021
|
+
// src/l2-operational/context-gate.ts
|
|
7558
8022
|
init_encoding();
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
8023
|
+
init_hashing();
|
|
8024
|
+
var MAX_CONTEXT_FIELDS = 1e3;
|
|
8025
|
+
var MAX_POLICY_RULES = 50;
|
|
8026
|
+
var MAX_PATTERNS_PER_ARRAY = 500;
|
|
8027
|
+
function evaluateField(policy, provider, field) {
|
|
8028
|
+
const exactRule = policy.rules.find((r) => r.provider === provider);
|
|
8029
|
+
const wildcardRule = policy.rules.find((r) => r.provider === "*");
|
|
8030
|
+
const matchedRule = exactRule ?? wildcardRule;
|
|
8031
|
+
if (!matchedRule) {
|
|
8032
|
+
return {
|
|
8033
|
+
field,
|
|
8034
|
+
action: policy.default_action === "deny" ? "deny" : "redact",
|
|
8035
|
+
reason: `No rule matches provider "${provider}"; applying default (${policy.default_action})`
|
|
8036
|
+
};
|
|
8037
|
+
}
|
|
8038
|
+
if (matchesPattern(field, matchedRule.redact)) {
|
|
8039
|
+
return {
|
|
8040
|
+
field,
|
|
8041
|
+
action: "redact",
|
|
8042
|
+
reason: `Field "${field}" is explicitly redacted for ${matchedRule.provider} provider`
|
|
8043
|
+
};
|
|
8044
|
+
}
|
|
8045
|
+
if (matchesPattern(field, matchedRule.hash)) {
|
|
8046
|
+
return {
|
|
8047
|
+
field,
|
|
8048
|
+
action: "hash",
|
|
8049
|
+
reason: `Field "${field}" is hashed for ${matchedRule.provider} provider`
|
|
8050
|
+
};
|
|
8051
|
+
}
|
|
8052
|
+
if (matchesPattern(field, matchedRule.summarize)) {
|
|
8053
|
+
return {
|
|
8054
|
+
field,
|
|
8055
|
+
action: "summarize",
|
|
8056
|
+
reason: `Field "${field}" should be summarized for ${matchedRule.provider} provider`
|
|
8057
|
+
};
|
|
8058
|
+
}
|
|
8059
|
+
if (matchesPattern(field, matchedRule.allow)) {
|
|
8060
|
+
return {
|
|
8061
|
+
field,
|
|
8062
|
+
action: "allow",
|
|
8063
|
+
reason: `Field "${field}" is allowed for ${matchedRule.provider} provider`
|
|
8064
|
+
};
|
|
8065
|
+
}
|
|
8066
|
+
return {
|
|
8067
|
+
field,
|
|
8068
|
+
action: policy.default_action === "deny" ? "deny" : "redact",
|
|
8069
|
+
reason: `Field "${field}" not addressed in ${matchedRule.provider} rule; applying default (${policy.default_action})`
|
|
8070
|
+
};
|
|
8071
|
+
}
|
|
8072
|
+
function filterContext(policy, provider, context) {
|
|
8073
|
+
const fields = Object.keys(context);
|
|
8074
|
+
if (fields.length > MAX_CONTEXT_FIELDS) {
|
|
8075
|
+
throw new Error(
|
|
8076
|
+
`Context object has ${fields.length} fields, exceeding limit of ${MAX_CONTEXT_FIELDS}`
|
|
8077
|
+
);
|
|
8078
|
+
}
|
|
8079
|
+
const decisions = [];
|
|
8080
|
+
let allowed = 0;
|
|
8081
|
+
let redacted = 0;
|
|
8082
|
+
let hashed = 0;
|
|
8083
|
+
let summarized = 0;
|
|
8084
|
+
let denied = 0;
|
|
8085
|
+
for (const field of fields) {
|
|
8086
|
+
const result = evaluateField(policy, provider, field);
|
|
8087
|
+
if (result.action === "hash") {
|
|
8088
|
+
const value = typeof context[field] === "string" ? context[field] : JSON.stringify(context[field]);
|
|
8089
|
+
result.hash_value = hashToString(stringToBytes(value));
|
|
8090
|
+
}
|
|
8091
|
+
decisions.push(result);
|
|
8092
|
+
switch (result.action) {
|
|
8093
|
+
case "allow":
|
|
8094
|
+
allowed++;
|
|
8095
|
+
break;
|
|
8096
|
+
case "redact":
|
|
8097
|
+
redacted++;
|
|
8098
|
+
break;
|
|
8099
|
+
case "hash":
|
|
8100
|
+
hashed++;
|
|
8101
|
+
break;
|
|
8102
|
+
case "summarize":
|
|
8103
|
+
summarized++;
|
|
8104
|
+
break;
|
|
8105
|
+
case "deny":
|
|
8106
|
+
denied++;
|
|
8107
|
+
break;
|
|
8108
|
+
}
|
|
8109
|
+
}
|
|
8110
|
+
const originalHash = hashToString(
|
|
8111
|
+
stringToBytes(JSON.stringify(context))
|
|
7564
8112
|
);
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
8113
|
+
const filteredOutput = {};
|
|
8114
|
+
for (const decision of decisions) {
|
|
8115
|
+
switch (decision.action) {
|
|
8116
|
+
case "allow":
|
|
8117
|
+
filteredOutput[decision.field] = context[decision.field];
|
|
8118
|
+
break;
|
|
8119
|
+
case "redact":
|
|
8120
|
+
filteredOutput[decision.field] = "[REDACTED]";
|
|
8121
|
+
break;
|
|
8122
|
+
case "hash":
|
|
8123
|
+
filteredOutput[decision.field] = `[HASH:${decision.hash_value}]`;
|
|
8124
|
+
break;
|
|
8125
|
+
case "summarize":
|
|
8126
|
+
filteredOutput[decision.field] = "[SUMMARIZE]";
|
|
8127
|
+
break;
|
|
8128
|
+
}
|
|
8129
|
+
}
|
|
8130
|
+
const filteredHash = hashToString(
|
|
8131
|
+
stringToBytes(JSON.stringify(filteredOutput))
|
|
8132
|
+
);
|
|
8133
|
+
return {
|
|
8134
|
+
policy_id: policy.policy_id,
|
|
8135
|
+
provider,
|
|
8136
|
+
fields_allowed: allowed,
|
|
8137
|
+
fields_redacted: redacted,
|
|
8138
|
+
fields_hashed: hashed,
|
|
8139
|
+
fields_summarized: summarized,
|
|
8140
|
+
fields_denied: denied,
|
|
8141
|
+
decisions,
|
|
8142
|
+
original_context_hash: originalHash,
|
|
8143
|
+
filtered_context_hash: filteredHash,
|
|
8144
|
+
filtered_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
8145
|
+
};
|
|
8146
|
+
}
|
|
8147
|
+
function matchesPattern(field, patterns) {
|
|
8148
|
+
const normalizedField = field.toLowerCase();
|
|
8149
|
+
for (const pattern of patterns) {
|
|
8150
|
+
if (pattern === "*") return true;
|
|
8151
|
+
const normalizedPattern = pattern.toLowerCase();
|
|
8152
|
+
if (normalizedPattern === normalizedField) return true;
|
|
8153
|
+
if (normalizedPattern.endsWith("*") && normalizedField.startsWith(normalizedPattern.slice(0, -1))) return true;
|
|
8154
|
+
if (normalizedPattern.startsWith("*") && normalizedField.endsWith(normalizedPattern.slice(1))) return true;
|
|
8155
|
+
}
|
|
8156
|
+
return false;
|
|
8157
|
+
}
|
|
8158
|
+
var ContextGatePolicyStore = class {
|
|
8159
|
+
storage;
|
|
8160
|
+
encryptionKey;
|
|
8161
|
+
policies = /* @__PURE__ */ new Map();
|
|
8162
|
+
constructor(storage, masterKey) {
|
|
8163
|
+
this.storage = storage;
|
|
8164
|
+
this.encryptionKey = derivePurposeKey(masterKey, "l2-context-gate");
|
|
8165
|
+
}
|
|
8166
|
+
/**
|
|
8167
|
+
* Create and store a new context-gating policy.
|
|
8168
|
+
*/
|
|
8169
|
+
async create(policyName, rules, defaultAction, identityId) {
|
|
8170
|
+
const policyId = `cg-${Date.now()}-${toBase64url(randomBytes(8))}`;
|
|
8171
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
8172
|
+
const policy = {
|
|
8173
|
+
policy_id: policyId,
|
|
8174
|
+
policy_name: policyName,
|
|
8175
|
+
rules,
|
|
8176
|
+
default_action: defaultAction,
|
|
8177
|
+
identity_id: identityId,
|
|
8178
|
+
created_at: now,
|
|
8179
|
+
updated_at: now
|
|
8180
|
+
};
|
|
8181
|
+
await this.persist(policy);
|
|
8182
|
+
this.policies.set(policyId, policy);
|
|
8183
|
+
return policy;
|
|
8184
|
+
}
|
|
8185
|
+
/**
|
|
8186
|
+
* Get a policy by ID.
|
|
8187
|
+
*/
|
|
8188
|
+
async get(policyId) {
|
|
8189
|
+
if (this.policies.has(policyId)) {
|
|
8190
|
+
return this.policies.get(policyId);
|
|
8191
|
+
}
|
|
8192
|
+
const raw = await this.storage.read("_context_gate_policies", policyId);
|
|
8193
|
+
if (!raw) return null;
|
|
7572
8194
|
try {
|
|
7573
|
-
const
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
8195
|
+
const encrypted = JSON.parse(bytesToString(raw));
|
|
8196
|
+
const decrypted = decrypt(encrypted, this.encryptionKey);
|
|
8197
|
+
const policy = JSON.parse(bytesToString(decrypted));
|
|
8198
|
+
this.policies.set(policyId, policy);
|
|
8199
|
+
return policy;
|
|
8200
|
+
} catch {
|
|
8201
|
+
return null;
|
|
8202
|
+
}
|
|
8203
|
+
}
|
|
8204
|
+
/**
|
|
8205
|
+
* List all context-gating policies.
|
|
8206
|
+
*/
|
|
8207
|
+
async list() {
|
|
8208
|
+
await this.loadAll();
|
|
8209
|
+
return Array.from(this.policies.values());
|
|
8210
|
+
}
|
|
8211
|
+
/**
|
|
8212
|
+
* Load all persisted policies into memory.
|
|
8213
|
+
*/
|
|
8214
|
+
async loadAll() {
|
|
8215
|
+
try {
|
|
8216
|
+
const entries = await this.storage.list("_context_gate_policies");
|
|
8217
|
+
for (const meta of entries) {
|
|
8218
|
+
if (this.policies.has(meta.key)) continue;
|
|
8219
|
+
const raw = await this.storage.read("_context_gate_policies", meta.key);
|
|
8220
|
+
if (!raw) continue;
|
|
8221
|
+
try {
|
|
8222
|
+
const encrypted = JSON.parse(bytesToString(raw));
|
|
8223
|
+
const decrypted = decrypt(encrypted, this.encryptionKey);
|
|
8224
|
+
const policy = JSON.parse(bytesToString(decrypted));
|
|
8225
|
+
this.policies.set(policy.policy_id, policy);
|
|
8226
|
+
} catch {
|
|
8227
|
+
}
|
|
7577
8228
|
}
|
|
7578
8229
|
} catch {
|
|
7579
8230
|
}
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
8231
|
+
}
|
|
8232
|
+
async persist(policy) {
|
|
8233
|
+
const serialized = stringToBytes(JSON.stringify(policy));
|
|
8234
|
+
const encrypted = encrypt(serialized, this.encryptionKey);
|
|
8235
|
+
await this.storage.write(
|
|
8236
|
+
"_context_gate_policies",
|
|
8237
|
+
policy.policy_id,
|
|
8238
|
+
stringToBytes(JSON.stringify(encrypted))
|
|
8239
|
+
);
|
|
8240
|
+
}
|
|
8241
|
+
};
|
|
8242
|
+
|
|
8243
|
+
// src/l2-operational/context-gate-templates.ts
|
|
8244
|
+
var ALWAYS_REDACT_SECRETS = [
|
|
8245
|
+
"api_key",
|
|
8246
|
+
"secret_*",
|
|
8247
|
+
"*_secret",
|
|
8248
|
+
"*_token",
|
|
8249
|
+
"*_key",
|
|
8250
|
+
"password",
|
|
8251
|
+
"*_password",
|
|
8252
|
+
"credential",
|
|
8253
|
+
"*_credential",
|
|
8254
|
+
"private_key",
|
|
8255
|
+
"recovery_key",
|
|
8256
|
+
"passphrase",
|
|
8257
|
+
"auth_*"
|
|
8258
|
+
];
|
|
8259
|
+
var PII_PATTERNS = [
|
|
8260
|
+
"*_pii",
|
|
8261
|
+
"name",
|
|
8262
|
+
"full_name",
|
|
8263
|
+
"email",
|
|
8264
|
+
"email_address",
|
|
8265
|
+
"phone",
|
|
8266
|
+
"phone_number",
|
|
8267
|
+
"address",
|
|
8268
|
+
"ssn",
|
|
8269
|
+
"date_of_birth",
|
|
8270
|
+
"ip_address",
|
|
8271
|
+
"credit_card",
|
|
8272
|
+
"card_number",
|
|
8273
|
+
"cvv",
|
|
8274
|
+
"bank_account",
|
|
8275
|
+
"account_number",
|
|
8276
|
+
"routing_number"
|
|
8277
|
+
];
|
|
8278
|
+
var INTERNAL_STATE_PATTERNS = [
|
|
8279
|
+
"memory",
|
|
8280
|
+
"agent_memory",
|
|
8281
|
+
"internal_reasoning",
|
|
8282
|
+
"internal_state",
|
|
8283
|
+
"reasoning_trace",
|
|
8284
|
+
"chain_of_thought",
|
|
8285
|
+
"private_notes",
|
|
8286
|
+
"soul",
|
|
8287
|
+
"personality",
|
|
8288
|
+
"system_prompt"
|
|
8289
|
+
];
|
|
8290
|
+
var ID_PATTERNS = [
|
|
8291
|
+
"user_id",
|
|
8292
|
+
"session_id",
|
|
8293
|
+
"agent_id",
|
|
8294
|
+
"identity_id",
|
|
8295
|
+
"conversation_id",
|
|
8296
|
+
"thread_id"
|
|
8297
|
+
];
|
|
8298
|
+
var HISTORY_PATTERNS = [
|
|
8299
|
+
"conversation_history",
|
|
8300
|
+
"message_history",
|
|
8301
|
+
"chat_history",
|
|
8302
|
+
"context_window",
|
|
8303
|
+
"previous_messages"
|
|
8304
|
+
];
|
|
8305
|
+
var INFERENCE_MINIMAL = {
|
|
8306
|
+
id: "inference-minimal",
|
|
8307
|
+
name: "Inference Minimal",
|
|
8308
|
+
description: "Maximum privacy. Only the current task and query reach the LLM provider.",
|
|
8309
|
+
use_when: "You want the strictest possible context control for inference calls. The LLM sees only what it needs for the immediate task.",
|
|
8310
|
+
rules: [
|
|
8311
|
+
{
|
|
8312
|
+
provider: "inference",
|
|
8313
|
+
allow: [
|
|
8314
|
+
"task",
|
|
8315
|
+
"task_description",
|
|
8316
|
+
"current_query",
|
|
8317
|
+
"query",
|
|
8318
|
+
"prompt",
|
|
8319
|
+
"question",
|
|
8320
|
+
"instruction"
|
|
8321
|
+
],
|
|
8322
|
+
redact: [
|
|
8323
|
+
...ALWAYS_REDACT_SECRETS,
|
|
8324
|
+
...PII_PATTERNS,
|
|
8325
|
+
...INTERNAL_STATE_PATTERNS,
|
|
8326
|
+
...HISTORY_PATTERNS,
|
|
8327
|
+
"tool_results",
|
|
8328
|
+
"previous_results"
|
|
8329
|
+
],
|
|
8330
|
+
hash: [...ID_PATTERNS],
|
|
8331
|
+
summarize: []
|
|
8332
|
+
}
|
|
8333
|
+
],
|
|
8334
|
+
default_action: "redact"
|
|
8335
|
+
};
|
|
8336
|
+
var INFERENCE_STANDARD = {
|
|
8337
|
+
id: "inference-standard",
|
|
8338
|
+
name: "Inference Standard",
|
|
8339
|
+
description: "Balanced privacy. Task, query, and tool results pass through. History flagged for summarization. Secrets and PII redacted.",
|
|
8340
|
+
use_when: "You need the LLM to have enough context for multi-step tasks while keeping secrets, PII, and internal reasoning private.",
|
|
8341
|
+
rules: [
|
|
8342
|
+
{
|
|
8343
|
+
provider: "inference",
|
|
8344
|
+
allow: [
|
|
8345
|
+
"task",
|
|
8346
|
+
"task_description",
|
|
8347
|
+
"current_query",
|
|
8348
|
+
"query",
|
|
8349
|
+
"prompt",
|
|
8350
|
+
"question",
|
|
8351
|
+
"instruction",
|
|
8352
|
+
"tool_results",
|
|
8353
|
+
"tool_output",
|
|
8354
|
+
"previous_results",
|
|
8355
|
+
"current_step",
|
|
8356
|
+
"remaining_steps",
|
|
8357
|
+
"objective",
|
|
8358
|
+
"constraints",
|
|
8359
|
+
"format",
|
|
8360
|
+
"output_format"
|
|
8361
|
+
],
|
|
8362
|
+
redact: [
|
|
8363
|
+
...ALWAYS_REDACT_SECRETS,
|
|
8364
|
+
...PII_PATTERNS,
|
|
8365
|
+
...INTERNAL_STATE_PATTERNS
|
|
8366
|
+
],
|
|
8367
|
+
hash: [...ID_PATTERNS],
|
|
8368
|
+
summarize: [...HISTORY_PATTERNS]
|
|
8369
|
+
}
|
|
8370
|
+
],
|
|
8371
|
+
default_action: "redact"
|
|
8372
|
+
};
|
|
8373
|
+
var LOGGING_STRICT = {
|
|
8374
|
+
id: "logging-strict",
|
|
8375
|
+
name: "Logging Strict",
|
|
8376
|
+
description: "Redacts all content for logging and analytics providers. Only operation metadata passes through.",
|
|
8377
|
+
use_when: "You send telemetry to logging or analytics services and want usage metrics without any content exposure.",
|
|
8378
|
+
rules: [
|
|
8379
|
+
{
|
|
8380
|
+
provider: "logging",
|
|
8381
|
+
allow: [
|
|
8382
|
+
"operation",
|
|
8383
|
+
"operation_name",
|
|
8384
|
+
"tool_name",
|
|
8385
|
+
"timestamp",
|
|
8386
|
+
"duration_ms",
|
|
8387
|
+
"status",
|
|
8388
|
+
"error_code",
|
|
8389
|
+
"event_type"
|
|
8390
|
+
],
|
|
8391
|
+
redact: [
|
|
8392
|
+
...ALWAYS_REDACT_SECRETS,
|
|
8393
|
+
...PII_PATTERNS,
|
|
8394
|
+
...INTERNAL_STATE_PATTERNS,
|
|
8395
|
+
...HISTORY_PATTERNS
|
|
8396
|
+
],
|
|
8397
|
+
hash: [...ID_PATTERNS],
|
|
8398
|
+
summarize: []
|
|
8399
|
+
},
|
|
8400
|
+
{
|
|
8401
|
+
provider: "analytics",
|
|
8402
|
+
allow: [
|
|
8403
|
+
"event_type",
|
|
8404
|
+
"timestamp",
|
|
8405
|
+
"duration_ms",
|
|
8406
|
+
"status",
|
|
8407
|
+
"tool_name"
|
|
8408
|
+
],
|
|
8409
|
+
redact: [
|
|
8410
|
+
...ALWAYS_REDACT_SECRETS,
|
|
8411
|
+
...PII_PATTERNS,
|
|
8412
|
+
...INTERNAL_STATE_PATTERNS,
|
|
8413
|
+
...HISTORY_PATTERNS
|
|
8414
|
+
],
|
|
8415
|
+
hash: [...ID_PATTERNS],
|
|
8416
|
+
summarize: []
|
|
8417
|
+
}
|
|
8418
|
+
],
|
|
8419
|
+
default_action: "redact"
|
|
8420
|
+
};
|
|
8421
|
+
var TOOL_API_SCOPED = {
|
|
8422
|
+
id: "tool-api-scoped",
|
|
8423
|
+
name: "Tool API Scoped",
|
|
8424
|
+
description: "Allows tool-specific parameters for external API calls. Redacts memory, history, secrets, and PII.",
|
|
8425
|
+
use_when: "Your agent calls external APIs (search, database, web) and you want to send query parameters without full agent context. Note: 'headers' and 'body' are redacted by default because they frequently carry authorization tokens. Add them to 'allow' only if you verify they contain no credentials for your use case.",
|
|
8426
|
+
rules: [
|
|
8427
|
+
{
|
|
8428
|
+
provider: "tool-api",
|
|
8429
|
+
allow: [
|
|
8430
|
+
"task",
|
|
8431
|
+
"task_description",
|
|
8432
|
+
"query",
|
|
8433
|
+
"search_query",
|
|
8434
|
+
"tool_input",
|
|
8435
|
+
"tool_parameters",
|
|
8436
|
+
"url",
|
|
8437
|
+
"endpoint",
|
|
8438
|
+
"method",
|
|
8439
|
+
"filter",
|
|
8440
|
+
"sort",
|
|
8441
|
+
"limit",
|
|
8442
|
+
"offset"
|
|
8443
|
+
],
|
|
8444
|
+
redact: [
|
|
8445
|
+
...ALWAYS_REDACT_SECRETS,
|
|
8446
|
+
...PII_PATTERNS,
|
|
8447
|
+
...INTERNAL_STATE_PATTERNS,
|
|
8448
|
+
...HISTORY_PATTERNS
|
|
8449
|
+
],
|
|
8450
|
+
hash: [...ID_PATTERNS],
|
|
8451
|
+
summarize: []
|
|
8452
|
+
}
|
|
8453
|
+
],
|
|
8454
|
+
default_action: "redact"
|
|
8455
|
+
};
|
|
8456
|
+
var TEMPLATES = {
|
|
8457
|
+
"inference-minimal": INFERENCE_MINIMAL,
|
|
8458
|
+
"inference-standard": INFERENCE_STANDARD,
|
|
8459
|
+
"logging-strict": LOGGING_STRICT,
|
|
8460
|
+
"tool-api-scoped": TOOL_API_SCOPED
|
|
8461
|
+
};
|
|
8462
|
+
function listTemplateIds() {
|
|
8463
|
+
return Object.keys(TEMPLATES);
|
|
8464
|
+
}
|
|
8465
|
+
function getTemplate(id) {
|
|
8466
|
+
return TEMPLATES[id];
|
|
8467
|
+
}
|
|
8468
|
+
|
|
8469
|
+
// src/l2-operational/context-gate-recommend.ts
|
|
8470
|
+
var CLASSIFICATION_RULES = [
|
|
8471
|
+
// ── Secrets (always redact, high confidence) ─────────────────────
|
|
8472
|
+
{
|
|
8473
|
+
patterns: [
|
|
8474
|
+
"api_key",
|
|
8475
|
+
"apikey",
|
|
8476
|
+
"api_secret",
|
|
8477
|
+
"secret",
|
|
8478
|
+
"secret_key",
|
|
8479
|
+
"secret_token",
|
|
8480
|
+
"password",
|
|
8481
|
+
"passwd",
|
|
8482
|
+
"pass",
|
|
8483
|
+
"credential",
|
|
8484
|
+
"credentials",
|
|
8485
|
+
"private_key",
|
|
8486
|
+
"privkey",
|
|
8487
|
+
"recovery_key",
|
|
8488
|
+
"passphrase",
|
|
8489
|
+
"token",
|
|
8490
|
+
"access_token",
|
|
8491
|
+
"refresh_token",
|
|
8492
|
+
"bearer_token",
|
|
8493
|
+
"auth_token",
|
|
8494
|
+
"auth_header",
|
|
8495
|
+
"authorization",
|
|
8496
|
+
"encryption_key",
|
|
8497
|
+
"master_key",
|
|
8498
|
+
"signing_key",
|
|
8499
|
+
"webhook_secret",
|
|
8500
|
+
"client_secret",
|
|
8501
|
+
"connection_string"
|
|
8502
|
+
],
|
|
8503
|
+
action: "redact",
|
|
8504
|
+
confidence: "high",
|
|
8505
|
+
reason: "Matches known secret/credential pattern"
|
|
8506
|
+
},
|
|
8507
|
+
// ── PII (always redact, high confidence) ─────────────────────────
|
|
8508
|
+
{
|
|
8509
|
+
patterns: [
|
|
8510
|
+
"name",
|
|
8511
|
+
"full_name",
|
|
8512
|
+
"first_name",
|
|
8513
|
+
"last_name",
|
|
8514
|
+
"display_name",
|
|
8515
|
+
"email",
|
|
8516
|
+
"email_address",
|
|
8517
|
+
"phone",
|
|
8518
|
+
"phone_number",
|
|
8519
|
+
"mobile",
|
|
8520
|
+
"address",
|
|
8521
|
+
"street_address",
|
|
8522
|
+
"mailing_address",
|
|
8523
|
+
"ssn",
|
|
8524
|
+
"social_security",
|
|
8525
|
+
"date_of_birth",
|
|
8526
|
+
"dob",
|
|
8527
|
+
"birthday",
|
|
8528
|
+
"ip_address",
|
|
8529
|
+
"ip",
|
|
8530
|
+
"location",
|
|
8531
|
+
"geolocation",
|
|
8532
|
+
"coordinates",
|
|
8533
|
+
"credit_card",
|
|
8534
|
+
"card_number",
|
|
8535
|
+
"cvv",
|
|
8536
|
+
"bank_account",
|
|
8537
|
+
"routing_number",
|
|
8538
|
+
"passport",
|
|
8539
|
+
"drivers_license",
|
|
8540
|
+
"license_number"
|
|
8541
|
+
],
|
|
8542
|
+
action: "redact",
|
|
8543
|
+
confidence: "high",
|
|
8544
|
+
reason: "Matches known PII pattern"
|
|
8545
|
+
},
|
|
8546
|
+
// ── Internal agent state (redact, high confidence) ───────────────
|
|
8547
|
+
{
|
|
8548
|
+
patterns: [
|
|
8549
|
+
"memory",
|
|
8550
|
+
"agent_memory",
|
|
8551
|
+
"long_term_memory",
|
|
8552
|
+
"internal_reasoning",
|
|
8553
|
+
"reasoning_trace",
|
|
8554
|
+
"chain_of_thought",
|
|
8555
|
+
"internal_state",
|
|
8556
|
+
"agent_state",
|
|
8557
|
+
"private_notes",
|
|
8558
|
+
"scratchpad",
|
|
8559
|
+
"soul",
|
|
8560
|
+
"personality",
|
|
8561
|
+
"persona",
|
|
8562
|
+
"system_prompt",
|
|
8563
|
+
"system_message",
|
|
8564
|
+
"system_instruction",
|
|
8565
|
+
"preferences",
|
|
8566
|
+
"user_preferences",
|
|
8567
|
+
"agent_preferences",
|
|
8568
|
+
"beliefs",
|
|
8569
|
+
"goals",
|
|
8570
|
+
"motivations"
|
|
8571
|
+
],
|
|
8572
|
+
action: "redact",
|
|
8573
|
+
confidence: "high",
|
|
8574
|
+
reason: "Matches known internal agent state pattern"
|
|
8575
|
+
},
|
|
8576
|
+
// ── IDs (hash, medium confidence) ────────────────────────────────
|
|
8577
|
+
{
|
|
8578
|
+
patterns: [
|
|
8579
|
+
"user_id",
|
|
8580
|
+
"userid",
|
|
8581
|
+
"session_id",
|
|
8582
|
+
"sessionid",
|
|
8583
|
+
"agent_id",
|
|
8584
|
+
"agentid",
|
|
8585
|
+
"identity_id",
|
|
8586
|
+
"conversation_id",
|
|
8587
|
+
"thread_id",
|
|
8588
|
+
"threadid",
|
|
8589
|
+
"request_id",
|
|
8590
|
+
"requestid",
|
|
8591
|
+
"correlation_id",
|
|
8592
|
+
"trace_id",
|
|
8593
|
+
"traceid",
|
|
8594
|
+
"account_id",
|
|
8595
|
+
"accountid"
|
|
8596
|
+
],
|
|
8597
|
+
action: "hash",
|
|
8598
|
+
confidence: "medium",
|
|
8599
|
+
reason: "Matches known identifier pattern \u2014 hash preserves correlation without exposing value"
|
|
8600
|
+
},
|
|
8601
|
+
// ── History (summarize, medium confidence) ───────────────────────
|
|
8602
|
+
{
|
|
8603
|
+
patterns: [
|
|
8604
|
+
"conversation_history",
|
|
8605
|
+
"chat_history",
|
|
8606
|
+
"message_history",
|
|
8607
|
+
"messages",
|
|
8608
|
+
"previous_messages",
|
|
8609
|
+
"prior_messages",
|
|
8610
|
+
"context_window",
|
|
8611
|
+
"interaction_history",
|
|
8612
|
+
"audit_log",
|
|
8613
|
+
"event_log"
|
|
8614
|
+
],
|
|
8615
|
+
action: "summarize",
|
|
8616
|
+
confidence: "medium",
|
|
8617
|
+
reason: "Matches known history/log pattern \u2014 summarize to reduce exposure"
|
|
8618
|
+
},
|
|
8619
|
+
// ── Task/query (allow, medium confidence) ────────────────────────
|
|
8620
|
+
{
|
|
8621
|
+
patterns: [
|
|
8622
|
+
"task",
|
|
8623
|
+
"task_description",
|
|
8624
|
+
"query",
|
|
8625
|
+
"current_query",
|
|
8626
|
+
"search_query",
|
|
8627
|
+
"prompt",
|
|
8628
|
+
"user_prompt",
|
|
8629
|
+
"question",
|
|
8630
|
+
"current_question",
|
|
8631
|
+
"instruction",
|
|
8632
|
+
"instructions",
|
|
8633
|
+
"objective",
|
|
8634
|
+
"goal",
|
|
8635
|
+
"current_step",
|
|
8636
|
+
"next_step",
|
|
8637
|
+
"remaining_steps",
|
|
8638
|
+
"constraints",
|
|
8639
|
+
"requirements",
|
|
8640
|
+
"output_format",
|
|
8641
|
+
"format",
|
|
8642
|
+
"tool_results",
|
|
8643
|
+
"tool_output",
|
|
8644
|
+
"tool_input",
|
|
8645
|
+
"tool_parameters"
|
|
8646
|
+
],
|
|
8647
|
+
action: "allow",
|
|
8648
|
+
confidence: "medium",
|
|
8649
|
+
reason: "Matches known task/query pattern \u2014 likely needed for inference"
|
|
8650
|
+
}
|
|
8651
|
+
];
|
|
8652
|
+
function classifyField(fieldName) {
|
|
8653
|
+
const normalized = fieldName.toLowerCase().trim();
|
|
8654
|
+
for (const rule of CLASSIFICATION_RULES) {
|
|
8655
|
+
for (const pattern of rule.patterns) {
|
|
8656
|
+
if (matchesFieldPattern(normalized, pattern)) {
|
|
8657
|
+
return {
|
|
8658
|
+
field: fieldName,
|
|
8659
|
+
recommended_action: rule.action,
|
|
8660
|
+
reason: rule.reason,
|
|
8661
|
+
confidence: rule.confidence,
|
|
8662
|
+
matched_pattern: pattern
|
|
8663
|
+
};
|
|
8664
|
+
}
|
|
8665
|
+
}
|
|
8666
|
+
}
|
|
8667
|
+
return {
|
|
8668
|
+
field: fieldName,
|
|
8669
|
+
recommended_action: "redact",
|
|
8670
|
+
reason: "No known pattern matched \u2014 defaulting to redact (conservative)",
|
|
8671
|
+
confidence: "low",
|
|
8672
|
+
matched_pattern: null
|
|
8673
|
+
};
|
|
8674
|
+
}
|
|
8675
|
+
function recommendPolicy(context, provider = "inference") {
|
|
8676
|
+
const fields = Object.keys(context);
|
|
8677
|
+
const classifications = fields.map(classifyField);
|
|
8678
|
+
const warnings = [];
|
|
8679
|
+
const allow = [];
|
|
8680
|
+
const redact = [];
|
|
8681
|
+
const hash2 = [];
|
|
8682
|
+
const summarize = [];
|
|
8683
|
+
for (const c of classifications) {
|
|
8684
|
+
switch (c.recommended_action) {
|
|
8685
|
+
case "allow":
|
|
8686
|
+
allow.push(c.field);
|
|
8687
|
+
break;
|
|
8688
|
+
case "redact":
|
|
8689
|
+
redact.push(c.field);
|
|
8690
|
+
break;
|
|
8691
|
+
case "hash":
|
|
8692
|
+
hash2.push(c.field);
|
|
8693
|
+
break;
|
|
8694
|
+
case "summarize":
|
|
8695
|
+
summarize.push(c.field);
|
|
8696
|
+
break;
|
|
8697
|
+
}
|
|
8698
|
+
}
|
|
8699
|
+
const lowConfidence = classifications.filter((c) => c.confidence === "low");
|
|
8700
|
+
if (lowConfidence.length > 0) {
|
|
8701
|
+
warnings.push(
|
|
8702
|
+
`${lowConfidence.length} field(s) could not be classified by pattern and will default to redact: ${lowConfidence.map((c) => c.field).join(", ")}. Review these manually.`
|
|
8703
|
+
);
|
|
8704
|
+
}
|
|
8705
|
+
for (const [key, value] of Object.entries(context)) {
|
|
8706
|
+
if (typeof value === "string" && value.length > 5e3) {
|
|
8707
|
+
const existing = classifications.find((c) => c.field === key);
|
|
8708
|
+
if (existing && existing.recommended_action === "allow") {
|
|
8709
|
+
warnings.push(
|
|
8710
|
+
`Field "${key}" is allowed but contains ${value.length} characters. Consider summarizing it to reduce context size and exposure.`
|
|
8711
|
+
);
|
|
8712
|
+
}
|
|
8713
|
+
}
|
|
8714
|
+
}
|
|
8715
|
+
return {
|
|
8716
|
+
provider,
|
|
8717
|
+
classifications,
|
|
8718
|
+
recommended_rules: { allow, redact, hash: hash2, summarize },
|
|
8719
|
+
default_action: "redact",
|
|
8720
|
+
summary: {
|
|
8721
|
+
total_fields: fields.length,
|
|
8722
|
+
allow: allow.length,
|
|
8723
|
+
redact: redact.length,
|
|
8724
|
+
hash: hash2.length,
|
|
8725
|
+
summarize: summarize.length
|
|
8726
|
+
},
|
|
8727
|
+
warnings
|
|
8728
|
+
};
|
|
8729
|
+
}
|
|
8730
|
+
function matchesFieldPattern(normalizedField, pattern) {
|
|
8731
|
+
if (normalizedField === pattern) return true;
|
|
8732
|
+
if (pattern.length >= 3 && normalizedField.includes(pattern)) {
|
|
8733
|
+
const idx = normalizedField.indexOf(pattern);
|
|
8734
|
+
const before = idx === 0 || normalizedField[idx - 1] === "_" || normalizedField[idx - 1] === "-";
|
|
8735
|
+
const after = idx + pattern.length === normalizedField.length || normalizedField[idx + pattern.length] === "_" || normalizedField[idx + pattern.length] === "-";
|
|
8736
|
+
return before && after;
|
|
8737
|
+
}
|
|
8738
|
+
return false;
|
|
8739
|
+
}
|
|
8740
|
+
|
|
8741
|
+
// src/l2-operational/context-gate-tools.ts
|
|
8742
|
+
function createContextGateTools(storage, masterKey, auditLog) {
|
|
8743
|
+
const policyStore = new ContextGatePolicyStore(storage, masterKey);
|
|
8744
|
+
const tools = [
|
|
8745
|
+
// ── Set Policy ──────────────────────────────────────────────────
|
|
8746
|
+
{
|
|
8747
|
+
name: "sanctuary/context_gate_set_policy",
|
|
8748
|
+
description: "Create a context-gating policy that controls what information flows to remote providers (LLM APIs, tool APIs, logging services). Each rule specifies a provider category and which context fields to allow, redact, hash, or flag for summarization. Redact rules take absolute priority \u2014 if a field is in both 'allow' and 'redact', it is redacted. Default action applies to any field not mentioned in any rule. Use this to prevent your full agent context from being sent to remote LLM providers during inference calls.",
|
|
8749
|
+
inputSchema: {
|
|
8750
|
+
type: "object",
|
|
8751
|
+
properties: {
|
|
8752
|
+
policy_name: {
|
|
8753
|
+
type: "string",
|
|
8754
|
+
description: "Human-readable name for this policy (e.g., 'inference-minimal', 'tool-api-strict')"
|
|
8755
|
+
},
|
|
8756
|
+
rules: {
|
|
8757
|
+
type: "array",
|
|
8758
|
+
description: "Array of rules. Each rule has: provider (inference|tool-api|logging|analytics|peer-agent|custom|*), allow (fields to pass through), redact (fields to remove \u2014 highest priority), hash (fields to replace with SHA-256 hash), summarize (fields to flag for compression).",
|
|
8759
|
+
items: {
|
|
8760
|
+
type: "object",
|
|
8761
|
+
properties: {
|
|
8762
|
+
provider: {
|
|
8763
|
+
type: "string",
|
|
8764
|
+
description: "Provider category: inference, tool-api, logging, analytics, peer-agent, custom, or * for all"
|
|
8765
|
+
},
|
|
8766
|
+
allow: {
|
|
8767
|
+
type: "array",
|
|
8768
|
+
items: { type: "string" },
|
|
8769
|
+
description: "Fields/patterns to allow through (e.g., 'task_description', 'current_query', 'tool_*')"
|
|
8770
|
+
},
|
|
8771
|
+
redact: {
|
|
8772
|
+
type: "array",
|
|
8773
|
+
items: { type: "string" },
|
|
8774
|
+
description: "Fields/patterns to redact (e.g., 'conversation_history', 'secret_*', '*_pii'). Takes absolute priority."
|
|
8775
|
+
},
|
|
8776
|
+
hash: {
|
|
8777
|
+
type: "array",
|
|
8778
|
+
items: { type: "string" },
|
|
8779
|
+
description: "Fields/patterns to replace with SHA-256 hash (e.g., 'user_id', 'session_id')"
|
|
8780
|
+
},
|
|
8781
|
+
summarize: {
|
|
8782
|
+
type: "array",
|
|
8783
|
+
items: { type: "string" },
|
|
8784
|
+
description: "Fields/patterns to flag for summarization (advisory \u2014 agent should compress these before sending)"
|
|
8785
|
+
}
|
|
8786
|
+
},
|
|
8787
|
+
required: ["provider", "allow", "redact"]
|
|
8788
|
+
}
|
|
8789
|
+
},
|
|
8790
|
+
default_action: {
|
|
8791
|
+
type: "string",
|
|
8792
|
+
enum: ["redact", "deny"],
|
|
8793
|
+
description: "Action for fields not matched by any rule. 'redact' removes the field value; 'deny' blocks the entire request. Default: 'redact'."
|
|
8794
|
+
},
|
|
8795
|
+
identity_id: {
|
|
8796
|
+
type: "string",
|
|
8797
|
+
description: "Bind this policy to a specific identity (optional)"
|
|
8798
|
+
}
|
|
8799
|
+
},
|
|
8800
|
+
required: ["policy_name", "rules"]
|
|
8801
|
+
},
|
|
8802
|
+
handler: async (args) => {
|
|
8803
|
+
const policyName = args.policy_name;
|
|
8804
|
+
const rawRules = args.rules;
|
|
8805
|
+
const defaultAction = args.default_action ?? "redact";
|
|
8806
|
+
const identityId = args.identity_id;
|
|
8807
|
+
if (!Array.isArray(rawRules)) {
|
|
8808
|
+
return toolResult({ error: "invalid_rules", message: "rules must be an array" });
|
|
8809
|
+
}
|
|
8810
|
+
if (rawRules.length > MAX_POLICY_RULES) {
|
|
8811
|
+
return toolResult({
|
|
8812
|
+
error: "too_many_rules",
|
|
8813
|
+
message: `Policy has ${rawRules.length} rules, exceeding limit of ${MAX_POLICY_RULES}`
|
|
8814
|
+
});
|
|
8815
|
+
}
|
|
8816
|
+
const rules = [];
|
|
8817
|
+
for (const r of rawRules) {
|
|
8818
|
+
const allow = Array.isArray(r.allow) ? r.allow : [];
|
|
8819
|
+
const redact = Array.isArray(r.redact) ? r.redact : [];
|
|
8820
|
+
const hash2 = Array.isArray(r.hash) ? r.hash : [];
|
|
8821
|
+
const summarize = Array.isArray(r.summarize) ? r.summarize : [];
|
|
8822
|
+
for (const [name, arr] of [["allow", allow], ["redact", redact], ["hash", hash2], ["summarize", summarize]]) {
|
|
8823
|
+
if (arr.length > MAX_PATTERNS_PER_ARRAY) {
|
|
8824
|
+
return toolResult({
|
|
8825
|
+
error: "too_many_patterns",
|
|
8826
|
+
message: `Rule ${name} array has ${arr.length} patterns, exceeding limit of ${MAX_PATTERNS_PER_ARRAY}`
|
|
8827
|
+
});
|
|
8828
|
+
}
|
|
8829
|
+
}
|
|
8830
|
+
rules.push({
|
|
8831
|
+
provider: r.provider ?? "*",
|
|
8832
|
+
allow,
|
|
8833
|
+
redact,
|
|
8834
|
+
hash: hash2,
|
|
8835
|
+
summarize
|
|
8836
|
+
});
|
|
8837
|
+
}
|
|
8838
|
+
const policy = await policyStore.create(
|
|
8839
|
+
policyName,
|
|
8840
|
+
rules,
|
|
8841
|
+
defaultAction,
|
|
8842
|
+
identityId
|
|
8843
|
+
);
|
|
8844
|
+
auditLog.append("l2", "context_gate_set_policy", identityId ?? "system", {
|
|
8845
|
+
policy_id: policy.policy_id,
|
|
8846
|
+
policy_name: policyName,
|
|
8847
|
+
rule_count: rules.length,
|
|
8848
|
+
default_action: defaultAction
|
|
8849
|
+
});
|
|
8850
|
+
return toolResult({
|
|
8851
|
+
policy_id: policy.policy_id,
|
|
8852
|
+
policy_name: policy.policy_name,
|
|
8853
|
+
rules: policy.rules,
|
|
8854
|
+
default_action: policy.default_action,
|
|
8855
|
+
created_at: policy.created_at,
|
|
8856
|
+
message: "Context-gating policy created. Use sanctuary/context_gate_filter to apply this policy before making outbound calls."
|
|
8857
|
+
});
|
|
8858
|
+
}
|
|
8859
|
+
},
|
|
8860
|
+
// ── Apply Template ───────────────────────────────────────────────
|
|
8861
|
+
{
|
|
8862
|
+
name: "sanctuary/context_gate_apply_template",
|
|
8863
|
+
description: "Apply a starter context-gating template. Available templates: inference-minimal (strictest \u2014 only task and query pass through), inference-standard (balanced \u2014 adds tool results, summarizes history), logging-strict (redacts all content for telemetry services), tool-api-scoped (allows tool parameters, redacts agent state). Templates are starting points \u2014 customize after applying.",
|
|
8864
|
+
inputSchema: {
|
|
8865
|
+
type: "object",
|
|
8866
|
+
properties: {
|
|
8867
|
+
template_id: {
|
|
8868
|
+
type: "string",
|
|
8869
|
+
description: "Template to apply: inference-minimal, inference-standard, logging-strict, or tool-api-scoped"
|
|
8870
|
+
},
|
|
8871
|
+
identity_id: {
|
|
8872
|
+
type: "string",
|
|
8873
|
+
description: "Bind this policy to a specific identity (optional)"
|
|
8874
|
+
}
|
|
8875
|
+
},
|
|
8876
|
+
required: ["template_id"]
|
|
8877
|
+
},
|
|
8878
|
+
handler: async (args) => {
|
|
8879
|
+
const templateId = args.template_id;
|
|
8880
|
+
const identityId = args.identity_id;
|
|
8881
|
+
const template = getTemplate(templateId);
|
|
8882
|
+
if (!template) {
|
|
8883
|
+
return toolResult({
|
|
8884
|
+
error: "template_not_found",
|
|
8885
|
+
message: `Unknown template "${templateId}"`,
|
|
8886
|
+
available_templates: listTemplateIds().map((id) => {
|
|
8887
|
+
const t = TEMPLATES[id];
|
|
8888
|
+
return { id, name: t.name, description: t.description };
|
|
8889
|
+
})
|
|
8890
|
+
});
|
|
8891
|
+
}
|
|
8892
|
+
const policy = await policyStore.create(
|
|
8893
|
+
template.name,
|
|
8894
|
+
template.rules,
|
|
8895
|
+
template.default_action,
|
|
8896
|
+
identityId
|
|
8897
|
+
);
|
|
8898
|
+
auditLog.append("l2", "context_gate_apply_template", identityId ?? "system", {
|
|
8899
|
+
policy_id: policy.policy_id,
|
|
8900
|
+
template_id: templateId
|
|
8901
|
+
});
|
|
8902
|
+
return toolResult({
|
|
8903
|
+
policy_id: policy.policy_id,
|
|
8904
|
+
template_applied: templateId,
|
|
8905
|
+
policy_name: template.name,
|
|
8906
|
+
description: template.description,
|
|
8907
|
+
use_when: template.use_when,
|
|
8908
|
+
rules: policy.rules,
|
|
8909
|
+
default_action: policy.default_action,
|
|
8910
|
+
created_at: policy.created_at,
|
|
8911
|
+
message: "Template applied. Use sanctuary/context_gate_filter with this policy_id to filter context before outbound calls. Customize rules with sanctuary/context_gate_set_policy if needed."
|
|
8912
|
+
});
|
|
8913
|
+
}
|
|
8914
|
+
},
|
|
8915
|
+
// ── Recommend Policy ────────────────────────────────────────────
|
|
8916
|
+
{
|
|
8917
|
+
name: "sanctuary/context_gate_recommend",
|
|
8918
|
+
description: "Analyze a sample context object and recommend a context-gating policy based on field name heuristics. Classifies each field as allow, redact, hash, or summarize with confidence levels. Returns a ready-to-apply rule set. When in doubt, recommends redact (conservative). Review the recommendations before applying.",
|
|
8919
|
+
inputSchema: {
|
|
8920
|
+
type: "object",
|
|
8921
|
+
properties: {
|
|
8922
|
+
context: {
|
|
8923
|
+
type: "object",
|
|
8924
|
+
description: "A sample context object to analyze. Each top-level key will be classified. Values are inspected for size warnings but not stored."
|
|
8925
|
+
},
|
|
8926
|
+
provider: {
|
|
8927
|
+
type: "string",
|
|
8928
|
+
description: "Provider category to generate rules for. Default: 'inference'."
|
|
8929
|
+
}
|
|
8930
|
+
},
|
|
8931
|
+
required: ["context"]
|
|
8932
|
+
},
|
|
8933
|
+
handler: async (args) => {
|
|
8934
|
+
const context = args.context;
|
|
8935
|
+
const provider = args.provider ?? "inference";
|
|
8936
|
+
const contextKeys = Object.keys(context);
|
|
8937
|
+
if (contextKeys.length > MAX_CONTEXT_FIELDS) {
|
|
8938
|
+
return toolResult({
|
|
8939
|
+
error: "context_too_large",
|
|
8940
|
+
message: `Context has ${contextKeys.length} fields, exceeding limit of ${MAX_CONTEXT_FIELDS}`
|
|
8941
|
+
});
|
|
8942
|
+
}
|
|
8943
|
+
const recommendation = recommendPolicy(context, provider);
|
|
8944
|
+
auditLog.append("l2", "context_gate_recommend", "system", {
|
|
8945
|
+
provider,
|
|
8946
|
+
fields_analyzed: recommendation.summary.total_fields,
|
|
8947
|
+
fields_allow: recommendation.summary.allow,
|
|
8948
|
+
fields_redact: recommendation.summary.redact,
|
|
8949
|
+
fields_hash: recommendation.summary.hash,
|
|
8950
|
+
fields_summarize: recommendation.summary.summarize
|
|
8951
|
+
});
|
|
8952
|
+
return toolResult({
|
|
8953
|
+
...recommendation,
|
|
8954
|
+
next_steps: "Review the classifications above. If they look correct, you can apply them directly with sanctuary/context_gate_set_policy using the recommended_rules. Or start with a template via sanctuary/context_gate_apply_template and customize from there.",
|
|
8955
|
+
available_templates: listTemplateIds().map((id) => {
|
|
8956
|
+
const t = TEMPLATES[id];
|
|
8957
|
+
return { id, name: t.name, description: t.description };
|
|
8958
|
+
})
|
|
8959
|
+
});
|
|
8960
|
+
}
|
|
8961
|
+
},
|
|
8962
|
+
// ── Filter Context ──────────────────────────────────────────────
|
|
8963
|
+
{
|
|
8964
|
+
name: "sanctuary/context_gate_filter",
|
|
8965
|
+
description: "Filter agent context through a gating policy before sending to a remote provider. Returns per-field decisions (allow, redact, hash, summarize) and content hashes for the audit trail. Call this BEFORE making any outbound API call to ensure you are only sending the minimum necessary context. The filtered output tells you exactly what can be sent safely.",
|
|
8966
|
+
inputSchema: {
|
|
8967
|
+
type: "object",
|
|
8968
|
+
properties: {
|
|
8969
|
+
policy_id: {
|
|
8970
|
+
type: "string",
|
|
8971
|
+
description: "ID of the context-gating policy to apply"
|
|
8972
|
+
},
|
|
8973
|
+
provider: {
|
|
8974
|
+
type: "string",
|
|
8975
|
+
description: "Provider category for this call: inference, tool-api, logging, analytics, peer-agent, or custom"
|
|
8976
|
+
},
|
|
8977
|
+
context: {
|
|
8978
|
+
type: "object",
|
|
8979
|
+
description: "The context object to filter. Each top-level key is evaluated against the policy. Example keys: task_description, conversation_history, user_preferences, api_keys, memory, internal_reasoning"
|
|
8980
|
+
}
|
|
8981
|
+
},
|
|
8982
|
+
required: ["policy_id", "provider", "context"]
|
|
8983
|
+
},
|
|
8984
|
+
handler: async (args) => {
|
|
8985
|
+
const policyId = args.policy_id;
|
|
8986
|
+
const provider = args.provider;
|
|
8987
|
+
const context = args.context;
|
|
8988
|
+
const contextKeys = Object.keys(context);
|
|
8989
|
+
if (contextKeys.length > MAX_CONTEXT_FIELDS) {
|
|
8990
|
+
return toolResult({
|
|
8991
|
+
error: "context_too_large",
|
|
8992
|
+
message: `Context has ${contextKeys.length} fields, exceeding limit of ${MAX_CONTEXT_FIELDS}`
|
|
8993
|
+
});
|
|
8994
|
+
}
|
|
8995
|
+
const policy = await policyStore.get(policyId);
|
|
8996
|
+
if (!policy) {
|
|
8997
|
+
return toolResult({
|
|
8998
|
+
error: "policy_not_found",
|
|
8999
|
+
message: `No context-gating policy found with ID "${policyId}"`
|
|
9000
|
+
});
|
|
9001
|
+
}
|
|
9002
|
+
const result = filterContext(policy, provider, context);
|
|
9003
|
+
const deniedFields = result.decisions.filter((d) => d.action === "deny");
|
|
9004
|
+
if (deniedFields.length > 0) {
|
|
9005
|
+
auditLog.append("l2", "context_gate_deny", policy.identity_id ?? "system", {
|
|
9006
|
+
policy_id: policyId,
|
|
9007
|
+
provider,
|
|
9008
|
+
denied_fields: deniedFields.map((d) => d.field),
|
|
9009
|
+
original_context_hash: result.original_context_hash
|
|
9010
|
+
});
|
|
9011
|
+
return toolResult({
|
|
9012
|
+
blocked: true,
|
|
9013
|
+
reason: "Context contains fields that trigger deny action",
|
|
9014
|
+
denied_fields: deniedFields.map((d) => ({
|
|
9015
|
+
field: d.field,
|
|
9016
|
+
reason: d.reason
|
|
9017
|
+
})),
|
|
9018
|
+
recommendation: "Remove the denied fields from context before retrying, or update the policy to handle these fields differently."
|
|
9019
|
+
});
|
|
9020
|
+
}
|
|
9021
|
+
const safeContext = {};
|
|
9022
|
+
for (const decision of result.decisions) {
|
|
9023
|
+
switch (decision.action) {
|
|
9024
|
+
case "allow":
|
|
9025
|
+
safeContext[decision.field] = context[decision.field];
|
|
9026
|
+
break;
|
|
9027
|
+
case "redact":
|
|
9028
|
+
break;
|
|
9029
|
+
case "hash":
|
|
9030
|
+
safeContext[decision.field] = decision.hash_value;
|
|
9031
|
+
break;
|
|
9032
|
+
case "summarize":
|
|
9033
|
+
safeContext[decision.field] = context[decision.field];
|
|
9034
|
+
break;
|
|
9035
|
+
}
|
|
9036
|
+
}
|
|
9037
|
+
auditLog.append("l2", "context_gate_filter", policy.identity_id ?? "system", {
|
|
9038
|
+
policy_id: policyId,
|
|
9039
|
+
provider,
|
|
9040
|
+
fields_total: Object.keys(context).length,
|
|
9041
|
+
fields_allowed: result.fields_allowed,
|
|
9042
|
+
fields_redacted: result.fields_redacted,
|
|
9043
|
+
fields_hashed: result.fields_hashed,
|
|
9044
|
+
fields_summarized: result.fields_summarized,
|
|
9045
|
+
original_context_hash: result.original_context_hash,
|
|
9046
|
+
filtered_context_hash: result.filtered_context_hash
|
|
9047
|
+
});
|
|
9048
|
+
return toolResult({
|
|
9049
|
+
blocked: false,
|
|
9050
|
+
safe_context: safeContext,
|
|
9051
|
+
summary: {
|
|
9052
|
+
total_fields: Object.keys(context).length,
|
|
9053
|
+
allowed: result.fields_allowed,
|
|
9054
|
+
redacted: result.fields_redacted,
|
|
9055
|
+
hashed: result.fields_hashed,
|
|
9056
|
+
summarized: result.fields_summarized
|
|
9057
|
+
},
|
|
9058
|
+
decisions: result.decisions,
|
|
9059
|
+
audit: {
|
|
9060
|
+
original_context_hash: result.original_context_hash,
|
|
9061
|
+
filtered_context_hash: result.filtered_context_hash,
|
|
9062
|
+
filtered_at: result.filtered_at
|
|
9063
|
+
},
|
|
9064
|
+
guidance: result.fields_summarized > 0 ? "Some fields are marked for summarization. Consider compressing them before sending to reduce context size and information exposure." : void 0
|
|
9065
|
+
});
|
|
9066
|
+
}
|
|
9067
|
+
},
|
|
9068
|
+
// ── List Policies ───────────────────────────────────────────────
|
|
9069
|
+
{
|
|
9070
|
+
name: "sanctuary/context_gate_list_policies",
|
|
9071
|
+
description: "List all configured context-gating policies. Returns policy IDs, names, rule summaries, and default actions.",
|
|
9072
|
+
inputSchema: {
|
|
9073
|
+
type: "object",
|
|
9074
|
+
properties: {}
|
|
9075
|
+
},
|
|
9076
|
+
handler: async () => {
|
|
9077
|
+
const policies = await policyStore.list();
|
|
9078
|
+
auditLog.append("l2", "context_gate_list_policies", "system", {
|
|
9079
|
+
policy_count: policies.length
|
|
9080
|
+
});
|
|
9081
|
+
return toolResult({
|
|
9082
|
+
policies: policies.map((p) => ({
|
|
9083
|
+
policy_id: p.policy_id,
|
|
9084
|
+
policy_name: p.policy_name,
|
|
9085
|
+
rule_count: p.rules.length,
|
|
9086
|
+
providers: p.rules.map((r) => r.provider),
|
|
9087
|
+
default_action: p.default_action,
|
|
9088
|
+
identity_id: p.identity_id ?? null,
|
|
9089
|
+
created_at: p.created_at,
|
|
9090
|
+
updated_at: p.updated_at
|
|
9091
|
+
})),
|
|
9092
|
+
count: policies.length,
|
|
9093
|
+
message: policies.length === 0 ? "No context-gating policies configured. Use sanctuary/context_gate_set_policy to create one." : `${policies.length} context-gating ${policies.length === 1 ? "policy" : "policies"} configured.`
|
|
9094
|
+
});
|
|
9095
|
+
}
|
|
9096
|
+
}
|
|
9097
|
+
];
|
|
9098
|
+
return { tools, policyStore };
|
|
9099
|
+
}
|
|
9100
|
+
function checkMemoryProtection() {
|
|
9101
|
+
const checks = {
|
|
9102
|
+
aslr_enabled: checkASLR(),
|
|
9103
|
+
stack_canaries: true,
|
|
9104
|
+
// Enabled by default in Node.js runtime
|
|
9105
|
+
secure_buffer_zeros: true,
|
|
9106
|
+
// We use crypto.randomBytes and explicit zeroing
|
|
9107
|
+
argon2id_kdf: true
|
|
9108
|
+
// Master key derivation uses Argon2id
|
|
9109
|
+
};
|
|
9110
|
+
const activeCount = Object.values(checks).filter((v) => v).length;
|
|
9111
|
+
const overall = activeCount >= 4 ? "full" : activeCount >= 3 ? "partial" : "minimal";
|
|
9112
|
+
return {
|
|
9113
|
+
...checks,
|
|
9114
|
+
overall
|
|
9115
|
+
};
|
|
9116
|
+
}
|
|
9117
|
+
function checkASLR() {
|
|
9118
|
+
if (process.platform === "linux") {
|
|
9119
|
+
try {
|
|
9120
|
+
const result = execSync("cat /proc/sys/kernel/randomize_va_space", {
|
|
9121
|
+
encoding: "utf-8",
|
|
9122
|
+
stdio: ["pipe", "pipe", "ignore"]
|
|
9123
|
+
}).trim();
|
|
9124
|
+
return result === "2";
|
|
9125
|
+
} catch {
|
|
9126
|
+
return false;
|
|
9127
|
+
}
|
|
9128
|
+
}
|
|
9129
|
+
if (process.platform === "darwin") {
|
|
9130
|
+
return true;
|
|
9131
|
+
}
|
|
9132
|
+
return false;
|
|
9133
|
+
}
|
|
9134
|
+
function checkProcessIsolation() {
|
|
9135
|
+
const isContainer = detectContainer();
|
|
9136
|
+
const isVM = detectVM();
|
|
9137
|
+
const isSandboxed = detectSandbox();
|
|
9138
|
+
let isolationLevel = "none";
|
|
9139
|
+
if (isContainer) isolationLevel = "hardened";
|
|
9140
|
+
else if (isVM) isolationLevel = "hardened";
|
|
9141
|
+
else if (isSandboxed) isolationLevel = "basic";
|
|
9142
|
+
const details = {};
|
|
9143
|
+
if (isContainer && isContainer !== true) details.container_type = isContainer;
|
|
9144
|
+
if (isVM && isVM !== true) details.vm_type = isVM;
|
|
9145
|
+
if (isSandboxed && isSandboxed !== true) details.sandbox_type = isSandboxed;
|
|
9146
|
+
return {
|
|
9147
|
+
isolation_level: isolationLevel,
|
|
9148
|
+
is_container: isContainer !== false,
|
|
9149
|
+
is_vm: isVM !== false,
|
|
9150
|
+
is_sandboxed: isSandboxed !== false,
|
|
9151
|
+
is_tee: false,
|
|
9152
|
+
details
|
|
9153
|
+
};
|
|
9154
|
+
}
|
|
9155
|
+
function detectContainer() {
|
|
9156
|
+
try {
|
|
9157
|
+
if (process.env.DOCKER_HOST) return "docker";
|
|
9158
|
+
try {
|
|
9159
|
+
statSync("/.dockerenv");
|
|
9160
|
+
return "docker";
|
|
9161
|
+
} catch {
|
|
9162
|
+
}
|
|
9163
|
+
if (process.platform === "linux") {
|
|
9164
|
+
const cgroup = execSync("cat /proc/1/cgroup 2>/dev/null || echo ''", {
|
|
9165
|
+
encoding: "utf-8"
|
|
9166
|
+
});
|
|
9167
|
+
if (cgroup.includes("docker")) return "docker";
|
|
9168
|
+
if (cgroup.includes("lxc")) return "lxc";
|
|
9169
|
+
if (cgroup.includes("kubepods") || cgroup.includes("kubernetes")) return "kubernetes";
|
|
9170
|
+
}
|
|
9171
|
+
if (process.env.container === "podman") return "podman";
|
|
9172
|
+
if (process.env.CONTAINER_ID) return "oci";
|
|
9173
|
+
return false;
|
|
9174
|
+
} catch {
|
|
9175
|
+
return false;
|
|
9176
|
+
}
|
|
9177
|
+
}
|
|
9178
|
+
function detectVM() {
|
|
9179
|
+
if (process.platform === "linux") {
|
|
9180
|
+
try {
|
|
9181
|
+
const dmidecode = execSync("dmidecode -s system-product-name 2>/dev/null || echo ''", {
|
|
9182
|
+
encoding: "utf-8"
|
|
9183
|
+
}).toLowerCase();
|
|
9184
|
+
if (dmidecode.includes("vmware")) return "vmware";
|
|
9185
|
+
if (dmidecode.includes("virtualbox")) return "virtualbox";
|
|
9186
|
+
if (dmidecode.includes("kvm")) return "kvm";
|
|
9187
|
+
if (dmidecode.includes("xen")) return "xen";
|
|
9188
|
+
if (dmidecode.includes("hyper-v")) return "hyper-v";
|
|
9189
|
+
const cpuinfo = execSync("grep -i hypervisor /proc/cpuinfo || echo ''", {
|
|
9190
|
+
encoding: "utf-8"
|
|
9191
|
+
});
|
|
9192
|
+
if (cpuinfo.length > 0) return "detected";
|
|
9193
|
+
} catch {
|
|
9194
|
+
}
|
|
9195
|
+
}
|
|
9196
|
+
if (process.platform === "darwin") {
|
|
9197
|
+
try {
|
|
9198
|
+
const bootargs = execSync(
|
|
9199
|
+
"nvram boot-args 2>/dev/null | grep -i 'parallels\\|vmware\\|virtualbox' || echo ''",
|
|
9200
|
+
{
|
|
9201
|
+
encoding: "utf-8"
|
|
9202
|
+
}
|
|
9203
|
+
);
|
|
9204
|
+
if (bootargs.length > 0) return "detected";
|
|
9205
|
+
} catch {
|
|
9206
|
+
}
|
|
9207
|
+
}
|
|
9208
|
+
return false;
|
|
9209
|
+
}
|
|
9210
|
+
function detectSandbox() {
|
|
9211
|
+
if (process.platform === "darwin") {
|
|
9212
|
+
if (process.env.APP_SANDBOX_READ_ONLY_HOME === "1") return "app-sandbox";
|
|
9213
|
+
if (process.env.TMPDIR && process.env.TMPDIR.includes("AppSandbox")) return "app-sandbox";
|
|
9214
|
+
}
|
|
9215
|
+
if (process.platform === "openbsd") {
|
|
9216
|
+
try {
|
|
9217
|
+
const pledge = execSync("pledge -v 2>/dev/null || echo ''", {
|
|
9218
|
+
encoding: "utf-8"
|
|
9219
|
+
});
|
|
9220
|
+
if (pledge.length > 0) return "pledge";
|
|
9221
|
+
} catch {
|
|
9222
|
+
}
|
|
9223
|
+
}
|
|
9224
|
+
if (process.platform === "linux") {
|
|
9225
|
+
if (process.env.container === "lxc") return "lxc";
|
|
9226
|
+
try {
|
|
9227
|
+
const context = execSync("getenforce 2>/dev/null || echo ''", {
|
|
9228
|
+
encoding: "utf-8"
|
|
9229
|
+
}).trim();
|
|
9230
|
+
if (context === "Enforcing") return "selinux";
|
|
9231
|
+
} catch {
|
|
9232
|
+
}
|
|
9233
|
+
}
|
|
9234
|
+
return false;
|
|
9235
|
+
}
|
|
9236
|
+
function checkFilesystemPermissions(storagePath) {
|
|
9237
|
+
try {
|
|
9238
|
+
const stats = statSync(storagePath);
|
|
9239
|
+
const mode = stats.mode & parseInt("777", 8);
|
|
9240
|
+
const modeString = mode.toString(8).padStart(3, "0");
|
|
9241
|
+
const isSecure = mode === parseInt("700", 8);
|
|
9242
|
+
const groupReadable = (mode & parseInt("040", 8)) !== 0;
|
|
9243
|
+
const othersReadable = (mode & parseInt("007", 8)) !== 0;
|
|
9244
|
+
const currentUid = process.getuid?.() || -1;
|
|
9245
|
+
const ownerIsCurrentUser = stats.uid === currentUid;
|
|
9246
|
+
let overall = "secure";
|
|
9247
|
+
if (groupReadable || othersReadable) overall = "insecure";
|
|
9248
|
+
else if (!ownerIsCurrentUser) overall = "warning";
|
|
9249
|
+
return {
|
|
9250
|
+
sanctuary_storage_protected: isSecure,
|
|
9251
|
+
sanctuary_storage_mode: modeString,
|
|
9252
|
+
owner_is_current_user: ownerIsCurrentUser,
|
|
9253
|
+
group_readable: groupReadable,
|
|
9254
|
+
others_readable: othersReadable,
|
|
9255
|
+
overall
|
|
9256
|
+
};
|
|
9257
|
+
} catch {
|
|
9258
|
+
return {
|
|
9259
|
+
sanctuary_storage_protected: false,
|
|
9260
|
+
sanctuary_storage_mode: "unknown",
|
|
9261
|
+
owner_is_current_user: false,
|
|
9262
|
+
group_readable: false,
|
|
9263
|
+
others_readable: false,
|
|
9264
|
+
overall: "warning"
|
|
9265
|
+
};
|
|
9266
|
+
}
|
|
9267
|
+
}
|
|
9268
|
+
function checkRuntimeIntegrity() {
|
|
9269
|
+
return {
|
|
9270
|
+
config_hash_stable: true,
|
|
9271
|
+
environment_state: "clean",
|
|
9272
|
+
discrepancies: []
|
|
9273
|
+
};
|
|
9274
|
+
}
|
|
9275
|
+
function assessL2Hardening(storagePath) {
|
|
9276
|
+
const memory = checkMemoryProtection();
|
|
9277
|
+
const isolation = checkProcessIsolation();
|
|
9278
|
+
const filesystem = checkFilesystemPermissions(storagePath);
|
|
9279
|
+
const integrity = checkRuntimeIntegrity();
|
|
9280
|
+
let checksPassed = 0;
|
|
9281
|
+
let checksTotal = 0;
|
|
9282
|
+
if (memory.aslr_enabled) checksPassed++;
|
|
9283
|
+
checksTotal++;
|
|
9284
|
+
if (memory.stack_canaries) checksPassed++;
|
|
9285
|
+
checksTotal++;
|
|
9286
|
+
if (memory.secure_buffer_zeros) checksPassed++;
|
|
9287
|
+
checksTotal++;
|
|
9288
|
+
if (memory.argon2id_kdf) checksPassed++;
|
|
9289
|
+
checksTotal++;
|
|
9290
|
+
if (isolation.is_container) checksPassed++;
|
|
9291
|
+
checksTotal++;
|
|
9292
|
+
if (isolation.is_vm) checksPassed++;
|
|
9293
|
+
checksTotal++;
|
|
9294
|
+
if (isolation.is_sandboxed) checksPassed++;
|
|
9295
|
+
checksTotal++;
|
|
9296
|
+
if (filesystem.sanctuary_storage_protected) checksPassed++;
|
|
9297
|
+
checksTotal++;
|
|
9298
|
+
{
|
|
9299
|
+
checksPassed++;
|
|
9300
|
+
}
|
|
9301
|
+
checksTotal++;
|
|
9302
|
+
let hardeningLevel = isolation.isolation_level;
|
|
9303
|
+
if (filesystem.overall === "insecure" || memory.overall === "none" || memory.overall === "minimal") {
|
|
9304
|
+
if (hardeningLevel === "hardened") {
|
|
9305
|
+
hardeningLevel = "basic";
|
|
9306
|
+
} else if (hardeningLevel === "basic") {
|
|
9307
|
+
hardeningLevel = "none";
|
|
9308
|
+
}
|
|
9309
|
+
}
|
|
9310
|
+
const summaryParts = [];
|
|
9311
|
+
if (isolation.is_container || isolation.is_vm) {
|
|
9312
|
+
summaryParts.push(`Running in ${isolation.details.container_type || isolation.details.vm_type || "isolated environment"}`);
|
|
9313
|
+
}
|
|
9314
|
+
if (memory.aslr_enabled) {
|
|
9315
|
+
summaryParts.push("ASLR enabled");
|
|
9316
|
+
}
|
|
9317
|
+
if (filesystem.sanctuary_storage_protected) {
|
|
9318
|
+
summaryParts.push("Storage permissions secured (0700)");
|
|
9319
|
+
}
|
|
9320
|
+
const summary = summaryParts.length > 0 ? summaryParts.join("; ") : "No process-level hardening detected";
|
|
9321
|
+
return {
|
|
9322
|
+
hardening_level: hardeningLevel,
|
|
9323
|
+
memory_protection: memory,
|
|
9324
|
+
process_isolation: isolation,
|
|
9325
|
+
filesystem_permissions: filesystem,
|
|
9326
|
+
runtime_integrity: integrity,
|
|
9327
|
+
checks_passed: checksPassed,
|
|
9328
|
+
checks_total: checksTotal,
|
|
9329
|
+
summary
|
|
9330
|
+
};
|
|
9331
|
+
}
|
|
9332
|
+
|
|
9333
|
+
// src/l2-operational/hardening-tools.ts
|
|
9334
|
+
function createL2HardeningTools(storagePath, auditLog) {
|
|
9335
|
+
return [
|
|
9336
|
+
{
|
|
9337
|
+
name: "sanctuary/l2_hardening_status",
|
|
9338
|
+
description: "L2 Process Hardening Status \u2014 Verify software-based operational isolation. Reports memory protection, process isolation level, filesystem permissions, and overall hardening assessment. Read-only. Tier 3 \u2014 always allowed.",
|
|
9339
|
+
inputSchema: {
|
|
9340
|
+
type: "object",
|
|
9341
|
+
properties: {
|
|
9342
|
+
include_details: {
|
|
9343
|
+
type: "boolean",
|
|
9344
|
+
description: "If true, include detailed check results for memory, process, and filesystem. If false, show summary only.",
|
|
9345
|
+
default: false
|
|
9346
|
+
}
|
|
9347
|
+
}
|
|
9348
|
+
},
|
|
9349
|
+
handler: async (args) => {
|
|
9350
|
+
const includeDetails = args.include_details ?? false;
|
|
9351
|
+
const status = assessL2Hardening(storagePath);
|
|
9352
|
+
auditLog.append(
|
|
9353
|
+
"l2",
|
|
9354
|
+
"l2_hardening_status",
|
|
9355
|
+
"system",
|
|
9356
|
+
{ include_details: includeDetails }
|
|
9357
|
+
);
|
|
9358
|
+
if (includeDetails) {
|
|
9359
|
+
return toolResult({
|
|
9360
|
+
hardening_level: status.hardening_level,
|
|
9361
|
+
summary: status.summary,
|
|
9362
|
+
checks_passed: status.checks_passed,
|
|
9363
|
+
checks_total: status.checks_total,
|
|
9364
|
+
memory_protection: {
|
|
9365
|
+
aslr_enabled: status.memory_protection.aslr_enabled,
|
|
9366
|
+
stack_canaries: status.memory_protection.stack_canaries,
|
|
9367
|
+
secure_buffer_zeros: status.memory_protection.secure_buffer_zeros,
|
|
9368
|
+
argon2id_kdf: status.memory_protection.argon2id_kdf,
|
|
9369
|
+
overall: status.memory_protection.overall
|
|
9370
|
+
},
|
|
9371
|
+
process_isolation: {
|
|
9372
|
+
isolation_level: status.process_isolation.isolation_level,
|
|
9373
|
+
is_container: status.process_isolation.is_container,
|
|
9374
|
+
is_vm: status.process_isolation.is_vm,
|
|
9375
|
+
is_sandboxed: status.process_isolation.is_sandboxed,
|
|
9376
|
+
is_tee: status.process_isolation.is_tee,
|
|
9377
|
+
details: status.process_isolation.details
|
|
9378
|
+
},
|
|
9379
|
+
filesystem_permissions: {
|
|
9380
|
+
sanctuary_storage_protected: status.filesystem_permissions.sanctuary_storage_protected,
|
|
9381
|
+
sanctuary_storage_mode: status.filesystem_permissions.sanctuary_storage_mode,
|
|
9382
|
+
owner_is_current_user: status.filesystem_permissions.owner_is_current_user,
|
|
9383
|
+
group_readable: status.filesystem_permissions.group_readable,
|
|
9384
|
+
others_readable: status.filesystem_permissions.others_readable,
|
|
9385
|
+
overall: status.filesystem_permissions.overall
|
|
9386
|
+
},
|
|
9387
|
+
runtime_integrity: {
|
|
9388
|
+
config_hash_stable: status.runtime_integrity.config_hash_stable,
|
|
9389
|
+
environment_state: status.runtime_integrity.environment_state,
|
|
9390
|
+
discrepancies: status.runtime_integrity.discrepancies
|
|
9391
|
+
}
|
|
9392
|
+
});
|
|
9393
|
+
} else {
|
|
9394
|
+
return toolResult({
|
|
9395
|
+
hardening_level: status.hardening_level,
|
|
9396
|
+
summary: status.summary,
|
|
9397
|
+
checks_passed: status.checks_passed,
|
|
9398
|
+
checks_total: status.checks_total,
|
|
9399
|
+
note: "Pass include_details: true to see full breakdown of memory, process isolation, and filesystem checks."
|
|
9400
|
+
});
|
|
9401
|
+
}
|
|
9402
|
+
}
|
|
9403
|
+
},
|
|
9404
|
+
{
|
|
9405
|
+
name: "sanctuary/l2_verify_isolation",
|
|
9406
|
+
description: "Verify L2 process isolation at runtime. Checks whether the Sanctuary server is running in an isolated environment (container, VM, sandbox) and validates filesystem and memory protections. Reports isolation level and any issues. Read-only. Tier 3 \u2014 always allowed.",
|
|
9407
|
+
inputSchema: {
|
|
9408
|
+
type: "object",
|
|
9409
|
+
properties: {
|
|
9410
|
+
check_filesystem: {
|
|
9411
|
+
type: "boolean",
|
|
9412
|
+
description: "If true, verify Sanctuary storage directory permissions.",
|
|
9413
|
+
default: true
|
|
9414
|
+
},
|
|
9415
|
+
check_memory: {
|
|
9416
|
+
type: "boolean",
|
|
9417
|
+
description: "If true, verify memory protection mechanisms (ASLR, etc.).",
|
|
9418
|
+
default: true
|
|
9419
|
+
},
|
|
9420
|
+
check_process: {
|
|
9421
|
+
type: "boolean",
|
|
9422
|
+
description: "If true, detect container, VM, or sandbox environment.",
|
|
9423
|
+
default: true
|
|
9424
|
+
}
|
|
9425
|
+
}
|
|
9426
|
+
},
|
|
9427
|
+
handler: async (args) => {
|
|
9428
|
+
const checkFilesystem = args.check_filesystem ?? true;
|
|
9429
|
+
const checkMemory = args.check_memory ?? true;
|
|
9430
|
+
const checkProcess = args.check_process ?? true;
|
|
9431
|
+
const status = assessL2Hardening(storagePath);
|
|
9432
|
+
auditLog.append(
|
|
9433
|
+
"l2",
|
|
9434
|
+
"l2_verify_isolation",
|
|
9435
|
+
"system",
|
|
9436
|
+
{
|
|
9437
|
+
check_filesystem: checkFilesystem,
|
|
9438
|
+
check_memory: checkMemory,
|
|
9439
|
+
check_process: checkProcess
|
|
9440
|
+
}
|
|
9441
|
+
);
|
|
9442
|
+
const results = {
|
|
9443
|
+
isolation_level: status.hardening_level,
|
|
9444
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
9445
|
+
};
|
|
9446
|
+
if (checkFilesystem) {
|
|
9447
|
+
const fs = status.filesystem_permissions;
|
|
9448
|
+
results.filesystem = {
|
|
9449
|
+
sanctuary_storage_protected: fs.sanctuary_storage_protected,
|
|
9450
|
+
storage_mode: fs.sanctuary_storage_mode,
|
|
9451
|
+
is_secure: fs.overall === "secure",
|
|
9452
|
+
issues: fs.overall === "insecure" ? [
|
|
9453
|
+
"Storage directory is readable by group or others. Recommend: chmod 700 on Sanctuary storage path."
|
|
9454
|
+
] : fs.overall === "warning" ? [
|
|
9455
|
+
"Storage directory not owned by current user. Verify correct user is running Sanctuary."
|
|
9456
|
+
] : []
|
|
9457
|
+
};
|
|
9458
|
+
}
|
|
9459
|
+
if (checkMemory) {
|
|
9460
|
+
const mem = status.memory_protection;
|
|
9461
|
+
const issues = [];
|
|
9462
|
+
if (!mem.aslr_enabled) {
|
|
9463
|
+
issues.push(
|
|
9464
|
+
"ASLR not detected. On Linux, enable with: echo 2 | sudo tee /proc/sys/kernel/randomize_va_space"
|
|
9465
|
+
);
|
|
9466
|
+
}
|
|
9467
|
+
results.memory = {
|
|
9468
|
+
aslr_enabled: mem.aslr_enabled,
|
|
9469
|
+
stack_canaries: mem.stack_canaries,
|
|
9470
|
+
secure_buffer_handling: mem.secure_buffer_zeros,
|
|
9471
|
+
argon2id_key_derivation: mem.argon2id_kdf,
|
|
9472
|
+
protection_level: mem.overall,
|
|
9473
|
+
issues
|
|
9474
|
+
};
|
|
9475
|
+
}
|
|
9476
|
+
if (checkProcess) {
|
|
9477
|
+
const iso = status.process_isolation;
|
|
9478
|
+
results.process = {
|
|
9479
|
+
isolation_level: iso.isolation_level,
|
|
9480
|
+
in_container: iso.is_container,
|
|
9481
|
+
in_vm: iso.is_vm,
|
|
9482
|
+
sandboxed: iso.is_sandboxed,
|
|
9483
|
+
has_tee: iso.is_tee,
|
|
9484
|
+
environment: iso.details,
|
|
9485
|
+
recommendation: iso.isolation_level === "none" ? "Consider running Sanctuary in a container or VM for improved isolation." : iso.isolation_level === "basic" ? "Basic isolation detected. Container or VM would provide stronger guarantees." : "Running in isolated environment \u2014 process-level isolation is strong."
|
|
9486
|
+
};
|
|
9487
|
+
}
|
|
9488
|
+
return toolResult({
|
|
9489
|
+
status: "verified",
|
|
9490
|
+
results
|
|
9491
|
+
});
|
|
9492
|
+
}
|
|
9493
|
+
}
|
|
9494
|
+
];
|
|
9495
|
+
}
|
|
9496
|
+
|
|
9497
|
+
// src/index.ts
|
|
9498
|
+
init_encoding();
|
|
9499
|
+
async function createSanctuaryServer(options) {
|
|
9500
|
+
const config = await loadConfig(options?.configPath);
|
|
9501
|
+
await mkdir(config.storage_path, { recursive: true, mode: 448 });
|
|
9502
|
+
const storage = options?.storage ?? new FilesystemStorage(
|
|
9503
|
+
`${config.storage_path}/state`
|
|
9504
|
+
);
|
|
9505
|
+
let masterKey;
|
|
9506
|
+
let keyProtection;
|
|
9507
|
+
let recoveryKey;
|
|
9508
|
+
const passphrase = options?.passphrase ?? process.env.SANCTUARY_PASSPHRASE;
|
|
9509
|
+
if (passphrase) {
|
|
9510
|
+
keyProtection = "passphrase";
|
|
9511
|
+
let existingParams;
|
|
9512
|
+
try {
|
|
9513
|
+
const raw = await storage.read("_meta", "key-params");
|
|
9514
|
+
if (raw) {
|
|
9515
|
+
const { bytesToString: bytesToString2 } = await Promise.resolve().then(() => (init_encoding(), encoding_exports));
|
|
9516
|
+
existingParams = JSON.parse(bytesToString2(raw));
|
|
9517
|
+
}
|
|
9518
|
+
} catch {
|
|
9519
|
+
}
|
|
9520
|
+
const result = await deriveMasterKey(passphrase, existingParams);
|
|
9521
|
+
masterKey = result.key;
|
|
9522
|
+
if (!existingParams) {
|
|
9523
|
+
const { stringToBytes: stringToBytes2 } = await Promise.resolve().then(() => (init_encoding(), encoding_exports));
|
|
7584
9524
|
await storage.write(
|
|
7585
9525
|
"_meta",
|
|
7586
9526
|
"key-params",
|
|
@@ -7720,7 +9660,7 @@ async function createSanctuaryServer(options) {
|
|
|
7720
9660
|
layer: "l2",
|
|
7721
9661
|
description: "Process-level isolation only (no TEE)",
|
|
7722
9662
|
severity: "warning",
|
|
7723
|
-
mitigation: "TEE support planned for
|
|
9663
|
+
mitigation: "TEE support planned for a future release"
|
|
7724
9664
|
});
|
|
7725
9665
|
if (config.disclosure.proof_system === "commitment-only") {
|
|
7726
9666
|
degradations.push({
|
|
@@ -7860,7 +9800,7 @@ async function createSanctuaryServer(options) {
|
|
|
7860
9800
|
},
|
|
7861
9801
|
limitations: [
|
|
7862
9802
|
"L1 identity uses ed25519 only; KERI support planned for v0.2.0",
|
|
7863
|
-
"L2 isolation is process-level only; TEE support planned for
|
|
9803
|
+
"L2 isolation is process-level only; TEE support planned for a future release",
|
|
7864
9804
|
"L3 uses commitment schemes only; ZK proofs planned for v0.2.0",
|
|
7865
9805
|
"L4 Sybil resistance is escrow-based only",
|
|
7866
9806
|
"Spec license: CC-BY-4.0 | Code license: Apache-2.0"
|
|
@@ -7881,7 +9821,7 @@ async function createSanctuaryServer(options) {
|
|
|
7881
9821
|
masterKey,
|
|
7882
9822
|
auditLog
|
|
7883
9823
|
);
|
|
7884
|
-
const { tools: l4Tools
|
|
9824
|
+
const { tools: l4Tools} = createL4Tools(
|
|
7885
9825
|
storage,
|
|
7886
9826
|
masterKey,
|
|
7887
9827
|
identityManager,
|
|
@@ -7900,6 +9840,12 @@ async function createSanctuaryServer(options) {
|
|
|
7900
9840
|
handshakeResults
|
|
7901
9841
|
);
|
|
7902
9842
|
const { tools: auditTools } = createAuditTools(config);
|
|
9843
|
+
const { tools: contextGateTools } = createContextGateTools(
|
|
9844
|
+
storage,
|
|
9845
|
+
masterKey,
|
|
9846
|
+
auditLog
|
|
9847
|
+
);
|
|
9848
|
+
const hardeningTools = createL2HardeningTools(config.storage_path, auditLog);
|
|
7903
9849
|
const policy = await loadPrincipalPolicy(config.storage_path);
|
|
7904
9850
|
const baseline = new BaselineTracker(storage, masterKey);
|
|
7905
9851
|
await baseline.load();
|
|
@@ -7949,6 +9895,8 @@ async function createSanctuaryServer(options) {
|
|
|
7949
9895
|
...federationTools,
|
|
7950
9896
|
...bridgeTools,
|
|
7951
9897
|
...auditTools,
|
|
9898
|
+
...contextGateTools,
|
|
9899
|
+
...hardeningTools,
|
|
7952
9900
|
manifestTool
|
|
7953
9901
|
];
|
|
7954
9902
|
const server = createServer(allTools, { gate });
|
|
@@ -7973,8 +9921,78 @@ async function createSanctuaryServer(options) {
|
|
|
7973
9921
|
}
|
|
7974
9922
|
return { server, config };
|
|
7975
9923
|
}
|
|
7976
|
-
|
|
7977
|
-
|
|
9924
|
+
var REGISTRY_URL = "https://registry.npmjs.org/@sanctuary-framework/mcp-server/latest";
|
|
9925
|
+
var TIMEOUT_MS = 3e3;
|
|
9926
|
+
function isNewerVersion(current, latest) {
|
|
9927
|
+
const parse = (v) => v.replace(/^v/, "").split(".").map(Number);
|
|
9928
|
+
const [curMajor = 0, curMinor = 0, curPatch = 0] = parse(current);
|
|
9929
|
+
const [latMajor = 0, latMinor = 0, latPatch = 0] = parse(latest);
|
|
9930
|
+
if (latMajor !== curMajor) return latMajor > curMajor;
|
|
9931
|
+
if (latMinor !== curMinor) return latMinor > curMinor;
|
|
9932
|
+
return latPatch > curPatch;
|
|
9933
|
+
}
|
|
9934
|
+
function formatUpdateMessage(current, latest) {
|
|
9935
|
+
return `[Sanctuary] Update available: ${current} \u2192 ${latest} \u2014 run: npx @sanctuary-framework/mcp-server@latest`;
|
|
9936
|
+
}
|
|
9937
|
+
function fetchLatestVersion(currentVersion) {
|
|
9938
|
+
return new Promise((resolve) => {
|
|
9939
|
+
const req = get(
|
|
9940
|
+
REGISTRY_URL,
|
|
9941
|
+
{
|
|
9942
|
+
headers: { Accept: "application/json" },
|
|
9943
|
+
timeout: TIMEOUT_MS
|
|
9944
|
+
},
|
|
9945
|
+
(res) => {
|
|
9946
|
+
if (res.statusCode !== 200) {
|
|
9947
|
+
res.resume();
|
|
9948
|
+
resolve(null);
|
|
9949
|
+
return;
|
|
9950
|
+
}
|
|
9951
|
+
let data = "";
|
|
9952
|
+
res.setEncoding("utf-8");
|
|
9953
|
+
res.on("data", (chunk) => {
|
|
9954
|
+
data += chunk;
|
|
9955
|
+
if (data.length > 32768) {
|
|
9956
|
+
res.destroy();
|
|
9957
|
+
resolve(null);
|
|
9958
|
+
}
|
|
9959
|
+
});
|
|
9960
|
+
res.on("end", () => {
|
|
9961
|
+
try {
|
|
9962
|
+
const json = JSON.parse(data);
|
|
9963
|
+
const latest = json.version;
|
|
9964
|
+
if (typeof latest === "string" && isNewerVersion(currentVersion, latest)) {
|
|
9965
|
+
resolve(latest);
|
|
9966
|
+
} else {
|
|
9967
|
+
resolve(null);
|
|
9968
|
+
}
|
|
9969
|
+
} catch {
|
|
9970
|
+
resolve(null);
|
|
9971
|
+
}
|
|
9972
|
+
});
|
|
9973
|
+
}
|
|
9974
|
+
);
|
|
9975
|
+
req.on("error", () => resolve(null));
|
|
9976
|
+
req.on("timeout", () => {
|
|
9977
|
+
req.destroy();
|
|
9978
|
+
resolve(null);
|
|
9979
|
+
});
|
|
9980
|
+
});
|
|
9981
|
+
}
|
|
9982
|
+
async function checkForUpdate(currentVersion) {
|
|
9983
|
+
if (process.env.SANCTUARY_NO_UPDATE_CHECK === "1") {
|
|
9984
|
+
return;
|
|
9985
|
+
}
|
|
9986
|
+
try {
|
|
9987
|
+
const latest = await fetchLatestVersion(currentVersion);
|
|
9988
|
+
if (latest) {
|
|
9989
|
+
console.error(formatUpdateMessage(currentVersion, latest));
|
|
9990
|
+
}
|
|
9991
|
+
} catch {
|
|
9992
|
+
}
|
|
9993
|
+
}
|
|
9994
|
+
var require5 = createRequire(import.meta.url);
|
|
9995
|
+
var { version: PKG_VERSION4 } = require5("../package.json");
|
|
7978
9996
|
async function main() {
|
|
7979
9997
|
const args = process.argv.slice(2);
|
|
7980
9998
|
let passphrase = process.env.SANCTUARY_PASSPHRASE;
|
|
@@ -7987,7 +10005,7 @@ async function main() {
|
|
|
7987
10005
|
printHelp();
|
|
7988
10006
|
process.exit(0);
|
|
7989
10007
|
} else if (args[i] === "--version" || args[i] === "-v") {
|
|
7990
|
-
console.log(
|
|
10008
|
+
console.log(`@sanctuary-framework/mcp-server ${PKG_VERSION4}`);
|
|
7991
10009
|
process.exit(0);
|
|
7992
10010
|
}
|
|
7993
10011
|
}
|
|
@@ -7998,6 +10016,7 @@ async function main() {
|
|
|
7998
10016
|
console.error(`Sanctuary MCP Server v${config.version} running (stdio)`);
|
|
7999
10017
|
console.error(`Storage: ${config.storage_path}`);
|
|
8000
10018
|
console.error("Tools: all registered");
|
|
10019
|
+
checkForUpdate(PKG_VERSION4);
|
|
8001
10020
|
} else {
|
|
8002
10021
|
console.error("HTTP transport not yet implemented. Use stdio.");
|
|
8003
10022
|
process.exit(1);
|
|
@@ -8005,7 +10024,7 @@ async function main() {
|
|
|
8005
10024
|
}
|
|
8006
10025
|
function printHelp() {
|
|
8007
10026
|
console.log(`
|
|
8008
|
-
@sanctuary-framework/mcp-server
|
|
10027
|
+
@sanctuary-framework/mcp-server v${PKG_VERSION4}
|
|
8009
10028
|
|
|
8010
10029
|
Sovereignty infrastructure for agents in the agentic economy.
|
|
8011
10030
|
|
|
@@ -8027,6 +10046,7 @@ Environment variables:
|
|
|
8027
10046
|
SANCTUARY_WEBHOOK_ENABLED "true" to enable webhook approvals
|
|
8028
10047
|
SANCTUARY_WEBHOOK_URL Webhook target URL
|
|
8029
10048
|
SANCTUARY_WEBHOOK_SECRET HMAC-SHA256 shared secret
|
|
10049
|
+
SANCTUARY_NO_UPDATE_CHECK "1" to disable startup update check
|
|
8030
10050
|
|
|
8031
10051
|
For more info: https://github.com/eriknewton/sanctuary-framework
|
|
8032
10052
|
`);
|