aegisone 1.0.38 → 1.0.40
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/LICENSING.md +186 -0
- package/README.md +2 -2
- package/bin/aegis.js +1 -1
- package/package.json +3 -2
- package/scripts/predist.mjs +1 -1
- package/src/child.js +1 -1
- package/src/permissions.js +1 -1
- package/vendor/cli/package.json +4 -2
- package/vendor/cli/src/app.js +1 -1
- package/vendor/cli/src/chatflow.js +1 -1
- package/vendor/cli/src/commands.js +3 -1
- package/vendor/cli/src/config.js +1 -1
- package/vendor/cli/src/engine.js +1 -1
- package/vendor/cli/src/history.js +1 -1
- package/vendor/cli/src/models.js +1 -1
- package/vendor/cli/src/overlays.js +1 -1
- package/vendor/cli/src/panels.js +1 -1
- package/vendor/cli/vendor/client/brain-catalog.js +1 -1
- package/vendor/cli/vendor/client/byok-catalog.js +1 -1
- package/vendor/cli/vendor/client/credits.js +45 -0
- package/vendor/cli/vendor/client/foreign-sessions.js +3 -0
- package/vendor/cli/vendor/client/naming.js +1 -1
- package/vendor/cli/vendor/client/prefs.js +1 -1
- package/vendor/cli/vendor/client/session-search.js +3 -0
- package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/integrity.js +42 -2
- package/vendor/cli/vendor/desktop/lib/local/perm-rules.js +206 -0
- package/vendor/cli/vendor/desktop/lib/local/perm-store.js +298 -0
- package/vendor/cli/vendor/desktop/lib/local/perm-write.js +199 -0
- package/vendor/cli/vendor/desktop/lib/local/pro-sessions.js +3 -0
- package/vendor/cli/vendor/desktop/lib/local/sandbox-appcontainer.js +242 -0
- package/vendor/cli/vendor/desktop/lib/local/sandbox-bwrap.js +316 -0
- package/vendor/cli/vendor/desktop/lib/local/sandbox-seatbelt.js +380 -0
- package/vendor/cli/vendor/desktop/lib/local/sandbox.js +493 -0
- package/vendor/cli/vendor/desktop/lib/local/shell.js +155 -20
- package/vendor/cli/vendor/desktop/lib/local/tools.js +29 -4
- package/vendor/cli/vendor/desktop/lib/settings.js +1 -1
- package/vendor/cli/vendor/desktop/main.js +774 -37
- package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1
- package/vendor/cli/vendor/mcp/admission.js +3 -0
- package/vendor/cli/vendor/mcp/server.js +1 -1
- package/vendor/cli/vendor/one/src/child.js +1 -1
- package/vendor/cli/vendor/one/src/permissions.js +1 -1
- package/vendor/desktop/bin/aegis.js +1 -1
- package/vendor/desktop/lib/local/claude-pro.js +1 -1
- package/vendor/desktop/lib/local/engine.js +1 -1
- package/vendor/desktop/lib/local/integrity.js +42 -2
- package/vendor/desktop/lib/local/perm-rules.js +206 -0
- package/vendor/desktop/lib/local/perm-store.js +298 -0
- package/vendor/desktop/lib/local/perm-write.js +199 -0
- package/vendor/desktop/lib/local/pro-sessions.js +3 -0
- package/vendor/desktop/lib/local/sandbox-appcontainer.js +242 -0
- package/vendor/desktop/lib/local/sandbox-bwrap.js +316 -0
- package/vendor/desktop/lib/local/sandbox-seatbelt.js +380 -0
- package/vendor/desktop/lib/local/sandbox.js +493 -0
- package/vendor/desktop/lib/local/shell.js +155 -20
- package/vendor/desktop/lib/local/tools.js +29 -4
- package/vendor/desktop/lib/settings.js +1 -1
- package/vendor/desktop/lib/sync/memory-store.js +3 -0
- package/vendor/desktop/main.js +774 -37
- package/vendor/desktop/package.json +20 -7
- package/vendor/desktop/preload.js +1 -1
- package/vendor/desktop/renderer/app.js +5 -1
- package/vendor/desktop/renderer/index.html +221 -5
- package/vendor/desktop/renderer/provider-mark.js +1 -1
- package/vendor/desktop/renderer/provider-toolbar.js +1 -1
- package/vendor/desktop/renderer/providers.js +1 -1
- package/vendor/desktop/renderer/style.css +223 -6
- package/vendor/desktop/renderer/usage.js +1 -1
- package/vendor/desktop/vendor/brain-catalog.js +1 -1
- package/vendor/desktop/vendor/byok-catalog.js +1 -1
- package/vendor/desktop/vendor/credits.js +45 -0
- package/vendor/desktop/vendor/faces/cli/package.json +3 -2
- package/vendor/desktop/vendor/faces/cli/src/app.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/chatflow.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/commands.js +3 -1
- package/vendor/desktop/vendor/faces/cli/src/config.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/engine.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/history.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/models.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/overlays.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/panels.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/client/brain-catalog.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/client/byok-catalog.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/client/credits.js +45 -0
- package/vendor/desktop/vendor/faces/cli/vendor/client/foreign-sessions.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/client/naming.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/client/prefs.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/client/session-search.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/claude-pro.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/engine.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/integrity.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/perm-rules.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/perm-store.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/perm-write.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/pro-sessions.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-appcontainer.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-bwrap.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-seatbelt.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/shell.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/tools.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/settings.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/main.js +4 -2
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/renderer/usage.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/mcp/admission.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/mcp/server.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/one/src/child.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/one/src/permissions.js +1 -1
- package/vendor/desktop/vendor/foreign-sessions.js +3 -0
- package/vendor/desktop/vendor/naming.js +1 -1
- package/vendor/desktop/vendor/prefs.js +1 -1
- package/vendor/desktop/vendor/sandbox/provenance.json +20 -0
- package/vendor/desktop/vendor/sandbox/x64-linux/bwrap +0 -0
- package/vendor/desktop/vendor/session-search.js +3 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
2
|
+
// AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
//
|
|
5
|
+
// ── "Always allow this command" — persisting an exact rule ─────────────────
|
|
6
|
+
//
|
|
7
|
+
// §3 of ~/plan/agent-safety-plan.md. §2 taught the desktop gate to *read*
|
|
8
|
+
// `~/.aegiscode/permissions.json`. This module is the other direction: the card
|
|
9
|
+
// gains an answer that outlives the window.
|
|
10
|
+
//
|
|
11
|
+
// ## The two defects this closes
|
|
12
|
+
//
|
|
13
|
+
// The gate's only durable-ish answer was "Allow for this session", which is in
|
|
14
|
+
// memory and is keyed on the TOOL NAME (`sessionAllowlists`, engine.js). So:
|
|
15
|
+
//
|
|
16
|
+
// scope approving one `exec` allowed EVERY `exec` for the rest of the
|
|
17
|
+
// conversation — `npm test` was approved, and `rm -rf ~/work` was
|
|
18
|
+
// thereby also approved. The user answered about a command and the
|
|
19
|
+
// engine remembered a tool.
|
|
20
|
+
// lifetime "this session" is cleared by `newChat()` and never survives a
|
|
21
|
+
// restart, so the same safe `npm test` was re-asked every morning.
|
|
22
|
+
//
|
|
23
|
+
// Persisting an exact rule fixes both at once: the rule is the *command*, and
|
|
24
|
+
// it is in the shared store the CLI already reads, so one face's answer governs
|
|
25
|
+
// the other.
|
|
26
|
+
//
|
|
27
|
+
// ## Why the rule is composed, never globbed from the command
|
|
28
|
+
//
|
|
29
|
+
// The tempting implementation is `exec(${command})`. It is wrong, and the rule
|
|
30
|
+
// grammar is why: `globToRegex` (cli/src/permissions.js) maps `*` to `.*` and
|
|
31
|
+
// has NO escape syntax for a literal one. A command the user approved that
|
|
32
|
+
// happens to contain `*` — `ls *.js`, `find . -name '*.tmp' -delete` — would be
|
|
33
|
+
// persisted as a WILDCARD wider than what they clicked. So a subject containing
|
|
34
|
+
// `*`, `?` or a newline is refused rather than approximated: the card's other
|
|
35
|
+
// three answers remain, and this one declines with a reason. Widening a
|
|
36
|
+
// permission because the input could not be expressed honestly is the exact
|
|
37
|
+
// class of bug this whole plan exists to prevent.
|
|
38
|
+
//
|
|
39
|
+
// ## What a persisted rule may NOT be
|
|
40
|
+
//
|
|
41
|
+
// `exec` with no pattern matches every shell call, and an allow rule is
|
|
42
|
+
// consulted BEFORE the multi-`cd` rail (`evalPermission`: deny, allow,
|
|
43
|
+
// isMultiDirCommand, ask, explicitAsk). Persisting one would therefore disable
|
|
44
|
+
// that rail permanently — silently, with the gate still looking healthy. So an
|
|
45
|
+
// empty subject is refused: no subject, no rule.
|
|
46
|
+
//
|
|
47
|
+
// A multi-`cd` command is treated differently, and deliberately: the exact
|
|
48
|
+
// string is stored (`exec(cd a && cd b && ls)`), which suppresses the rail for
|
|
49
|
+
// THAT command only. The rail's purpose is per-invocation scrutiny of a command
|
|
50
|
+
// that changes directories twice; a rule that can only ever match the precise
|
|
51
|
+
// string the user was shown and clicked does not remove that scrutiny from any
|
|
52
|
+
// other command. A bare/wildcard form would, which is why those stay refused.
|
|
53
|
+
//
|
|
54
|
+
// ## The writer is the CLI's, deliberately
|
|
55
|
+
//
|
|
56
|
+
// Rules are written through `cli/src/config.js`'s `addPermissionRule` +
|
|
57
|
+
// `savePermissions` — the same pair `/permissions` uses — so there is one rule
|
|
58
|
+
// schema and one file format (D8 rule 1). This module composes a string and
|
|
59
|
+
// delegates; it never writes JSON itself. `explicitAsk` is stripped before
|
|
60
|
+
// saving because it is DERIVED from `defaultMode` at read time, and persisting
|
|
61
|
+
// it produces the disagreeing-file bug `saveRuleMode` documents.
|
|
62
|
+
|
|
63
|
+
'use strict';
|
|
64
|
+
|
|
65
|
+
const { loadShared } = require('./perm-rules.js');
|
|
66
|
+
|
|
67
|
+
// ── Composing the rule ────────────────────────────────────────────────────
|
|
68
|
+
|
|
69
|
+
/** Characters the rule grammar cannot express literally. `*` and `?` are its
|
|
70
|
+
* wildcards and `globToRegex` offers no escape; a newline does not match
|
|
71
|
+
* `RULE_RE`'s `.*` at all, so a multi-line command would half-match or not
|
|
72
|
+
* match while still being stored. */
|
|
73
|
+
const INEXPRESSIBLE = /[*?\n\r]/;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Build the exact rule for one approved call.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} name tool name as the engine spells it (`exec`, `writeFile`)
|
|
79
|
+
* @param {object} args normalised args
|
|
80
|
+
* @param {object} [opts]
|
|
81
|
+
* @param {object} [opts.dir] override the module-layout search root (tests)
|
|
82
|
+
* @returns {{ok: boolean, rule?: string, subject?: string, reason?: string}}
|
|
83
|
+
* `ok: false` is a refusal, not an error — the caller keeps the card's other
|
|
84
|
+
* answers and shows `reason`.
|
|
85
|
+
*/
|
|
86
|
+
function composeRule(name, args, opts = {}) {
|
|
87
|
+
const tool = String(name || '').trim();
|
|
88
|
+
if (!tool) return { ok: false, reason: 'no tool name' };
|
|
89
|
+
|
|
90
|
+
const shared = loadShared(opts.dir);
|
|
91
|
+
if (!shared) return { ok: false, reason: 'one/src/permissions.js not found' };
|
|
92
|
+
|
|
93
|
+
let subjectFor;
|
|
94
|
+
try {
|
|
95
|
+
subjectFor = shared.permissions.loadEvaluator().subjectFor;
|
|
96
|
+
} catch (e) {
|
|
97
|
+
return { ok: false, reason: (e && e.message) || String(e) };
|
|
98
|
+
}
|
|
99
|
+
if (typeof subjectFor !== 'function') return { ok: false, reason: 'rule evaluator is incomplete' };
|
|
100
|
+
|
|
101
|
+
const subject = subjectFor(tool, args || {});
|
|
102
|
+
// An empty subject means the tool carries no addressable target (a bare
|
|
103
|
+
// `exec` with no command, say). Persisting that would be a tool-wide allow —
|
|
104
|
+
// see the header on the multi-`cd` rail.
|
|
105
|
+
if (!subject) return { ok: false, reason: 'this call has no command or path to scope a rule to' };
|
|
106
|
+
if (INEXPRESSIBLE.test(subject)) {
|
|
107
|
+
return {
|
|
108
|
+
ok: false,
|
|
109
|
+
reason: 'this command contains a wildcard character, which the rule language cannot match literally',
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The rule grammar's own limit: `RULE_RE` is `^(\w+)(?:\((.*)\))?$` and `.*`
|
|
114
|
+
// is greedy, so a subject whose own parentheses balance is safe (the last `)`
|
|
115
|
+
// closes the rule) — but one that *ends* in `)` still parses correctly for the
|
|
116
|
+
// same reason. Verified in test/local-perm-write.test.mjs rather than assumed.
|
|
117
|
+
return { ok: true, rule: `${tool}(${subject})`, subject, tool };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** A human label for the card, so the button can say what it will store. */
|
|
121
|
+
function describeRule(name, args, opts = {}) {
|
|
122
|
+
const composed = composeRule(name, args, opts);
|
|
123
|
+
return composed.ok ? composed.rule : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ── Persisting it ─────────────────────────────────────────────────────────
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Append an exact allow rule to the shared permission file.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} rule from `composeRule`
|
|
132
|
+
* @param {object} [opts]
|
|
133
|
+
* @param {object} [opts.dir] layout override (tests)
|
|
134
|
+
* @param {object} [opts.config] injected config-store module (tests) — when
|
|
135
|
+
* present the real file is never read or written
|
|
136
|
+
* @returns {{ok: boolean, added?: boolean, rules?: object, source?: string, reason?: string}}
|
|
137
|
+
*/
|
|
138
|
+
function persistAllow(rule, opts = {}) {
|
|
139
|
+
if (!rule || typeof rule !== 'string') return { ok: false, reason: 'no rule to persist' };
|
|
140
|
+
|
|
141
|
+
let config = opts.config;
|
|
142
|
+
if (!config) {
|
|
143
|
+
const shared = loadShared(opts.dir);
|
|
144
|
+
if (!shared) return { ok: false, reason: 'one/src/permissions.js not found' };
|
|
145
|
+
try {
|
|
146
|
+
config = shared.permissions.loadConfigStore();
|
|
147
|
+
} catch (e) {
|
|
148
|
+
return { ok: false, reason: (e && e.message) || String(e) };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!config || typeof config.addPermissionRule !== 'function' || typeof config.savePermissions !== 'function') {
|
|
152
|
+
return { ok: false, reason: 'the permissions store is unavailable, so no rule was written' };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let current;
|
|
156
|
+
try {
|
|
157
|
+
current = typeof config.loadPermissions === 'function' ? config.loadPermissions() : {};
|
|
158
|
+
} catch (e) {
|
|
159
|
+
return { ok: false, reason: (e && e.message) || String(e) };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// `explicitAsk` is derived from `defaultMode` by loadPermissions() and is not
|
|
163
|
+
// a field of the file. Saving it back would leave a file that disagrees with
|
|
164
|
+
// itself — the bug cli/src/config.js's saveRuleMode documents at length.
|
|
165
|
+
const { explicitAsk, ...rest } = current || {};
|
|
166
|
+
const base = {
|
|
167
|
+
defaultMode: rest.defaultMode === 'allow' || rest.defaultMode === 'deny' ? rest.defaultMode : 'ask',
|
|
168
|
+
allow: Array.isArray(rest.allow) ? rest.allow : [],
|
|
169
|
+
deny: Array.isArray(rest.deny) ? rest.deny : [],
|
|
170
|
+
ask: Array.isArray(rest.ask) ? rest.ask : [],
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
let next;
|
|
174
|
+
try {
|
|
175
|
+
const res = config.addPermissionRule('allow', rule, base);
|
|
176
|
+
next = res && res.rules ? res.rules : base;
|
|
177
|
+
if (res && res.added === false) return { ok: true, added: false, rules: next, source: 'store' };
|
|
178
|
+
config.savePermissions(next);
|
|
179
|
+
} catch (e) {
|
|
180
|
+
return { ok: false, reason: (e && e.message) || String(e) };
|
|
181
|
+
}
|
|
182
|
+
return { ok: true, added: true, rules: next, source: 'store' };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The whole answer: compose and persist in one call, in that order, so an
|
|
187
|
+
* inexpressible subject never reaches the writer.
|
|
188
|
+
*
|
|
189
|
+
* @returns {{ok: boolean, rule?: string, added?: boolean, reason?: string}}
|
|
190
|
+
*/
|
|
191
|
+
function alwaysAllow(name, args, opts = {}) {
|
|
192
|
+
const composed = composeRule(name, args, opts);
|
|
193
|
+
if (!composed.ok) return { ok: false, reason: composed.reason };
|
|
194
|
+
const saved = persistAllow(composed.rule, opts);
|
|
195
|
+
if (!saved.ok) return { ok: false, rule: composed.rule, reason: saved.reason };
|
|
196
|
+
return { ok: true, rule: composed.rule, added: saved.added !== false };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
module.exports = { composeRule, describeRule, persistAllow, alwaysAllow };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
"use strict";const fs=require("node:fs"),os=require("node:os"),path=require("node:path"),MAX_ENTRIES=200;function storePath(e=process.env){const t=e||{},r=process.env||{},n=t.AEGIS_PRO_SESSIONS_FILE||r.AEGIS_PRO_SESSIONS_FILE;if(n)return n;const s=t.AEGISCODE_HOME||t.AEGIS_HOME||r.AEGISCODE_HOME||r.AEGIS_HOME;return path.join(s?path.resolve(String(s).trim()):path.join(os.homedir(),".aegiscode"),"pro-sessions.json")}function read(e=process.env){try{const t=fs.readFileSync(storePath(e),"utf8"),r=JSON.parse(t);if(!r||"object"!=typeof r||Array.isArray(r))return{};const n={};for(const[e,t]of Object.entries(r))t&&"object"==typeof t&&"string"==typeof t.id&&t.id&&(n[e]={id:t.id,at:Number(t.at)||0});return n}catch{return{}}}function prune(e){const t=Object.keys(e);if(t.length<=MAX_ENTRIES)return e;t.sort(((t,r)=>(e[r].at||0)-(e[t].at||0)));const r={};for(const n of t.slice(0,MAX_ENTRIES))r[n]=e[n];return r}function write(e,t=process.env){try{const r=storePath(t);fs.mkdirSync(path.dirname(r),{recursive:!0});const n=`${r}.${process.pid}.tmp`;return fs.writeFileSync(n,JSON.stringify(prune(e),null,2),{mode:384}),fs.renameSync(n,r),!0}catch{return!1}}function get(e,t=process.env){if(!e)return null;const r=read(t);return r[e]?r[e].id:null}function set(e,t,r=process.env){if(!e||"string"!=typeof t||!t)return!1;const n=read(r);return n[e]={id:t,at:Date.now()},write(n,r)}function del(e,t=process.env){if(!e)return!1;const r=read(t);return!r[e]||(delete r[e],write(r,t))}module.exports={storePath:storePath,read:read,write:write,get:get,set:set,del:del,MAX_ENTRIES:MAX_ENTRIES};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
+
// AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
|
|
4
|
+
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
+
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* sandbox-appcontainer.js — the Windows mechanism behind `sandbox.js` (plan §1e).
|
|
10
|
+
*
|
|
11
|
+
* ── The disagreement this file is named after ────────────────────────────────
|
|
12
|
+
*
|
|
13
|
+
* Linux has `bwrap` and macOS has `sandbox-exec`: both are *wrappers* that take
|
|
14
|
+
* a child argv and exec it confined, so a per-command bound is a argv prefix and
|
|
15
|
+
* the whole thing is pure construction. **Windows has no equivalent wrapper.**
|
|
16
|
+
* AppContainer confinement is not something you pass a command to; it is a set
|
|
17
|
+
* of token attributes applied to a process BEFORE it starts, via
|
|
18
|
+
* `CreateProcessAsUser`/`UpdateProcThreadAttribute` with a security-capability
|
|
19
|
+
* SID — a native Win32 sequence with no command-line surface at all.
|
|
20
|
+
*
|
|
21
|
+
* So there are exactly three honest options, and this file picks the third:
|
|
22
|
+
*
|
|
23
|
+
* 1. **Fake it.** Emit an "unavailable"/"degraded" sandwich that prints
|
|
24
|
+
* "sandbox: workspace-write" while nothing is confined. Forbidden — that is
|
|
25
|
+
* the false assurance `sandbox.js`'s header spends a paragraph outlawing.
|
|
26
|
+
* 2. **Shell out to PowerShell to build a job object.** `New-JobObject` does
|
|
27
|
+
* not exist; PowerShell has no AppContainer API. A job object can bound
|
|
28
|
+
* process count, CPU and memory, but NOT filesystem access — which is the
|
|
29
|
+
* entire point of the policy. So this would confine the wrong axis and
|
|
30
|
+
* would be reported as a file bound it does not provide.
|
|
31
|
+
* 3. **Report the truth and refuse to claim the mode.** `detect()` returns
|
|
32
|
+
* unavailable with a specific reason, `sandbox.js`'s existing contract
|
|
33
|
+
* turns that into a loud degrade, and `strict: true` refuses to spawn.
|
|
34
|
+
* Everything below is written so that the *moment* a helper binary exists
|
|
35
|
+
* it can be wired in without touching the policy layer.
|
|
36
|
+
*
|
|
37
|
+
* ── What the helper has to be, when someone builds it ────────────────────────
|
|
38
|
+
*
|
|
39
|
+
* A small signed executable — `aegis-sandbox-host.exe` — that:
|
|
40
|
+
*
|
|
41
|
+
* · creates an AppContainer profile (`CreateAppContainerProfile`) whose
|
|
42
|
+
* security-capability SID is derived per workspace, or reuses a cached one;
|
|
43
|
+
* · grants that SID ACLs on exactly the policy's write grants, and REMOVES it
|
|
44
|
+
* everywhere else (`SetEntriesInAcl` on the workspace root is not enough —
|
|
45
|
+
* the inherited-DACL walk is what people get wrong);
|
|
46
|
+
* · starts the child with `PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES`;
|
|
47
|
+
* · adds a job object with `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE` so a killed
|
|
48
|
+
* turn does not orphan a detached process tree (bwrap's
|
|
49
|
+
* `--die-with-parent`, which Windows does not provide for free);
|
|
50
|
+
* · removes the capability SID from the profile on exit, or the next run
|
|
51
|
+
* reuses a grant nobody re-approved.
|
|
52
|
+
*
|
|
53
|
+
* That is a native project, not a JS one. `helperCandidates()` below is the
|
|
54
|
+
* single place its path would be named, so the wiring is a one-line change to
|
|
55
|
+
* `detect()` rather than a redesign.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
const fs = require('node:fs');
|
|
59
|
+
const path = require('node:path');
|
|
60
|
+
|
|
61
|
+
/** Where a vendored helper would live, relative to the app dir. */
|
|
62
|
+
const VENDOR_REL = path.join('vendor', 'sandbox');
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The executable a future implementation would wrap.
|
|
66
|
+
*
|
|
67
|
+
* Named `host` rather than `bwrap` deliberately: it is not a wrapper in the
|
|
68
|
+
* bwrap sense (argv prefix), it is a launcher that applies token attributes and
|
|
69
|
+
* then starts the child, so the file+args shape differs. Pretending it is a
|
|
70
|
+
* bwrap drop-in would make the eventual implementation a rewrite of `wrap()`.
|
|
71
|
+
*/
|
|
72
|
+
function helperCandidates(appDir, env = process.env) {
|
|
73
|
+
const out = [];
|
|
74
|
+
if (env && env.AEGIS_SANDBOX_HOST) out.push(String(env.AEGIS_SANDBOX_HOST));
|
|
75
|
+
if (appDir) {
|
|
76
|
+
out.push(path.join(appDir, VENDOR_REL, `${process.arch}-win32`, 'aegis-sandbox-host.exe'));
|
|
77
|
+
out.push(path.join(appDir, VENDOR_REL, 'win32', 'aegis-sandbox-host.exe'));
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** First existing helper, or null. */
|
|
83
|
+
function findHelper(appDir, env) {
|
|
84
|
+
for (const c of helperCandidates(appDir, env)) {
|
|
85
|
+
try {
|
|
86
|
+
const st = fs.statSync(c);
|
|
87
|
+
if (st.isFile()) return c;
|
|
88
|
+
} catch {
|
|
89
|
+
/* try the next candidate */
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Report availability truthfully.
|
|
97
|
+
*
|
|
98
|
+
* Two distinct unavailable reasons, because they mean different things to
|
|
99
|
+
* whoever reads the transcript:
|
|
100
|
+
*
|
|
101
|
+
* · no helper at all → `reason` names the missing mechanism
|
|
102
|
+
* · helper present, unproven → still unavailable, because a present binary
|
|
103
|
+
* that has never been exercised is not evidence it confines. A probe (start
|
|
104
|
+
* a child that must fail to write outside the grant) is the only thing that
|
|
105
|
+
* would make it available, and it is not written yet — this function says
|
|
106
|
+
* so instead of trusting the file's existence.
|
|
107
|
+
*
|
|
108
|
+
* If a helper appears AND a probe is supplied, this returns available. That is
|
|
109
|
+
* the seam: implementation work lands in `probeHelper`, not in this contract.
|
|
110
|
+
*/
|
|
111
|
+
function detect({ appDir, env = process.env, platform = process.platform, probe } = {}) {
|
|
112
|
+
if (platform !== 'win32') {
|
|
113
|
+
return {
|
|
114
|
+
available: false,
|
|
115
|
+
path: null,
|
|
116
|
+
reason: `no win32 mechanism on ${platform}`,
|
|
117
|
+
probed: false,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const bin = findHelper(appDir, env);
|
|
121
|
+
if (!bin) {
|
|
122
|
+
return {
|
|
123
|
+
available: false,
|
|
124
|
+
path: null,
|
|
125
|
+
reason:
|
|
126
|
+
'AppContainer has no command-line wrapper; a signed aegis-sandbox-host.exe is required and is not shipped',
|
|
127
|
+
probed: false,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (typeof probe !== 'function') {
|
|
131
|
+
return {
|
|
132
|
+
available: false,
|
|
133
|
+
path: bin,
|
|
134
|
+
reason: 'aegis-sandbox-host.exe present but unproven — no confinement probe is implemented',
|
|
135
|
+
probed: false,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const res = probe(bin);
|
|
139
|
+
if (res && res.ok) {
|
|
140
|
+
return { available: true, path: bin, reason: null, probed: true, mechanism: 'appcontainer' };
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
available: false,
|
|
144
|
+
path: bin,
|
|
145
|
+
reason: (res && res.reason) || 'aegis-sandbox-host probe failed',
|
|
146
|
+
probed: true,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Build the launcher argv for one command — shaped for the helper described in
|
|
152
|
+
* the header, not for bwrap.
|
|
153
|
+
*
|
|
154
|
+
* Kept here (rather than omitted) so the policy→argv translation is reviewable
|
|
155
|
+
* and testable on any host, and so the eventual native author has the exact
|
|
156
|
+
* contract to implement against. It is NOT reachable from production today:
|
|
157
|
+
* `detect()` cannot return available without a real helper and a real probe, and
|
|
158
|
+
* `sandbox.js` refuses to spawn a wrapped command when the state is unavailable.
|
|
159
|
+
*/
|
|
160
|
+
function wrap(policyInput, command, opts = {}) {
|
|
161
|
+
const { host, workspace, argv = [], cwd } = opts;
|
|
162
|
+
if (!host) return { ok: false, reason: 'no aegis-sandbox-host binary' };
|
|
163
|
+
const policy = policyInput || {};
|
|
164
|
+
if (policy.mode === 'off') return { ok: false, reason: 'sandbox disabled by policy' };
|
|
165
|
+
|
|
166
|
+
const ws = workspace ? path.resolve(workspace) : null;
|
|
167
|
+
const entries = (policy.fileSystem && Array.isArray(policy.fileSystem.entries))
|
|
168
|
+
? policy.fileSystem.entries
|
|
169
|
+
: [];
|
|
170
|
+
|
|
171
|
+
// Root write is refused for the same reason as on the other platforms: honouring
|
|
172
|
+
// it would make the confinement a no-op while the state still said "sandboxed".
|
|
173
|
+
for (const e of entries) {
|
|
174
|
+
if (!e || e.access !== 'write') continue;
|
|
175
|
+
const p = e.path;
|
|
176
|
+
if (p && p.type === 'special' && p.value && p.value.kind === 'root') {
|
|
177
|
+
return {
|
|
178
|
+
ok: false,
|
|
179
|
+
policyFault: true,
|
|
180
|
+
reason: 'policy grants write to the filesystem root, which a sandbox cannot honour',
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const grants = [];
|
|
186
|
+
let tmpGrant = false;
|
|
187
|
+
for (const e of entries) {
|
|
188
|
+
if (!e || e.access !== 'write') continue;
|
|
189
|
+
const p = e.path;
|
|
190
|
+
if (!p) continue;
|
|
191
|
+
if (p.type === 'special') {
|
|
192
|
+
if (p.value && p.value.kind === 'slash_tmp') tmpGrant = true;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (p.type !== 'path' || typeof p.path !== 'string' || !p.path) continue;
|
|
196
|
+
grants.push(path.resolve(p.path));
|
|
197
|
+
}
|
|
198
|
+
if (ws && policy.mode === 'workspace-write' && !grants.includes(ws)) grants.push(ws);
|
|
199
|
+
|
|
200
|
+
// The helper takes the grant list explicitly rather than reading the policy
|
|
201
|
+
// itself: the policy vocabulary lives in one module, and a native copy of it
|
|
202
|
+
// would drift the moment `normalize()` changed.
|
|
203
|
+
const out = [host];
|
|
204
|
+
out.push('--mode', String(policy.mode));
|
|
205
|
+
out.push('--network', policy.network === 'open' ? 'open' : 'restricted');
|
|
206
|
+
if (tmpGrant) out.push('--grant-tmp');
|
|
207
|
+
for (const g of grants) out.push('--grant-write', g);
|
|
208
|
+
if (cwd) out.push('--cwd', String(cwd));
|
|
209
|
+
out.push('--');
|
|
210
|
+
for (const a of argv) out.push(String(a));
|
|
211
|
+
out.push(String(command));
|
|
212
|
+
return { ok: true, argv: out, guarantee: 'capability', pending: true };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The sentence the UI prints.
|
|
217
|
+
*
|
|
218
|
+
* Same rule as elsewhere: never claim enforcement that did not run. On Windows
|
|
219
|
+
* this will read to a user as "not supported yet", which is the truth.
|
|
220
|
+
*/
|
|
221
|
+
function describe(state, policy) {
|
|
222
|
+
if (!state || !state.available) {
|
|
223
|
+
return `sandbox: OFF — ${(state && state.reason) || 'unavailable'} (commands run with full user access)`;
|
|
224
|
+
}
|
|
225
|
+
const mode = (policy && policy.mode) || 'workspace-write';
|
|
226
|
+
const net = (policy && policy.network) === 'open' ? 'network open' : 'network restricted';
|
|
227
|
+
return `sandbox: ${mode} via AppContainer — ${net}`;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module.exports = {
|
|
231
|
+
name: 'win32',
|
|
232
|
+
mechanism: 'appcontainer',
|
|
233
|
+
guarantee: 'capability',
|
|
234
|
+
/** True when the mechanism exists in this build. Wired to reality, not hope. */
|
|
235
|
+
implemented: false,
|
|
236
|
+
VENDOR_REL,
|
|
237
|
+
helperCandidates,
|
|
238
|
+
findHelper,
|
|
239
|
+
detect,
|
|
240
|
+
wrap,
|
|
241
|
+
describe,
|
|
242
|
+
};
|