fullcourtdefense-cli 1.35.10 → 1.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actionPolicyEngine.d.ts +24 -0
- package/dist/actionPolicyEngine.js +79 -19
- package/dist/approvalPrompt.d.ts +15 -0
- package/dist/approvalPrompt.js +157 -20
- package/dist/askDialog.d.ts +2 -0
- package/dist/askDialog.js +15 -1
- package/dist/askHeader.d.ts +81 -0
- package/dist/askHeader.js +573 -0
- package/dist/blockExplanation.d.ts +9 -0
- package/dist/blockExplanation.js +14 -0
- package/dist/callerEnv.d.ts +1 -1
- package/dist/callerEnv.js +14 -0
- package/dist/cloudGrant.d.ts +46 -0
- package/dist/cloudGrant.js +420 -0
- package/dist/cloudGrantTools.d.ts +97 -0
- package/dist/cloudGrantTools.js +1112 -0
- package/dist/commandNarrative.d.ts +8 -0
- package/dist/commandNarrative.js +222 -49
- package/dist/commands/cmdGuard.js +3 -1
- package/dist/commands/daemon.js +56 -2
- package/dist/commands/deterministicGuard.d.ts +70 -4
- package/dist/commands/deterministicGuard.js +494 -63
- package/dist/commands/discover.js +50 -16
- package/dist/commands/discoverAgentFiles.d.ts +2 -0
- package/dist/commands/discoverAgentFiles.js +1 -0
- package/dist/commands/discoverPaths.d.ts +4 -0
- package/dist/commands/discoverPaths.js +19 -1
- package/dist/commands/discoverProjectRoots.d.ts +72 -0
- package/dist/commands/discoverProjectRoots.js +327 -0
- package/dist/commands/discoverProxy.d.ts +1 -1
- package/dist/commands/discoverProxy.js +1 -1
- package/dist/commands/discoverSecrets.d.ts +44 -0
- package/dist/commands/discoverSecrets.js +158 -14
- package/dist/commands/hook.js +25 -10
- package/dist/commands/knownMcpServers.d.ts +8 -2
- package/dist/commands/knownMcpServers.js +33 -2
- package/dist/commands/mcpGateway.js +9 -7
- package/dist/commands/posixShellGuard.js +1 -1
- package/dist/commands/shellGuard.js +86 -26
- package/dist/commands/uninstallAll.d.ts +1 -7
- package/dist/commands/uninstallAll.js +6 -45
- package/dist/commands/watchdog.js +17 -3
- package/dist/config.d.ts +1 -1
- package/dist/config.js +3 -3
- package/dist/credentialGrant.d.ts +48 -0
- package/dist/credentialGrant.js +29 -18
- package/dist/credentialStore.js +1 -1
- package/dist/devConfirm.d.ts +51 -3
- package/dist/devConfirm.js +226 -33
- package/dist/distress.d.ts +2 -0
- package/dist/distress.js +2 -0
- package/dist/grantTargets.d.ts +21 -0
- package/dist/grantTargets.js +235 -0
- package/dist/localSafetySnapshot.js +2 -0
- package/dist/msiProductCode.d.ts +10 -0
- package/dist/msiProductCode.js +124 -0
- package/dist/notify.js +1 -0
- package/dist/selfTest.d.ts +1 -1
- package/dist/selfTest.js +1 -1
- package/dist/selfUpdate.d.ts +108 -0
- package/dist/selfUpdate.js +353 -18
- package/dist/shellAst.d.ts +2 -0
- package/dist/shellAst.js +7 -1
- package/dist/shellAstLoader.js +14 -1
- package/dist/telemetry.d.ts +3 -0
- package/dist/telemetry.js +1 -0
- package/dist/version.json +1 -1
- package/installer/macos/guardian/ai.fullcourtdefense.guardian.plist +19 -0
- package/installer/macos/guardian/fcd-guardian.sh +590 -0
- package/installer/macos/guardian/install-guardian.sh +32 -0
- package/installer/macos/guardian/uninstall-guardian.sh +12 -0
- package/installer/windows/README.md +88 -0
- package/installer/windows/rescue/FullCourtDefense-Rescue.ps1 +229 -0
- package/package.json +11 -1
package/dist/devConfirm.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AlwaysCovers, type AskSubject, type NativeDialogView } from './approvalPrompt';
|
|
1
2
|
import { type CredentialGrantBinding, type CredentialRuleFacts } from './credentialGrant';
|
|
2
3
|
export { isCiEnvironment, isHumanPresent } from './callerEnv';
|
|
3
4
|
export type ConfirmRemember = 'none' | 'session' | '1h';
|
|
@@ -44,9 +45,30 @@ export interface NativeDialogOptions {
|
|
|
44
45
|
alwaysScopeLabel?: string;
|
|
45
46
|
/** How long / how many times it would hold, e.g. "30 days" or "7 days or 20 uses". */
|
|
46
47
|
alwaysLimitsLabel?: string;
|
|
48
|
+
/** What / How / Where the grant covers (`grantCoverage`), shown as one compact row. */
|
|
49
|
+
alwaysCovers?: AlwaysCovers;
|
|
50
|
+
/** Two buttons: why "Always allow" is not offered (`grantNotOfferedReason`), one short line. */
|
|
51
|
+
alwaysNotOffered?: string;
|
|
52
|
+
/** Envelope facts for the "Why you're asked" header (grant scope, rule id). */
|
|
53
|
+
subject?: AskSubject;
|
|
47
54
|
/** Icon and copy. Buttons stay Deny / Allow once / Always allow for `ask`. */
|
|
48
55
|
tone?: 'ask' | 'approval' | 'block';
|
|
49
56
|
}
|
|
57
|
+
/** Card HTML for macOS WKWebView. Button labels stay the existing Deny / Allow once / Always allow. */
|
|
58
|
+
export declare function dialogCardHtml(view: NativeDialogView, options: NativeDialogOptions): string;
|
|
59
|
+
/**
|
|
60
|
+
* The layout facts for the Windows card, base64 JSON, written to the dialog's STDIN.
|
|
61
|
+
* `-EncodedCommand` carries the script as UTF-16 base64 and Windows caps a command line
|
|
62
|
+
* at 32,767 characters: with the view inside it, a long script (a 9-step token query)
|
|
63
|
+
* failed to spawn and the ask silently fell back to the IDE card.
|
|
64
|
+
*/
|
|
65
|
+
export declare function windowsDialogPayload(view: NativeDialogView): string;
|
|
66
|
+
/**
|
|
67
|
+
* Windows branded card. Compact prompt text stays the first payload so tests still
|
|
68
|
+
* read the dialog copy; layout facts arrive on stdin (`windowsDialogPayload`).
|
|
69
|
+
* Exit codes: 0 = Allow once, 3 = Always allow, 2 = timed out, anything else = Deny.
|
|
70
|
+
*/
|
|
71
|
+
export declare function windowsDialogScript(message: string, timeoutSeconds: number, options: NativeDialogOptions, title: string, view: NativeDialogView): string;
|
|
50
72
|
export declare function confirmNativeActionDetailed(reason: string, timeoutMs?: number, options?: NativeDialogOptions): Promise<{
|
|
51
73
|
outcome: NativeDialogOutcome;
|
|
52
74
|
latencyMs: number;
|
|
@@ -125,12 +147,31 @@ export interface GrantScope {
|
|
|
125
147
|
operation: string;
|
|
126
148
|
/** Host the action reaches (engine `destination.domain`), when any. */
|
|
127
149
|
destinationDomain?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Remote-control bridges the action starts, as `<package> <mode>`
|
|
152
|
+
* (`@wonderwhy-er/desktop-commander remote`). The launcher (`npx`, `npm exec`,
|
|
153
|
+
* `pnpm dlx`, `bunx`) is never a program of such a grant: a grant for one
|
|
154
|
+
* bridge covers that bridge in that mode, never another bridge or another npx tool.
|
|
155
|
+
*/
|
|
156
|
+
bridges?: string[];
|
|
128
157
|
/**
|
|
129
158
|
* Credential-command rules only: where the credential goes and which secret
|
|
130
159
|
* is read (`credentialGrant.ts`). A grant without it (recorded before the
|
|
131
160
|
* binding existed) never covers a credential-rule ask — asked again.
|
|
132
161
|
*/
|
|
133
162
|
credential?: CredentialGrantBinding;
|
|
163
|
+
/**
|
|
164
|
+
* Shell only, when the line runs a cloud CLI: `gcloud|<how>|<where>` per use,
|
|
165
|
+
* sorted and unique (`cloudGrant.ts`). A grant without it (recorded before
|
|
166
|
+
* the binding existed) never covers a cloud line — asked again.
|
|
167
|
+
*/
|
|
168
|
+
cloud?: string[];
|
|
169
|
+
/**
|
|
170
|
+
* Set when the rule that asked is about a removal that can never be granted
|
|
171
|
+
* (home folder, a drive, the filesystem root): no Always allow is offered,
|
|
172
|
+
* none is stored, and no standing grant covers it. Not part of the grant key.
|
|
173
|
+
*/
|
|
174
|
+
refusal?: 'destructive_scope';
|
|
134
175
|
}
|
|
135
176
|
/**
|
|
136
177
|
* A developer's standing "Always allow" for one scope under one rule. Bound to the
|
|
@@ -337,10 +378,13 @@ export declare function shellProgramsForRule(command: string, ruleCommands?: rea
|
|
|
337
378
|
export declare function splitLocalSafetyRuleIds(matchedRule?: string): string[] | undefined;
|
|
338
379
|
/**
|
|
339
380
|
* Can "Always allow" exist for this scope at all? Not for a shell line whose
|
|
340
|
-
* programs could not be read (empty set)
|
|
341
|
-
* destination or secret could not be read
|
|
342
|
-
* outside its issuer
|
|
381
|
+
* programs could not be read (empty set), not for a credential line whose
|
|
382
|
+
* destination or secret could not be read or that sends the credential
|
|
383
|
+
* outside its issuer, and not for a cloud line that deletes, changes
|
|
384
|
+
* permissions or whose target cannot be read. The dialog offers two
|
|
385
|
+
* buttons and says why in one line; no grant matches.
|
|
343
386
|
*/
|
|
387
|
+
export declare function grantNotOfferedReason(scope: GrantScope): string | undefined;
|
|
344
388
|
export declare function grantOffered(scope: GrantScope): boolean;
|
|
345
389
|
/** The caps a grant for this scope is created under: credential grants live 7 days at most. */
|
|
346
390
|
export declare function capGrantLimitsForScope(limits: GrantLimits | null, scope: GrantScope): GrantLimits | null;
|
|
@@ -384,6 +428,8 @@ export declare function describeGrantScope(scope: GrantScope, rule?: {
|
|
|
384
428
|
policyId?: string;
|
|
385
429
|
policyName?: string;
|
|
386
430
|
}): string;
|
|
431
|
+
/** What / How / Where an "Always allow" covers, as the dialog's compact rows. */
|
|
432
|
+
export declare function grantCoverage(scope: GrantScope): AlwaysCovers;
|
|
387
433
|
/**
|
|
388
434
|
* Which line-level facts the RULE that asked actually depends on. A grant binds
|
|
389
435
|
* the facts the rule fired on and nothing else: `gcloud_access_token_cmd` fired
|
|
@@ -407,6 +453,8 @@ export interface GrantRuleFacts {
|
|
|
407
453
|
* credential goes (issuer domain or exact hosts) and the secret read.
|
|
408
454
|
*/
|
|
409
455
|
credential?: CredentialRuleFacts;
|
|
456
|
+
/** The rule is a home / drive / root delete (`NEVER_GRANTED_ITEMS`): the scope carries a refusal. */
|
|
457
|
+
neverGrant?: boolean;
|
|
410
458
|
}
|
|
411
459
|
/**
|
|
412
460
|
* Derive `GrantRuleFacts` from the source of the ask. Unknown = bound (the
|
package/dist/devConfirm.js
CHANGED
|
@@ -37,6 +37,9 @@ exports.GRANT_MAX_USES_LIMIT = exports.GRANT_TTL_MS = exports.CONFIRMED_ACTION_T
|
|
|
37
37
|
exports.looksLikeClientAutoAnswer = looksLikeClientAutoAnswer;
|
|
38
38
|
exports.confirmNativeAction = confirmNativeAction;
|
|
39
39
|
exports.nativeDialogAvailable = nativeDialogAvailable;
|
|
40
|
+
exports.dialogCardHtml = dialogCardHtml;
|
|
41
|
+
exports.windowsDialogPayload = windowsDialogPayload;
|
|
42
|
+
exports.windowsDialogScript = windowsDialogScript;
|
|
40
43
|
exports.confirmNativeActionDetailed = confirmNativeActionDetailed;
|
|
41
44
|
exports.resolveGrantLimits = resolveGrantLimits;
|
|
42
45
|
exports.describeGrantLimits = describeGrantLimits;
|
|
@@ -56,6 +59,7 @@ exports.scanShellPrograms = scanShellPrograms;
|
|
|
56
59
|
exports.shellPrograms = shellPrograms;
|
|
57
60
|
exports.shellProgramsForRule = shellProgramsForRule;
|
|
58
61
|
exports.splitLocalSafetyRuleIds = splitLocalSafetyRuleIds;
|
|
62
|
+
exports.grantNotOfferedReason = grantNotOfferedReason;
|
|
59
63
|
exports.grantOffered = grantOffered;
|
|
60
64
|
exports.capGrantLimitsForScope = capGrantLimitsForScope;
|
|
61
65
|
exports.findDeveloperGrant = findDeveloperGrant;
|
|
@@ -63,6 +67,7 @@ exports.recordDeveloperGrant = recordDeveloperGrant;
|
|
|
63
67
|
exports.listDeveloperGrants = listDeveloperGrants;
|
|
64
68
|
exports.revokeDeveloperGrants = revokeDeveloperGrants;
|
|
65
69
|
exports.describeGrantScope = describeGrantScope;
|
|
70
|
+
exports.grantCoverage = grantCoverage;
|
|
66
71
|
exports.grantRuleFactsFor = grantRuleFactsFor;
|
|
67
72
|
exports.grantScopeFor = grantScopeFor;
|
|
68
73
|
exports.isConfirmationRemembered = isConfirmationRemembered;
|
|
@@ -98,6 +103,7 @@ const approvalPrompt_1 = require("./approvalPrompt");
|
|
|
98
103
|
const deterministicGuard_1 = require("./commands/deterministicGuard");
|
|
99
104
|
const shellQuoteMask_1 = require("./shellQuoteMask");
|
|
100
105
|
const credentialGrant_1 = require("./credentialGrant");
|
|
106
|
+
const cloudGrant_1 = require("./cloudGrant");
|
|
101
107
|
const callerEnv_1 = require("./callerEnv");
|
|
102
108
|
var callerEnv_2 = require("./callerEnv");
|
|
103
109
|
Object.defineProperty(exports, "isCiEnvironment", { enumerable: true, get: function () { return callerEnv_2.isCiEnvironment; } });
|
|
@@ -158,6 +164,20 @@ function argb(hex) {
|
|
|
158
164
|
const n = hex.replace('#', '');
|
|
159
165
|
return `${parseInt(n.slice(0, 2), 16)},${parseInt(n.slice(2, 4), 16)},${parseInt(n.slice(4, 6), 16)}`;
|
|
160
166
|
}
|
|
167
|
+
/** "Why you're asked" + Command / Action / Where / Always allow. Production is red AND spelled out. */
|
|
168
|
+
function headerHtml(header) {
|
|
169
|
+
const tag = header.tag ? ` · <span class="tag tag-${header.tag}"><span class="tdot"></span>${htmlEsc(header.tag)} (by name)</span>` : '';
|
|
170
|
+
const row = (label, value) => `<tr><th>${htmlEsc(label)}</th><td>${value}</td></tr>`;
|
|
171
|
+
return `<div class="ask${header.tag === 'production' || header.danger ? ' prod' : ''}"><p class="who">${htmlEsc(header.who)}</p><div class="k">Why you're asked</div>
|
|
172
|
+
<p class="lead">${htmlEsc(header.why)}</p><table class="facts">
|
|
173
|
+
${row(header.commandLabel, `<code>${htmlEsc(header.command)}</code>`)}
|
|
174
|
+
${row('Action', htmlEsc(header.action))}
|
|
175
|
+
${header.affects ? row('Affects', header.danger ? `<span class="tag tag-production"><span class="tdot"></span>${htmlEsc(header.affects)}</span>` : htmlEsc(header.affects)) : ''}
|
|
176
|
+
${row('Where', `${htmlEsc(header.where)}${tag}`)}
|
|
177
|
+
${header.secretSentTo ? row(header.secretSentTo.label, htmlEsc(header.secretSentTo.value)) : ''}
|
|
178
|
+
${row('Always allow', htmlEsc(header.always))}
|
|
179
|
+
</table></div>`;
|
|
180
|
+
}
|
|
161
181
|
/** Card HTML for macOS WKWebView. Button labels stay the existing Deny / Allow once / Always allow. */
|
|
162
182
|
function dialogCardHtml(view, options) {
|
|
163
183
|
const theme = toneTheme(view.tone);
|
|
@@ -175,8 +195,15 @@ function dialogCardHtml(view, options) {
|
|
|
175
195
|
h1{margin:0 0 4px;font-size:22px}.sub{color:#64748b;margin:0 0 14px}
|
|
176
196
|
.box{border:1px solid #e2e8f0;border-radius:12px;padding:12px 14px;margin:0 0 10px;background:#f8fafc}
|
|
177
197
|
h2{margin:0 0 6px;font-size:13px}.k{color:#64748b;font-size:11px;font-weight:700}
|
|
178
|
-
.action{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;white-space:pre-wrap;word-break:break-word;background:#fff;border:1px solid #e2e8f0;border-radius:8px;padding:8px 10px;max-height:
|
|
179
|
-
.
|
|
198
|
+
.action{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;white-space:pre-wrap;word-break:break-word;background:#fff;border:1px solid #e2e8f0;border-radius:8px;padding:8px 10px;max-height:132px;overflow:auto}
|
|
199
|
+
.ask{border:1px solid #bfdbfe;background:#eff6ff;border-radius:12px;padding:10px 14px;margin:0 0 10px}.ask.prod{border-color:#fecaca;background:#fef2f2}
|
|
200
|
+
.who{margin:0 0 6px;font-size:13px;font-weight:600;color:#0f172a}
|
|
201
|
+
.lead{margin:2px 0 6px;font-size:14px;font-weight:700}.prod .lead{color:#b91c1c}
|
|
202
|
+
.facts{border-collapse:collapse;width:100%}.facts th{text-align:left;vertical-align:top;color:#64748b;font-size:11px;font-weight:700;width:96px;padding:2px 8px 2px 0;white-space:nowrap}.facts td{padding:2px 0;word-break:break-word}
|
|
203
|
+
.facts code{font:12px/1.4 ui-monospace,Menlo,Consolas,monospace}
|
|
204
|
+
.tag{font-weight:700}.tag-production{color:#b91c1c}.tag-staging{color:#b45309}.tag-dev{color:#475569}
|
|
205
|
+
.tdot{display:inline-block;width:8px;height:8px;border-radius:50%;margin:0 4px 1px 0;background:currentColor}
|
|
206
|
+
.steps{margin:0 0 8px}.steps li{margin:1px 0}.steps .n{color:#64748b;font-weight:700;min-width:18px}
|
|
180
207
|
ul{list-style:none;margin:0;padding:0}li{display:flex;gap:8px;margin:6px 0}
|
|
181
208
|
.dot{width:8px;height:8px;border-radius:50%;margin-top:6px;flex:none}
|
|
182
209
|
.row{display:flex;justify-content:flex-end;gap:8px;align-items:center;margin-top:14px;flex-wrap:wrap}
|
|
@@ -191,12 +218,12 @@ button{font:600 13px/1 -apple-system,Segoe UI,sans-serif;border-radius:8px;paddi
|
|
|
191
218
|
<h1>${htmlEsc(view.headline)}</h1>
|
|
192
219
|
<p class="sub">${htmlEsc(view.subtitle)}</p>
|
|
193
220
|
</div></div>
|
|
194
|
-
|
|
195
|
-
${view.
|
|
196
|
-
${view.
|
|
221
|
+
${view.header ? headerHtml(view.header) : ''}
|
|
222
|
+
${view.header && !view.steps.length && !view.action ? '' : `<div class="box">${view.header ? '' : `<h2>Action</h2>
|
|
223
|
+
${view.kind ? `<div class="k">${htmlEsc(view.kind)}</div>` : ''}`}
|
|
224
|
+
${view.steps.length ? `<div class="k"${view.header ? '' : ' style="margin-top:6px"'}>What it does</div><ol class="steps">${view.steps.map((step, index) => `<li><span class="n">${index + 1}.</span>${htmlEsc(step)}</li>`).join('')}</ol><div class="k">Full script</div>` : ''}
|
|
197
225
|
${view.action ? `<div class="action">${htmlEsc(view.action)}</div>` : '<p class="sub">The action is described in the IDE message.</p>'}
|
|
198
|
-
</div
|
|
199
|
-
${view.policy ? `<div class="box"><h2>Matched policy</h2><div><span class="k">Policy</span> ${htmlEsc(view.policy)}</div>${view.scope ? `<div><span class="k">Scope</span> ${htmlEsc(view.scope)}</div>` : ''}</div>` : ''}
|
|
226
|
+
</div>`}
|
|
200
227
|
<h2>Why it triggered</h2><ul>${bullets(view.why, theme.icon)}</ul>
|
|
201
228
|
<h2>What happens next</h2><ul>${bullets(view.next, '#2563EB')}</ul>
|
|
202
229
|
<div class="row">${always}
|
|
@@ -206,15 +233,24 @@ ${view.policy ? `<div class="box"><h2>Matched policy</h2><div><span class="k">Po
|
|
|
206
233
|
<p class="foot">${htmlEsc(view.footer)}</p>
|
|
207
234
|
</div></body></html>`;
|
|
208
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* The layout facts for the Windows card, base64 JSON, written to the dialog's STDIN.
|
|
238
|
+
* `-EncodedCommand` carries the script as UTF-16 base64 and Windows caps a command line
|
|
239
|
+
* at 32,767 characters: with the view inside it, a long script (a 9-step token query)
|
|
240
|
+
* failed to spawn and the ask silently fell back to the IDE card.
|
|
241
|
+
*/
|
|
242
|
+
function windowsDialogPayload(view) {
|
|
243
|
+
// A multiline WinForms TextBox breaks lines only on CRLF; a bare LF runs every line together.
|
|
244
|
+
return b64(JSON.stringify(view.action ? { ...view, action: view.action.replace(/\r?\n/g, '\r\n') } : view));
|
|
245
|
+
}
|
|
209
246
|
/**
|
|
210
247
|
* Windows branded card. Compact prompt text stays the first payload so tests still
|
|
211
|
-
* read the dialog copy; layout facts
|
|
248
|
+
* read the dialog copy; layout facts arrive on stdin (`windowsDialogPayload`).
|
|
212
249
|
* Exit codes: 0 = Allow once, 3 = Always allow, 2 = timed out, anything else = Deny.
|
|
213
250
|
*/
|
|
214
251
|
function windowsDialogScript(message, timeoutSeconds, options, title, view) {
|
|
215
252
|
const encoded = b64(message);
|
|
216
253
|
const encodedTitle = b64(title);
|
|
217
|
-
const encodedView = b64(JSON.stringify(view));
|
|
218
254
|
const theme = toneTheme(view.tone);
|
|
219
255
|
return [
|
|
220
256
|
`# ${exports.DIALOG_SCRIPT_MARKER}`,
|
|
@@ -222,13 +258,15 @@ function windowsDialogScript(message, timeoutSeconds, options, title, view) {
|
|
|
222
258
|
'[System.Windows.Forms.Application]::EnableVisualStyles()',
|
|
223
259
|
`$msg=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${encoded}'))`,
|
|
224
260
|
`$title=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${encodedTitle}'))`,
|
|
225
|
-
|
|
261
|
+
// The view (windowsDialogPayload) arrives on stdin as base64: ASCII-safe under any console code page.
|
|
262
|
+
"$v=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String([Console]::In.ReadToEnd().Trim())) | ConvertFrom-Json",
|
|
226
263
|
"$bg=[Drawing.Color]::White; $muted=[Drawing.Color]::FromArgb(100,116,139); $ink=[Drawing.Color]::FromArgb(15,23,42)",
|
|
227
264
|
`$accent=[Drawing.Color]::FromArgb(${argb(theme.icon)}); $badgeBg=[Drawing.Color]::FromArgb(${argb(theme.badgeBg)}); $badgeFg=[Drawing.Color]::FromArgb(${argb(theme.badgeFg)})`,
|
|
228
265
|
"$f=New-Object Windows.Forms.Form; $f.Text=$title; $f.TopMost=$true; $f.StartPosition='CenterScreen'; $f.FormBorderStyle='FixedDialog'; $f.MaximizeBox=$false; $f.MinimizeBox=$false; $f.ShowInTaskbar=$true; $f.BackColor=$bg; $f.Font=New-Object Drawing.Font('Segoe UI',9.75); $f.ClientSize=New-Object Drawing.Size(700,640)",
|
|
229
266
|
// Panel.Padding does not move absolutely positioned children: every control takes $x0 explicitly.
|
|
230
267
|
"$root=New-Object Windows.Forms.Panel; $root.Dock='Fill'; $root.AutoScroll=$true; $root.BackColor=$bg; $f.Controls.Add($root)",
|
|
231
|
-
|
|
268
|
+
// UseMnemonic off: a Label hides `&` (mnemonic prefix), so `2>&1` read as `2>1` and `a & b` lost the `&`.
|
|
269
|
+
"function AddLabel($parent,$text,$font,$color,$y,$w,$x){ $l=New-Object Windows.Forms.Label; $l.UseMnemonic=$false; $l.Text=$text; $l.Font=$font; $l.ForeColor=$color; $l.AutoSize=$true; $l.MaximumSize=New-Object Drawing.Size($w,0); $l.Location=New-Object Drawing.Point($(if($x){$x}else{$x0}),$y); $parent.Controls.Add($l); return $l }",
|
|
232
270
|
"$x0=24; $y=18; $w=652",
|
|
233
271
|
"AddLabel $root 'FullCourtDefense' (New-Object Drawing.Font('Segoe UI',9.75,[Drawing.FontStyle]::Bold)) $muted $y $w | Out-Null; $y+=30",
|
|
234
272
|
`$icon=New-Object Windows.Forms.Label; $icon.Text='${theme.glyph}'; $icon.Font=New-Object Drawing.Font('Segoe UI',18,[Drawing.FontStyle]::Bold); $icon.TextAlign='MiddleCenter'; $icon.Size=New-Object Drawing.Size(44,44); $icon.Location=New-Object Drawing.Point($x0,$y); $icon.ForeColor=$accent; $icon.BackColor=$badgeBg; $root.Controls.Add($icon)`,
|
|
@@ -236,13 +274,28 @@ function windowsDialogScript(message, timeoutSeconds, options, title, view) {
|
|
|
236
274
|
"$badge=AddLabel $root ([string]$v.badge) (New-Object Drawing.Font('Segoe UI',8.25,[Drawing.FontStyle]::Bold)) $badgeFg $y $hw $hx; $badge.BackColor=$badgeBg; $badge.Padding=New-Object Windows.Forms.Padding(6,2,6,2)",
|
|
237
275
|
"$h=AddLabel $root ([string]$v.headline) (New-Object Drawing.Font('Segoe UI',16,[Drawing.FontStyle]::Bold)) $ink ($badge.Bottom+4) $hw $hx",
|
|
238
276
|
"$s=AddLabel $root ([string]$v.subtitle) (New-Object Drawing.Font('Segoe UI',9.75)) $muted ($h.Bottom+4) $hw $hx; $y=[Math]::Max($icon.Bottom,$s.Bottom)+18",
|
|
239
|
-
|
|
240
|
-
|
|
277
|
+
// Why you're asked: one sentence, then Command / Action / Where / Always allow as label-value rows.
|
|
278
|
+
// The row label is double-quoted: the single-quoted button label marks a three-button dialog.
|
|
279
|
+
// Production is red and bold, and the word "production" is always in the text.
|
|
280
|
+
// A home / drive / root delete is drawn like production: red and bold, with the words in the text.
|
|
281
|
+
"if($v.header){ $hd=$v.header; $prod=([string]$hd.tag -eq 'production'); $danger=[bool]$hd.danger; $red=[Drawing.Color]::FromArgb(185,28,28)",
|
|
282
|
+
" $who=AddLabel $root ([string]$hd.who) (New-Object Drawing.Font('Segoe UI',9.75,[Drawing.FontStyle]::Bold)) $ink $y $w; $y=$who.Bottom+6",
|
|
283
|
+
" AddLabel $root \"Why you're asked\" (New-Object Drawing.Font('Segoe UI',8.25,[Drawing.FontStyle]::Bold)) $muted $y $w | Out-Null; $y+=18",
|
|
284
|
+
" $lead=AddLabel $root ([string]$hd.why) (New-Object Drawing.Font('Segoe UI',11,[Drawing.FontStyle]::Bold)) $(if($prod -or $danger){$red}else{$ink}) $y $w; $y=$lead.Bottom+6; $kx=$x0+104; $kw=$w-104",
|
|
285
|
+
" $rows=@(@([string]$hd.commandLabel,[string]$hd.command,'mono'),@('Action',[string]$hd.action,''))",
|
|
286
|
+
" if($hd.affects){ $rows+=,@('Affects',[string]$hd.affects,$(if($danger){'danger'}else{''})) }; $rows+=,@('Where',[string]$hd.whereText,'where')",
|
|
287
|
+
" if($hd.secretSentTo){ $rows+=,@([string]$hd.secretSentTo.label,[string]$hd.secretSentTo.value,'') }; $rows+=,@(\"Always allow\",[string]$hd.always,'')",
|
|
288
|
+
" foreach($row in $rows){",
|
|
289
|
+
" $k=AddLabel $root $row[0] (New-Object Drawing.Font('Segoe UI',8.25,[Drawing.FontStyle]::Bold)) $muted ($y+2) 100",
|
|
290
|
+
" $isWhere=($row[2] -eq 'where'); $strong=(($isWhere -and $prod) -or $row[2] -eq 'danger'); $font=$(if($row[2] -eq 'mono'){New-Object Drawing.Font('Consolas',9.75)}elseif($strong){New-Object Drawing.Font('Segoe UI',9.75,[Drawing.FontStyle]::Bold)}else{New-Object Drawing.Font('Segoe UI',9.75)})",
|
|
291
|
+
" $val=AddLabel $root $row[1] $font $(if($strong){$red}else{$ink}) $y $kw $kx; $y=[Math]::Max($k.Bottom,$val.Bottom)+1 }",
|
|
292
|
+
" $y+=10 }",
|
|
293
|
+
"if(-not $v.header){ AddLabel $root 'Action' (New-Object Drawing.Font('Segoe UI',9.75,[Drawing.FontStyle]::Bold)) $ink $y $w | Out-Null; $y+=22 }",
|
|
294
|
+
"if($v.kind -and -not $v.header){ AddLabel $root ([string]$v.kind) (New-Object Drawing.Font('Segoe UI',8.25,[Drawing.FontStyle]::Bold)) $muted $y $w | Out-Null; $y+=18 }",
|
|
241
295
|
// What it does: one numbered plain-words line per step, then the FULL script in a
|
|
242
296
|
// read-only scrolling box (fixed height, so a long script never pushes the buttons away).
|
|
243
|
-
"$steps=@($v.steps); if($steps.Count -gt 0){ AddLabel $root 'What it does' (New-Object Drawing.Font('Segoe UI',8.25,[Drawing.FontStyle]::Bold)) $muted $y $w | Out-Null; $y+=18; $n=0; foreach($st in $steps){ $n++; $row=AddLabel $root (\"$n. $st\") (New-Object Drawing.Font('Segoe UI',9
|
|
244
|
-
"if($v.action){ $a=New-Object Windows.Forms.TextBox; $a.Multiline=$true; $a.ReadOnly=$true; $a.WordWrap=$true; $a.ScrollBars='Vertical'; $a.BorderStyle='FixedSingle'; $a.BackColor=[Drawing.Color]::FromArgb(248,250,252); $a.ForeColor=$ink; $a.Font=New-Object Drawing.Font('Consolas',9.75); $a.Text=[string]$v.action; $lines=[Math]::Max(1,[Math]::Min(
|
|
245
|
-
"if($v.policy){ AddLabel $root 'Matched policy' (New-Object Drawing.Font('Segoe UI',9.75,[Drawing.FontStyle]::Bold)) $ink $y $w | Out-Null; $y+=22; $pn=AddLabel $root ([string]$v.policy) (New-Object Drawing.Font('Segoe UI',9.75)) $ink $y $w; $y=$pn.Bottom+2; if($v.scope){ $ps=AddLabel $root ([string]$v.scope) (New-Object Drawing.Font('Segoe UI',9)) $muted $y $w; $y=$ps.Bottom+12 } }",
|
|
297
|
+
"$steps=@($v.steps); if($steps.Count -gt 0){ AddLabel $root 'What it does' (New-Object Drawing.Font('Segoe UI',8.25,[Drawing.FontStyle]::Bold)) $muted $y $w | Out-Null; $y+=18; $n=0; foreach($st in $steps){ $n++; $row=AddLabel $root (\"$n. $st\") (New-Object Drawing.Font('Segoe UI',9)) $ink $y $w; $y=$row.Bottom }; $y+=6; AddLabel $root 'Full script' (New-Object Drawing.Font('Segoe UI',8.25,[Drawing.FontStyle]::Bold)) $muted $y $w | Out-Null; $y+=18 }",
|
|
298
|
+
"if($v.action){ $a=New-Object Windows.Forms.TextBox; $a.Multiline=$true; $a.ReadOnly=$true; $a.WordWrap=$true; $a.ScrollBars='Vertical'; $a.BorderStyle='FixedSingle'; $a.BackColor=[Drawing.Color]::FromArgb(248,250,252); $a.ForeColor=$ink; $a.Font=New-Object Drawing.Font('Consolas',9.75); $a.Text=[string]$v.action; $lines=[Math]::Max(1,[Math]::Min(7,([string]$v.action).Length/80+([string]$v.action).Split([char]10).Count)); $a.Size=New-Object Drawing.Size($w,[int](18*$lines+12)); $a.Location=New-Object Drawing.Point($x0,$y); $a.TabStop=$false; $root.Controls.Add($a); $y=$a.Bottom+12 } else { $y+=8 }",
|
|
246
299
|
"AddLabel $root 'Why it triggered' (New-Object Drawing.Font('Segoe UI',9.75,[Drawing.FontStyle]::Bold)) $ink $y $w | Out-Null; $y+=22",
|
|
247
300
|
"foreach($item in @($v.why)){ $row=AddLabel $root ('• '+$item) (New-Object Drawing.Font('Segoe UI',9.75)) $ink $y $w; $y=$row.Bottom+2 }",
|
|
248
301
|
"$y+=10; AddLabel $root 'What happens next' (New-Object Drawing.Font('Segoe UI',9.75,[Drawing.FontStyle]::Bold)) $ink $y $w | Out-Null; $y+=22",
|
|
@@ -298,14 +351,50 @@ win.close();
|
|
|
298
351
|
result;
|
|
299
352
|
`;
|
|
300
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Test-harness contract. A suite that sets `FCD_TEST_NO_REAL_DIALOG=1` promises the OS
|
|
356
|
+
* dialog is faked in every process it spawns (scripts/lib/fake-os-dialog.js stamps
|
|
357
|
+
* `FCD_FAKE_DIALOG_PID` with the pid it patched). A process under that marker without
|
|
358
|
+
* the fake never opens a real window on the developer's desktop: it says so on stderr,
|
|
359
|
+
* appends to `FCD_TEST_REAL_DIALOG_LOG` (the suite fails on it) and reports "no dialog".
|
|
360
|
+
*/
|
|
361
|
+
function realDialogRefusedUnderTest(title) {
|
|
362
|
+
if (process.env.FCD_TEST_NO_REAL_DIALOG !== '1')
|
|
363
|
+
return false;
|
|
364
|
+
if (process.env.FCD_FAKE_DIALOG_PID === String(process.pid))
|
|
365
|
+
return false;
|
|
366
|
+
const note = `[FullCourtDefense] test guard: a REAL OS dialog would have been shown ("${title}") in pid ${process.pid} without the fake dialog preload — refused.`;
|
|
367
|
+
try {
|
|
368
|
+
process.stderr.write(`${note}\n`);
|
|
369
|
+
}
|
|
370
|
+
catch { /* stderr gone */ }
|
|
371
|
+
const log = process.env.FCD_TEST_REAL_DIALOG_LOG;
|
|
372
|
+
if (log) {
|
|
373
|
+
try {
|
|
374
|
+
fs.appendFileSync(log, `${JSON.stringify({ t: Date.now(), pid: process.pid, argv: process.argv.slice(1, 4), title })}\n`);
|
|
375
|
+
}
|
|
376
|
+
catch { /* best effort */ }
|
|
377
|
+
}
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
301
380
|
async function confirmNativeActionDetailed(reason, timeoutMs = 60_000, options = {}) {
|
|
302
381
|
if (!nativeDialogAvailable())
|
|
303
382
|
return { outcome: 'unavailable', latencyMs: 0 };
|
|
383
|
+
if (realDialogRefusedUnderTest((0, approvalPrompt_1.nativeApprovalTitle)(reason)))
|
|
384
|
+
return { outcome: 'unavailable', latencyMs: 0 };
|
|
304
385
|
const started = Date.now();
|
|
305
386
|
let executable;
|
|
306
387
|
let args;
|
|
307
|
-
const
|
|
308
|
-
|
|
388
|
+
const copy = {
|
|
389
|
+
allowAlways: options.allowAlways,
|
|
390
|
+
alwaysScopeLabel: options.alwaysScopeLabel,
|
|
391
|
+
alwaysLimitsLabel: options.alwaysLimitsLabel,
|
|
392
|
+
alwaysCovers: options.alwaysCovers,
|
|
393
|
+
alwaysNotOffered: options.alwaysNotOffered,
|
|
394
|
+
subject: options.subject,
|
|
395
|
+
};
|
|
396
|
+
const message = (0, approvalPrompt_1.nativeApprovalMessage)(reason, copy);
|
|
397
|
+
const view = (0, approvalPrompt_1.nativeDialogView)(reason, { ...copy, tone: options.tone || 'ask' });
|
|
309
398
|
// The title names the kind of action and the policy, so the window itself says what is asking.
|
|
310
399
|
const title = (0, approvalPrompt_1.nativeApprovalTitle)(reason);
|
|
311
400
|
const timeoutSeconds = Math.max(1, Math.ceil(timeoutMs / 1000));
|
|
@@ -339,13 +428,19 @@ async function confirmNativeActionDetailed(reason, timeoutMs = 60_000, options =
|
|
|
339
428
|
};
|
|
340
429
|
const cancelChild = () => child?.kill();
|
|
341
430
|
const timer = setTimeout(() => { child?.kill(); done('timeout'); }, timeoutMs + 1000);
|
|
431
|
+
const stdin = process.platform === 'win32' ? windowsDialogPayload(view) : undefined;
|
|
342
432
|
try {
|
|
343
|
-
child = (0, child_process_1.spawn)(executable, args, { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
|
|
433
|
+
child = (0, child_process_1.spawn)(executable, args, { stdio: [stdin === undefined ? 'ignore' : 'pipe', 'pipe', 'ignore'], windowsHide: true });
|
|
344
434
|
}
|
|
345
435
|
catch {
|
|
346
436
|
done('unavailable');
|
|
347
437
|
return;
|
|
348
438
|
}
|
|
439
|
+
if (stdin !== undefined) {
|
|
440
|
+
// A dialog that exits before reading (killed, failed start) must not crash the hook.
|
|
441
|
+
child.stdin?.on('error', () => { });
|
|
442
|
+
child.stdin?.end(stdin);
|
|
443
|
+
}
|
|
349
444
|
process.once('exit', cancelChild);
|
|
350
445
|
child.stdout?.on('data', (chunk) => { if (stdout.length < 256)
|
|
351
446
|
stdout += String(chunk); });
|
|
@@ -383,6 +478,8 @@ async function confirmNativeActionDetailed(reason, timeoutMs = 60_000, options =
|
|
|
383
478
|
});
|
|
384
479
|
});
|
|
385
480
|
}
|
|
481
|
+
/** Local Safety items whose every ask is a delete of the home folder, a drive or the root: never granted. */
|
|
482
|
+
const NEVER_GRANTED_ITEMS = new Set(['rm_rf_root', 'rm_rf_home', 'windows_drive_delete', 'windows_drive_rmdir', 'windows_system_dir_delete']);
|
|
386
483
|
/** A raised confirmation that received no post-execution signal in time counts as not approved. */
|
|
387
484
|
exports.CONFIRM_PENDING_TTL_MS = 10 * 60_000;
|
|
388
485
|
const REMEMBER_1H_MS = 60 * 60_000;
|
|
@@ -461,6 +558,26 @@ function readLedger() {
|
|
|
461
558
|
return { pending: [], remembered: [], confirmedActions: [], grants: [] };
|
|
462
559
|
}
|
|
463
560
|
}
|
|
561
|
+
/** Windows: antivirus / the indexer hold a just-written file for a moment (EPERM on rename). */
|
|
562
|
+
const TRANSIENT_FS_CODES = new Set(['EPERM', 'EACCES', 'EBUSY']);
|
|
563
|
+
const LEDGER_RETRY_MS = 500;
|
|
564
|
+
function sleepSync(ms) {
|
|
565
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
566
|
+
}
|
|
567
|
+
/** Bounded retry of one filesystem step on the codes in `retryOn`; the last error is thrown. */
|
|
568
|
+
function retryFs(step, retryOn) {
|
|
569
|
+
const deadline = Date.now() + LEDGER_RETRY_MS;
|
|
570
|
+
for (let attempt = 0;; attempt++) {
|
|
571
|
+
try {
|
|
572
|
+
return step();
|
|
573
|
+
}
|
|
574
|
+
catch (error) {
|
|
575
|
+
if (!retryOn.has(String(error?.code)) || Date.now() >= deadline)
|
|
576
|
+
throw error;
|
|
577
|
+
sleepSync(Math.min(50, 5 * 2 ** attempt));
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
464
581
|
function writeLedger(ledger) {
|
|
465
582
|
const temp = `${ledgerFile()}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
466
583
|
try {
|
|
@@ -472,7 +589,7 @@ function writeLedger(ledger) {
|
|
|
472
589
|
finally {
|
|
473
590
|
fs.closeSync(fd);
|
|
474
591
|
}
|
|
475
|
-
fs.renameSync(temp, ledgerFile());
|
|
592
|
+
retryFs(() => fs.renameSync(temp, ledgerFile()), TRANSIENT_FS_CODES);
|
|
476
593
|
}
|
|
477
594
|
finally {
|
|
478
595
|
try {
|
|
@@ -481,8 +598,10 @@ function writeLedger(ledger) {
|
|
|
481
598
|
catch { /* renamed or not created */ }
|
|
482
599
|
}
|
|
483
600
|
}
|
|
601
|
+
const LOCK_WAIT_CODES = new Set(['EEXIST', ...TRANSIENT_FS_CODES]);
|
|
484
602
|
/** Serialize every mutation: a stale writer must not resurrect a consumed approval.
|
|
485
|
-
* Contention, failed persistence or a leftover lock loses reuse, never grants access
|
|
603
|
+
* Contention, failed persistence or a leftover lock loses reuse, never grants access
|
|
604
|
+
* (after a bounded wait for a concurrent hook or a delete-pending lock).
|
|
486
605
|
* No stale-lock stealing: deleting another process's lock introduces a replay race.
|
|
487
606
|
*/
|
|
488
607
|
function mutateLedger(fallback, mutate) {
|
|
@@ -490,7 +609,7 @@ function mutateLedger(fallback, mutate) {
|
|
|
490
609
|
let fd;
|
|
491
610
|
try {
|
|
492
611
|
fs.mkdirSync(path.dirname(lock), { recursive: true });
|
|
493
|
-
fd = fs.openSync(lock, 'wx', 0o600);
|
|
612
|
+
fd = retryFs(() => fs.openSync(lock, 'wx', 0o600), LOCK_WAIT_CODES);
|
|
494
613
|
return mutate();
|
|
495
614
|
}
|
|
496
615
|
catch {
|
|
@@ -1209,18 +1328,43 @@ function grantKey(scope, policyId, matchedRule, policyHash) {
|
|
|
1209
1328
|
const { mode, issuers, hosts, resources } = scope.credential;
|
|
1210
1329
|
parts.push(mode === 'issuer' ? { mode, issuers, resources: resources || null } : { mode, hosts, resources: resources || null });
|
|
1211
1330
|
}
|
|
1331
|
+
if (scope.bridges && scope.bridges.length)
|
|
1332
|
+
parts.push({ bridges: scope.bridges });
|
|
1333
|
+
if (scope.cloud && scope.cloud.length)
|
|
1334
|
+
parts.push({ cloud: scope.cloud });
|
|
1212
1335
|
return sha256(JSON.stringify(parts));
|
|
1213
1336
|
}
|
|
1337
|
+
/** Bridges match by inclusion; an action that starts a bridge the grant never named is not covered. */
|
|
1338
|
+
function bridgesCovered(granted, live) {
|
|
1339
|
+
if (!live || live.length === 0)
|
|
1340
|
+
return !granted || granted.length === 0;
|
|
1341
|
+
return Array.isArray(granted) && live.every(bridge => granted.includes(bridge));
|
|
1342
|
+
}
|
|
1214
1343
|
/**
|
|
1215
1344
|
* Can "Always allow" exist for this scope at all? Not for a shell line whose
|
|
1216
|
-
* programs could not be read (empty set)
|
|
1217
|
-
* destination or secret could not be read
|
|
1218
|
-
* outside its issuer
|
|
1345
|
+
* programs could not be read (empty set), not for a credential line whose
|
|
1346
|
+
* destination or secret could not be read or that sends the credential
|
|
1347
|
+
* outside its issuer, and not for a cloud line that deletes, changes
|
|
1348
|
+
* permissions or whose target cannot be read. The dialog offers two
|
|
1349
|
+
* buttons and says why in one line; no grant matches.
|
|
1219
1350
|
*/
|
|
1351
|
+
function grantNotOfferedReason(scope) {
|
|
1352
|
+
if (scope.refusal === 'destructive_scope') {
|
|
1353
|
+
return 'Always allow is not offered for deleting your home folder, a drive or the filesystem root — each one is confirmed.';
|
|
1354
|
+
}
|
|
1355
|
+
if (scope.event === 'shell' && (!scope.programs || scope.programs.length === 0) && !(scope.bridges && scope.bridges.length)) {
|
|
1356
|
+
return 'Always allow is not offered: the programs this command runs could not be read.';
|
|
1357
|
+
}
|
|
1358
|
+
if (scope.credential?.refused) {
|
|
1359
|
+
return scope.credential.refused === 'outside_issuer'
|
|
1360
|
+
? 'Always allow is not offered: the credential goes outside its provider.'
|
|
1361
|
+
: 'Always allow is not offered: where the credential goes could not be read.';
|
|
1362
|
+
}
|
|
1363
|
+
const cloud = (0, cloudGrant_1.cloudGrantRefusal)(scope.cloud);
|
|
1364
|
+
return cloud ? (0, cloudGrant_1.describeCloudRefusal)(cloud, scope.cloud) : undefined;
|
|
1365
|
+
}
|
|
1220
1366
|
function grantOffered(scope) {
|
|
1221
|
-
|
|
1222
|
-
return false;
|
|
1223
|
-
return !scope.credential?.refused;
|
|
1367
|
+
return grantNotOfferedReason(scope) === undefined;
|
|
1224
1368
|
}
|
|
1225
1369
|
/** The caps a grant for this scope is created under: credential grants live 7 days at most. */
|
|
1226
1370
|
function capGrantLimitsForScope(limits, scope) {
|
|
@@ -1262,8 +1406,11 @@ function findDeveloperGrant(scope, rule, limits = { ttlMs: exports.GRANT_TTL_MS
|
|
|
1262
1406
|
// shortened the ceiling after the click still wins.
|
|
1263
1407
|
&& now.getTime() - Date.parse(g.grantedAt) < ttlCap
|
|
1264
1408
|
&& !grantExhausted(g, limits)
|
|
1409
|
+
&& bridgesCovered(g.scope.bridges, scope.bridges)
|
|
1410
|
+
&& (0, cloudGrant_1.cloudGrantCovers)(g.scope.cloud, scope.cloud)
|
|
1265
1411
|
&& (scope.event !== 'shell'
|
|
1266
|
-
|| (Array.isArray(g.scope.programs) && (scope.programs || []).length > 0
|
|
1412
|
+
|| (Array.isArray(g.scope.programs) && ((scope.programs || []).length > 0 || (scope.bridges || []).length > 0)
|
|
1413
|
+
&& (scope.programs || []).every(p => g.scope.programs.includes(p))))
|
|
1267
1414
|
&& (!(g.scope.scripts && g.scope.scripts.length)
|
|
1268
1415
|
|| ((scope.scripts || []).length > 0 && (scope.scripts || []).every(s => g.scope.scripts.includes(s))))
|
|
1269
1416
|
// A credential rule's grant must also cover where the credential goes now.
|
|
@@ -1348,6 +1495,10 @@ function describeGrantScope(scope, rule) {
|
|
|
1348
1495
|
return ruleName ? `${base} under rule ${ruleName}` : base;
|
|
1349
1496
|
}
|
|
1350
1497
|
function describeGrantTarget(scope) {
|
|
1498
|
+
if (scope.bridges && scope.bridges.length) {
|
|
1499
|
+
const others = scope.event === 'shell' && scope.programs && scope.programs.length ? ` with \`${scope.programs.join('`, `')}\`` : '';
|
|
1500
|
+
return `starting \`${scope.bridges.join('`, `')}\`${others}`;
|
|
1501
|
+
}
|
|
1351
1502
|
const what = scope.event === 'shell'
|
|
1352
1503
|
? (scope.scripts && scope.scripts.length
|
|
1353
1504
|
? `running ${scope.scripts.map(s => `\`${s}\``).join(', ')}`
|
|
@@ -1358,7 +1509,26 @@ function describeGrantTarget(scope) {
|
|
|
1358
1509
|
const op = scope.operation && scope.operation !== 'SHELL' ? ` (${scope.operation.toLowerCase()})` : '';
|
|
1359
1510
|
const where = scope.destinationDomain ? ` to ${scope.destinationDomain}` : '';
|
|
1360
1511
|
const credential = scope.credential ? (0, credentialGrant_1.describeCredentialBinding)(scope.credential) : '';
|
|
1361
|
-
|
|
1512
|
+
const cloud = scope.cloud && scope.cloud.length ? (({ how, where: target }) => ` (${how} in ${target})`)((0, cloudGrant_1.describeCloudEntries)(scope.cloud)) : '';
|
|
1513
|
+
return `${what}${op}${cloud}${where}${credential}`;
|
|
1514
|
+
}
|
|
1515
|
+
/** What / How / Where an "Always allow" covers, as the dialog's compact rows. */
|
|
1516
|
+
function grantCoverage(scope) {
|
|
1517
|
+
const what = scope.bridges && scope.bridges.length
|
|
1518
|
+
? [...scope.bridges, ...(scope.event === 'shell' ? scope.programs || [] : [])].join(', ')
|
|
1519
|
+
: scope.event === 'shell'
|
|
1520
|
+
? (scope.scripts && scope.scripts.length ? scope.scripts.join(', ') : (scope.programs || []).join(', '))
|
|
1521
|
+
: scope.event === 'mcp'
|
|
1522
|
+
? scope.toolName.replace(/^mcp__/, '').replace(/__/g, ' / ')
|
|
1523
|
+
: `${scope.toolName} ${scope.event}`;
|
|
1524
|
+
const cloud = scope.cloud && scope.cloud.length ? (0, cloudGrant_1.describeCloudEntries)(scope.cloud) : undefined;
|
|
1525
|
+
const how = cloud?.how || (scope.operation && scope.operation !== 'SHELL' ? scope.operation.toLowerCase() : undefined);
|
|
1526
|
+
const where = [
|
|
1527
|
+
cloud?.where,
|
|
1528
|
+
scope.destinationDomain,
|
|
1529
|
+
scope.credential ? (0, credentialGrant_1.describeCredentialBinding)(scope.credential).replace(/^,\s*/, '') : undefined,
|
|
1530
|
+
].filter(Boolean).join('; ');
|
|
1531
|
+
return { what, ...(how ? { how } : {}), ...(where ? { where } : {}) };
|
|
1362
1532
|
}
|
|
1363
1533
|
/** The scope a grant would have for this action — from engine facts, never from text. */
|
|
1364
1534
|
function scriptGrantKeys(command, cwd) {
|
|
@@ -1395,6 +1565,9 @@ function grantRuleFactsFor(source) {
|
|
|
1395
1565
|
facts.credential = (0, credentialGrant_1.credentialRuleFacts)([]);
|
|
1396
1566
|
else if (source.localFinding.category === 'credential_command')
|
|
1397
1567
|
facts.credential = (0, credentialGrant_1.credentialRuleFacts)([]);
|
|
1568
|
+
// A combined ask (`rm_rf_home+x`) is refused when any part is a home / drive / root delete.
|
|
1569
|
+
if (itemIds.some(id => NEVER_GRANTED_ITEMS.has(id)) && source.localFinding.source !== 'custom')
|
|
1570
|
+
facts.neverGrant = true;
|
|
1398
1571
|
return facts;
|
|
1399
1572
|
}
|
|
1400
1573
|
const policy = source.policyId ? source.policies?.find(p => p.id === source.policyId) : undefined;
|
|
@@ -1424,24 +1597,44 @@ function localSafetyRuleCommands(finding) {
|
|
|
1424
1597
|
/** Grants made without rule facts (MCP gateway, older callers) keep the narrow, host-bound shape. */
|
|
1425
1598
|
const DEFAULT_GRANT_RULE_FACTS = { bindsDestination: true };
|
|
1426
1599
|
function grantScopeFor(event, toolName, toolArgs, operation, context, facts = DEFAULT_GRANT_RULE_FACTS) {
|
|
1427
|
-
const scope = { event, toolName, operation: String(operation || '').trim() || 'unknown' };
|
|
1600
|
+
const scope = { event, toolName, operation: String(operation || '').trim() || 'unknown', ...(facts.neverGrant ? { refusal: 'destructive_scope' } : {}) };
|
|
1428
1601
|
if (event === 'shell') {
|
|
1429
1602
|
const command = typeof toolArgs?.command === 'string' ? toolArgs.command : typeof toolArgs?.cmd === 'string' ? toolArgs.cmd : '';
|
|
1430
|
-
|
|
1603
|
+
// A bridge launch is keyed by its package + mode; the programs are what else the line runs.
|
|
1604
|
+
const launches = (0, deterministicGuard_1.remoteControlLaunches)(command);
|
|
1605
|
+
if (launches.bridges.length)
|
|
1606
|
+
scope.bridges = launches.bridges;
|
|
1607
|
+
const scanned = launches.bridges.length ? launches.rest : command;
|
|
1608
|
+
const scan = scanShellPrograms(scanned);
|
|
1431
1609
|
scope.programs = programsForRule(scan, facts.ruleCommands);
|
|
1432
1610
|
if (facts.credential) {
|
|
1433
|
-
scope.credential = (0, credentialGrant_1.credentialBindingFor)(
|
|
1611
|
+
scope.credential = (0, credentialGrant_1.credentialBindingFor)(scanned, scan.uses, name => scan.programs.get(name) === true, facts.credential.commands || facts.ruleCommands || [], facts.credential);
|
|
1434
1612
|
}
|
|
1435
1613
|
const cwd = typeof toolArgs?.cwd === 'string' ? toolArgs.cwd : undefined;
|
|
1436
1614
|
const scripts = scriptGrantKeys(command, cwd);
|
|
1437
1615
|
if (scripts.length)
|
|
1438
1616
|
scope.scripts = scripts;
|
|
1617
|
+
const ruleDomain = context?.['destination.domain'];
|
|
1618
|
+
const destinationBound = Boolean(scope.credential && !scope.credential.refused) || (facts.bindsDestination && typeof ruleDomain === 'string' && Boolean(ruleDomain.trim()));
|
|
1619
|
+
const cloud = (0, cloudGrant_1.cloudGrantEntries)(scanned, scan.uses, configuration => (0, cloudGrant_1.activeGcloudProject)(configuration), { destinationBound, cwd });
|
|
1620
|
+
if (cloud.length)
|
|
1621
|
+
scope.cloud = cloud;
|
|
1439
1622
|
// A shell line's identity is its programs. The engine verb (`write` for a
|
|
1440
1623
|
// POST, `SHELL` otherwise) describes the line, not the app the rule asked
|
|
1441
1624
|
// about, and it changed the key between two `gcloud … ; Invoke-RestMethod`
|
|
1442
1625
|
// lines that fired the very same rule. One verb for every shell grant.
|
|
1443
1626
|
scope.operation = 'SHELL';
|
|
1444
1627
|
}
|
|
1628
|
+
else {
|
|
1629
|
+
// An MCP terminal tool (`start_process`, `execute_command`) starting a bridge.
|
|
1630
|
+
const bridges = new Set();
|
|
1631
|
+
for (const value of Object.values(toolArgs || {})) {
|
|
1632
|
+
if (typeof value === 'string')
|
|
1633
|
+
(0, deterministicGuard_1.remoteControlLaunches)(value).bridges.forEach(bridge => bridges.add(bridge));
|
|
1634
|
+
}
|
|
1635
|
+
if (bridges.size)
|
|
1636
|
+
scope.bridges = [...bridges].sort();
|
|
1637
|
+
}
|
|
1445
1638
|
const domain = context?.['destination.domain'];
|
|
1446
1639
|
if (facts.bindsDestination && typeof domain === 'string' && domain.trim())
|
|
1447
1640
|
scope.destinationDomain = domain.trim().toLowerCase();
|
package/dist/distress.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export declare const DISTRESS: {
|
|
|
43
43
|
readonly BACKEND_REJECTED: "backend_rejected";
|
|
44
44
|
/** Self-update triggered repeatedly for the same target without the version changing. */
|
|
45
45
|
readonly UPDATE_LOOP: "update_loop";
|
|
46
|
+
/** npm self-update cannot write the global prefix (CLI installed as root, daemon runs as a user); detail carries the fix command. */
|
|
47
|
+
readonly UPDATE_NEEDS_ADMIN: "update_needs_admin";
|
|
46
48
|
/** MSI updater scheduled task missing and could not be re-registered. */
|
|
47
49
|
readonly UPDATER_TASK_MISSING: "updater_task_missing";
|
|
48
50
|
/** Config file missing/unreadable — machine likely not enrolled or wiped. */
|
package/dist/distress.js
CHANGED
|
@@ -88,6 +88,8 @@ exports.DISTRESS = {
|
|
|
88
88
|
BACKEND_REJECTED: 'backend_rejected',
|
|
89
89
|
/** Self-update triggered repeatedly for the same target without the version changing. */
|
|
90
90
|
UPDATE_LOOP: 'update_loop',
|
|
91
|
+
/** npm self-update cannot write the global prefix (CLI installed as root, daemon runs as a user); detail carries the fix command. */
|
|
92
|
+
UPDATE_NEEDS_ADMIN: 'update_needs_admin',
|
|
91
93
|
/** MSI updater scheduled task missing and could not be re-registered. */
|
|
92
94
|
UPDATER_TASK_MISSING: 'updater_task_missing',
|
|
93
95
|
/** Config file missing/unreadable — machine likely not enrolled or wiped. */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What cannot be read yet; the dialog says "until the <noun> can be read". */
|
|
2
|
+
export type TargetNoun = 'environment' | 'database' | 'host' | 'destination' | 'registry' | 'secret';
|
|
3
|
+
/** `npx prisma …` -> `prisma …`; `python -m twine …` -> `twine …`; else the use itself. */
|
|
4
|
+
export declare function throughRunner(name: string, argv: readonly string[]): {
|
|
5
|
+
name: string;
|
|
6
|
+
argv: string[];
|
|
7
|
+
};
|
|
8
|
+
export interface UnreadTarget {
|
|
9
|
+
label: string;
|
|
10
|
+
noun: TargetNoun;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The unread remote target of one program use, or undefined when the use is
|
|
14
|
+
* local or already read elsewhere (gcloud, aws, kube tools). `env` is the
|
|
15
|
+
* caller's environment (`DOCKER_HOST`); `destinationBound` = the grant already
|
|
16
|
+
* binds where data goes (a credential binding or the rule's destination host),
|
|
17
|
+
* so a web write is not refused for an unknown destination.
|
|
18
|
+
*/
|
|
19
|
+
export declare function unreadTarget(programName: string, programArgv: readonly string[], env: NodeJS.ProcessEnv, destinationBound: boolean): UnreadTarget | undefined;
|
|
20
|
+
/** The noun of an unread entry label (`git push` -> destination). */
|
|
21
|
+
export declare function unreadNoun(label: string): TargetNoun;
|