@yagyeshvyas/vibeguard 1.12.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +34 -17
  3. package/bin/cli.js +2753 -2753
  4. package/bin/cmd-mcp-firewall.js +1 -0
  5. package/bin/cmd-platform.js +3 -0
  6. package/ci/vibeguard.yml +42 -42
  7. package/package.json +2 -2
  8. package/scripts/counts.js +93 -93
  9. package/scripts/postinstall.js +26 -26
  10. package/src/auto.js +427 -427
  11. package/src/daemon.js +343 -343
  12. package/src/dashboard.js +278 -278
  13. package/src/engine.js +297 -297
  14. package/src/hook.js +151 -151
  15. package/src/install.js +298 -298
  16. package/src/integrity.js +1 -0
  17. package/src/integrity.json +9 -6
  18. package/src/mcp-firewall.js +11 -0
  19. package/src/platform/approval-service.js +124 -0
  20. package/src/platform/approval.js +16 -0
  21. package/src/platform/oauth-server.js +89 -0
  22. package/src/platform/os-sandbox.js +52 -1
  23. package/src/platform/runtime-monitor.js +69 -0
  24. package/src/platform/sandbox-manager.js +5 -0
  25. package/src/plugin.js +182 -182
  26. package/src/privacy-audit.js +272 -272
  27. package/src/repl.js +150 -150
  28. package/src/report.js +331 -331
  29. package/src/rules-pack.js +3068 -3068
  30. package/src/rules.js +1822 -1822
  31. package/src/sbom.js +193 -193
  32. package/src/scanner.js +1032 -1032
  33. package/src/shell-guard.js +302 -302
  34. package/src/slopsquat.js +144 -144
  35. package/src/trace.js +220 -220
  36. package/src/.vibeguard/cache/file-hashes.json +0 -60
  37. package/src/.vibeguard/latest-snapshot.json +0 -36
  38. package/src/.vibeguard/mcp-pins.json +0 -1
  39. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +0 -428
  40. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +0 -344
  41. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +0 -279
  42. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +0 -297
  43. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +0 -151
  44. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +0 -299
  45. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +0 -65
  46. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +0 -2051
  47. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +0 -168
  48. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +0 -362
  49. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +0 -150
  50. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +0 -1611
  51. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +0 -164
  52. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +0 -292
  53. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +0 -144
  54. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +0 -220
  55. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +0 -428
  56. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +0 -344
  57. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +0 -297
  58. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +0 -299
  59. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +0 -37
  60. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +0 -2055
  61. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +0 -168
  62. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +0 -362
  63. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +0 -220
  64. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +0 -428
  65. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +0 -344
  66. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +0 -279
  67. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +0 -297
  68. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +0 -151
  69. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +0 -299
  70. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +0 -65
  71. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +0 -2055
  72. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +0 -168
  73. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +0 -362
  74. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +0 -150
  75. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +0 -1611
  76. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +0 -164
  77. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +0 -292
  78. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +0 -144
  79. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +0 -220
  80. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +0 -428
  81. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +0 -344
  82. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +0 -279
  83. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +0 -297
  84. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +0 -151
  85. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +0 -299
  86. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +0 -65
  87. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +0 -2054
  88. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +0 -168
  89. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +0 -362
  90. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +0 -150
  91. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +0 -1611
  92. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +0 -164
  93. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +0 -292
  94. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +0 -144
  95. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +0 -220
  96. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +0 -428
  97. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +0 -344
  98. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +0 -297
  99. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +0 -299
  100. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +0 -37
  101. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +0 -2055
  102. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +0 -168
  103. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +0 -362
  104. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +0 -220
  105. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +0 -428
  106. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +0 -344
  107. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +0 -297
  108. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +0 -33
  109. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +0 -2055
  110. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +0 -1611
  111. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +0 -292
  112. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +0 -220
  113. package/src/.vibeguard-baseline.json +0 -5226
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "tool": "vibeguard",
3
- "generatedAt": "2026-11-22T19:31:04.837Z",
3
+ "generatedAt": "2026-11-22T20:37:46.905Z",
4
4
  "algo": "sha256",
