@yagyeshvyas/vibeguard 1.12.0 → 1.13.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/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
3
3
  All notable changes to VibeGuard are documented here.
4
4
  Format based on [Keep a Changelog](https://keepachangelog.com/).
5
5
 
6
+ ## [1.13.0] - 2026-11-22
7
+
8
+ ### Added
9
+
10
+ - Linux bubblewrap filesystem/network/PID isolation and Windows Job Object containment (AppContainer/WFP still absent).
11
+ - macOS `sandbox-exec` backend (deprecated profile; not App Sandbox/VM).
12
+ - Hosted approval API with authenticated tickets/proofs, JSON persistence, key rotation and read-only dashboard.
13
+ - Local OAuth 2.1 authorization-code + PKCE server with JWKS and aud/scope validation.
14
+ - Runtime RSS monitor with `--max-rss` quarantine kill.
15
+ - External audit anchor and HTTPS/mTLS bridge options.
16
+
17
+ ### Breaking
18
+
19
+ - `ApprovalBroker.decide()` requires signed approver proof by default.
20
+
6
21
  ## [1.12.0] - 2026-11-22
7
22
 
8
23
  ### Added
package/README.md CHANGED
@@ -32,7 +32,7 @@ Offline by default · Zero telemetry · No paid APIs · Free forever.
32
32
  <img src="https://img.shields.io/badge/compliance-10%20frameworks-orange?style=flat-square" alt="10 compliance frameworks" />
33
33
  <img src="https://img.shields.io/badge/AI--safety%20F1-96.8%25-brightgreen?style=flat-square" alt="AI-safety F1 96.8%" />
34
34
  <img src="https://img.shields.io/badge/telemetry-zero-brightgreen?style=flat-square" alt="Zero telemetry" />
35
- <img src="https://img.shields.io/badge/tests-625%20passed-blue?style=flat-square" alt="625 tests pass" />
35
+ <img src="https://img.shields.io/badge/tests-629%20passed-blue?style=flat-square" alt="629 tests pass" />
36
36
  <img src="https://img.shields.io/badge/self--scan-Grade%20A-brightgreen?style=flat-square" alt="Self-scan Grade A" />
37
37
  </p>
38
38
 
@@ -66,7 +66,7 @@ Offline by default · Zero telemetry · No paid APIs · Free forever.
66
66
 
67
67
  ---
68
68
 
69
- ## 🆕 What's New — v1.12.0
69
+ ## 🆕 What's New — v1.13.0
70
70
 
71
71
  **Security foundation v2 (internal testing).** This release is not beta or
72
72
  production-ready; it is the verified internal-testing build described in
@@ -81,12 +81,12 @@ production-ready; it is the verified internal-testing build described in
81
81
  - Linux `unshare` network/PID namespace sandbox with `sandbox verify`.
82
82
  - Memory provenance and multi-agent delegation guards; labeled detection corpus;
83
83
  AISVS-style readiness mapping.
84
- - **625 tests, 0 failures** on Windows Node24/Node18 and Linux Node22; 31/31
84
+ - **629 tests, 0 failures** on Windows Node24/Node18 and Linux Node22; 35/35
85
85
  platform tests on Windows/Linux/macOS CI.
86
86
 
87
- Install note: v1.12.0 is distributed as `@yagyeshvyas/vibeguard@1.12.0`. If a
87
+ Install note: v1.13.0 is distributed as `@yagyeshvyas/vibeguard@1.13.0`. If a
88
88
  registry mirror still serves an older build, use the exact
89
- [v1.12.0 GitHub release tarball](https://github.com/yagyeshVyas/VibeGuard/releases/tag/v1.12.0).
89
+ [v1.13.0 GitHub release tarball](https://github.com/yagyeshVyas/VibeGuard/releases/tag/v1.13.0).
90
90
 
91
91
  ## 🆕 What's New — v1.10.0
92
92
 
@@ -146,9 +146,9 @@ Full details, policy schema and honest limits: [MCP-FIREWALL.md](MCP-FIREWALL.md
146
146
 
147
147
  ---
148
148
 
149
- ## Security baseline v2 — v1.12.0 status (internal testing)
149
+ ## Security baseline v2 — v1.13.0 status (internal testing)
150
150
 
151
- This repository contains the v1.12.0 security foundation. It is **not** a
151
+ This repository contains the v1.13.0 security foundation. It is **not** a
152
152
  production-ready agent security platform. Linux network/PID namespace isolation
153
153
  is available; Windows/macOS OS isolation is not implemented.
154
154
 
@@ -166,8 +166,9 @@ Implemented and tested:
166
166
  - Authenticated loopback **HTTP JSON-RPC + SSE** MCP bridge with upstream stdio.
167
167
  - Optional **kill-on-block/block-budget** quarantine response.
168
168
  - **Linux bubblewrap** sandbox with verified network/PID/filesystem isolation,
169
- plus `unshare` fallback. **Windows Job Object** process/memory containment is
170
- available; AppContainer/WFP and macOS VM are still absent.
169
+ plus `unshare` fallback. **Windows Job Object** process/memory containment and
170
+ macOS `sandbox-exec` are available; AppContainer/WFP and macOS App Sandbox/VM
171
+ are still absent.
171
172
  - Memory provenance guard and signed multi-agent delegation library.
172
173
  - Labeled detection corpus runner and AISVS-style readiness mapping.
173
174
  - Target-controlled scanner plugins are **disabled by default**; code execution
@@ -184,16 +185,16 @@ Not implemented or not verified:
184
185
  Object provides process/memory containment only; it does not isolate files or
185
186
  network. Linux bubblewrap isolates network/PID/filesystem when installed, but
186
187
  is not a VM/hardware boundary.
187
- - **External audit anchor** is supported (`audit verify --anchor`); legacy
188
+ - **External audit anchor** and checkpoint sidecars are supported; legacy
188
189
  non-strict gateway audit is still the legacy hash chain.
189
- - **Approval service/UI**: `ApprovalBroker.decide()` now requires a signed
190
- approver proof; there is still no hosted approval UI/service.
191
- - Remote OAuth multi-session deployment; TLS/mTLS server options exist, but
192
- live OAuth authorization-server flow and persistence are not implemented.
190
+ - **Approval service**: hosted API with authenticated tickets, signed approver
191
+ proofs, JSON persistence, key rotation and a read-only dashboard; no SSO/IdP.
192
+ - A **local OAuth 2.1 code+PKCE server** and TLS/mTLS bridge options exist;
193
+ multi-session persistence and a full remote IdP/lifecycle remain incomplete.
193
194
  - Persistent memory/multi-agent runtime; `MemoryGuard`/`DelegationGraph` are
194
195
  tested libraries only.
195
196
  - Independent penetration test, representative precision/recall corpus, macOS
196
- full-suite evidence. npm 1.12.0 is published; GitHub Actions still lacks the
197
+ full-suite evidence. npm 1.13.0 is published; GitHub Actions still lacks the
197
198
  NPM_TOKEN secret and skips its publish step.
198
199
  - Dashboard/SDK and full AISVS certification; AISVS is an internal mapping.
199
200
 
package/bin/cli.js CHANGED
@@ -23,7 +23,7 @@ const {
23
23
  } = require('../src/report');
24
24
 
25
25
  // Flags that take a value (support both --flag=value and --flag value).
26
- const VALUE_FLAGS = new Set(['fail-on', 'scope', 'focus', 'model', 'since', 'base', 'o', 'output', 'file', 'types', 'min-confidence', 'trust', 'allow', 'save', 'max-blobs', 'max-commits', 'port', 'upstream', 'mode', 'api-key', 'token', 'token-header', 'timeout', 'pentest-url', 'pentest-verify-ssrf', 'budget', 'server', 'exec', 'command', 'policy', 'audit', 'check', 'tool', 'args', 'isolation', 'frameworks', 'framework', 'interval', 'dir', 'memory', 'pub', 'key', 'key-id', 'out', 'max-blocks', 'token-pub', 'token-issuer', 'token-tenant', 'token-key-id', 'approval-token', 'approval-pub', 'approval-issuer', 'approval-tenant', 'approval-key-id', 'anchor']);
26
+ const VALUE_FLAGS = new Set(['fail-on', 'scope', 'focus', 'model', 'since', 'base', 'o', 'output', 'file', 'types', 'min-confidence', 'trust', 'allow', 'save', 'max-blobs', 'max-commits', 'port', 'upstream', 'mode', 'api-key', 'token', 'token-header', 'timeout', 'pentest-url', 'pentest-verify-ssrf', 'budget', 'server', 'exec', 'command', 'policy', 'audit', 'check', 'tool', 'args', 'isolation', 'frameworks', 'framework', 'interval', 'dir', 'memory', 'pub', 'key', 'key-id', 'out', 'max-blocks', 'token-pub', 'token-issuer', 'token-tenant', 'token-key-id', 'approval-token', 'approval-pub', 'approval-issuer', 'approval-tenant', 'approval-key-id', 'anchor', 'max-rss']);
27
27
 
28
28
  function parseArgs(argv) {
29
29
  const args = { _: [], flags: {} };
@@ -178,6 +178,7 @@ function cmdMcpFirewall(args, flags) {
178
178
  approvalTenant: flags['approval-tenant'],
179
179
  approvalKeyId: flags['approval-key-id'],
180
180
  maxBlocks: flags['max-blocks'] ? Number(flags['max-blocks']) : 0,
181
+ maxRssMb: flags['max-rss'] ? Number(flags['max-rss']) : 0,
181
182
  });
182
183
 
183
184
  proxy.child.once('spawn', () => {
@@ -96,6 +96,9 @@ async function cmdSandbox(args, flags) {
96
96
  if (process.platform === 'win32') {
97
97
  const { WindowsJobSandbox } = require('../src/platform/windows-sandbox');
98
98
  backend = new WindowsJobSandbox();
99
+ } else if (process.platform === 'darwin') {
100
+ const { MacSandboxExecSandbox } = require('../src/platform/os-sandbox');
101
+ backend = new MacSandboxExecSandbox();
99
102
  } else {
100
103
  const { getLinuxBackend } = require('../src/platform/os-sandbox');
101
104
  backend = getLinuxBackend();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yagyeshvyas/vibeguard",
3
- "version": "1.12.0",
4
- "description": "Offline-by-default security scanner and runtime firewall for AI-coded apps and MCP agents. 861 rules, 93 MCP tools, signed default-deny policy, tool-poisoning/prompt-injection/secret-exfiltration detection, signed audit with external anchor, authenticated HTTP/SSE MCP bridge with TLS, Linux bubblewrap network/PID/filesystem isolation, Windows Job Object containment, and OWASP Agentic AI + MCP coverage. Zero telemetry.",
3
+ "version": "1.13.0",
4
+ "description": "Offline-by-default security scanner and runtime firewall for AI-coded apps and MCP agents. 861 rules, 93 MCP tools, signed default-deny policy, tool-poisoning/prompt-injection/secret-exfiltration detection, signed audit + external anchor, hosted approvals with signed proofs, HTTP/SSE MCP bridge with OAuth/TLS, Linux bubblewrap isolation, Windows Job containment and macOS sandbox-exec. Zero telemetry.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "author": "Yagyesh Vyas <https://www.linkedin.com/in/yagyeshvyas/>",
package/src/integrity.js CHANGED
@@ -40,6 +40,7 @@ const CRITICAL_MODULES = [
40
40
  'platform/sandbox-manager.js', 'platform/os-sandbox.js', 'platform/windows-sandbox.js',
41
41
  'platform/mcp-http-bridge.js', 'platform/memory-guard.js',
42
42
  'platform/delegation.js', 'platform/aisvs.js',
43
+ 'platform/approval-service.js', 'platform/oauth-server.js', 'platform/runtime-monitor.js',
43
44
  ];
44
45
 
45
46
  function hashFile(p) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "tool": "vibeguard",
3
- "generatedAt": "2026-11-22T19:31:04.837Z",
3
+ "generatedAt": "2026-11-22T19:55:42.417Z",
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',