@glassbox-ai/engine 0.1.0 → 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/README.md +2 -0
- package/dist/action/acc.d.ts +1 -1
- package/dist/action/builtin-tools.d.ts +5 -0
- package/dist/action/builtin-tools.js +74 -0
- package/dist/action/inline.js +2 -2
- package/dist/action/paths.js +1 -1
- package/dist/action/powershell.js +2 -2
- package/dist/action/shell/analyze.js +36 -9
- package/dist/action/shell/parse.js +1 -1
- package/dist/action/shell/view.js +1 -1
- package/dist/action/sql.js +1 -1
- package/dist/action/tools.js +68 -3
- package/dist/analysis/fields.js +3 -3
- package/dist/analysis/findings.js +1 -1
- package/dist/analysis/gate.js +8 -6
- package/dist/analysis/manifest.js +2 -2
- package/dist/analysis/match.js +2 -2
- package/dist/analysis/scan.js +1 -1
- package/dist/canon/decode.js +1 -1
- package/dist/canon/views.js +1 -1
- package/dist/evidence/evidence.js +1 -1
- package/dist/fingerprint/diff.js +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +6 -2
- package/dist/intake/json.js +1 -1
- package/dist/intake/snapshot.js +1 -1
- package/dist/policy/decide.d.ts +7 -1
- package/dist/policy/decide.js +42 -11
- package/dist/ruleset/load.d.ts +2 -3
- package/dist/ruleset/load.js +20 -6
- package/dist/ruleset/schema.d.ts +1 -1
- package/dist/ruleset/schema.js +1 -1
- package/dist/ruleset-entry.js +1 -1
- package/dist/secrets/detect.js +2 -2
- package/dist/secrets/redact.js +1 -1
- package/dist/types.d.ts +21 -0
- package/dist/types.js +1 -1
- package/dist/util/jcs.js +1 -1
- package/dist/util/re.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @glassbox-ai/engine
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@glassbox-ai/engine)
|
|
4
|
+
|
|
3
5
|
Checks what an AI agent is about to do and what it reads. For each step it answers allow,
|
|
4
6
|
warn, ask or deny. It also grades MCP servers from their metadata. It's a library with no I/O;
|
|
5
7
|
it is deterministic and never throws.
|
package/dist/action/acc.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface CodeFinding {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class Acc {
|
|
8
8
|
level: ActionRiskLevel;
|
|
9
|
-
tags: Set<"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"
|
|
9
|
+
tags: Set<"self-protection" | "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">;
|
|
10
10
|
unanalyzableReasons: string[];
|
|
11
11
|
selfProtection: boolean;
|
|
12
12
|
findings: CodeFinding[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BuiltinToolCategory } from "../types.js";
|
|
2
|
+
export declare const BUILTIN_TOOLS: Readonly<Record<string, BuiltinToolCategory>>;
|
|
3
|
+
/** Category of a built-in tool, matched case-insensitively; undefined if unknown. */
|
|
4
|
+
export declare function builtinCategory(name: string): BuiltinToolCategory | undefined;
|
|
5
|
+
//# sourceMappingURL=builtin-tools.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export const BUILTIN_TOOLS = Object.freeze({
|
|
2
|
+
// Runs commands: full shell analysis.
|
|
3
|
+
Bash: "command",
|
|
4
|
+
PowerShell: "command",
|
|
5
|
+
Monitor: "command",
|
|
6
|
+
// Writes files.
|
|
7
|
+
Edit: "write",
|
|
8
|
+
Write: "write",
|
|
9
|
+
NotebookEdit: "write",
|
|
10
|
+
EnterWorktree: "write",
|
|
11
|
+
ExitWorktree: "write",
|
|
12
|
+
// Network: sends data off the machine.
|
|
13
|
+
WebFetch: "network",
|
|
14
|
+
WebSearch: "network",
|
|
15
|
+
Artifact: "network",
|
|
16
|
+
ShareOnboardingGuide: "network",
|
|
17
|
+
// Spawns agents or schedules agent work. Their tool calls are checked on their own.
|
|
18
|
+
Agent: "agent",
|
|
19
|
+
Workflow: "agent",
|
|
20
|
+
Skill: "agent",
|
|
21
|
+
SendMessage: "agent",
|
|
22
|
+
CronCreate: "agent",
|
|
23
|
+
ScheduleWakeup: "agent",
|
|
24
|
+
RemoteTrigger: "agent",
|
|
25
|
+
// Reads only.
|
|
26
|
+
Read: "read",
|
|
27
|
+
Glob: "read",
|
|
28
|
+
Grep: "read",
|
|
29
|
+
LSP: "read",
|
|
30
|
+
ListMcpResourcesTool: "read",
|
|
31
|
+
ReadMcpResourceTool: "read",
|
|
32
|
+
ToolSearch: "read",
|
|
33
|
+
TaskGet: "read",
|
|
34
|
+
TaskList: "read",
|
|
35
|
+
CronList: "read",
|
|
36
|
+
ListAgents: "read",
|
|
37
|
+
ListPlugins: "read",
|
|
38
|
+
ListSkills: "read",
|
|
39
|
+
SearchPlugins: "read",
|
|
40
|
+
SearchSkills: "read",
|
|
41
|
+
WaitForMcpServers: "read",
|
|
42
|
+
// Other: conversation, planning, task list and notification tools that act only inside the session.
|
|
43
|
+
AskUserQuestion: "other",
|
|
44
|
+
EndConversation: "other",
|
|
45
|
+
EnterPlanMode: "other",
|
|
46
|
+
ExitPlanMode: "other",
|
|
47
|
+
propose_skills: "other",
|
|
48
|
+
PushNotification: "other",
|
|
49
|
+
ReportFindings: "other",
|
|
50
|
+
SendFeedback: "other",
|
|
51
|
+
SendUserFile: "other",
|
|
52
|
+
SubagentHandback: "other",
|
|
53
|
+
SuggestPluginInstall: "other",
|
|
54
|
+
SuggestSkills: "other",
|
|
55
|
+
TaskCreate: "other",
|
|
56
|
+
TaskStop: "other",
|
|
57
|
+
TaskUpdate: "other",
|
|
58
|
+
TodoWrite: "other",
|
|
59
|
+
CronDelete: "other",
|
|
60
|
+
// Older names still accepted from earlier Claude Code versions.
|
|
61
|
+
Task: "agent",
|
|
62
|
+
MultiEdit: "write",
|
|
63
|
+
LS: "read",
|
|
64
|
+
NotebookRead: "read",
|
|
65
|
+
TodoRead: "other",
|
|
66
|
+
BashOutput: "read",
|
|
67
|
+
TaskOutput: "read",
|
|
68
|
+
});
|
|
69
|
+
const LOWER = new Map(Object.entries(BUILTIN_TOOLS).map(([k, v]) => [k.toLowerCase(), v]));
|
|
70
|
+
/** Category of a built-in tool, matched case-insensitively; undefined if unknown. */
|
|
71
|
+
export function builtinCategory(name) {
|
|
72
|
+
return LOWER.get(name.toLowerCase());
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=builtin-tools.js.map
|
package/dist/action/inline.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Interpreter inline code
|
|
1
|
+
// Interpreter inline code.
|
|
2
2
|
// A token heuristic: obfuscation markers → unanalyzable; dangerous tokens → high-risk;
|
|
3
|
-
// otherwise write-reversible. Bypassable by design
|
|
3
|
+
// otherwise write-reversible. Bypassable by design.
|
|
4
4
|
import { test } from "../util/re.js";
|
|
5
5
|
const MARKERS = [
|
|
6
6
|
["__import__", "__import__"],
|
package/dist/action/paths.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Path normalization and the protected / protected-read / sensitive sets
|
|
1
|
+
// Path normalization and the protected / protected-read / sensitive sets.
|
|
2
2
|
// Purely lexical: the engine can't see the filesystem.
|
|
3
3
|
import { trimEndChars } from "../util/misc.js";
|
|
4
4
|
import { JOB_LABEL } from "./schedule.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// PowerShell analysis
|
|
2
|
-
// cmdlet classes; native programs go through the
|
|
1
|
+
// PowerShell analysis: hand-written tokenizer, alias table,
|
|
2
|
+
// cmdlet classes; native programs go through the shell command table.
|
|
3
3
|
import { Acc } from "./acc.js";
|
|
4
4
|
import { homeTopLevel, isProtected, isProtectedRead, normalizePath, persistenceHit, sensitiveLabel } from "./paths.js";
|
|
5
5
|
import { isProtectedWrite } from "./protected-write.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Shell classification
|
|
1
|
+
// Shell classification over the parsed AST.
|
|
2
2
|
import { Acc } from "../acc.js";
|
|
3
3
|
import { allLoopback, classifyUpload, recordUpload } from "../upload.js";
|
|
4
4
|
import { commandFiles, schtasksJob } from "../schedule.js";
|
|
@@ -560,10 +560,7 @@ function classify(name0, args, cmd, st, acc, pctx, cwd, envPrefix, functions, un
|
|
|
560
560
|
}
|
|
561
561
|
// ── Self-protection commands ───────────────────────────────────────────
|
|
562
562
|
if (lower === "glassbox" || lower === "glassbox.exe") {
|
|
563
|
-
|
|
564
|
-
const mutating = ["mode", "allow", "uninstall", "logout", "login", "install", "pair", "unpair", "config", "set", "disable", "enable", "reset"].includes(sub) || (sub === "doctor" && hasFlag(args, "--fix"));
|
|
565
|
-
if (mutating || args.some((a) => a.value === null))
|
|
566
|
-
acc.protect("CP-SELF-003", "changes Glassbox protection settings");
|
|
563
|
+
glassboxCli(args, acc);
|
|
567
564
|
return;
|
|
568
565
|
}
|
|
569
566
|
if (lower === "claude" || lower === "claude.exe")
|
|
@@ -912,6 +909,13 @@ function interpreter(lower, args, c) {
|
|
|
912
909
|
return;
|
|
913
910
|
}
|
|
914
911
|
}
|
|
912
|
+
// An interpreter running the Glassbox CLI script directly (node …/glassbox/dist/cli.js allow …).
|
|
913
|
+
const gbScript = args.findIndex((a) => a.value !== null && !a.value.startsWith("-") && a.value.toLowerCase().includes("glassbox"));
|
|
914
|
+
if (gbScript >= 0) {
|
|
915
|
+
glassboxCli(args.slice(gbScript + 1), acc);
|
|
916
|
+
if (acc.selfProtection)
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
915
919
|
const hereStr = cmd.redirects.find((r) => r.op === "<<<")?.target;
|
|
916
920
|
const body = cmd.redirects.find((r) => r.heredoc)?.heredoc?.body ?? (hereStr ? wordInfo(hereStr).value ?? "" : "");
|
|
917
921
|
if (body && protectedText(body, pctx)) {
|
|
@@ -927,7 +931,7 @@ function interpreter(lower, args, c) {
|
|
|
927
931
|
acc.unanalyzable("inline code isn't a literal string");
|
|
928
932
|
return;
|
|
929
933
|
}
|
|
930
|
-
// Protected paths inside the code → self-protection
|
|
934
|
+
// Protected paths inside the code → self-protection.
|
|
931
935
|
if (protectedText(code.value, pctx)) {
|
|
932
936
|
const lowerCode = code.value.toLowerCase();
|
|
933
937
|
acc.protect(lowerCode.includes(".key") || lowerCode.includes("device") ? "CP-SELF-002" : "CP-SELF-001", "inline code refers to a protected agent or Glassbox file");
|
|
@@ -1008,6 +1012,17 @@ function protectedText(text, pctx) {
|
|
|
1008
1012
|
needles.push(norm(sp));
|
|
1009
1013
|
return needles.some((n) => n.length > 0 && t.includes(n));
|
|
1010
1014
|
}
|
|
1015
|
+
/**
|
|
1016
|
+
* The Glassbox CLI: subcommands that change protection are self-protection (the agent may
|
|
1017
|
+
* never run them, however it launches the CLI). A non-literal argument counts as changing.
|
|
1018
|
+
*/
|
|
1019
|
+
const GLASSBOX_MUTATING = new Set(["mode", "allow", "uninstall", "logout", "login", "install", "pair", "unpair", "config", "set", "disable", "enable", "reset", "deny", "forget", "revoke"]);
|
|
1020
|
+
function glassboxCli(args, acc) {
|
|
1021
|
+
const sub = (operands(args)[0]?.value ?? "").toLowerCase();
|
|
1022
|
+
const mutating = GLASSBOX_MUTATING.has(sub) || (sub === "doctor" && hasFlag(args, "--fix"));
|
|
1023
|
+
if (mutating || args.some((a) => a.value === null))
|
|
1024
|
+
acc.protect("CP-SELF-003", "changes Glassbox protection settings");
|
|
1025
|
+
}
|
|
1011
1026
|
function projectTool(rest, c, unwrapDepth) {
|
|
1012
1027
|
const h = rest[0];
|
|
1013
1028
|
if (!h || h.value === null) {
|
|
@@ -1015,6 +1030,11 @@ function projectTool(rest, c, unwrapDepth) {
|
|
|
1015
1030
|
return;
|
|
1016
1031
|
}
|
|
1017
1032
|
const n = (() => { const v = h.value; const slash = v.lastIndexOf("/"); const at = v.indexOf("@", slash + 1); return (at >= 0 ? v.slice(0, at) : v).split("/").pop() ?? ""; })();
|
|
1033
|
+
// A package runner launching the Glassbox CLI (npx glassbox allow …, pnpm dlx @glassbox-ai/…).
|
|
1034
|
+
if (h.value.toLowerCase().includes("glassbox")) {
|
|
1035
|
+
glassboxCli(rest.slice(1), c.acc);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1018
1038
|
if (PROJECT.has(n) || READ.has(n)) {
|
|
1019
1039
|
c.acc.tag("write-reversible", "exec.project-code");
|
|
1020
1040
|
return;
|
|
@@ -1918,9 +1938,16 @@ function gh(args, c) {
|
|
|
1918
1938
|
acc.network = true;
|
|
1919
1939
|
const vals = args.map((a) => a.value ?? "");
|
|
1920
1940
|
const [a, b] = operands(args, new Set(["-R", "--repo", "-t", "--title", "-b", "--body", "-F", "--body-file", "-m", "--milestone", "-l", "--label", "-a", "--assignee", "-B", "--base", "-H", "--head", "-L", "--limit", "-q", "--jq", "--json", "-r", "--reviewer", "-n", "--notes"])).map((x) => x.value ?? "");
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1941
|
+
// Pull requests and issues are conversations with the repo's collaborators: message.send
|
|
1942
|
+
// (asks by default; can be remembered). Releases, gists, repos, secrets and workflows publish
|
|
1943
|
+
// or change what others get: publish.public (hard floor).
|
|
1944
|
+
const message = (a === "pr" && ["create", "comment", "merge", "review", "close", "reopen", "edit", "ready"].includes(b ?? "")) ||
|
|
1945
|
+
(a === "issue" && ["create", "comment", "close", "reopen", "edit", "delete", "transfer", "lock"].includes(b ?? ""));
|
|
1946
|
+
if (message) {
|
|
1947
|
+
acc.tags.add("message.send");
|
|
1948
|
+
acc.reason("posts or changes a pull request or issue on GitHub");
|
|
1949
|
+
}
|
|
1950
|
+
const publish = (a === "release" && ["create", "upload", "edit", "delete"].includes(b ?? "")) ||
|
|
1924
1951
|
(a === "gist" && ["create", "edit", "delete"].includes(b ?? "")) ||
|
|
1925
1952
|
(a === "repo" && ["create", "delete", "edit", "rename", "archive", "fork"].includes(b ?? "")) ||
|
|
1926
1953
|
(a === "secret" && ["set", "delete"].includes(b ?? "")) || (a === "variable" && ["set", "delete"].includes(b ?? "")) ||
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Hand-written bash/sh parser
|
|
1
|
+
// Hand-written bash/sh parser. Recursive descent over a defined
|
|
2
2
|
// subset, bounded (bytes, nesting, tokens). Anything outside the subset → unanalyzable.
|
|
3
3
|
export const MAX_NESTING = 8;
|
|
4
4
|
export const MAX_TOKENS = 4096;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// T-DIFF support
|
|
1
|
+
// T-DIFF support: the parser's view of which commands a shell string
|
|
2
2
|
// runs, as argv lists. Unknown words are null (they match zero or more real words).
|
|
3
3
|
import { analyzeShellCommand, wordInfo } from "./analyze.js";
|
|
4
4
|
import { parseShell } from "./parse.js";
|
package/dist/action/sql.js
CHANGED
package/dist/action/tools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { get, getString, isRecord } from "../util/misc.js";
|
|
2
2
|
import { Acc } from "./acc.js";
|
|
3
3
|
import { coversProtectedRead, globCoversProtectedRead, isProtected, isProtectedRead, normalizePath, persistenceHit, sensitiveLabel, } from "./paths.js";
|
|
4
|
+
import { builtinCategory } from "./builtin-tools.js";
|
|
4
5
|
import { analyzePowerShell } from "./powershell.js";
|
|
5
6
|
import { isProtectedWrite } from "./protected-write.js";
|
|
6
7
|
import { analyzeShellCommand } from "./shell/analyze.js";
|
|
@@ -68,6 +69,26 @@ export function classifyBuiltin(toolName, args, t) {
|
|
|
68
69
|
writePath(p, acc, t);
|
|
69
70
|
return acc;
|
|
70
71
|
}
|
|
72
|
+
if (name === "monitor") {
|
|
73
|
+
// Monitor runs a background shell command (or watches a WebSocket) and streams its output
|
|
74
|
+
// to the agent. The command gets the full shell analysis, like Bash.
|
|
75
|
+
const cmd = str("command");
|
|
76
|
+
let out = cmd !== undefined ? analyzeShellCommand(cmd, { pctx: t.pctx, depth: 0, maxBytes: t.maxCommandBytes }) : null;
|
|
77
|
+
const wsUrl = getString(get(args, "ws"), "url");
|
|
78
|
+
if (wsUrl !== undefined) {
|
|
79
|
+
const a = out ?? acc;
|
|
80
|
+
a.tag("high-risk", "net.egress");
|
|
81
|
+
a.network = true;
|
|
82
|
+
const h = hostOf(wsUrl);
|
|
83
|
+
a.reason(h ? `watches a WebSocket on ${h}` : "watches a WebSocket on an unknown host");
|
|
84
|
+
out = a;
|
|
85
|
+
}
|
|
86
|
+
if (out === null) {
|
|
87
|
+
acc.unanalyzable("Monitor call without a command string");
|
|
88
|
+
return acc;
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
71
92
|
if (name === "webfetch") {
|
|
72
93
|
acc.tag("high-risk", "net.egress");
|
|
73
94
|
acc.network = true;
|
|
@@ -75,6 +96,19 @@ export function classifyBuiltin(toolName, args, t) {
|
|
|
75
96
|
acc.reason(h ? `destination host: ${h}` : "destination host unknown");
|
|
76
97
|
return acc;
|
|
77
98
|
}
|
|
99
|
+
if (name === "enterworktree") {
|
|
100
|
+
acc.tag("write-reversible", "fs.write");
|
|
101
|
+
const p = str("path");
|
|
102
|
+
if (p !== undefined)
|
|
103
|
+
writePath(p, acc, t);
|
|
104
|
+
acc.reason("creates or enters a git worktree");
|
|
105
|
+
return acc;
|
|
106
|
+
}
|
|
107
|
+
if (name === "exitworktree") {
|
|
108
|
+
acc.tag("write-reversible", "fs.write");
|
|
109
|
+
acc.reason("leaves a git worktree");
|
|
110
|
+
return acc;
|
|
111
|
+
}
|
|
78
112
|
if (READ_TOOLS.has(name)) {
|
|
79
113
|
if (name === "read" || name === "notebookread" || name === "lsp") {
|
|
80
114
|
const p = str("file_path") ?? str("filePath") ?? str("path") ?? str("notebook_path");
|
|
@@ -95,8 +129,39 @@ export function classifyBuiltin(toolName, args, t) {
|
|
|
95
129
|
}
|
|
96
130
|
return acc;
|
|
97
131
|
}
|
|
98
|
-
|
|
99
|
-
|
|
132
|
+
const label = toolName.slice(0, 40);
|
|
133
|
+
switch (builtinCategory(toolName)) {
|
|
134
|
+
case "network":
|
|
135
|
+
// Artifact, ShareOnboardingGuide: publish local content to a hosted page.
|
|
136
|
+
acc.tag("high-risk", "net.egress");
|
|
137
|
+
acc.network = true;
|
|
138
|
+
acc.reason(`sends content off the machine (${label})`);
|
|
139
|
+
return acc;
|
|
140
|
+
case "agent":
|
|
141
|
+
if (name === "remotetrigger") {
|
|
142
|
+
acc.tag("high-risk", "exec.nested-agent");
|
|
143
|
+
acc.reason("creates or runs a scheduled agent in the cloud, where these checks don't run");
|
|
144
|
+
return acc;
|
|
145
|
+
}
|
|
146
|
+
// Agent, Workflow, Skill, SendMessage, CronCreate, ScheduleWakeup: the work they start runs
|
|
147
|
+
// as ordinary tool calls in this Claude Code, and each of those is checked.
|
|
148
|
+
acc.raise("write-reversible");
|
|
149
|
+
acc.reason(`starts agent work (${label}); its tool calls are checked one by one`);
|
|
150
|
+
return acc;
|
|
151
|
+
case "other":
|
|
152
|
+
acc.raise("write-reversible");
|
|
153
|
+
acc.reason(`acts inside the session (${label})`);
|
|
154
|
+
return acc;
|
|
155
|
+
case "read":
|
|
156
|
+
return acc;
|
|
157
|
+
case "command":
|
|
158
|
+
case "write":
|
|
159
|
+
case undefined:
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
// A built-in tool this engine doesn't know: it may run commands or write files, and nothing
|
|
163
|
+
// here can tell. Unanalyzable (ask; deny in autopilot), never "harmless".
|
|
164
|
+
acc.unanalyzable(`unknown agent tool ${label}`);
|
|
100
165
|
return acc;
|
|
101
166
|
}
|
|
102
167
|
// ── MCP tools ────────────────────────────────────────────────────────────
|
|
@@ -218,7 +283,7 @@ export function classifyMcp(name, args, descriptor, t) {
|
|
|
218
283
|
}
|
|
219
284
|
}
|
|
220
285
|
if (sqlSeen) {
|
|
221
|
-
// The statement decides, not the tool's verb
|
|
286
|
+
// The statement decides, not the tool's verb.
|
|
222
287
|
const keep = new Acc();
|
|
223
288
|
keep.merge(sqlAcc);
|
|
224
289
|
for (const f of acc.findings)
|
package/dist/analysis/fields.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// C3
|
|
1
|
+
// C3: field enumeration with roles, per surface. Iterative.
|
|
2
2
|
import { jcs } from "../util/jcs.js";
|
|
3
3
|
import { isRecord, ptrSeg } from "../util/misc.js";
|
|
4
4
|
function walk(root, base, emit, maxNodes = 200_000) {
|
|
@@ -49,7 +49,7 @@ function schemaRole(path, isKey) {
|
|
|
49
49
|
export function manifestFields(m, maxTools) {
|
|
50
50
|
const out = [];
|
|
51
51
|
walk(m, "", (w, isKey) => {
|
|
52
|
-
// "key~dupN"
|
|
52
|
+
// "key~dupN" takes the role of "key".
|
|
53
53
|
const p = w.path.map((seg) => seg.replace(/~dup\d+$/, ""));
|
|
54
54
|
let role = "manifest.other";
|
|
55
55
|
let toolIndex;
|
|
@@ -84,7 +84,7 @@ export function manifestFields(m, maxTools) {
|
|
|
84
84
|
return;
|
|
85
85
|
out.push({ pointer: w.pointer, kind: isKey ? "key" : "string", role, text: String(w.v), keyName: w.key, ...(toolIndex !== undefined ? { toolIndex } : {}) });
|
|
86
86
|
});
|
|
87
|
-
// Non-string enum/default/const values are scanned in JCS form
|
|
87
|
+
// Non-string enum/default/const values are scanned in JCS form.
|
|
88
88
|
const tools = isRecord(m) && Array.isArray(m["tools"]) ? m["tools"] : [];
|
|
89
89
|
tools.slice(0, maxTools).forEach((t, ti) => {
|
|
90
90
|
for (const s of ["inputSchema", "outputSchema"]) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Finding construction
|
|
1
|
+
// Finding construction and the rule-metadata lookup.
|
|
2
2
|
import { makeEvidence } from "../evidence/evidence.js";
|
|
3
3
|
import { sha256Hex } from "../util/hash.js";
|
|
4
4
|
/** Minimal metadata for engine-emitted rules, used only if a ruleset lacks the rule. */
|
package/dist/analysis/gate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The gate: checkToolCall / checkToolResult / checkServerRequest
|
|
1
|
+
// The gate: checkToolCall / checkToolResult / checkServerRequest.
|
|
2
2
|
import { Acc } from "../action/acc.js";
|
|
3
3
|
import { normalizePath, pathCtxFrom } from "../action/paths.js";
|
|
4
4
|
import { commandFiles, cronLines, desktopJob, JOB_LABEL, plistJob, psTaskJob, unitJob } from "../action/schedule.js";
|
|
@@ -20,7 +20,7 @@ import { tokenize } from "./match.js";
|
|
|
20
20
|
import { scanFields } from "./scan.js";
|
|
21
21
|
const now = () => performance.now();
|
|
22
22
|
/**
|
|
23
|
-
* The gate's time backstop
|
|
23
|
+
* The gate's time backstop: true once this call has run longer than
|
|
24
24
|
* the limit, not counting one-time initialization (regex compiles, tables), which the first
|
|
25
25
|
* call in a process pays and later calls don't.
|
|
26
26
|
*/
|
|
@@ -338,13 +338,15 @@ export function checkToolCallImpl(input, ctxIn, t0) {
|
|
|
338
338
|
if (c.protectionDegraded)
|
|
339
339
|
signals.push({ kind: "protection-degraded", reason: degradedReason(c), atCall: at });
|
|
340
340
|
// A job that creates or changes something runs its files later. The caller keeps this signal
|
|
341
|
-
// only if the call is approved and runs
|
|
341
|
+
// only if the call is approved and runs; it doesn't expire.
|
|
342
342
|
for (const j of jobs)
|
|
343
343
|
if (j.verb !== "removes" && j.files.length > 0)
|
|
344
344
|
signals.push({ kind: "scheduled-job", job: j.kind, schedule: j.schedule, files: j.files, atCall: at });
|
|
345
345
|
const out = decide({
|
|
346
346
|
kind: "call", risk, findings: fs, degraded, protectionDegraded: c.protectionDegraded, ruleset: c.ruleset, policy: c.raw.policy,
|
|
347
|
-
minConfidence: c.limits.minConfidenceForVerdict, serverId, toolName, remembered: Array.isArray(c.raw.remembered) ? c.raw.remembered : [],
|
|
347
|
+
minConfidence: c.limits.minConfidenceForVerdict, serverId, toolName, remembered: Array.isArray(c.raw.remembered) ? c.raw.remembered.slice(0, 1000) : [],
|
|
348
|
+
projectIdHash: typeof c.raw.projectIdHash === "string" ? c.raw.projectIdHash : undefined, sessionId: typeof c.raw.sessionId === "string" ? c.raw.sessionId : "",
|
|
349
|
+
sessionGrants: Array.isArray(c.raw.sessionGrants) ? c.raw.sessionGrants.slice(0, 1000) : [],
|
|
348
350
|
});
|
|
349
351
|
return {
|
|
350
352
|
verdict: out.verdict,
|
|
@@ -462,7 +464,7 @@ export function checkToolResultImpl(input, ctxIn, t0) {
|
|
|
462
464
|
signals.push({ kind: "protection-degraded", reason: degradedReason(c), atCall: at });
|
|
463
465
|
const out = decide({
|
|
464
466
|
kind: "result", risk, findings: fs, degraded, protectionDegraded: c.protectionDegraded, ruleset: c.ruleset, policy: c.raw.policy,
|
|
465
|
-
minConfidence: c.limits.minConfidenceForVerdict, serverId, toolName, remembered: [],
|
|
467
|
+
minConfidence: c.limits.minConfidenceForVerdict, serverId, toolName, remembered: [], sessionId: "", sessionGrants: [],
|
|
466
468
|
});
|
|
467
469
|
let resultRewrite;
|
|
468
470
|
if (out.verdict === "deny") {
|
|
@@ -556,7 +558,7 @@ export function checkServerRequestImpl(input, ctxIn, t0) {
|
|
|
556
558
|
const degraded = ink.degraded || scan.windowed || scan.timedOut;
|
|
557
559
|
const out = decide({
|
|
558
560
|
kind: "server-request", risk, findings: fs, degraded, protectionDegraded: c.protectionDegraded, ruleset: c.ruleset, policy: c.raw.policy,
|
|
559
|
-
minConfidence: c.limits.minConfidenceForVerdict, serverId, toolName: method, remembered: [], requestVerdict: { verdict: choice, locked },
|
|
561
|
+
minConfidence: c.limits.minConfidenceForVerdict, serverId, toolName: method, remembered: [], sessionId: "", sessionGrants: [], requestVerdict: { verdict: choice, locked },
|
|
560
562
|
});
|
|
561
563
|
return {
|
|
562
564
|
verdict: out.verdict,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// analyzeServer
|
|
1
|
+
// analyzeServer: metadata-only analysis of an MCP manifest.
|
|
2
2
|
import { buildViews } from "../canon/views.js";
|
|
3
3
|
import { profileMcpTool, nameWords } from "../action/tools.js";
|
|
4
4
|
import { fingerprintOf } from "../fingerprint/fingerprint.js";
|
|
@@ -143,7 +143,7 @@ export function analyzeServerImpl(manifestIn, opts, t0) {
|
|
|
143
143
|
const tools = toolsRaw.slice(0, limits.maxTools);
|
|
144
144
|
// Layer 1 over every field.
|
|
145
145
|
const fields = manifestFields(m, limits.maxTools);
|
|
146
|
-
// The grader's time backstop
|
|
146
|
+
// The grader's time backstop.
|
|
147
147
|
const deadline = t0 + (opts?.limits?.hardStopMs ?? 2000);
|
|
148
148
|
const scan = scanFields(fields, "manifest", ff, ruleset.rules, limits, true, deadline);
|
|
149
149
|
findings.push(...scan.findings);
|
package/dist/analysis/match.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Layer 1 declarative matching
|
|
1
|
+
// Layer 1 declarative matching.
|
|
2
2
|
import { findDecodable } from "../canon/decode.js";
|
|
3
3
|
import { buildViews, normChar } from "../canon/views.js";
|
|
4
4
|
import { detectSecrets } from "../secrets/detect.js";
|
|
@@ -7,7 +7,7 @@ const RE_WORDCH = /^[\p{L}\p{M}\p{N}]$/u;
|
|
|
7
7
|
const RE_WS = /^\p{White_Space}$/u;
|
|
8
8
|
function rawNormOf(s) {
|
|
9
9
|
// Like norm, but invisibles/ANSI/bidi/tags are NOT removed: used to tell whether a
|
|
10
|
-
// match only exists because hidden characters were stripped
|
|
10
|
+
// match only exists because hidden characters were stripped.
|
|
11
11
|
let out = "";
|
|
12
12
|
let space = false;
|
|
13
13
|
for (const ch of s) {
|
package/dist/analysis/scan.js
CHANGED
|
@@ -20,7 +20,7 @@ export function mixedScript(text) {
|
|
|
20
20
|
}
|
|
21
21
|
export function scanFields(fields, surface, ff, rules, limits, hidden, deadline = Number.POSITIVE_INFINITY) {
|
|
22
22
|
// The time backstop: checked before each field and between rules, so one large field
|
|
23
|
-
// can't run far past it
|
|
23
|
+
// can't run far past it.
|
|
24
24
|
const late = typeof deadline === "function" ? deadline : () => performance.now() > deadline;
|
|
25
25
|
const findings = [];
|
|
26
26
|
const scans = new Map();
|
package/dist/canon/decode.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// C5
|
|
1
|
+
// C5: find encoded blobs with a linear scanner and decode them.
|
|
2
2
|
// Kept only if the result is valid UTF-8 with ≥ 80% printable code points.
|
|
3
3
|
import { trimEndChars } from "../util/misc.js";
|
|
4
4
|
const B64 = new Set("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/-_=");
|
package/dist/canon/views.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// C4
|
|
1
|
+
// C4: Unicode views with offset maps back to the original string.
|
|
2
2
|
// All transforms are per code point (after invisible/ANSI removal), so each view is
|
|
3
3
|
// idempotent (P1) and every output position maps to an original position.
|
|
4
4
|
import { CONFUSABLES } from "./confusables.generated.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Evidence construction
|
|
1
|
+
// Evidence construction and renderForModel.
|
|
2
2
|
import { DEFAULT_LIMITS } from "../limits.js";
|
|
3
3
|
import { redactString } from "../secrets/redact.js";
|
|
4
4
|
const MARKUP = new Set(["\\", "`", "*", "_", "[", "]", "(", ")", "<", ">", "#", "|", "~", "!", "{", "}", '"']);
|
package/dist/fingerprint/diff.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Fingerprint diff
|
|
1
|
+
// Fingerprint diff and the cloaking check.
|
|
2
2
|
import { FindingFactory } from "../analysis/findings.js";
|
|
3
3
|
import { displayTokens } from "../evidence/evidence.js";
|
|
4
4
|
import { EMBEDDED_BASELINE } from "../ruleset/baseline.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { ActionContext, ActionRisk, AnalyzeOptions, Decision, DiffOptions, Finding, Fingerprint, FingerprintResult, LoadedRuleset, ManifestDiff, RedactOptions, Redacted, ServerReport, SessionContext } from "./types.js";
|
|
2
2
|
export * from "./types.js";
|
|
3
|
+
/** Built-in Claude Code tools the engine knows, by category. Any other built-in tool is unanalyzable. */
|
|
4
|
+
export { BUILTIN_TOOLS } from "./action/builtin-tools.js";
|
|
5
|
+
/** Actions that always ask (deny in autopilot), whatever the user set up or the ruleset says. */
|
|
6
|
+
export { HARD_FLOOR_TAGS } from "./policy/decide.js";
|
|
3
7
|
export declare const ENGINE_VERSION: string;
|
|
4
8
|
export declare const EMBEDDED_BASELINE: LoadedRuleset;
|
|
5
|
-
/** The only wording a grade may be presented with
|
|
9
|
+
/** The only wording a grade may be presented with. */
|
|
6
10
|
export declare const GRADE_SCOPE_STATEMENT = "A grade checks what a server says about its tools. It doesn't inspect the server's code.";
|
|
7
11
|
export declare function analyzeServer(manifest: unknown, opts?: AnalyzeOptions): ServerReport;
|
|
8
12
|
export declare function fingerprint(manifest: unknown): FingerprintResult;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @glassbox-ai/engine public API
|
|
1
|
+
// @glassbox-ai/engine public API. Every function is synchronous, pure and
|
|
2
2
|
// total: none of them throws, and a failure never becomes a silent allow.
|
|
3
3
|
import { classifyBuiltin, classifyMcp } from "./action/tools.js";
|
|
4
4
|
import { pathCtxFrom } from "./action/paths.js";
|
|
@@ -15,9 +15,13 @@ import { get, getString, isRecord } from "./util/misc.js";
|
|
|
15
15
|
import { ENGINE_VERSION as VERSION } from "./version.js";
|
|
16
16
|
import { resolveLimits } from "./limits.js";
|
|
17
17
|
export * from "./types.js";
|
|
18
|
+
/** Built-in Claude Code tools the engine knows, by category. Any other built-in tool is unanalyzable. */
|
|
19
|
+
export { BUILTIN_TOOLS } from "./action/builtin-tools.js";
|
|
20
|
+
/** Actions that always ask (deny in autopilot), whatever the user set up or the ruleset says. */
|
|
21
|
+
export { HARD_FLOOR_TAGS } from "./policy/decide.js";
|
|
18
22
|
export const ENGINE_VERSION = VERSION;
|
|
19
23
|
export const EMBEDDED_BASELINE = BASELINE;
|
|
20
|
-
/** The only wording a grade may be presented with
|
|
24
|
+
/** The only wording a grade may be presented with. */
|
|
21
25
|
export const GRADE_SCOPE_STATEMENT = "A grade checks what a server says about its tools. It doesn't inspect the server's code.";
|
|
22
26
|
const t = () => performance.now();
|
|
23
27
|
export function analyzeServer(manifest, opts) {
|
package/dist/intake/json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// C1–C2
|
|
1
|
+
// C1–C2: strict, bounded, iterative JSON parser.
|
|
2
2
|
// - builds null-prototype objects; __proto__/constructor/prototype are plain data (CP-PARSE-003)
|
|
3
3
|
// - duplicate keys are kept as "key~dupN" (CP-PARSE-001)
|
|
4
4
|
// - lone surrogates (escaped or raw) are flagged (CP-PARSE-005)
|
package/dist/intake/snapshot.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// C2.4
|
|
1
|
+
// C2.4: snapshot an object input into frozen null-prototype data.
|
|
2
2
|
// Reads only own enumerable data properties via descriptors (getters are never invoked),
|
|
3
3
|
// detects cycles, drops non-JSON values, survives hostile Proxies, bounded and iterative.
|
|
4
4
|
import { parseJsonStrict } from "./json.js";
|
package/dist/policy/decide.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActionRisk, Finding, LoadedRuleset, RememberedRule, UserPolicy, Verdict } from "../types.js";
|
|
1
|
+
import type { ActionRisk, ActionTag, Finding, LoadedRuleset, RememberedRule, SessionGrant, UserPolicy, Verdict } from "../types.js";
|
|
2
2
|
export declare const vmax: (a: Verdict, b: Verdict) => Verdict;
|
|
3
3
|
export interface DecideInput {
|
|
4
4
|
kind: "call" | "result" | "server-request";
|
|
@@ -12,6 +12,10 @@ export interface DecideInput {
|
|
|
12
12
|
serverId: string;
|
|
13
13
|
toolName: string;
|
|
14
14
|
remembered: readonly RememberedRule[];
|
|
15
|
+
/** The current project; a remembered rule applies only when its projectIdHash equals this. */
|
|
16
|
+
projectIdHash?: string | undefined;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
sessionGrants: readonly SessionGrant[];
|
|
15
19
|
/** checkServerRequest: verdict from the kind's policy (R13) and whether it's locked (R14). */
|
|
16
20
|
requestVerdict?: {
|
|
17
21
|
verdict: Verdict;
|
|
@@ -22,5 +26,7 @@ export interface DecideOutput {
|
|
|
22
26
|
verdict: Verdict;
|
|
23
27
|
verdictBeforeMode?: Verdict;
|
|
24
28
|
}
|
|
29
|
+
/** Fixed in the engine, not in the ruleset: no ruleset can remove a tag from the hard floor. */
|
|
30
|
+
export declare const HARD_FLOOR_TAGS: readonly ActionTag[];
|
|
25
31
|
export declare function decide(d: DecideInput): DecideOutput;
|
|
26
32
|
//# sourceMappingURL=decide.d.ts.map
|
package/dist/policy/decide.js
CHANGED
|
@@ -2,35 +2,66 @@ const ORDER = ["allow", "warn", "ask", "deny"];
|
|
|
2
2
|
export const vmax = (a, b) => (ORDER.indexOf(a) >= ORDER.indexOf(b) ? a : b);
|
|
3
3
|
const SEV = ["info", "low", "medium", "high", "critical"];
|
|
4
4
|
/**
|
|
5
|
-
* R3 by mode
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* R3 by mode.
|
|
6
|
+
* - Hard floor (HARD_FLOOR_TAGS, whatever the ruleset says): force push,
|
|
7
|
+
* history rewrite, wipes, payments, production deploys and publishing ask in every mode, and
|
|
8
|
+
* autopilot turns that into deny (R15). Nothing the user set up earlier lowers them: a
|
|
9
|
+
* tagOverride can only raise them to deny; remembered rules and session grants never lift them.
|
|
10
|
+
* - Other irreversible-or-public tags ask in every mode by default, but they are ordinary
|
|
11
|
+
* mode asks: a tagOverride, remembered rule or session grant can lift them.
|
|
12
|
+
* - Other high-risk tags: strict asks, balanced and autopilot warn.
|
|
8
13
|
*/
|
|
9
14
|
function modeVerdict(tag, mode, irreversible) {
|
|
10
15
|
if (tag !== null && irreversible.has(tag))
|
|
11
16
|
return "ask";
|
|
12
17
|
return mode === "strict" ? "ask" : "warn";
|
|
13
18
|
}
|
|
19
|
+
/** Fixed in the engine, not in the ruleset: no ruleset can remove a tag from the hard floor. */
|
|
20
|
+
export const HARD_FLOOR_TAGS = Object.freeze(["vcs.force-push", "vcs.history-rewrite", "fs.destroy", "payment", "deploy.prod", "publish.public"]);
|
|
21
|
+
// Private copy used for decisions: a Set can't be frozen, so the exported list is a frozen array
|
|
22
|
+
// and changing anything a caller can reach doesn't change the floor.
|
|
23
|
+
const HARD_FLOOR = new Set(HARD_FLOOR_TAGS);
|
|
24
|
+
const str = (x) => typeof x === "string" && x.length > 0;
|
|
25
|
+
/** A remembered rule (this project) or session grant (this session) covering (server, tool, tag). */
|
|
26
|
+
function lifted(d, tag) {
|
|
27
|
+
// Own string properties only: a field inherited through a prototype doesn't count.
|
|
28
|
+
const own = (m, k, want) => Object.hasOwn(m, k) && m[k] === want;
|
|
29
|
+
const match = (m, scopeKey, scope) => typeof m === "object" && m !== null && own(m, "serverId", d.serverId) && own(m, "toolName", d.toolName) && own(m, "actionTag", tag) && own(m, scopeKey, scope);
|
|
30
|
+
const project = d.projectIdHash;
|
|
31
|
+
if (str(project) && d.remembered.some((m) => match(m, "projectIdHash", project)))
|
|
32
|
+
return true;
|
|
33
|
+
return str(d.sessionId) && d.sessionGrants.some((g) => match(g, "sessionId", d.sessionId));
|
|
34
|
+
}
|
|
14
35
|
export function decide(d) {
|
|
15
36
|
const mode = d.policy.mode;
|
|
16
37
|
let v = "allow";
|
|
17
38
|
const irreversible = new Set(d.ruleset.irreversibleTags);
|
|
18
|
-
// R3 (calls only): high-risk action, by mode, then tagOverrides, then remembered rules
|
|
39
|
+
// R3 (calls only): high-risk action, by mode, then tagOverrides, then remembered rules and
|
|
40
|
+
// session grants (mode-driven asks only, never the hard floor).
|
|
19
41
|
if (d.kind === "call" && d.risk.level === "high-risk") {
|
|
20
42
|
const tags = d.risk.tags.filter((t) => t !== "self-protection");
|
|
21
43
|
let r3 = "allow";
|
|
22
|
-
|
|
44
|
+
let floorAsk = false;
|
|
45
|
+
const liftable = [];
|
|
23
46
|
const list = tags.length > 0 ? tags : [null];
|
|
24
47
|
for (const t of list) {
|
|
25
|
-
let tv = modeVerdict(t, mode, irreversible);
|
|
26
48
|
const o = t !== null ? d.policy.tagOverrides?.[t] : undefined;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
let tv;
|
|
50
|
+
if (t !== null && HARD_FLOOR.has(t)) {
|
|
51
|
+
tv = o === "deny" ? "deny" : "ask";
|
|
52
|
+
if (tv === "ask")
|
|
53
|
+
floorAsk = true;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
tv = modeVerdict(t, mode, irreversible);
|
|
57
|
+
if (o === "allow" || o === "ask" || o === "deny")
|
|
58
|
+
tv = o;
|
|
59
|
+
if (tv === "ask" && t !== null)
|
|
60
|
+
liftable.push(t);
|
|
61
|
+
}
|
|
31
62
|
r3 = vmax(r3, tv);
|
|
32
63
|
}
|
|
33
|
-
if (r3 === "ask" &&
|
|
64
|
+
if (r3 === "ask" && !floorAsk && liftable.length > 0 && liftable.every((t) => lifted(d, t)))
|
|
34
65
|
r3 = "allow";
|
|
35
66
|
v = vmax(v, r3);
|
|
36
67
|
}
|
package/dist/ruleset/load.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { LoadedRuleset, LoadRulesetOptions, TrustedKey } from "../types.js";
|
|
2
2
|
import { type RulesetPayload } from "./schema.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* embedded baseline is used (the fail-safe direction).
|
|
4
|
+
* A copy for callers to inspect. Typed arrays can't be frozen, so verification uses the
|
|
5
|
+
* private list above: changing these bytes doesn't change which keys the engine trusts.
|
|
7
6
|
*/
|
|
8
7
|
export declare const EMBEDDED_TRUSTED_KEYS: readonly TrustedKey[];
|
|
9
8
|
export declare const REVOKED_KEY_IDS: readonly string[];
|
package/dist/ruleset/load.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ruleset loading
|
|
1
|
+
// Ruleset loading.
|
|
2
2
|
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
import { decodeBase64 } from "../canon/decode.js";
|
|
@@ -11,11 +11,25 @@ import { EMBEDDED_BASELINE } from "./baseline.js";
|
|
|
11
11
|
import { EnvelopeSchema, PayloadSchema } from "./schema.js";
|
|
12
12
|
import { runRuleSelfTests } from "./selftest.js";
|
|
13
13
|
/**
|
|
14
|
-
* Trusted signing keys embedded in the engine build
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* Trusted signing keys embedded in the engine build (Ed25519, raw 32-byte public keys).
|
|
15
|
+
* The private keys are held offline by the maintainer and are never on a server, in CI or in
|
|
16
|
+
* this repository. Rotation: a release adds the new key, rulesets are re-signed, and a later
|
|
17
|
+
* release lists the old keyId in REVOKED_KEY_IDS.
|
|
18
|
+
*
|
|
19
|
+
* gbx-2026-a: created 2026-11-25. SHA-256 of the raw key:
|
|
20
|
+
* 67872a7dd309ddc3c7eb69e20a67125c77767673976bae97149ec782799f62a0
|
|
17
21
|
*/
|
|
18
|
-
|
|
22
|
+
const TRUSTED = Object.freeze([
|
|
23
|
+
Object.freeze({
|
|
24
|
+
keyId: "gbx-2026-a",
|
|
25
|
+
publicKey: new Uint8Array([190, 180, 255, 177, 167, 215, 118, 25, 172, 139, 36, 151, 55, 199, 138, 140, 220, 236, 181, 189, 112, 11, 85, 89, 56, 26, 137, 165, 154, 237, 99, 79]),
|
|
26
|
+
}),
|
|
27
|
+
]);
|
|
28
|
+
/**
|
|
29
|
+
* A copy for callers to inspect. Typed arrays can't be frozen, so verification uses the
|
|
30
|
+
* private list above: changing these bytes doesn't change which keys the engine trusts.
|
|
31
|
+
*/
|
|
32
|
+
export const EMBEDDED_TRUSTED_KEYS = Object.freeze(TRUSTED.map((k) => Object.freeze({ keyId: k.keyId, publicKey: k.publicKey.slice() })));
|
|
19
33
|
export const REVOKED_KEY_IDS = Object.freeze([]);
|
|
20
34
|
const DOMAIN = utf8("glassbox-ruleset-v1\u0000");
|
|
21
35
|
const MAX_RULESET_BYTES = 4 * 1024 * 1024;
|
|
@@ -99,7 +113,7 @@ export function buildLoaded(payload, now, extra = {}) {
|
|
|
99
113
|
}
|
|
100
114
|
export function loadRuleset(envelope, opts) {
|
|
101
115
|
try {
|
|
102
|
-
const keys = opts?.trustedKeys ??
|
|
116
|
+
const keys = opts?.trustedKeys ?? TRUSTED;
|
|
103
117
|
const minSequence = typeof opts?.minSequence === "number" ? opts.minSequence : 0;
|
|
104
118
|
const now = typeof opts?.now === "string" ? opts.now : "";
|
|
105
119
|
const size = typeof envelope === "string" ? envelope.length : envelope instanceof Uint8Array ? envelope.length : -1;
|
package/dist/ruleset/schema.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare const PayloadSchema: v.ObjectSchema<{
|
|
|
71
71
|
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
72
72
|
id: string;
|
|
73
73
|
revision: number;
|
|
74
|
-
category: "
|
|
74
|
+
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";
|
|
75
75
|
severity: "info" | "low" | "medium" | "high" | "critical";
|
|
76
76
|
confidence: number;
|
|
77
77
|
surfaces: ("server-request" | "manifest" | "call" | "result")[];
|
package/dist/ruleset/schema.js
CHANGED
package/dist/ruleset-entry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @glassbox-ai/engine/ruleset: loading signed ruleset caches
|
|
1
|
+
// @glassbox-ai/engine/ruleset: loading signed ruleset caches.
|
|
2
2
|
// Kept out of the main entry so an ordinary hook call doesn't pay for Ed25519 and schema
|
|
3
3
|
// validation at start-up (150 ms hook budget). Import this only when a cache file exists.
|
|
4
4
|
export { loadRuleset, EMBEDDED_TRUSTED_KEYS, REVOKED_KEY_IDS } from "./ruleset/load.js";
|
package/dist/secrets/detect.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Secret detectors
|
|
1
|
+
// Secret detectors. Patterns run on the linear regex engine (re2js).
|
|
2
2
|
import { findAll } from "../util/re.js";
|
|
3
3
|
const PLACEHOLDER = /^(\*+|x+|password|passwd|secret|changeme|<[^>]*>|\$\{[^}]*\}|\$[A-Z_]+|%[A-Z_]+%|\{\{[^}]*\}\})$/i;
|
|
4
4
|
function entropy(s) {
|
|
@@ -202,7 +202,7 @@ function resolveOverlaps(hits) {
|
|
|
202
202
|
}
|
|
203
203
|
return kept.sort((a, b) => a.start - b.start);
|
|
204
204
|
}
|
|
205
|
-
// ── Masking
|
|
205
|
+
// ── Masking ───────────────────────────────────────────────────────
|
|
206
206
|
const PUBLIC_PREFIXES = [
|
|
207
207
|
"github_pat_", "ghp_", "gho_", "ghu_", "ghs_", "ghr_", "glpat-", "gldt-", "glrt-", "xoxb-", "xoxa-", "xoxp-", "xoxr-", "xoxs-", "xapp-",
|
|
208
208
|
"sk_live_", "sk_test_", "rk_live_", "rk_test_", "whsec_", "sk-proj-", "sk-svcacct-", "sk-admin-", "AKIA", "ASIA", "ABIA", "ACCA", "AIza", "eyJ",
|
package/dist/secrets/redact.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// redact()
|
|
1
|
+
// redact(): deep copy with every detected secret masked.
|
|
2
2
|
// Unscanned content is replaced, never passed through raw.
|
|
3
3
|
import { findDecodable } from "../canon/decode.js";
|
|
4
4
|
import { resolveLimits } from "../limits.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -213,6 +213,13 @@ export interface ServerRequestInput {
|
|
|
213
213
|
serverId: string;
|
|
214
214
|
message: unknown;
|
|
215
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
|
+
*/
|
|
216
223
|
export interface RememberedRule {
|
|
217
224
|
projectIdHash: string;
|
|
218
225
|
serverId: string;
|
|
@@ -220,6 +227,17 @@ export interface RememberedRule {
|
|
|
220
227
|
actionTag: ActionTag;
|
|
221
228
|
createdAt: string;
|
|
222
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
|
+
}
|
|
223
241
|
export type PolicyChoice = "allow" | "ask" | "deny";
|
|
224
242
|
export interface UserPolicy {
|
|
225
243
|
mode: ApprovalMode;
|
|
@@ -237,7 +255,10 @@ export interface SessionContext {
|
|
|
237
255
|
platform: "linux" | "darwin" | "win32";
|
|
238
256
|
claudeConfigDir?: string;
|
|
239
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;
|
|
240
260
|
remembered?: readonly RememberedRule[];
|
|
261
|
+
sessionGrants?: readonly SessionGrant[];
|
|
241
262
|
homeDir: string;
|
|
242
263
|
cwd: string;
|
|
243
264
|
caseInsensitiveFs: boolean;
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Public types
|
|
1
|
+
// Public types. Kept free of logic.
|
|
2
2
|
export const ACTION_TAGS = [
|
|
3
3
|
"fs.read", "fs.read.sensitive", "fs.write", "fs.delete", "fs.destroy", "fs.move", "net.egress",
|
|
4
4
|
"net.fetch.package-manager", "net.fetch.vcs", "vcs.commit", "vcs.push", "vcs.force-push",
|
package/dist/util/jcs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// RFC 8785 JSON Canonicalization Scheme, hand-written
|
|
1
|
+
// RFC 8785 JSON Canonicalization Scheme, hand-written.
|
|
2
2
|
// Works on snapshot values (null-prototype objects, arrays, strings, finite numbers,
|
|
3
3
|
// booleans, null). Iterative, so input depth can't overflow the stack.
|
|
4
4
|
export class JcsError extends Error {
|
package/dist/util/re.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Linear-time regex
|
|
1
|
+
// Linear-time regex: every pattern applied to untrusted text goes
|
|
2
2
|
// through re2js. Compiled patterns are cached per pattern string (bounded cache).
|
|
3
3
|
import { RE2JS } from "re2js";
|
|
4
4
|
import { initTimed } from "./initclock.js";
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const ENGINE_VERSION = "0.1.
|
|
1
|
+
export declare const ENGINE_VERSION = "0.1.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const ENGINE_VERSION = "0.1.
|
|
1
|
+
export const ENGINE_VERSION = "0.1.1";
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glassbox-ai/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Glassbox security engine: pure, deterministic analysis of MCP metadata and agent tool calls.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -42,6 +42,11 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=24.11.0"
|
|
44
44
|
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -b",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"prepublishOnly": "tsc -b"
|
|
49
|
+
},
|
|
45
50
|
"dependencies": {
|
|
46
51
|
"@noble/curves": "2.4.0",
|
|
47
52
|
"@noble/hashes": "2.4.0",
|
|
@@ -50,9 +55,5 @@
|
|
|
50
55
|
},
|
|
51
56
|
"publishConfig": {
|
|
52
57
|
"access": "public"
|
|
53
|
-
},
|
|
54
|
-
"scripts": {
|
|
55
|
-
"build": "tsc -b",
|
|
56
|
-
"test": "vitest run"
|
|
57
58
|
}
|
|
58
|
-
}
|
|
59
|
+
}
|