5
5
  "hashes": {
6
6
  "action-guard.js": "764f02ee6d4a1dc95939642f120ac7c233f66aee2794dd71efa15f5690fc43b0",
@@ -25,7 +25,7 @@
25
25
  "bundles.js": "7c6535e4be4566edd2aec0d9d63c58e200813b621e503ad1d51a5a4840a1b359",
26
26
  "agentic.js": "4b7130e1e15f603df8ceb7ef8284db8d1784e8dd450a8ed332873271f7cec4ee",
27
27
  "suppress.js": "3c34ebbdabb0338fe3bf00d399aaa9ab04fb796067fe33a4a4b52884eb5c4fda",
28
- "mcp-firewall.js": "9ec7d5ec73b37b226027346e1eb81a68cfe200ba16561897e139cdd8f404c794",
28
+ "mcp-firewall.js": "576cdbbf231c589dd10436f9053fbe43db18cf0ab14ea697b6bf419c7c49b70b",
29
29
  "agent-policy.js": "5735aca870b7ecfe55c3525f7a338e9f97e3c1ca000dbb16850c312db53eb9e9",
30
30
  "skill-scan.js": "b172529a94333f8fb07098df518ecce3be9cf93242830e140ade48c2742f50e0",
31
31
  "owasp-agentic.js": "7ca8dca83b633ae62607b2ab24696bdfbf34b4a7b96c3b26ba1035b9b05e9a99",
@@ -36,18 +36,21 @@
36
36
  "platform/contracts.js": "9c66ed174220e2f0b26adec8a222f2b370b4d1a7d55d272043f0154c958ad5ed",
37
37
  "platform/canonical.js": "a354597d9f81278ea14c76cbb726207ca228c2652876517838708769f70156e3",
38
38
  "platform/identity.js": "fc91495ef08c92b77dfaa0c6d11f4c837a0e309022fa683e7140803270606cc4",
39
- "platform/approval.js": "a9d2e97ba80df37461e95aeff19eb4fd8bcba0d026e97c956158d1fce3f368da",
39
+ "platform/approval.js": "f9f1a873b4a5eb17529d35d1aa5fde8c6a11016fa9db0f35ec0eafccadc9ec1b",
40
40
  "platform/signed-audit.js": "46471ebb5765cb2725f3d1bccbef7bf1fef59f1f2e777f528e999fa96638621d",
41
41
  "platform/policy.js": "c54bca0290605ea74be72b9a7e06d6d3049ef53bf837e45e7d03330da5ecc1cc",
42
42
  "platform/jwt.js": "51c42b6f998b00c2a689194d9d60e6176df2f9b78406cd0e3b682cfcbba9a142",
43
43
  "platform/ssrf.js": "613e46a02c8930aed93b6d7227451167ae0349ab53b3d9ffefa997b2a5ba4e12",
44
44
  "platform/http-gateway.js": "357749ea416bc242b20c2a5b5e92e179d99d7d6b41a62b84517b91f2147b5c8d",
45
- "platform/sandbox-manager.js": "d882c114c4c640ca722dec11b351a4ec30b62c45254c2266706f0db617c32eb9",
46
- "platform/os-sandbox.js": "b503f0e422c4005c57f11384fb1fbe474a94dd96c11340576da8e2e1d34a60d8",
45
+ "platform/sandbox-manager.js": "b646cfbe80a2fcfc7ea7e942c9f38e19294d6bcfee83e2502abf567911118ff1",
46
+ "platform/os-sandbox.js": "126b7ddb1bb804c8a441e5fd7f339254ccede42d3428408158299183a0a50cc1",
47
47
  "platform/windows-sandbox.js": "d3c5e5280aa81b740afd5fbbd31b9664d426e12154c4b199232932426aab3a08",
48
48
  "platform/mcp-http-bridge.js": "21175c0fa187710e3af69b11b8b9017cdc321f6bb309aced4dd83a9789044a9a",
49
49
  "platform/memory-guard.js": "468da6d5483cb44ae2e2f3051b011afee44bbc0a900892950aabf9ac26ee3eae",
50
50
  "platform/delegation.js": "b7d4aa6c0885528f26de47c072b5e53e1b96bdc393a02fce3c6e8cbd780ad5cb",
51
- "platform/aisvs.js": "711fa398da46c8deb386b6397d0b104905cc761145656c8bdd1ce5e78d394a35"
51
+ "platform/aisvs.js": "711fa398da46c8deb386b6397d0b104905cc761145656c8bdd1ce5e78d394a35",
52
+ "platform/approval-service.js": "6c4cfc3b24e4a8dd53c343604adea55941fe8218b1232a71c56d5a03a06f1f3c",
53
+ "platform/oauth-server.js": "bc41bfd676a19766dde9399958e4db70d0512dc028ec37585d17267cabd5dc29",
54
+ "platform/runtime-monitor.js": "b3b18bc0164869ba32fd8bf1927f25aa376dbc72d5d1ae0de4b459b3f179737c"
52
55
  }
