@omercnet/paseo-omp 5.4.0-next.410.1 → 5.4.0-next.412.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/omp-config-surface.tsx +114 -82
- package/client/omp-config-views.ts +7 -3
- package/client/omp-security-section.tsx +99 -0
- package/client/omp-security-state.ts +14 -0
- package/client/omp-tool-policy-state.ts +101 -0
- package/client/omp-tool-policy.tsx +435 -0
- package/index.server.ts +3 -0
- package/package.json +1 -1
- package/server/omp-security.ts +169 -0
- package/server/omp-settings.ts +68 -4
- package/server/package-version.ts +1 -1
- package/shared/omp-security.ts +50 -0
- package/shared/omp-settings.ts +99 -4
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { TextInput } from "@getpaseo/plugin/client/ui";
|
|
2
|
+
import { type ReactNode, useRef, useState } from "react";
|
|
3
|
+
import { Pressable, Text, View } from "react-native";
|
|
4
|
+
import {
|
|
5
|
+
type OmpBashRule,
|
|
6
|
+
OmpBashRuleSchema,
|
|
7
|
+
OmpRestrictedFoldersSchema,
|
|
8
|
+
type OmpSetting,
|
|
9
|
+
type OmpToolApproval,
|
|
10
|
+
} from "../shared/omp-settings";
|
|
11
|
+
import type { OmpConfigStyles } from "./omp-config-styles";
|
|
12
|
+
import {
|
|
13
|
+
canAddBashRule,
|
|
14
|
+
canAddToolRule,
|
|
15
|
+
moveRule,
|
|
16
|
+
policyWarnings,
|
|
17
|
+
readBashRuleDraft,
|
|
18
|
+
readBashRules,
|
|
19
|
+
readFolders,
|
|
20
|
+
readToolPolicies,
|
|
21
|
+
} from "./omp-tool-policy-state";
|
|
22
|
+
|
|
23
|
+
type PolicyDraft = { operation: "set"; value: unknown } | { operation: "reset" };
|
|
24
|
+
|
|
25
|
+
const APPROVALS: readonly { value: OmpToolApproval; label: string }[] = [
|
|
26
|
+
{ value: "allow", label: "Allow" },
|
|
27
|
+
{ value: "prompt", label: "Ask" },
|
|
28
|
+
{ value: "deny", label: "Deny" },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const CAVEATS = [
|
|
32
|
+
"Deny, Ask and restricted-folder rules also apply in Full Access.",
|
|
33
|
+
"A new Deny rule may not guard an agent that is already running until it is reloaded.",
|
|
34
|
+
"Bash rules do not cover commands run through eval, are not a sandbox, and only support * wildcards. The first matching rule wins.",
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
interface ToolPolicyCardProps {
|
|
38
|
+
settings: readonly OmpSetting[];
|
|
39
|
+
visiblePaths: readonly string[];
|
|
40
|
+
drafts: Readonly<Record<string, PolicyDraft>>;
|
|
41
|
+
disabled: boolean;
|
|
42
|
+
workspaceScoped: boolean;
|
|
43
|
+
resetLabel: string;
|
|
44
|
+
styles: OmpConfigStyles;
|
|
45
|
+
onSet(path: string, value: unknown): void;
|
|
46
|
+
onReset(path: string): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const ACTION_GROUP = { flexDirection: "row", flexWrap: "wrap", gap: 8 } as const;
|
|
50
|
+
|
|
51
|
+
function Action({
|
|
52
|
+
label,
|
|
53
|
+
text,
|
|
54
|
+
disabled,
|
|
55
|
+
selected,
|
|
56
|
+
styles,
|
|
57
|
+
onPress,
|
|
58
|
+
}: {
|
|
59
|
+
label: string;
|
|
60
|
+
text: string;
|
|
61
|
+
disabled: boolean;
|
|
62
|
+
selected?: boolean;
|
|
63
|
+
styles: OmpConfigStyles;
|
|
64
|
+
onPress(): void;
|
|
65
|
+
}) {
|
|
66
|
+
return (
|
|
67
|
+
<Pressable
|
|
68
|
+
accessibilityRole="button"
|
|
69
|
+
accessibilityLabel={label}
|
|
70
|
+
accessibilityState={{ selected: selected === true }}
|
|
71
|
+
disabled={disabled}
|
|
72
|
+
onPress={onPress}
|
|
73
|
+
style={[styles.editorAction, selected ? styles.editorActionPrimary : null]}
|
|
74
|
+
>
|
|
75
|
+
<Text style={[styles.editorActionText, selected ? styles.editorActionTextPrimary : null]}>
|
|
76
|
+
{text}
|
|
77
|
+
</Text>
|
|
78
|
+
</Pressable>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function ApprovalChoice({
|
|
83
|
+
subject,
|
|
84
|
+
value,
|
|
85
|
+
disabled,
|
|
86
|
+
styles,
|
|
87
|
+
onChange,
|
|
88
|
+
}: {
|
|
89
|
+
subject: string;
|
|
90
|
+
value: OmpToolApproval;
|
|
91
|
+
disabled: boolean;
|
|
92
|
+
styles: OmpConfigStyles;
|
|
93
|
+
onChange(value: OmpToolApproval): void;
|
|
94
|
+
}) {
|
|
95
|
+
return (
|
|
96
|
+
<>
|
|
97
|
+
{APPROVALS.map((choice) => (
|
|
98
|
+
<Action
|
|
99
|
+
key={choice.value}
|
|
100
|
+
label={`${choice.label} ${subject}`}
|
|
101
|
+
text={choice.label}
|
|
102
|
+
disabled={disabled}
|
|
103
|
+
selected={value === choice.value}
|
|
104
|
+
styles={styles}
|
|
105
|
+
onPress={() => onChange(choice.value)}
|
|
106
|
+
/>
|
|
107
|
+
))}
|
|
108
|
+
</>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function PolicySection({
|
|
113
|
+
title,
|
|
114
|
+
description,
|
|
115
|
+
pending,
|
|
116
|
+
showReset,
|
|
117
|
+
resetLabel,
|
|
118
|
+
disabled,
|
|
119
|
+
styles,
|
|
120
|
+
onReset,
|
|
121
|
+
children,
|
|
122
|
+
}: {
|
|
123
|
+
title: string;
|
|
124
|
+
description: string;
|
|
125
|
+
pending: boolean;
|
|
126
|
+
showReset: boolean;
|
|
127
|
+
resetLabel: string;
|
|
128
|
+
disabled: boolean;
|
|
129
|
+
styles: OmpConfigStyles;
|
|
130
|
+
onReset(): void;
|
|
131
|
+
children: ReactNode;
|
|
132
|
+
}) {
|
|
133
|
+
return (
|
|
134
|
+
<View style={styles.setting}>
|
|
135
|
+
<Text style={styles.cardTitle}>{title}</Text>
|
|
136
|
+
<Text style={styles.settingDescription}>{description}</Text>
|
|
137
|
+
{pending ? (
|
|
138
|
+
<Text style={styles.muted}>{resetLabel} when changes are applied</Text>
|
|
139
|
+
) : (
|
|
140
|
+
<View style={styles.recordList}>{children}</View>
|
|
141
|
+
)}
|
|
142
|
+
{showReset ? (
|
|
143
|
+
<Pressable accessibilityRole="button" disabled={disabled} onPress={onReset}>
|
|
144
|
+
<Text style={styles.resetAction}>{resetLabel}</Text>
|
|
145
|
+
</Pressable>
|
|
146
|
+
) : null}
|
|
147
|
+
</View>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function AddRow({
|
|
152
|
+
label,
|
|
153
|
+
inputLabel,
|
|
154
|
+
placeholder,
|
|
155
|
+
valid,
|
|
156
|
+
disabled,
|
|
157
|
+
styles,
|
|
158
|
+
onAdd,
|
|
159
|
+
}: {
|
|
160
|
+
label: string;
|
|
161
|
+
inputLabel: string;
|
|
162
|
+
placeholder: string;
|
|
163
|
+
valid(text: string): boolean;
|
|
164
|
+
disabled: boolean;
|
|
165
|
+
styles: OmpConfigStyles;
|
|
166
|
+
onAdd(text: string): void;
|
|
167
|
+
}) {
|
|
168
|
+
const [text, setText] = useState("");
|
|
169
|
+
const trimmed = text.trim();
|
|
170
|
+
return (
|
|
171
|
+
<View style={styles.recordRow}>
|
|
172
|
+
<TextInput
|
|
173
|
+
accessibilityLabel={inputLabel}
|
|
174
|
+
editable={!disabled}
|
|
175
|
+
placeholder={placeholder}
|
|
176
|
+
value={text}
|
|
177
|
+
onChangeText={setText}
|
|
178
|
+
style={styles.scalarInput}
|
|
179
|
+
/>
|
|
180
|
+
<Action
|
|
181
|
+
label={label}
|
|
182
|
+
text="Add"
|
|
183
|
+
disabled={disabled || !valid(trimmed)}
|
|
184
|
+
styles={styles}
|
|
185
|
+
onPress={() => {
|
|
186
|
+
onAdd(trimmed);
|
|
187
|
+
setText("");
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
</View>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Rules have no identity of their own and their order is the data, so each row carries an id that follows it through moves and removals. */
|
|
195
|
+
function useRuleIds(length: number) {
|
|
196
|
+
const ids = useRef<number[]>([]);
|
|
197
|
+
const nextId = useRef(0);
|
|
198
|
+
while (ids.current.length < length) ids.current.push(nextId.current++);
|
|
199
|
+
ids.current.length = length;
|
|
200
|
+
return ids;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function ToolPolicyCard({
|
|
204
|
+
settings,
|
|
205
|
+
visiblePaths,
|
|
206
|
+
drafts,
|
|
207
|
+
disabled,
|
|
208
|
+
workspaceScoped,
|
|
209
|
+
resetLabel,
|
|
210
|
+
styles,
|
|
211
|
+
onSet,
|
|
212
|
+
onReset,
|
|
213
|
+
}: ToolPolicyCardProps) {
|
|
214
|
+
const byPath = new Map(settings.map((setting) => [setting.path, setting]));
|
|
215
|
+
const current = (path: string): unknown => {
|
|
216
|
+
const draft = drafts[path];
|
|
217
|
+
return draft?.operation === "set" ? draft.value : byPath.get(path)?.value;
|
|
218
|
+
};
|
|
219
|
+
const resetting = (path: string) => drafts[path]?.operation === "reset";
|
|
220
|
+
const canReset = (path: string) =>
|
|
221
|
+
!workspaceScoped || byPath.get(path)?.workspaceOverride === true;
|
|
222
|
+
const inheritedPolicies = readToolPolicies(
|
|
223
|
+
workspaceScoped ? byPath.get("tools.approval")?.userValue : undefined,
|
|
224
|
+
);
|
|
225
|
+
const policies = readToolPolicies(current("tools.approval"));
|
|
226
|
+
const bashDraft = drafts["bash.patterns"];
|
|
227
|
+
const rules =
|
|
228
|
+
bashDraft?.operation === "set"
|
|
229
|
+
? readBashRuleDraft(bashDraft.value)
|
|
230
|
+
: readBashRules(byPath.get("bash.patterns")?.value);
|
|
231
|
+
const folders = readFolders(current("tools.restrictedFolders"));
|
|
232
|
+
const ruleIds = useRuleIds(rules.length);
|
|
233
|
+
const warnings = policyWarnings({ policies, rules });
|
|
234
|
+
const setRule = (index: number, rule: OmpBashRule) =>
|
|
235
|
+
onSet(
|
|
236
|
+
"bash.patterns",
|
|
237
|
+
rules.map((existing, position) => (position === index ? rule : existing)),
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
<View style={styles.card}>
|
|
242
|
+
<View style={styles.cardHeader}>
|
|
243
|
+
<Text style={styles.cardTitle}>Tool policy</Text>
|
|
244
|
+
</View>
|
|
245
|
+
{visiblePaths.includes("tools.approval") ? (
|
|
246
|
+
<PolicySection
|
|
247
|
+
title="Per-tool approval"
|
|
248
|
+
description="Allow runs a tool without asking, Ask requires confirmation and Deny blocks it. These rules win over the approval mode."
|
|
249
|
+
pending={resetting("tools.approval")}
|
|
250
|
+
showReset={canReset("tools.approval")}
|
|
251
|
+
resetLabel={resetLabel}
|
|
252
|
+
disabled={disabled}
|
|
253
|
+
styles={styles}
|
|
254
|
+
onReset={() => onReset("tools.approval")}
|
|
255
|
+
>
|
|
256
|
+
{Object.entries(policies).map(([tool, approval]) => (
|
|
257
|
+
<View key={tool} style={styles.recordRow}>
|
|
258
|
+
<Text selectable style={styles.recordKey}>
|
|
259
|
+
{tool}
|
|
260
|
+
</Text>
|
|
261
|
+
<View style={ACTION_GROUP}>
|
|
262
|
+
<ApprovalChoice
|
|
263
|
+
subject={tool}
|
|
264
|
+
value={approval}
|
|
265
|
+
disabled={disabled}
|
|
266
|
+
styles={styles}
|
|
267
|
+
onChange={(next) => onSet("tools.approval", { ...policies, [tool]: next })}
|
|
268
|
+
/>
|
|
269
|
+
{inheritedPolicies[tool] === approval ? (
|
|
270
|
+
<Text style={styles.muted}>From user config</Text>
|
|
271
|
+
) : (
|
|
272
|
+
<Action
|
|
273
|
+
label={`Remove ${tool}`}
|
|
274
|
+
text="Remove"
|
|
275
|
+
disabled={disabled}
|
|
276
|
+
styles={styles}
|
|
277
|
+
onPress={() =>
|
|
278
|
+
onSet(
|
|
279
|
+
"tools.approval",
|
|
280
|
+
Object.fromEntries(
|
|
281
|
+
Object.entries(policies).filter(([name]) => name !== tool),
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
/>
|
|
286
|
+
)}
|
|
287
|
+
</View>
|
|
288
|
+
</View>
|
|
289
|
+
))}
|
|
290
|
+
<AddRow
|
|
291
|
+
label="Add tool rule"
|
|
292
|
+
inputLabel="Tool name"
|
|
293
|
+
placeholder="Tool, e.g. eval"
|
|
294
|
+
valid={(text) => canAddToolRule(policies, text)}
|
|
295
|
+
disabled={disabled}
|
|
296
|
+
styles={styles}
|
|
297
|
+
onAdd={(tool) => onSet("tools.approval", { ...policies, [tool]: "prompt" })}
|
|
298
|
+
/>
|
|
299
|
+
</PolicySection>
|
|
300
|
+
) : null}
|
|
301
|
+
{visiblePaths.includes("bash.patterns") ? (
|
|
302
|
+
<PolicySection
|
|
303
|
+
title="Bash command rules"
|
|
304
|
+
description="Matched top to bottom against each bash command; the first match decides. Use * as a wildcard, for example npm test* or git push --force*."
|
|
305
|
+
pending={resetting("bash.patterns")}
|
|
306
|
+
showReset={canReset("bash.patterns")}
|
|
307
|
+
resetLabel={resetLabel}
|
|
308
|
+
disabled={disabled}
|
|
309
|
+
styles={styles}
|
|
310
|
+
onReset={() => onReset("bash.patterns")}
|
|
311
|
+
>
|
|
312
|
+
{rules.map((rule, index) => (
|
|
313
|
+
<View key={ruleIds.current[index]} style={styles.recordRow}>
|
|
314
|
+
<Text style={styles.recordKey}>{index + 1}</Text>
|
|
315
|
+
<TextInput
|
|
316
|
+
accessibilityLabel={`Bash rule ${index + 1} pattern`}
|
|
317
|
+
editable={!disabled}
|
|
318
|
+
value={rule.match}
|
|
319
|
+
onChangeText={(match) => setRule(index, { ...rule, match })}
|
|
320
|
+
style={styles.scalarInput}
|
|
321
|
+
/>
|
|
322
|
+
{OmpBashRuleSchema.safeParse(rule).success ? null : (
|
|
323
|
+
<Text style={styles.error}>Enter a pattern of 1 to 512 characters.</Text>
|
|
324
|
+
)}
|
|
325
|
+
<View style={ACTION_GROUP}>
|
|
326
|
+
<ApprovalChoice
|
|
327
|
+
subject={`for bash rule ${index + 1}`}
|
|
328
|
+
value={rule.approval}
|
|
329
|
+
disabled={disabled}
|
|
330
|
+
styles={styles}
|
|
331
|
+
onChange={(approval) => setRule(index, { ...rule, approval })}
|
|
332
|
+
/>
|
|
333
|
+
<Action
|
|
334
|
+
label={`Move bash rule ${index + 1} up`}
|
|
335
|
+
text="Up"
|
|
336
|
+
disabled={disabled || index === 0}
|
|
337
|
+
styles={styles}
|
|
338
|
+
onPress={() => {
|
|
339
|
+
ruleIds.current = moveRule(ruleIds.current, index, -1);
|
|
340
|
+
onSet("bash.patterns", moveRule(rules, index, -1));
|
|
341
|
+
}}
|
|
342
|
+
/>
|
|
343
|
+
<Action
|
|
344
|
+
label={`Move bash rule ${index + 1} down`}
|
|
345
|
+
text="Down"
|
|
346
|
+
disabled={disabled || index === rules.length - 1}
|
|
347
|
+
styles={styles}
|
|
348
|
+
onPress={() => {
|
|
349
|
+
ruleIds.current = moveRule(ruleIds.current, index, 1);
|
|
350
|
+
onSet("bash.patterns", moveRule(rules, index, 1));
|
|
351
|
+
}}
|
|
352
|
+
/>
|
|
353
|
+
<Action
|
|
354
|
+
label={`Remove bash rule ${index + 1}`}
|
|
355
|
+
text="Remove"
|
|
356
|
+
disabled={disabled}
|
|
357
|
+
styles={styles}
|
|
358
|
+
onPress={() => {
|
|
359
|
+
ruleIds.current = ruleIds.current.filter((_, position) => position !== index);
|
|
360
|
+
onSet(
|
|
361
|
+
"bash.patterns",
|
|
362
|
+
rules.filter((_, position) => position !== index),
|
|
363
|
+
);
|
|
364
|
+
}}
|
|
365
|
+
/>
|
|
366
|
+
</View>
|
|
367
|
+
</View>
|
|
368
|
+
))}
|
|
369
|
+
<AddRow
|
|
370
|
+
label="Add bash rule"
|
|
371
|
+
inputLabel="Bash command pattern"
|
|
372
|
+
placeholder="Pattern, e.g. npm test*"
|
|
373
|
+
valid={(text) => canAddBashRule(rules, text)}
|
|
374
|
+
disabled={disabled}
|
|
375
|
+
styles={styles}
|
|
376
|
+
onAdd={(match) => onSet("bash.patterns", [...rules, { match, approval: "prompt" }])}
|
|
377
|
+
/>
|
|
378
|
+
</PolicySection>
|
|
379
|
+
) : null}
|
|
380
|
+
{visiblePaths.includes("tools.restrictedFolders") ? (
|
|
381
|
+
<PolicySection
|
|
382
|
+
title="Restricted folders"
|
|
383
|
+
description="Every read, write, edit, search or command in these folders, and everything under them, needs an explicit approval in every mode."
|
|
384
|
+
pending={resetting("tools.restrictedFolders")}
|
|
385
|
+
showReset={canReset("tools.restrictedFolders")}
|
|
386
|
+
resetLabel={resetLabel}
|
|
387
|
+
disabled={disabled}
|
|
388
|
+
styles={styles}
|
|
389
|
+
onReset={() => onReset("tools.restrictedFolders")}
|
|
390
|
+
>
|
|
391
|
+
{folders.map((folder, index) => (
|
|
392
|
+
<View key={folder} style={styles.recordRow}>
|
|
393
|
+
<Text selectable style={styles.recordValue}>
|
|
394
|
+
{folder}
|
|
395
|
+
</Text>
|
|
396
|
+
<Action
|
|
397
|
+
label={`Remove ${folder}`}
|
|
398
|
+
text="Remove"
|
|
399
|
+
disabled={disabled}
|
|
400
|
+
styles={styles}
|
|
401
|
+
onPress={() =>
|
|
402
|
+
onSet(
|
|
403
|
+
"tools.restrictedFolders",
|
|
404
|
+
folders.filter((_, position) => position !== index),
|
|
405
|
+
)
|
|
406
|
+
}
|
|
407
|
+
/>
|
|
408
|
+
</View>
|
|
409
|
+
))}
|
|
410
|
+
<AddRow
|
|
411
|
+
label="Add restricted folder"
|
|
412
|
+
inputLabel="Restricted folder path"
|
|
413
|
+
placeholder="Path, e.g. ~/secrets"
|
|
414
|
+
valid={(text) => OmpRestrictedFoldersSchema.safeParse([...folders, text]).success}
|
|
415
|
+
disabled={disabled}
|
|
416
|
+
styles={styles}
|
|
417
|
+
onAdd={(folder) => onSet("tools.restrictedFolders", [...folders, folder])}
|
|
418
|
+
/>
|
|
419
|
+
</PolicySection>
|
|
420
|
+
) : null}
|
|
421
|
+
<View style={styles.setting}>
|
|
422
|
+
{warnings.map((warning) => (
|
|
423
|
+
<Text key={warning} style={styles.error}>
|
|
424
|
+
{warning}
|
|
425
|
+
</Text>
|
|
426
|
+
))}
|
|
427
|
+
{CAVEATS.map((caveat) => (
|
|
428
|
+
<Text key={caveat} style={styles.settingDescription}>
|
|
429
|
+
{caveat}
|
|
430
|
+
</Text>
|
|
431
|
+
))}
|
|
432
|
+
</View>
|
|
433
|
+
</View>
|
|
434
|
+
);
|
|
435
|
+
}
|
package/index.server.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from "./server/omp-plugins";
|
|
25
25
|
import { readHostAppendPrompt, readOmpPromptFiles } from "./server/omp-prompt-files";
|
|
26
26
|
import { resolveListOmpRules } from "./server/omp-rules";
|
|
27
|
+
import { resolveListOmpSecurity } from "./server/omp-security";
|
|
27
28
|
import { resolveListOmpSettings, resolveUpdateOmpSettings } from "./server/omp-settings";
|
|
28
29
|
import {
|
|
29
30
|
resolveDeleteOmpManagedSkill,
|
|
@@ -92,6 +93,7 @@ import {
|
|
|
92
93
|
} from "./shared/omp-plugins";
|
|
93
94
|
import { getOmpPromptFiles } from "./shared/omp-prompt-files";
|
|
94
95
|
import { listOmpRules } from "./shared/omp-rules";
|
|
96
|
+
import { listOmpSecurity } from "./shared/omp-security";
|
|
95
97
|
import { listOmpSettings, updateOmpSettings } from "./shared/omp-settings";
|
|
96
98
|
import { deleteOmpManagedSkill, listOmpSkills, setOmpSkillEnabled } from "./shared/omp-skills";
|
|
97
99
|
import { listOmpStores, type OmpStore } from "./shared/omp-store";
|
|
@@ -219,6 +221,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
219
221
|
server.handle(listOmpRules, scoped(resolveListOmpRules));
|
|
220
222
|
server.handle(listOmpExtensions, scoped(resolveListOmpExtensions));
|
|
221
223
|
server.handle(setOmpExtensionEnabled, scoped(resolveSetOmpExtensionEnabled));
|
|
224
|
+
server.handle(listOmpSecurity, scoped(resolveListOmpSecurity));
|
|
222
225
|
server.handle(listOmpSkills, scoped(resolveListOmpSkills));
|
|
223
226
|
server.handle(setOmpSkillEnabled, scoped(resolveSetOmpSkillEnabled));
|
|
224
227
|
server.handle(deleteOmpManagedSkill, scoped(resolveDeleteOmpManagedSkill));
|
package/package.json
CHANGED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
type listOmpSecurity,
|
|
5
|
+
type OmpSecurityList,
|
|
6
|
+
type OmpSecurityScan,
|
|
7
|
+
type OmpSecuritySeverity,
|
|
8
|
+
OmpSecuritySeveritySchema,
|
|
9
|
+
} from "../shared/omp-security";
|
|
10
|
+
import {
|
|
11
|
+
type OmpListDependencies,
|
|
12
|
+
ompListDependencies,
|
|
13
|
+
requireOmpExecutable,
|
|
14
|
+
} from "./omp-list-setting";
|
|
15
|
+
import { inOmpScope, readSetting } from "./omp-rules";
|
|
16
|
+
import { OmpPublicError } from "./provider/security";
|
|
17
|
+
|
|
18
|
+
const MAX_SCANS = 20;
|
|
19
|
+
const MAX_PARALLEL_READS = 4;
|
|
20
|
+
const MAX_FIELD_CHARS = 256;
|
|
21
|
+
const DASH = "\u2014";
|
|
22
|
+
const SCAN_LINE = new RegExp(
|
|
23
|
+
`^- \`(secscan_[A-Za-z0-9]+)\` ${DASH} (\\w+); (\\d+) finding\\(s\\); (.*); (\\S+)$`,
|
|
24
|
+
"u",
|
|
25
|
+
);
|
|
26
|
+
const FINDING_LINE = new RegExp(`^- \`[^\`]+\` \\*\\*(\\w+)\\*\\* ${DASH} `, "u");
|
|
27
|
+
const EnabledSchema = z.object({ value: z.boolean() });
|
|
28
|
+
|
|
29
|
+
export class OmpSecurityError extends OmpPublicError {}
|
|
30
|
+
|
|
31
|
+
interface ListedScan {
|
|
32
|
+
id: string;
|
|
33
|
+
phase: string;
|
|
34
|
+
findingCount: number;
|
|
35
|
+
producer: string;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface ParsedScans {
|
|
40
|
+
scans: ListedScan[];
|
|
41
|
+
/** Bullet lines that did not parse, or repeated an id: an odd producer name can break a line. */
|
|
42
|
+
skipped: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The scan lines of `security://scans`. A heading or a blank line is ignored; a bullet that does
|
|
47
|
+
* not parse, or whose id was already listed, is counted as skipped so the tab can say so.
|
|
48
|
+
*/
|
|
49
|
+
export function parseScanLines(text: string): ParsedScans {
|
|
50
|
+
const scans: ListedScan[] = [];
|
|
51
|
+
const seen = new Set<string>();
|
|
52
|
+
let skipped = 0;
|
|
53
|
+
for (const line of text.split("\n")) {
|
|
54
|
+
if (!line.startsWith("- `")) continue;
|
|
55
|
+
const match = SCAN_LINE.exec(line);
|
|
56
|
+
if (!match || seen.has(match[1])) {
|
|
57
|
+
skipped += 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const [, id, phase, count, producer, createdAt] = match;
|
|
61
|
+
seen.add(id);
|
|
62
|
+
scans.push({
|
|
63
|
+
id: id.slice(0, MAX_FIELD_CHARS),
|
|
64
|
+
phase: phase.slice(0, MAX_FIELD_CHARS),
|
|
65
|
+
findingCount: Number(count),
|
|
66
|
+
producer: producer.slice(0, MAX_FIELD_CHARS),
|
|
67
|
+
createdAt: createdAt.slice(0, MAX_FIELD_CHARS),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return { scans, skipped };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Counts the severity at the start of each finding line; a title can never be mistaken for one. */
|
|
74
|
+
export function countSeverities(text: string): Record<OmpSecuritySeverity, number> {
|
|
75
|
+
const counts: Record<OmpSecuritySeverity, number> = {
|
|
76
|
+
critical: 0,
|
|
77
|
+
high: 0,
|
|
78
|
+
medium: 0,
|
|
79
|
+
low: 0,
|
|
80
|
+
informational: 0,
|
|
81
|
+
};
|
|
82
|
+
for (const line of text.split("\n")) {
|
|
83
|
+
const level = OmpSecuritySeveritySchema.safeParse(FINDING_LINE.exec(line)?.[1]);
|
|
84
|
+
if (level.success) counts[level.data] += 1;
|
|
85
|
+
}
|
|
86
|
+
return counts;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function readResource(
|
|
90
|
+
dependencies: OmpListDependencies,
|
|
91
|
+
executable: string,
|
|
92
|
+
url: string,
|
|
93
|
+
cwd: string,
|
|
94
|
+
): Promise<string> {
|
|
95
|
+
const run = await dependencies.run(executable, ["read", url], cwd);
|
|
96
|
+
if (run.outcome === "timeout") throw new OmpSecurityError(`omp read ${url} timed out`);
|
|
97
|
+
if (run.outcome !== "exited" || run.exitCode !== 0 || run.truncated) {
|
|
98
|
+
throw new OmpSecurityError(`omp read ${url} failed`);
|
|
99
|
+
}
|
|
100
|
+
return run.stdout;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A scan whose findings cannot be read still lists, with its counts marked incomplete. */
|
|
104
|
+
async function withSeverities(
|
|
105
|
+
dependencies: OmpListDependencies,
|
|
106
|
+
executable: string,
|
|
107
|
+
scan: ListedScan,
|
|
108
|
+
cwd: string,
|
|
109
|
+
): Promise<OmpSecurityScan> {
|
|
110
|
+
const url = `security://scans/${scan.id}/findings`;
|
|
111
|
+
const text =
|
|
112
|
+
scan.findingCount === 0
|
|
113
|
+
? ""
|
|
114
|
+
: await readResource(dependencies, executable, url, cwd).catch((error: unknown) => {
|
|
115
|
+
if (error instanceof OmpSecurityError) return null;
|
|
116
|
+
throw error;
|
|
117
|
+
});
|
|
118
|
+
const severities = countSeverities(text ?? "");
|
|
119
|
+
const counted = Object.values(severities).reduce((sum, count) => sum + count, 0);
|
|
120
|
+
return {
|
|
121
|
+
...scan,
|
|
122
|
+
severities,
|
|
123
|
+
severitiesComplete: text !== null && counted === scan.findingCount,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Scans live in OMP's private, project-keyed store. The plugin reads them through OMP itself
|
|
129
|
+
* (`omp read security://...`), the documented read-only surface, so the store layout, profiles and
|
|
130
|
+
* XDG roots stay OMP's business. Only phase and counts leave the server, never finding details.
|
|
131
|
+
*/
|
|
132
|
+
export async function listOmpSecurityWithDependencies(
|
|
133
|
+
input: RpcInput<typeof listOmpSecurity>,
|
|
134
|
+
dependencies: OmpListDependencies,
|
|
135
|
+
): Promise<OmpSecurityList> {
|
|
136
|
+
try {
|
|
137
|
+
const executable = await requireOmpExecutable(dependencies);
|
|
138
|
+
return await inOmpScope(input.cwd, dependencies, async (runIn) => {
|
|
139
|
+
const enabled = await readSetting(
|
|
140
|
+
dependencies,
|
|
141
|
+
executable,
|
|
142
|
+
"security.enabled",
|
|
143
|
+
EnabledSchema,
|
|
144
|
+
runIn,
|
|
145
|
+
);
|
|
146
|
+
if (!enabled) return { status: "off" as const };
|
|
147
|
+
const text = await readResource(dependencies, executable, "security://scans", runIn);
|
|
148
|
+
const { scans: listed, skipped } = parseScanLines(text);
|
|
149
|
+
const shown = listed.slice(0, MAX_SCANS);
|
|
150
|
+
const scans: OmpSecurityScan[] = [];
|
|
151
|
+
for (let start = 0; start < shown.length; start += MAX_PARALLEL_READS) {
|
|
152
|
+
const batch = shown.slice(start, start + MAX_PARALLEL_READS);
|
|
153
|
+
scans.push(
|
|
154
|
+
...(await Promise.all(
|
|
155
|
+
batch.map((scan) => withSeverities(dependencies, executable, scan, runIn)),
|
|
156
|
+
)),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return { status: "ready" as const, scans, truncated: listed.length > shown.length, skipped };
|
|
160
|
+
});
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (error instanceof OmpPublicError) return { status: "error", message: error.message };
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function resolveListOmpSecurity(input: RpcInput<typeof listOmpSecurity>) {
|
|
168
|
+
return listOmpSecurityWithDependencies(input, ompListDependencies);
|
|
169
|
+
}
|