@glassbox-ai/engine 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +33 -2
- package/dist/action/acc.d.ts +48 -0
- package/dist/action/acc.js +117 -0
- package/dist/action/builtin-tools.d.ts +5 -0
- package/dist/action/builtin-tools.js +74 -0
- package/dist/action/inline.d.ts +14 -0
- package/dist/action/inline.js +54 -0
- package/dist/action/paths.d.ts +71 -0
- package/dist/action/paths.js +398 -0
- package/dist/action/powershell.d.ts +9 -0
- package/dist/action/powershell.js +848 -0
- package/dist/action/protected-write.d.ts +11 -0
- package/dist/action/protected-write.js +113 -0
- package/dist/action/schedule.d.ts +43 -0
- package/dist/action/schedule.js +213 -0
- package/dist/action/shell/analyze.d.ts +28 -0
- package/dist/action/shell/analyze.js +2057 -0
- package/dist/action/shell/parse.d.ts +74 -0
- package/dist/action/shell/parse.js +1037 -0
- package/dist/action/shell/view.d.ts +6 -0
- package/dist/action/shell/view.js +89 -0
- package/dist/action/sql.d.ts +3 -0
- package/dist/action/sql.js +259 -0
- package/dist/action/tools.d.ts +20 -0
- package/dist/action/tools.js +305 -0
- package/dist/action/upload.d.ts +17 -0
- package/dist/action/upload.js +72 -0
- package/dist/analysis/fields.d.ts +14 -0
- package/dist/analysis/fields.js +136 -0
- package/dist/analysis/findings.d.ts +25 -0
- package/dist/analysis/findings.js +82 -0
- package/dist/analysis/gate.d.ts +16 -0
- package/dist/analysis/gate.js +662 -0
- package/dist/analysis/manifest.d.ts +3 -0
- package/dist/analysis/manifest.js +369 -0
- package/dist/analysis/match.d.ts +54 -0
- package/dist/analysis/match.js +352 -0
- package/dist/analysis/scan.d.ts +17 -0
- package/dist/analysis/scan.js +97 -0
- package/dist/canon/confusables.generated.d.ts +3 -0
- package/dist/canon/confusables.generated.js +6 -0
- package/dist/canon/decode.d.ts +11 -0
- package/dist/canon/decode.js +147 -0
- package/dist/canon/views.d.ts +36 -0
- package/dist/canon/views.js +283 -0
- package/dist/evidence/evidence.d.ts +12 -0
- package/dist/evidence/evidence.js +149 -0
- package/dist/fingerprint/diff.d.ts +3 -0
- package/dist/fingerprint/diff.js +273 -0
- package/dist/fingerprint/fingerprint.d.ts +4 -0
- package/dist/fingerprint/fingerprint.js +77 -0
- package/dist/grade/score.d.ts +19 -0
- package/dist/grade/score.js +89 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +152 -0
- package/dist/intake/json.d.ts +17 -0
- package/dist/intake/json.js +284 -0
- package/dist/intake/snapshot.d.ts +14 -0
- package/dist/intake/snapshot.js +130 -0
- package/dist/limits.d.ts +4 -0
- package/dist/limits.js +30 -0
- package/dist/policy/decide.d.ts +32 -0
- package/dist/policy/decide.js +105 -0
- package/dist/rules/ids.d.ts +2 -0
- package/dist/rules/ids.js +99 -0
- package/dist/ruleset/baseline-tests.generated.d.ts +6 -0
- package/dist/ruleset/baseline-tests.generated.js +2935 -0
- package/dist/ruleset/baseline.d.ts +3 -0
- package/dist/ruleset/baseline.generated.d.ts +3 -0
- package/dist/ruleset/baseline.generated.js +5 -0
- package/dist/ruleset/baseline.js +44 -0
- package/dist/ruleset/fakes.d.ts +3 -0
- package/dist/ruleset/fakes.js +26 -0
- package/dist/ruleset/load.d.ts +13 -0
- package/dist/ruleset/load.js +187 -0
- package/dist/ruleset/schema.d.ts +120 -0
- package/dist/ruleset/schema.js +54 -0
- package/dist/ruleset/selftest.d.ts +18 -0
- package/dist/ruleset/selftest.js +42 -0
- package/dist/ruleset-entry.d.ts +5 -0
- package/dist/ruleset-entry.js +7 -0
- package/dist/secrets/detect.d.ts +17 -0
- package/dist/secrets/detect.js +236 -0
- package/dist/secrets/redact.d.ts +19 -0
- package/dist/secrets/redact.js +116 -0
- package/dist/types.d.ts +455 -0
- package/dist/types.js +10 -0
- package/dist/util/hash.d.ts +4 -0
- package/dist/util/hash.js +16 -0
- package/dist/util/initclock.d.ts +3 -0
- package/dist/util/initclock.js +17 -0
- package/dist/util/jcs.d.ts +4 -0
- package/dist/util/jcs.js +91 -0
- package/dist/util/misc.d.ts +17 -0
- package/dist/util/misc.js +77 -0
- package/dist/util/re.d.ts +14 -0
- package/dist/util/re.js +47 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +57 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
export type Verdict = "allow" | "warn" | "ask" | "deny";
|
|
2
|
+
export type Severity = "info" | "low" | "medium" | "high" | "critical";
|
|
3
|
+
export type ActionRiskLevel = "read" | "write-reversible" | "high-risk";
|
|
4
|
+
export type ApprovalMode = "autopilot" | "balanced" | "strict";
|
|
5
|
+
export type Grade = "A" | "B" | "C" | "D" | "F";
|
|
6
|
+
export type Category = "tool-poisoning" | "hidden-content" | "prompt-injection" | "shadowing" | "rug-pull" | "exfiltration" | "secret-exposure" | "dangerous-action" | "obfuscation" | "capability-mismatch" | "self-protection" | "integrity" | "resource-limit" | "hygiene" | "server-request" | "toxic-flow";
|
|
7
|
+
export declare const ACTION_TAGS: readonly ["fs.read", "fs.read.sensitive", "fs.write", "fs.delete", "fs.destroy", "fs.move", "net.egress", "net.fetch.package-manager", "net.fetch.vcs", "vcs.commit", "vcs.push", "vcs.force-push", "vcs.history-rewrite", "vcs.discard-changes", "db.read", "db.write", "db.delete", "db.ddl", "db.unscoped-write", "deploy.prod", "deploy.other", "infra.change", "payment", "publish.public", "message.send", "perm.change", "exec.inline-code", "exec.project-code", "exec.unknown", "exec.nested-agent", "config.agent", "self-protection"];
|
|
8
|
+
export type ActionTag = (typeof ACTION_TAGS)[number];
|
|
9
|
+
export type ViaKind = "base64" | "hex" | "url" | "tag-chars" | "concat" | "skeleton" | "invisible-stripped";
|
|
10
|
+
export interface Finding {
|
|
11
|
+
id: string;
|
|
12
|
+
ruleId: string;
|
|
13
|
+
ruleSource: "baseline" | "private";
|
|
14
|
+
category: Category;
|
|
15
|
+
severity: Severity;
|
|
16
|
+
confidence: number;
|
|
17
|
+
location: string;
|
|
18
|
+
span?: {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
};
|
|
22
|
+
via?: readonly ViaKind[];
|
|
23
|
+
related?: readonly string[];
|
|
24
|
+
evidence: string;
|
|
25
|
+
explanation: string;
|
|
26
|
+
remediation: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ActionRisk {
|
|
29
|
+
level: ActionRiskLevel;
|
|
30
|
+
tags: readonly ActionTag[];
|
|
31
|
+
unanalyzable: boolean;
|
|
32
|
+
selfProtection: boolean;
|
|
33
|
+
reasons: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
export type SessionSignal = {
|
|
36
|
+
kind: "sensitive-read";
|
|
37
|
+
label: string;
|
|
38
|
+
atCall: number;
|
|
39
|
+
} | {
|
|
40
|
+
kind: "injection-seen";
|
|
41
|
+
serverId: string;
|
|
42
|
+
mentionedTools: readonly string[];
|
|
43
|
+
atCall: number;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "secret-seen";
|
|
46
|
+
secretType: string;
|
|
47
|
+
atCall: number;
|
|
48
|
+
} | {
|
|
49
|
+
kind: "private-data-read";
|
|
50
|
+
source: string;
|
|
51
|
+
serverId: string;
|
|
52
|
+
toolName: string;
|
|
53
|
+
atCall: number;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "untrusted-content-seen";
|
|
56
|
+
serverId: string;
|
|
57
|
+
toolName: string;
|
|
58
|
+
atCall: number;
|
|
59
|
+
} | {
|
|
60
|
+
kind: "external-write";
|
|
61
|
+
serverId: string;
|
|
62
|
+
toolName: string;
|
|
63
|
+
tags: readonly ActionTag[];
|
|
64
|
+
atCall: number;
|
|
65
|
+
} | {
|
|
66
|
+
kind: "protection-degraded";
|
|
67
|
+
reason: "tampered" | "downgrade" | "internal-error";
|
|
68
|
+
atCall: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A scheduled job created or changed by this call, and the files it runs (rev 9). Keep it only
|
|
72
|
+
* if the call was approved and ran; it doesn't expire. Later edits of these files ask (CP-SELF-007).
|
|
73
|
+
*/
|
|
74
|
+
| {
|
|
75
|
+
kind: "scheduled-job";
|
|
76
|
+
job: "cron" | "systemd" | "at" | "launchd" | "autostart" | "startup-folder" | "task-scheduler" | "service" | "boot-script";
|
|
77
|
+
schedule: string | null;
|
|
78
|
+
files: readonly string[];
|
|
79
|
+
atCall: number;
|
|
80
|
+
};
|
|
81
|
+
export interface Decision {
|
|
82
|
+
verdict: Verdict;
|
|
83
|
+
actionRisk: ActionRisk;
|
|
84
|
+
findings: readonly Finding[];
|
|
85
|
+
rulesetVersion: string;
|
|
86
|
+
engineVersion: string;
|
|
87
|
+
degraded: boolean;
|
|
88
|
+
degradedReasons: readonly string[];
|
|
89
|
+
protectionDegraded: boolean;
|
|
90
|
+
signals: readonly SessionSignal[];
|
|
91
|
+
suppressed: readonly {
|
|
92
|
+
ruleId: string;
|
|
93
|
+
count: number;
|
|
94
|
+
}[];
|
|
95
|
+
mode: ApprovalMode;
|
|
96
|
+
verdictBeforeMode?: Verdict;
|
|
97
|
+
inputDigest: string;
|
|
98
|
+
resultRewrite?: {
|
|
99
|
+
kind: "redact-secrets" | "replace-with-notice";
|
|
100
|
+
value: unknown;
|
|
101
|
+
};
|
|
102
|
+
elapsedMs: number;
|
|
103
|
+
}
|
|
104
|
+
export interface ToolDef {
|
|
105
|
+
name: string;
|
|
106
|
+
title?: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
inputSchema?: unknown;
|
|
109
|
+
outputSchema?: unknown;
|
|
110
|
+
annotations?: {
|
|
111
|
+
title?: string;
|
|
112
|
+
readOnlyHint?: boolean;
|
|
113
|
+
destructiveHint?: boolean;
|
|
114
|
+
idempotentHint?: boolean;
|
|
115
|
+
openWorldHint?: boolean;
|
|
116
|
+
[k: string]: unknown;
|
|
117
|
+
};
|
|
118
|
+
[k: string]: unknown;
|
|
119
|
+
}
|
|
120
|
+
export interface ServerManifest {
|
|
121
|
+
serverId?: string;
|
|
122
|
+
initialize?: {
|
|
123
|
+
protocolVersion?: string;
|
|
124
|
+
serverInfo?: {
|
|
125
|
+
name?: string;
|
|
126
|
+
version?: string;
|
|
127
|
+
title?: string;
|
|
128
|
+
[k: string]: unknown;
|
|
129
|
+
};
|
|
130
|
+
capabilities?: Record<string, unknown>;
|
|
131
|
+
instructions?: string;
|
|
132
|
+
[k: string]: unknown;
|
|
133
|
+
};
|
|
134
|
+
tools?: readonly ToolDef[];
|
|
135
|
+
prompts?: readonly Record<string, unknown>[];
|
|
136
|
+
resources?: readonly Record<string, unknown>[];
|
|
137
|
+
resourceTemplates?: readonly Record<string, unknown>[];
|
|
138
|
+
[k: string]: unknown;
|
|
139
|
+
}
|
|
140
|
+
export interface Limits {
|
|
141
|
+
maxInputBytes: number;
|
|
142
|
+
maxDepth: number;
|
|
143
|
+
maxNodes: number;
|
|
144
|
+
maxTools: number;
|
|
145
|
+
maxDescriptionBytes: number;
|
|
146
|
+
maxFieldScanBytes: number;
|
|
147
|
+
maxCommandBytes: number;
|
|
148
|
+
maxSqlBytes: number;
|
|
149
|
+
maxDecodeDepth: number;
|
|
150
|
+
maxDecodedBytes: number;
|
|
151
|
+
maxFindings: number;
|
|
152
|
+
maxStringBytes: number;
|
|
153
|
+
timeBudgetMs: number;
|
|
154
|
+
hardStopMs: number;
|
|
155
|
+
signalTtlCalls: number;
|
|
156
|
+
minConfidenceForVerdict: number;
|
|
157
|
+
}
|
|
158
|
+
export interface AnalyzeOptions {
|
|
159
|
+
knownTools?: readonly {
|
|
160
|
+
serverId: string;
|
|
161
|
+
name: string;
|
|
162
|
+
}[];
|
|
163
|
+
limits?: Partial<Limits>;
|
|
164
|
+
ruleset?: LoadedRuleset;
|
|
165
|
+
evidenceMode?: "snippet" | "none";
|
|
166
|
+
sessionIdShape?: ServerReport["sessionIdShape"];
|
|
167
|
+
}
|
|
168
|
+
export interface ServerReport {
|
|
169
|
+
grade: Grade;
|
|
170
|
+
score: number;
|
|
171
|
+
partial: boolean;
|
|
172
|
+
caps: readonly {
|
|
173
|
+
cap: Grade;
|
|
174
|
+
reason: string;
|
|
175
|
+
findingIds: readonly string[];
|
|
176
|
+
}[];
|
|
177
|
+
deductions: readonly {
|
|
178
|
+
findingId: string;
|
|
179
|
+
points: number;
|
|
180
|
+
}[];
|
|
181
|
+
findings: readonly Finding[];
|
|
182
|
+
capabilityProfile: readonly {
|
|
183
|
+
tool: string;
|
|
184
|
+
risk: ActionRisk;
|
|
185
|
+
}[];
|
|
186
|
+
scope: "metadata-only";
|
|
187
|
+
sessionIdShape?: {
|
|
188
|
+
length: number;
|
|
189
|
+
charset: "hex" | "base64" | "alnum" | "digits" | "other";
|
|
190
|
+
sequentialSuspected: boolean;
|
|
191
|
+
};
|
|
192
|
+
fingerprint: Fingerprint;
|
|
193
|
+
rulesetVersion: string;
|
|
194
|
+
engineVersion: string;
|
|
195
|
+
degraded: boolean;
|
|
196
|
+
degradedReasons: readonly string[];
|
|
197
|
+
elapsedMs: number;
|
|
198
|
+
}
|
|
199
|
+
export interface ToolCallInput {
|
|
200
|
+
serverId: string;
|
|
201
|
+
toolName: string;
|
|
202
|
+
arguments: unknown;
|
|
203
|
+
descriptor?: ToolDef;
|
|
204
|
+
agent?: string;
|
|
205
|
+
}
|
|
206
|
+
export interface ToolResultInput {
|
|
207
|
+
call: ToolCallInput;
|
|
208
|
+
result: unknown;
|
|
209
|
+
isError?: boolean;
|
|
210
|
+
}
|
|
211
|
+
export type ServerRequestKind = "sampling" | "elicitation" | "roots" | "ping" | "notification" | "unknown";
|
|
212
|
+
export interface ServerRequestInput {
|
|
213
|
+
serverId: string;
|
|
214
|
+
message: unknown;
|
|
215
|
+
}
|
|
216
|
+
/** What a built-in agent tool can do (see BUILTIN_TOOLS). */
|
|
217
|
+
export type BuiltinToolCategory = "read" | "write" | "command" | "network" | "agent" | "other";
|
|
218
|
+
/**
|
|
219
|
+
* "Allow & remember", set by the user outside the agent. Applies only in the project whose
|
|
220
|
+
* `projectIdHash` equals `SessionContext.projectIdHash`. Lifts a mode-driven ask only: never an
|
|
221
|
+
* irreversible-or-public ask, a finding ≥ high, or any locked row.
|
|
222
|
+
*/
|
|
223
|
+
export interface RememberedRule {
|
|
224
|
+
projectIdHash: string;
|
|
225
|
+
serverId: string;
|
|
226
|
+
toolName: string;
|
|
227
|
+
actionTag: ActionTag;
|
|
228
|
+
createdAt: string;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* A permission the user granted for one session (`glassbox allow --session …`), outside the agent.
|
|
232
|
+
* Applies only when `sessionId` equals `SessionContext.sessionId`; same limits as RememberedRule.
|
|
233
|
+
*/
|
|
234
|
+
export interface SessionGrant {
|
|
235
|
+
sessionId: string;
|
|
236
|
+
serverId: string;
|
|
237
|
+
toolName: string;
|
|
238
|
+
actionTag: ActionTag;
|
|
239
|
+
createdAt: string;
|
|
240
|
+
}
|
|
241
|
+
export type PolicyChoice = "allow" | "ask" | "deny";
|
|
242
|
+
export interface UserPolicy {
|
|
243
|
+
mode: ApprovalMode;
|
|
244
|
+
tagOverrides?: Partial<Record<ActionTag, PolicyChoice>>;
|
|
245
|
+
disabledRules?: readonly string[];
|
|
246
|
+
extraProtectedPaths?: readonly string[];
|
|
247
|
+
extraSensitivePaths?: readonly string[];
|
|
248
|
+
serverRequests?: {
|
|
249
|
+
default?: Partial<Record<ServerRequestKind, PolicyChoice>>;
|
|
250
|
+
perServer?: Readonly<Record<string, Partial<Record<ServerRequestKind, PolicyChoice>>>>;
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
export interface SessionContext {
|
|
254
|
+
sessionId: string;
|
|
255
|
+
platform: "linux" | "darwin" | "win32";
|
|
256
|
+
claudeConfigDir?: string;
|
|
257
|
+
glassboxSecretPaths?: readonly string[];
|
|
258
|
+
/** The current project's id (caller-computed, e.g. HMAC of the project root). Remembered rules need it. */
|
|
259
|
+
projectIdHash?: string;
|
|
260
|
+
remembered?: readonly RememberedRule[];
|
|
261
|
+
sessionGrants?: readonly SessionGrant[];
|
|
262
|
+
homeDir: string;
|
|
263
|
+
cwd: string;
|
|
264
|
+
caseInsensitiveFs: boolean;
|
|
265
|
+
glassboxDirs: readonly string[];
|
|
266
|
+
resolvedPaths?: Readonly<Record<string, string>>;
|
|
267
|
+
servers: readonly {
|
|
268
|
+
serverId: string;
|
|
269
|
+
toolNames: readonly string[];
|
|
270
|
+
highRiskTools?: readonly string[];
|
|
271
|
+
identity?: {
|
|
272
|
+
host?: string;
|
|
273
|
+
issuerTags?: readonly string[];
|
|
274
|
+
};
|
|
275
|
+
}[];
|
|
276
|
+
signals?: readonly SessionSignal[];
|
|
277
|
+
policy: UserPolicy;
|
|
278
|
+
ruleset: LoadedRuleset;
|
|
279
|
+
limits?: Partial<Limits>;
|
|
280
|
+
evidenceMode?: "snippet" | "none";
|
|
281
|
+
}
|
|
282
|
+
export interface ActionContext {
|
|
283
|
+
platform?: SessionContext["platform"];
|
|
284
|
+
homeDir?: string;
|
|
285
|
+
cwd?: string;
|
|
286
|
+
caseInsensitiveFs?: boolean;
|
|
287
|
+
glassboxDirs?: readonly string[];
|
|
288
|
+
}
|
|
289
|
+
export interface ItemFingerprint {
|
|
290
|
+
name: string;
|
|
291
|
+
hash: string;
|
|
292
|
+
}
|
|
293
|
+
export interface ToolFingerprint {
|
|
294
|
+
name: string;
|
|
295
|
+
hash: string;
|
|
296
|
+
parts: {
|
|
297
|
+
title: string;
|
|
298
|
+
description: string;
|
|
299
|
+
inputSchema: string;
|
|
300
|
+
outputSchema: string;
|
|
301
|
+
annotations: string;
|
|
302
|
+
};
|
|
303
|
+
snapshot: {
|
|
304
|
+
description: string;
|
|
305
|
+
inputSchema: unknown;
|
|
306
|
+
annotations: unknown;
|
|
307
|
+
title: string;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
export interface Fingerprint {
|
|
311
|
+
algorithm: "glassbox-fp-v1";
|
|
312
|
+
manifest: string;
|
|
313
|
+
server: {
|
|
314
|
+
instructions: string | null;
|
|
315
|
+
serverInfo: string | null;
|
|
316
|
+
};
|
|
317
|
+
serverSnapshot: {
|
|
318
|
+
name: string | null;
|
|
319
|
+
title: string | null;
|
|
320
|
+
version: string | null;
|
|
321
|
+
};
|
|
322
|
+
tools: readonly ToolFingerprint[];
|
|
323
|
+
prompts: readonly ItemFingerprint[];
|
|
324
|
+
resources: readonly ItemFingerprint[];
|
|
325
|
+
resourceTemplates: readonly ItemFingerprint[];
|
|
326
|
+
truncated: boolean;
|
|
327
|
+
}
|
|
328
|
+
export type FingerprintResult = {
|
|
329
|
+
ok: true;
|
|
330
|
+
fingerprint: Fingerprint;
|
|
331
|
+
findings: readonly Finding[];
|
|
332
|
+
} | {
|
|
333
|
+
ok: false;
|
|
334
|
+
findings: readonly Finding[];
|
|
335
|
+
degraded: true;
|
|
336
|
+
};
|
|
337
|
+
export type ChangeKind = "tool-added" | "tool-removed" | "description-changed" | "title-changed" | "schema-widened" | "schema-narrowed" | "schema-changed-indeterminate" | "annotations-escalated" | "annotations-changed" | "server-instructions-changed" | "serverinfo-changed" | "prompt-added" | "resource-added" | "output-schema-changed" | "fingerprint-incomparable";
|
|
338
|
+
export interface ManifestChange {
|
|
339
|
+
kind: ChangeKind;
|
|
340
|
+
item: string;
|
|
341
|
+
pointer: string;
|
|
342
|
+
detail: string;
|
|
343
|
+
}
|
|
344
|
+
export interface ManifestDiff {
|
|
345
|
+
changed: boolean;
|
|
346
|
+
changes: readonly ManifestChange[];
|
|
347
|
+
findings: readonly Finding[];
|
|
348
|
+
degraded: boolean;
|
|
349
|
+
}
|
|
350
|
+
export interface DiffOptions {
|
|
351
|
+
baseline?: "approved" | "public-grade";
|
|
352
|
+
}
|
|
353
|
+
export interface RedactOptions {
|
|
354
|
+
evidenceMode?: "snippet" | "none";
|
|
355
|
+
limits?: Partial<Limits>;
|
|
356
|
+
}
|
|
357
|
+
export interface Redacted {
|
|
358
|
+
value: unknown;
|
|
359
|
+
redactions: readonly {
|
|
360
|
+
pointer: string;
|
|
361
|
+
type: string;
|
|
362
|
+
masked: string;
|
|
363
|
+
}[];
|
|
364
|
+
truncated: boolean;
|
|
365
|
+
}
|
|
366
|
+
export type ViewName = "norm" | "skeleton" | "visible" | "original" | "tagDecoded" | "decoded";
|
|
367
|
+
export type Surface = "manifest" | "call" | "result" | "server-request";
|
|
368
|
+
export type Matcher = {
|
|
369
|
+
type: "phrase";
|
|
370
|
+
phrases: readonly string[];
|
|
371
|
+
wordBoundary: boolean;
|
|
372
|
+
maxGapWords?: number;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* `anchors` (spec rev 6): literals of which every match contains at least one, compared
|
|
376
|
+
* against the lowercased text. When none occurs, the regex pass is skipped. Anchors are
|
|
377
|
+
* lowercase; non-ASCII anchors are only allowed without the `i` flag (re2's case folding and
|
|
378
|
+
* toLowerCase differ outside ASCII). Baseline anchors are proven by test/ruleset/anchors.test.
|
|
379
|
+
*/
|
|
380
|
+
| {
|
|
381
|
+
type: "regex";
|
|
382
|
+
pattern: string;
|
|
383
|
+
flags?: "i";
|
|
384
|
+
anchors?: readonly string[];
|
|
385
|
+
} | {
|
|
386
|
+
type: "codepoints";
|
|
387
|
+
ranges: readonly (readonly [number, number])[];
|
|
388
|
+
minCount: number;
|
|
389
|
+
exclude?: "emoji-sequences";
|
|
390
|
+
} | {
|
|
391
|
+
type: "secret";
|
|
392
|
+
detector: string;
|
|
393
|
+
} | {
|
|
394
|
+
type: "structural";
|
|
395
|
+
check: string;
|
|
396
|
+
} | {
|
|
397
|
+
type: "all" | "any";
|
|
398
|
+
of: readonly Matcher[];
|
|
399
|
+
scope: "field";
|
|
400
|
+
} | {
|
|
401
|
+
type: "not";
|
|
402
|
+
of: Matcher;
|
|
403
|
+
};
|
|
404
|
+
export interface RuleTestCase {
|
|
405
|
+
surface: Surface;
|
|
406
|
+
input: unknown;
|
|
407
|
+
note?: string;
|
|
408
|
+
}
|
|
409
|
+
export interface RuleDef {
|
|
410
|
+
id: string;
|
|
411
|
+
revision: number;
|
|
412
|
+
category: Category;
|
|
413
|
+
severity: Severity;
|
|
414
|
+
confidence: number;
|
|
415
|
+
surfaces: readonly Surface[];
|
|
416
|
+
target: {
|
|
417
|
+
roles?: readonly string[];
|
|
418
|
+
keys?: boolean;
|
|
419
|
+
};
|
|
420
|
+
views: readonly ViewName[];
|
|
421
|
+
matcher: Matcher;
|
|
422
|
+
escalation?: boolean;
|
|
423
|
+
suppressible: boolean;
|
|
424
|
+
explanation: string;
|
|
425
|
+
remediation: string;
|
|
426
|
+
testCases: {
|
|
427
|
+
positive: readonly RuleTestCase[];
|
|
428
|
+
negative: readonly RuleTestCase[];
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
export interface LoadedRuleset {
|
|
432
|
+
status: "ok" | "loaded-with-errors" | "fallback" | "unavailable";
|
|
433
|
+
rulesetId: string;
|
|
434
|
+
version: string;
|
|
435
|
+
sequence: number;
|
|
436
|
+
expiresAt: string;
|
|
437
|
+
/** "now" passed to loadRuleset; used only to compute `expired`. */
|
|
438
|
+
expired: boolean;
|
|
439
|
+
protectionDegraded: boolean;
|
|
440
|
+
degradedCause?: "tampered" | "downgrade";
|
|
441
|
+
rules: readonly RuleDef[];
|
|
442
|
+
irreversibleTags: readonly ActionTag[];
|
|
443
|
+
errors: readonly string[];
|
|
444
|
+
}
|
|
445
|
+
export interface TrustedKey {
|
|
446
|
+
keyId: string;
|
|
447
|
+
publicKey: Uint8Array;
|
|
448
|
+
}
|
|
449
|
+
export interface LoadRulesetOptions {
|
|
450
|
+
minSequence: number;
|
|
451
|
+
now: string;
|
|
452
|
+
/** Test/dev only. Production callers must not pass this; the embedded keys apply. */
|
|
453
|
+
trustedKeys?: readonly TrustedKey[];
|
|
454
|
+
}
|
|
455
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Public types. Kept free of logic.
|
|
2
|
+
export const ACTION_TAGS = [
|
|
3
|
+
"fs.read", "fs.read.sensitive", "fs.write", "fs.delete", "fs.destroy", "fs.move", "net.egress",
|
|
4
|
+
"net.fetch.package-manager", "net.fetch.vcs", "vcs.commit", "vcs.push", "vcs.force-push",
|
|
5
|
+
"vcs.history-rewrite", "vcs.discard-changes", "db.read", "db.write", "db.delete", "db.ddl",
|
|
6
|
+
"db.unscoped-write", "deploy.prod", "deploy.other", "infra.change", "payment", "publish.public",
|
|
7
|
+
"message.send", "perm.change", "exec.inline-code", "exec.project-code", "exec.unknown",
|
|
8
|
+
"exec.nested-agent", "config.agent", "self-protection",
|
|
9
|
+
];
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
const HEX = "0123456789abcdef";
|
|
4
|
+
export function utf8(s) {
|
|
5
|
+
return encoder.encode(s);
|
|
6
|
+
}
|
|
7
|
+
export function toHex(bytes) {
|
|
8
|
+
let out = "";
|
|
9
|
+
for (const b of bytes)
|
|
10
|
+
out += HEX[b >> 4] + HEX[b & 15];
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
export function sha256Hex(s) {
|
|
14
|
+
return toHex(sha256(typeof s === "string" ? utf8(s) : s));
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Time spent on one-time initialization (compiling linear regexes, building lookup tables).
|
|
2
|
+
// The per-call hardStopMs backstop excludes it, so a cold first call isn't mistaken for a
|
|
3
|
+
// pathological input. Pure bookkeeping: it never changes a result.
|
|
4
|
+
let total = 0;
|
|
5
|
+
export function initTimed(fn) {
|
|
6
|
+
const t = performance.now();
|
|
7
|
+
try {
|
|
8
|
+
return fn();
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
total += performance.now() - t;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function initMs() {
|
|
15
|
+
return total;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=initclock.js.map
|
package/dist/util/jcs.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// RFC 8785 JSON Canonicalization Scheme, hand-written.
|
|
2
|
+
// Works on snapshot values (null-prototype objects, arrays, strings, finite numbers,
|
|
3
|
+
// booleans, null). Iterative, so input depth can't overflow the stack.
|
|
4
|
+
export class JcsError extends Error {
|
|
5
|
+
}
|
|
6
|
+
function serializeString(s) {
|
|
7
|
+
let out = '"';
|
|
8
|
+
for (let i = 0; i < s.length; i++) {
|
|
9
|
+
const c = s.charCodeAt(i);
|
|
10
|
+
if (c === 0x22)
|
|
11
|
+
out += '\\"';
|
|
12
|
+
else if (c === 0x5c)
|
|
13
|
+
out += "\\\\";
|
|
14
|
+
else if (c === 0x08)
|
|
15
|
+
out += "\\b";
|
|
16
|
+
else if (c === 0x0c)
|
|
17
|
+
out += "\\f";
|
|
18
|
+
else if (c === 0x0a)
|
|
19
|
+
out += "\\n";
|
|
20
|
+
else if (c === 0x0d)
|
|
21
|
+
out += "\\r";
|
|
22
|
+
else if (c === 0x09)
|
|
23
|
+
out += "\\t";
|
|
24
|
+
else if (c < 0x20)
|
|
25
|
+
out += "\\u" + c.toString(16).padStart(4, "0");
|
|
26
|
+
else
|
|
27
|
+
out += s[i];
|
|
28
|
+
}
|
|
29
|
+
return out + '"';
|
|
30
|
+
}
|
|
31
|
+
function serializeNumber(n) {
|
|
32
|
+
if (!Number.isFinite(n))
|
|
33
|
+
throw new JcsError("non-finite number");
|
|
34
|
+
// ECMAScript Number::toString is exactly the RFC 8785 number format.
|
|
35
|
+
return Object.is(n, -0) ? "0" : String(n);
|
|
36
|
+
}
|
|
37
|
+
/** Compare by UTF-16 code units, as RFC 8785 §3.2.3 requires. */
|
|
38
|
+
function compareKeys(a, b) {
|
|
39
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
40
|
+
}
|
|
41
|
+
export function jcs(value) {
|
|
42
|
+
const parts = [];
|
|
43
|
+
const stack = [{ kind: "value", v: value }];
|
|
44
|
+
let steps = 0;
|
|
45
|
+
while (stack.length > 0) {
|
|
46
|
+
if (++steps > 5_000_000)
|
|
47
|
+
throw new JcsError("too large");
|
|
48
|
+
const f = stack.pop();
|
|
49
|
+
if (f.kind === "text") {
|
|
50
|
+
parts.push(f.s);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const v = f.v;
|
|
54
|
+
if (v === null)
|
|
55
|
+
parts.push("null");
|
|
56
|
+
else if (typeof v === "boolean")
|
|
57
|
+
parts.push(v ? "true" : "false");
|
|
58
|
+
else if (typeof v === "number")
|
|
59
|
+
parts.push(serializeNumber(v));
|
|
60
|
+
else if (typeof v === "string")
|
|
61
|
+
parts.push(serializeString(v));
|
|
62
|
+
else if (Array.isArray(v)) {
|
|
63
|
+
const frames = [{ kind: "text", s: "[" }];
|
|
64
|
+
v.forEach((x, i) => {
|
|
65
|
+
if (i > 0)
|
|
66
|
+
frames.push({ kind: "text", s: "," });
|
|
67
|
+
frames.push({ kind: "value", v: x });
|
|
68
|
+
});
|
|
69
|
+
frames.push({ kind: "text", s: "]" });
|
|
70
|
+
for (let i = frames.length - 1; i >= 0; i--)
|
|
71
|
+
stack.push(frames[i]);
|
|
72
|
+
}
|
|
73
|
+
else if (typeof v === "object") {
|
|
74
|
+
const o = v;
|
|
75
|
+
const keys = Object.keys(o).filter((k) => o[k] !== undefined).sort(compareKeys);
|
|
76
|
+
const frames = [{ kind: "text", s: "{" }];
|
|
77
|
+
keys.forEach((k, i) => {
|
|
78
|
+
frames.push({ kind: "text", s: (i > 0 ? "," : "") + serializeString(k) + ":" });
|
|
79
|
+
frames.push({ kind: "value", v: o[k] });
|
|
80
|
+
});
|
|
81
|
+
frames.push({ kind: "text", s: "}" });
|
|
82
|
+
for (let i = frames.length - 1; i >= 0; i--)
|
|
83
|
+
stack.push(frames[i]);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new JcsError("non-JSON value");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return parts.join("");
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=jcs.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Deep-freeze plain data (iterative). */
|
|
2
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
3
|
+
/**
|
|
4
|
+
* Removes trailing characters in `chars`. Linear time: a regex like /[. ]+$/ backtracks
|
|
5
|
+
* quadratically in V8 on a long run that isn't at the end (a 120 KB path took 27 s).
|
|
6
|
+
*/
|
|
7
|
+
export declare function trimEndChars(s: string, chars: string): string;
|
|
8
|
+
export declare function isRecord(v: unknown): v is Record<string, unknown>;
|
|
9
|
+
/** Own data property read on a snapshot (null-prototype) object. */
|
|
10
|
+
export declare function get(v: unknown, key: string): unknown;
|
|
11
|
+
export declare function getString(v: unknown, key: string): string | undefined;
|
|
12
|
+
export declare function codePointLength(s: string): number;
|
|
13
|
+
/** RFC 6901 pointer segment escaping. */
|
|
14
|
+
export declare function ptrSeg(k: string | number): string;
|
|
15
|
+
export declare function utf8Length(s: string): number;
|
|
16
|
+
export declare function uniq<T>(xs: Iterable<T>): T[];
|
|
17
|
+
//# sourceMappingURL=misc.d.ts.map
|