53
56
  }
@@ -733,6 +733,16 @@ function startProxy(opts = {}) {
733
733
  setTimeout(() => process.exit(2), 10).unref();
734
734
  }
735
735
 
736
+ let resourceMonitor = null;
737
+ if (Number(opts.maxRssMb || 0) > 0 && child.pid) {
738
+ const { RuntimeMonitor } = require('./platform/runtime-monitor');
739
+ resourceMonitor = new RuntimeMonitor({
740
+ pid: child.pid,
741
+ maxRssBytes: Number(opts.maxRssMb) * 1024 * 1024,
742
+ onExceeded: (info) => quarantineKill(`RSS ${info.rss} exceeded ${info.maxRssBytes}`),
743
+ }).start();
744
+ }
745
+
736
746
  function forwardToServer(messages) {
737
747
  for (const message of messages) {
738
748
  if (message && typeof message === 'object' && message.method) {
@@ -833,6 +843,7 @@ function startProxy(opts = {}) {
833
843
  }
834
844
 
835
845
  child.on('exit', (code, signal) => {
846
+ if (resourceMonitor) resourceMonitor.stop();
836
847
  engine.logger.log('mcp_server_exit', { server: serverName, code, signal, stats: engine.getStats() });
837
848
  if (!closed) {
838
849
  closed = true;
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * src/platform/approval-service.js — hosted approval API + read-only dashboard.
5
+ *
6
+ * Agents request approval with a VGAT token. Human approvers authenticate with a
7
+ * human VGAT token AND a signed VGApprover proof; the broker issues a single-use
8
+ * VGApproval token. Tickets are persisted atomically to a JSON store and the
9
+ * service supports approver key rotation.
10
+ *
11
+ * This is a local/loopback service slice, not a full IAM/SSO product.
12
+ */
13
+
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+ const http = require('http');
17
+ const { ApprovalBroker } = require('./approval');
18
+ const { ERROR_CODES, VibeGuardError } = require('./contracts');
19
+
20
+ class JsonApprovalStore {
21
+ constructor(file) {
22
+ this.file = file ? path.resolve(file) : null;
23
+ this.data = { tickets: [], usedTokens: [] };
24
+ if (this.file && fs.existsSync(this.file)) {
25
+ try { this.data = JSON.parse(fs.readFileSync(this.file, 'utf8')); } catch { throw new VibeGuardError(ERROR_CODES.APPROVAL_INVALID, 'approval store is corrupt'); }
26
+ }
27
+ }
28
+ save(broker) {
29
+ const approverKeys = this.data.approverKeys || {};
30
+ this.data = { ...broker.exportState(), approverKeys };
31
+ if (!this.file) return;
32
+ fs.mkdirSync(path.dirname(this.file), { recursive: true, mode: 0o700 });
33
+ const tmp = this.file + '.tmp';
34
+ fs.writeFileSync(tmp, JSON.stringify(this.data, null, 2) + '\n', { mode: 0o600 });
35
+ fs.renameSync(tmp, this.file);
36
+ }
37
+ }
38
+
39
+ function json(res, status, body) {
40
+ const payload = JSON.stringify(body);
41
+ res.writeHead(status, { 'content-type': 'application/json', 'content-length': Buffer.byteLength(payload) });
42
+ res.end(payload);
43
+ }
44
+
45
+ function readBody(req) {
46
+ return new Promise((resolve, reject) => {
47
+ let s = '';
48
+ req.on('data', (c) => { s += c; if (s.length > 64 * 1024) { reject(new VibeGuardError(ERROR_CODES.LIMIT_EXCEEDED, 'request too large')); req.destroy(); } });
49
+ req.on('end', () => resolve(s));
50
+ req.on('error', reject);
51
+ });
52
+ }
53
+
54
+ function authenticate(req, authority) {
55
+ const h = req.headers.authorization || '';
56
+ const token = h.startsWith('Bearer ') ? h.slice(7) : '';
57
+ if (!token) throw new VibeGuardError(ERROR_CODES.AUTH_REQUIRED, 'bearer token required', { status: 401 });
58
+ return authority.verify(token).principal;
59
+ }
60
+
61
+ function dashboard(broker) {
62
+ const rows = [...broker.tickets.values()].map((t) => `<tr><td>${escapeHtml(t.ticketId)}</td><td>${escapeHtml(t.principal)}</td><td>${escapeHtml(t.action && t.action.tool)}</td><td>${escapeHtml(t.status)}</td><td>${escapeHtml(t.approver || '')}</td></tr>`).join('');
63
+ return `<!doctype html><html><head><meta charset="utf-8"><title>VibeGuard approvals</title><style>body{background:#070b12;color:#d6f6ff;font-family:monospace;padding:2rem}table{border-collapse:collapse;width:100%}td,th{border:1px solid #174455;padding:.5rem;text-align:left}</style></head><body><h1>VibeGuard approvals</h1><p>Read-only dashboard. Decisions require an authenticated human token and a signed approver proof via POST /approval/decision.</p><table><tr><th>Ticket</th><th>Agent</th><th>Tool</th><th>Status</th><th>Approver</th></tr>${rows}</table></body></html>`;
64
+ }
65
+
66
+ function escapeHtml(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c])); }
67
+
68
+ function createApprovalService(opts = {}) {
69
+ if (!opts.broker) throw new Error('approval service requires a broker');
70
+ if (!opts.authority) throw new Error('approval service requires an identity authority');
71
+ const broker = opts.broker;
72
+ const store = new JsonApprovalStore(opts.storeFile);
73
+ if (store.data.tickets && store.data.tickets.length) broker.importState(store.data);
74
+ for (const [principal, key] of Object.entries(store.data.approverKeys || {})) broker.rotateApproverKey(principal, key);
75
+ const server = http.createServer(async (req, res) => {
76
+ try {
77
+ if (req.method === 'GET' && req.url === '/health') return json(res, 200, { status: 'ok', service: 'vibeguard-approval' });
78
+ if (req.method === 'GET' && req.url === '/approval') {
79
+ res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
80
+ return res.end(dashboard(broker));
81
+ }
82
+ if (req.method === 'POST' && req.url === '/approval/request') {
83
+ const principal = authenticate(req, opts.authority);
84
+ if (!String(principal.principalId).startsWith('agent:')) throw new VibeGuardError(ERROR_CODES.AUTHORIZATION_DENIED, 'agent token required', { status: 403 });
85
+ const body = JSON.parse(await readBody(req) || '{}');
86
+ if (!body.action) throw new VibeGuardError(ERROR_CODES.SCHEMA_INVALID, 'action is required');
87
+ const t = broker.request({ principal: principal.principalId, action: body.action, reason: body.reason, ttlSeconds: body.ttlSeconds });
88
+ store.save(broker);
89
+ return json(res, 200, t);
90
+ }
91
+ if (req.method === 'POST' && req.url === '/approval/decision') {
92
+ const principal = authenticate(req, opts.authority);
93
+ if (!String(principal.principalId).startsWith('human:')) throw new VibeGuardError(ERROR_CODES.AUTHORIZATION_DENIED, 'human approver token required', { status: 403 });
94
+ const body = JSON.parse(await readBody(req) || '{}');
95
+ const d = broker.decide(body.ticketId, { approver: principal.principalId, approve: body.approve === true, proof: body.proof });
96
+ store.save(broker);
97
+ return json(res, 200, d);
98
+ }
99
+ if (req.method === 'POST' && req.url === '/approval/keys') {
100
+ const principal = authenticate(req, opts.authority);
101
+ if (!opts.adminPrincipals || !opts.adminPrincipals.includes(principal.principalId)) throw new VibeGuardError(ERROR_CODES.AUTHORIZATION_DENIED, 'admin principal required', { status: 403 });
102
+ const body = JSON.parse(await readBody(req) || '{}');
103
+ if (!body.principal || !body.publicKey) throw new VibeGuardError(ERROR_CODES.SCHEMA_INVALID, 'principal and publicKey are required');
104
+ const r = broker.rotateApproverKey(body.principal, body.publicKey);
105
+ store.data.approverKeys = store.data.approverKeys || {};
106
+ store.data.approverKeys[body.principal] = body.publicKey;
107
+ store.save(broker);
108
+ return json(res, 200, r);
109
+ }
110
+ return json(res, 404, { error: 'not found' });
111
+ } catch (err) {
112
+ return json(res, err.status || 400, { error: err.message, code: err.code || 'VG_APPROVAL_INVALID' });
113
+ }
114
+ });
115
+ return new Promise((resolve, reject) => {
116
+ server.once('error', reject);
117
+ server.listen(Number(opts.port || 0), opts.host || '127.0.0.1', () => {
118
+ const addr = server.address();
119
+ resolve({ server, host: addr.address, port: addr.port, url: `http://${addr.address}:${addr.port}`, broker, store, close: () => new Promise((r) => server.close(r)) });
120
+ });
121
+ });
122
+ }
123
+
124
+ module.exports = { createApprovalService, JsonApprovalStore };
@@ -140,6 +140,22 @@ class ApprovalBroker {
140
140
  return { status: 'approved', ticket: publicTicket(ticket), approvalToken: token };
141
141
  }
142
142
 
143
+ exportState() {
144
+ return { tickets: [...this.tickets.values()], usedTokens: [...this.usedTokens] };
145
+ }
146
+
147
+ importState(state = {}) {
148
+ this.tickets = new Map((state.tickets || []).map((t) => [t.ticketId, t]));
149
+ this.usedTokens = new Set(state.usedTokens || []);
150
+ return this;
151
+ }
152
+
153
+ rotateApproverKey(principal, key) {
154
+ if (!String(principal).startsWith('human:')) throw new VibeGuardError(ERROR_CODES.APPROVAL_INVALID, 'approver must be a human principal');
155
+ this.approverKeys.set(principal, loadPublicKey(key));
156
+ return { principal, rotatedAt: this.now().toISOString() };
157
+ }
158
+
143
159
  static signApproverProof({ ticketId, actionDigest: digest, nonce, approver, privateKey, ttlSeconds = 120, keyId = 'approver' } = {}) {
144
160
  if (!ticketId || !digest || !nonce || !approver || !privateKey) throw new Error('approver proof requires ticketId, actionDigest, nonce, approver, privateKey');
145
161
  const now = Math.floor(Date.now() / 1000);
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * src/platform/oauth-server.js — local OAuth 2.1 authorization-code + PKCE
5
+ * service for the MCP HTTP bridge. EdDSA access tokens, JWKS discovery, one-use
6
+ * authorization codes and client secrets. It is a loopback/library service, not
7
+ * an enterprise IdP.
8
+ */
9
+
10
+ const crypto = require('crypto');
11
+ const http = require('http');
12
+ const { signJws } = require('./identity');
13
+ const { ERROR_CODES, VibeGuardError } = require('./contracts');
14
+
15
+ function b64url(buf) { return Buffer.from(buf).toString('base64url'); }
16
+ function s256(verifier) { return b64url(crypto.createHash('sha256').update(verifier).digest()); }
17
+ function json(res, status, body) {
18
+ const payload = JSON.stringify(body);
19
+ res.writeHead(status, { 'content-type': 'application/json', 'content-length': Buffer.byteLength(payload), 'cache-control': 'no-store' });
20
+ res.end(payload);
21
+ }
22
+ function readJson(req) {
23
+ return new Promise((resolve, reject) => {
24
+ let s = '';
25
+ req.on('data', (c) => { s += c; if (s.length > 64 * 1024) { reject(new Error('too large')); req.destroy(); } });
26
+ req.on('end', () => { try { resolve(JSON.parse(s || '{}')); } catch { reject(new Error('invalid JSON')); } });
27
+ req.on('error', reject);
28
+ });
29
+ }
30
+
31
+ function createOAuthServer(opts = {}) {
32
+ if (!opts.privateKey || !opts.publicKey) throw new Error('oauth server requires privateKey and publicKey');
33
+ const issuer = opts.issuer || 'https://vibeguard.local';
34
+ const audience = opts.audience || 'vibeguard-gateway';
35
+ const keyId = opts.keyId || 'oauth-key';
36
+ const clients = new Map(Object.entries(opts.clients || {}));
37
+ if (!clients.size) throw new Error('oauth server requires at least one client secret');
38
+ const codes = new Map();
39
+ const now = opts.now || (() => new Date());
40
+ const codeTtl = opts.codeTtlSeconds || 60;
41
+ const tokenTtl = opts.tokenTtlSeconds || 300;
42
+
43
+ const server = http.createServer(async (req, res) => {
44
+ try {
45
+ const u = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
46
+ if (req.method === 'GET' && u.pathname === '/.well-known/openid-configuration') {
47
+ return json(res, 200, { issuer, authorization_endpoint: `${issuer}/authorize`, token_endpoint: `${issuer}/token`, jwks_uri: `${issuer}/jwks`, response_types_supported: ['code'], grant_types_supported: ['authorization_code'], code_challenge_methods_supported: ['S256'] });
48
+ }
49
+ if (req.method === 'GET' && u.pathname === '/jwks') {
50
+ return json(res, 200, { keys: [require('./identity').publicKeyToJwk(opts.publicKey, keyId)] });
51
+ }
52
+ if (req.method === 'POST' && u.pathname === '/authorize') {
53
+ const body = await readJson(req);
54
+ const secret = req.headers['x-client-secret'];
55
+ if (!body.client_id || clients.get(body.client_id) !== secret) throw new VibeGuardError(ERROR_CODES.AUTH_INVALID, 'invalid client credentials', { status: 401 });
56
+ if (!body.redirect_uri || !body.code_challenge) throw new VibeGuardError(ERROR_CODES.SCHEMA_INVALID, 'redirect_uri and code_challenge are required');
57
+ const code = crypto.randomBytes(24).toString('base64url');
58
+ codes.set(code, { clientId: body.client_id, redirectUri: body.redirect_uri, challenge: body.code_challenge, scope: String(body.scope || ''), principal: String(body.principal || 'agent:oauth/user'), expiresAt: now().getTime() + codeTtl * 1000, used: false });
59
+ return json(res, 200, { code, expires_in: codeTtl });
60
+ }
61
+ if (req.method === 'POST' && u.pathname === '/token') {
62
+ const body = await readJson(req);
63
+ if (body.grant_type !== 'authorization_code') throw new VibeGuardError(ERROR_CODES.AUTH_INVALID, 'unsupported grant_type');
64
+ const code = codes.get(body.code);
65
+ if (!code || code.used || code.expiresAt <= now().getTime()) throw new VibeGuardError(ERROR_CODES.AUTH_INVALID, 'invalid or expired authorization code');
66
+ if (clients.get(code.clientId) !== (req.headers['x-client-secret'] || body.client_secret)) throw new VibeGuardError(ERROR_CODES.AUTH_INVALID, 'invalid client credentials');
67
+ if (code.redirectUri !== body.redirect_uri) throw new VibeGuardError(ERROR_CODES.AUTH_INVALID, 'redirect_uri mismatch');
68
+ if (!body.code_verifier || s256(body.code_verifier) !== code.challenge) throw new VibeGuardError(ERROR_CODES.AUTH_INVALID, 'PKCE verification failed');
69
+ code.used = true;
70
+ const iat = Math.floor(now().getTime() / 1000);
71
+ const payload = { iss: issuer, aud: audience, sub: code.principal, scope: code.scope, iat, exp: iat + tokenTtl, jti: crypto.randomBytes(12).toString('base64url') };
72
+ const token = signJws({ alg: 'EdDSA', typ: 'at+jwt', kid: keyId }, payload, opts.privateKey);
73
+ return json(res, 200, { access_token: token, token_type: 'Bearer', expires_in: tokenTtl, scope: code.scope });
74
+ }
75
+ return json(res, 404, { error: 'not found' });
76
+ } catch (err) {
77
+ return json(res, err.status || 400, { error: err.message, code: err.code || 'VG_AUTH_INVALID' });
78
+ }
79
+ });
80
+ return new Promise((resolve, reject) => {
81
+ server.once('error', reject);
82
+ server.listen(Number(opts.port || 0), opts.host || '127.0.0.1', () => {
83
+ const addr = server.address();
84
+ resolve({ server, url: `http://${addr.address}:${addr.port}`, issuer, audience, keyId, close: () => new Promise((r) => server.close(r)) });
85
+ });
86
+ });
87
+ }
88
+
89
+ module.exports = { createOAuthServer };
@@ -242,10 +242,61 @@ async function verifyFilesystemIsolation(bwrap, nodePath) {
242
242
 
243
243
  function cryptoRandom() { return require('crypto').randomBytes(8).toString('hex'); }
244
244
 
245
+
246
+ class MacSandboxExecSandbox {
247
+ constructor(opts = {}) {
248
+ this.id = 'macos-sandbox-exec';
249
+ this.isolationClass = ISOLATION.OS;
250
+ this.verified = false;
251
+ this.verification = 'unverified';
252
+ this.limitations = ['deprecated sandbox-exec profile; not an App Sandbox entitlement or VM', 'network and selected filesystem writes denied by profile'];
253
+ this.nodePath = opts.nodePath || process.execPath;
254
+ this.sandboxExec = opts.sandboxExec || (process.platform === 'darwin' ? '/usr/bin/sandbox-exec' : null);
255
+ }
256
+ available() { return process.platform === 'darwin' && Boolean(this.sandboxExec) && fs.existsSync(this.sandboxExec); }
257
+ _profile(dir) {
258
+ const nodeRoot = path.dirname(path.dirname(this.nodePath));
259
+ return [
260
+ '(version 1)', '(deny default)',
261
+ '(allow process*)',
262
+ '(allow sysctl-read)',
263
+ '(allow mach-lookup)',
264
+ '(allow file-read* (subpath "/usr") (subpath "/System") (subpath "/Library") (subpath "/bin") (subpath "/sbin") (subpath "/dev") (subpath "/private/etc") (subpath "/private/var/db"))',
265
+ '(allow file-read* (subpath ' + JSON.stringify(nodeRoot) + ') (subpath ' + JSON.stringify(dir) + '))',
266
+ '(allow file-write* (subpath "/tmp") (subpath "/private/tmp"))',
267
+ '(deny network*)',
268
+ ].join('\n');
269
+ }
270
+ run(code, opts = {}) {
271
+ const started = Date.now();
272
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'vg-mac-'));
273
+ fs.writeFileSync(path.join(dir, 'user.js'), String(code), 'utf8');
274
+ fs.writeFileSync(path.join(dir, 'harness.js'), HARNESS_SOURCE, 'utf8');
275
+ const result = { success: false, output: null, error: null, duration: 0, isolation: this.id, isolationClass: ISOLATION.OS, verified: this.verified, verification: this.verification, limitations: this.limitations.slice() };
276
+ if (!this.available()) { result.error = 'macOS sandbox-exec backend unavailable'; return Promise.resolve(result); }
277
+ return new Promise((resolve) => {
278
+ const child = spawn(this.sandboxExec, ['-p', this._profile(dir), this.nodePath, path.join(dir, 'harness.js')], { cwd: dir, env: { PATH: '/usr/bin:/bin', HOME: '/tmp' }, stdio: ['ignore', 'pipe', 'pipe'], shell: false });
279
+ let stdout = ''; let stderr = '';
280
+ const timer = setTimeout(() => { try { child.kill('SIGKILL'); } catch {} }, opts.timeout || 5000);
281
+ child.stdout.on('data', (c) => { stdout += c.toString('utf8'); });
282
+ child.stderr.on('data', (c) => { stderr += c.toString('utf8').slice(0, 1024 * 1024); });
283
+ child.once('error', (err) => { clearTimeout(timer); result.error = err.message; result.duration = Date.now() - started; resolve(result); });
284
+ child.once('exit', (code, signal) => { clearTimeout(timer); Object.assign(result, parseHarnessOutput(stdout, stderr, signal, code)); result.duration = Date.now() - started; resolve(result); });
285
+ });
286
+ }
287
+ async verify() {
288
+ if (!this.available()) { this.verification = 'unavailable'; return false; }
289
+ const probe = await this.run('const x = 1 + 1; x', { timeout: 4000 });
290
+ this.verified = Boolean(probe.success);
291
+ this.verification = this.verified ? 'sandbox-exec-harness-verified' : 'verification-failed';
292
+ return this.verified;
293
+ }
294
+ }
295
+
245
296
  function getLinuxBackend(opts = {}) {
246
297
  const bwrap = new LinuxBubblewrapSandbox(opts);
247
298
  if (bwrap.available()) return bwrap;
248
299
  return new LinuxNamespaceSandbox(opts);
249
300
  }
250
301
 
251
- module.exports = { LinuxNamespaceSandbox, LinuxBubblewrapSandbox, getLinuxBackend };
302
+ module.exports = { LinuxNamespaceSandbox, LinuxBubblewrapSandbox, MacSandboxExecSandbox, getLinuxBackend };
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * src/platform/runtime-monitor.js — process-level runtime guard.
5
+ *
6
+ * Polls a child process RSS against a configured cap and invokes the configured
7
+ * quarantine callback once. This is not a filesystem or network monitor; those
8
+ * require OS-specific tracing/WFP/netns integrations.
9
+ */
10
+
11
+ const { execFileSync } = require('child_process');
12
+
13
+ function readRssBytes(pid, platform = process.platform) {
14
+ if (!pid) return null;
15
+ try {
16
+ if (platform === 'linux' || platform === 'darwin') {
17
+ const out = execFileSync('ps', ['-o', 'rss=', '-p', String(pid)], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
18
+ const kb = Number(String(out).trim());
19
+ return Number.isFinite(kb) && kb >= 0 ? kb * 1024 : null;
20
+ }
21
+ if (platform === 'win32') {
22
+ const out = execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', `(Get-Process -Id ${Number(pid)} -ErrorAction Stop).WorkingSet64`], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
23
+ const bytes = Number(String(out).trim());
24
+ return Number.isFinite(bytes) && bytes > 0 ? bytes : null;
25
+ }
26
+ } catch { /* process may have exited */ }
27
+ return null;
28
+ }
29
+
30
+ class RuntimeMonitor {
31
+ constructor(opts = {}) {
32
+ this.pid = opts.pid;
33
+ this.maxRssBytes = opts.maxRssBytes || 0;
34
+ this.intervalMs = opts.intervalMs || 2000;
35
+ this.onExceeded = opts.onExceeded || (() => {});
36
+ this.read = opts.read || ((pid) => readRssBytes(pid));
37
+ this.timer = null;
38
+ this.lastRss = null;
39
+ this.exceeded = false;
40
+ }
41
+
42
+ start() {
43
+ if (!this.pid || !this.maxRssBytes || this.timer) return this;
44
+ this.timer = setInterval(() => this.check(), this.intervalMs);
45
+ if (this.timer.unref) this.timer.unref();
46
+ return this;
47
+ }
48
+
49
+ check() {
50
+ if (this.exceeded) return { exceeded: true, rss: this.lastRss };
51
+ const rss = this.read(this.pid);
52
+ this.lastRss = rss;
53
+ if (rss != null && rss > this.maxRssBytes) {
54
+ this.exceeded = true;
55
+ this.stop();
56
+ try { this.onExceeded({ pid: this.pid, rss, maxRssBytes: this.maxRssBytes }); } catch { /* callback must not crash monitor */ }
57
+ return { exceeded: true, rss };
58
+ }
59
+ return { exceeded: false, rss };
60
+ }
61
+
62
+ stop() {
63
+ if (this.timer) clearInterval(this.timer);
64
+ this.timer = null;
65
+ return this;
66
+ }
67
+ }
68
+
69
+ module.exports = { RuntimeMonitor, readRssBytes };
@@ -76,6 +76,11 @@ function defaultManager() {
76
76
  const win = new WindowsJobSandbox();
77
77
  if (win.available()) manager.register(win);
78
78
  }
79
+ if (process.platform === 'darwin') {
80
+ const { MacSandboxExecSandbox } = require('./os-sandbox');
81
+ const mac = new MacSandboxExecSandbox();
82
+ if (mac.available()) manager.register(mac);
83
+ }
79
84
  } catch { /* optional platform backend */ }
80
85
  manager.register({
81
86
  id: 'process',