@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/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Adithya Ramesh
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glassbox-ai/engine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@glassbox-ai/engine)
|
|
4
|
+
|
|
5
|
+
Checks what an AI agent is about to do and what it reads. For each step it answers allow,
|
|
6
|
+
warn, ask or deny. It also grades MCP servers from their metadata. It's a library with no I/O;
|
|
7
|
+
it is deterministic and never throws.
|
|
8
|
+
|
|
9
|
+
**Status: early, v0.1.** The API and the rules will change.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @glassbox-ai/engine
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { EMBEDDED_BASELINE, checkToolCall } from "@glassbox-ai/engine";
|
|
17
|
+
|
|
18
|
+
const decision = checkToolCall(
|
|
19
|
+
{ serverId: "builtin", toolName: "Bash", arguments: { command: "rm -rf ~/Documents" } },
|
|
20
|
+
{
|
|
21
|
+
sessionId: "s1", platform: "linux", homeDir: "/home/me", cwd: "/home/me/project",
|
|
22
|
+
caseInsensitiveFs: false, glassboxDirs: ["/home/me/.glassbox"], servers: [],
|
|
23
|
+
policy: { mode: "balanced" }, ruleset: EMBEDDED_BASELINE,
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
decision.verdict; // "deny"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The full guide covers `checkToolResult`, `analyzeServer`, session signals and modes. The
|
|
30
|
+
benchmark results include their limits: on a sealed holdout, 50.9% of attacks were stopped
|
|
31
|
+
overall, 92.3% of tool poisoning but only 25.3% of prompt injection in tool results, and 2.1%
|
|
32
|
+
of benign cases were stopped. See https://github.com/Adithya6ramesh/Glassbox#readme
|
|
33
|
+
|
|
34
|
+
Apache-2.0.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ActionRiskLevel, ActionTag } from "../types.js";
|
|
2
|
+
import { type JobKind, type ScheduledJob } from "./schedule.js";
|
|
3
|
+
export interface CodeFinding {
|
|
4
|
+
ruleId: string;
|
|
5
|
+
note?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class Acc {
|
|
8
|
+
level: ActionRiskLevel;
|
|
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
|
+
unanalyzableReasons: string[];
|
|
11
|
+
selfProtection: boolean;
|
|
12
|
+
findings: CodeFinding[];
|
|
13
|
+
reasons: string[];
|
|
14
|
+
sensitive: string[];
|
|
15
|
+
network: boolean;
|
|
16
|
+
sensitiveArgs: boolean;
|
|
17
|
+
/** Prints the whole environment (env, printenv, set, export -p): harmless alone, exfiltration next to a network call. */
|
|
18
|
+
envDump: boolean;
|
|
19
|
+
/** Git remotes added or repointed in this command, and push destinations (CP-EXFIL-034). */
|
|
20
|
+
newRemotes: string[];
|
|
21
|
+
/** Local files this command uploads, by kind (upload.ts). */
|
|
22
|
+
uploads: ("sensitive" | "outside" | "project")[];
|
|
23
|
+
/** Scheduled jobs this command creates, changes or removes (schedule.ts). */
|
|
24
|
+
scheduledJobs: ScheduledJob[];
|
|
25
|
+
/** Normalized paths this command writes, moves or deletes. */
|
|
26
|
+
writes: string[];
|
|
27
|
+
pushedTo: string[];
|
|
28
|
+
/** Paths read that are sensitive (for signals); labels only. */
|
|
29
|
+
raise(level: ActionRiskLevel): void;
|
|
30
|
+
tag(level: ActionRiskLevel, ...tags: ActionTag[]): void;
|
|
31
|
+
unanalyzable(reason: string): void;
|
|
32
|
+
protect(ruleId: "CP-SELF-001" | "CP-SELF-002" | "CP-SELF-003" | "CP-SELF-004", reason: string): void;
|
|
33
|
+
/** A write or delete of a persistence location: protected (deny) or a CP-SELF-005 ask. */
|
|
34
|
+
persist(hit: {
|
|
35
|
+
kind: "deny" | "ask" | "job";
|
|
36
|
+
label: string;
|
|
37
|
+
job?: JobKind;
|
|
38
|
+
} | null, verb: "changes" | "deletes", path?: string | null): void;
|
|
39
|
+
/** Creating, changing or removing a scheduled job: CP-SELF-006 (ask; deny in autopilot). */
|
|
40
|
+
scheduleJob(job: ScheduledJob): void;
|
|
41
|
+
/** A path this command writes, moves or deletes (for CP-SELF-007). */
|
|
42
|
+
wrote(path: string | null): void;
|
|
43
|
+
find(ruleId: string, note?: string): void;
|
|
44
|
+
reason(r: string): void;
|
|
45
|
+
merge(o: Acc): void;
|
|
46
|
+
get unanalyzableFlag(): boolean;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=acc.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { JOB_LABEL } from "./schedule.js";
|
|
2
|
+
export class Acc {
|
|
3
|
+
level = "read";
|
|
4
|
+
tags = new Set();
|
|
5
|
+
unanalyzableReasons = [];
|
|
6
|
+
selfProtection = false;
|
|
7
|
+
findings = [];
|
|
8
|
+
reasons = [];
|
|
9
|
+
sensitive = [];
|
|
10
|
+
network = false;
|
|
11
|
+
sensitiveArgs = false;
|
|
12
|
+
/** Prints the whole environment (env, printenv, set, export -p): harmless alone, exfiltration next to a network call. */
|
|
13
|
+
envDump = false;
|
|
14
|
+
/** Git remotes added or repointed in this command, and push destinations (CP-EXFIL-034). */
|
|
15
|
+
newRemotes = [];
|
|
16
|
+
/** Local files this command uploads, by kind (upload.ts). */
|
|
17
|
+
uploads = [];
|
|
18
|
+
/** Scheduled jobs this command creates, changes or removes (schedule.ts). */
|
|
19
|
+
scheduledJobs = [];
|
|
20
|
+
/** Normalized paths this command writes, moves or deletes. */
|
|
21
|
+
writes = [];
|
|
22
|
+
pushedTo = [];
|
|
23
|
+
/** Paths read that are sensitive (for signals); labels only. */
|
|
24
|
+
raise(level) {
|
|
25
|
+
const order = ["read", "write-reversible", "high-risk"];
|
|
26
|
+
if (order.indexOf(level) > order.indexOf(this.level))
|
|
27
|
+
this.level = level;
|
|
28
|
+
}
|
|
29
|
+
tag(level, ...tags) {
|
|
30
|
+
this.raise(level);
|
|
31
|
+
for (const t of tags)
|
|
32
|
+
this.tags.add(t);
|
|
33
|
+
}
|
|
34
|
+
unanalyzable(reason) {
|
|
35
|
+
if (!this.unanalyzableReasons.includes(reason) && this.unanalyzableReasons.length < 10)
|
|
36
|
+
this.unanalyzableReasons.push(reason);
|
|
37
|
+
this.raise("high-risk");
|
|
38
|
+
this.find("CP-SHELL-001", reason);
|
|
39
|
+
}
|
|
40
|
+
protect(ruleId, reason) {
|
|
41
|
+
this.selfProtection = true;
|
|
42
|
+
this.raise("high-risk");
|
|
43
|
+
this.tags.add("self-protection");
|
|
44
|
+
this.find(ruleId, reason);
|
|
45
|
+
this.reason(reason);
|
|
46
|
+
}
|
|
47
|
+
/** A write or delete of a persistence location: protected (deny) or a CP-SELF-005 ask. */
|
|
48
|
+
persist(hit, verb, path = null) {
|
|
49
|
+
if (hit === null)
|
|
50
|
+
return;
|
|
51
|
+
const why = `${verb} a ${hit.label}`;
|
|
52
|
+
if (hit.kind === "deny") {
|
|
53
|
+
this.protect("CP-SELF-004", why);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (hit.kind === "job" && hit.job) {
|
|
57
|
+
// The job file itself is recorded: it runs (Startup folder, cron.daily, init.d) or defines the job.
|
|
58
|
+
this.scheduleJob({ kind: hit.job, verb: verb === "deletes" ? "removes" : "changes", path, schedule: null, files: verb === "deletes" || path === null ? [] : [path] });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.tag("high-risk", "config.agent");
|
|
62
|
+
this.find("CP-SELF-005", why);
|
|
63
|
+
this.reason(why);
|
|
64
|
+
}
|
|
65
|
+
/** Creating, changing or removing a scheduled job: CP-SELF-006 (ask; deny in autopilot). */
|
|
66
|
+
scheduleJob(job) {
|
|
67
|
+
this.tag("high-risk", "infra.change");
|
|
68
|
+
const why = `${job.verb} a ${JOB_LABEL[job.kind]}`;
|
|
69
|
+
this.find("CP-SELF-006", why);
|
|
70
|
+
this.reason(why);
|
|
71
|
+
if (this.scheduledJobs.length < 20)
|
|
72
|
+
this.scheduledJobs.push(job);
|
|
73
|
+
}
|
|
74
|
+
/** A path this command writes, moves or deletes (for CP-SELF-007). */
|
|
75
|
+
wrote(path) {
|
|
76
|
+
if (path !== null && this.writes.length < 200 && !this.writes.includes(path))
|
|
77
|
+
this.writes.push(path);
|
|
78
|
+
}
|
|
79
|
+
find(ruleId, note) {
|
|
80
|
+
if (!this.findings.some((f) => f.ruleId === ruleId))
|
|
81
|
+
this.findings.push(note === undefined ? { ruleId } : { ruleId, note });
|
|
82
|
+
}
|
|
83
|
+
reason(r) {
|
|
84
|
+
if (!this.reasons.includes(r) && this.reasons.length < 20)
|
|
85
|
+
this.reasons.push(r);
|
|
86
|
+
}
|
|
87
|
+
merge(o) {
|
|
88
|
+
this.raise(o.level);
|
|
89
|
+
for (const t of o.tags)
|
|
90
|
+
this.tags.add(t);
|
|
91
|
+
for (const r of o.unanalyzableReasons)
|
|
92
|
+
if (!this.unanalyzableReasons.includes(r))
|
|
93
|
+
this.unanalyzableReasons.push(r);
|
|
94
|
+
if (o.selfProtection)
|
|
95
|
+
this.selfProtection = true;
|
|
96
|
+
for (const f of o.findings)
|
|
97
|
+
this.find(f.ruleId, f.note);
|
|
98
|
+
for (const r of o.reasons)
|
|
99
|
+
this.reason(r);
|
|
100
|
+
this.sensitive.push(...o.sensitive);
|
|
101
|
+
this.network ||= o.network;
|
|
102
|
+
this.sensitiveArgs ||= o.sensitiveArgs;
|
|
103
|
+
this.envDump ||= o.envDump;
|
|
104
|
+
this.newRemotes.push(...o.newRemotes);
|
|
105
|
+
this.uploads.push(...o.uploads);
|
|
106
|
+
for (const j of o.scheduledJobs)
|
|
107
|
+
if (this.scheduledJobs.length < 20)
|
|
108
|
+
this.scheduledJobs.push(j);
|
|
109
|
+
for (const w of o.writes)
|
|
110
|
+
this.wrote(w);
|
|
111
|
+
this.pushedTo.push(...o.pushedTo);
|
|
112
|
+
}
|
|
113
|
+
get unanalyzableFlag() {
|
|
114
|
+
return this.unanalyzableReasons.length > 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=acc.js.map
|
|
@@ -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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface InlineVerdict {
|
|
2
|
+
unanalyzable: string | null;
|
|
3
|
+
dangerous: boolean;
|
|
4
|
+
/** Deletes a whole directory tree (rmtree, rmSync recursive, rm_rf, File::Path). */
|
|
5
|
+
destroysTree: boolean;
|
|
6
|
+
/** Refers to the home directory or the filesystem root. */
|
|
7
|
+
homeOrRoot: boolean;
|
|
8
|
+
/** Uses the network. */
|
|
9
|
+
network: boolean;
|
|
10
|
+
/** Refers to credential files or reads the whole environment. */
|
|
11
|
+
sensitive: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function analyzeInlineCode(code: string): InlineVerdict;
|
|
14
|
+
//# sourceMappingURL=inline.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Interpreter inline code.
|
|
2
|
+
// A token heuristic: obfuscation markers → unanalyzable; dangerous tokens → high-risk;
|
|
3
|
+
// otherwise write-reversible. Bypassable by design.
|
|
4
|
+
import { test } from "../util/re.js";
|
|
5
|
+
const MARKERS = [
|
|
6
|
+
["__import__", "__import__"],
|
|
7
|
+
["importlib", "importlib"],
|
|
8
|
+
["\\b(getattr|setattr|delattr)\\s*\\(", "getattr/setattr"],
|
|
9
|
+
["\\b(globals|locals|vars)\\s*\\(", "globals/locals/vars"],
|
|
10
|
+
["(^|[^.\\w])(exec|eval|compile)\\s*\\(", "exec/eval/compile"],
|
|
11
|
+
["\\bFunction\\s*\\(", "Function constructor"],
|
|
12
|
+
["\\brequire\\s*\\(\\s*[^'\"\\s)]", "require with a computed name"],
|
|
13
|
+
["\\bimport\\s*\\(\\s*[^'\"\\s)]", "dynamic import with a computed name"],
|
|
14
|
+
["\\b(base64|codecs|binascii|atob|btoa)\\b", "decoding"],
|
|
15
|
+
["Buffer\\.from\\s*\\([^)]*(base64|hex)", "decoding"],
|
|
16
|
+
["fromCharCode|\\bchr\\s*\\(|\\bord\\s*\\(", "character arithmetic"],
|
|
17
|
+
["\\\\x[0-9a-fA-F]{2}|\\\\u[0-9a-fA-F]{4}|\\\\[0-7]{3}", "escape sequences"],
|
|
18
|
+
["\\.decode\\s*\\(", ".decode()"],
|
|
19
|
+
["(['\"][^'\"\\n]{0,200}[/\\\\][^'\"\\n]{0,200}['\"]\\s*\\+)|(\\+\\s*['\"][^'\"\\n]{0,200}[/\\\\.][^'\"\\n]{0,200}['\"])", "string-built path"],
|
|
20
|
+
["\\b(os\\.path\\.join|path\\.join|path\\.resolve|Path\\s*\\()", "built path"],
|
|
21
|
+
["\\bf['\"][^'\"\\n]{0,200}\\{[^}]{0,100}\\}[^'\"\\n]{0,200}[/\\\\]", "f-string path"],
|
|
22
|
+
["`[^`\\n]{0,200}\\$\\{[^}]{0,100}\\}[^`\\n]{0,200}[/\\\\]", "template-literal path"],
|
|
23
|
+
["\\[\\s*::-1\\s*\\]|\\.reverse\\(\\)\\.join|\\bjoin\\s*\\(\\s*reversed", "reversed string"],
|
|
24
|
+
];
|
|
25
|
+
const DANGEROUS = [
|
|
26
|
+
"\\b(rmtree|unlink|unlinkSync|rmdir|rmdirSync|rmSync|remove|removedirs|truncate)\\b", "\\bos\\.remove\\b", "\\bfs\\.(rm|unlink|rmdir|writeFile|appendFile)",
|
|
27
|
+
"\\b(socket|http|https|urllib|urllib2|urllib3|requests|httpx|aiohttp|fetch|axios|XMLHttpRequest|WebSocket|net\\.connect|smtplib|ftplib|paramiko)\\b",
|
|
28
|
+
"\\b(subprocess|child_process|spawn|spawnSync|execSync|execFile|execFileSync|popen|Popen|system|shell)\\b",
|
|
29
|
+
"\\bexec[A-Z_]", "\\bshutil\\b", "\\bos\\.(system|popen|exec|kill|chmod|chown|rename|replace)",
|
|
30
|
+
"open\\s*\\([^)]*,\\s*['\"](w|a|x|r\\+|wb|ab)", "\\bprocess\\.kill\\b", "\\bDeno\\.(run|remove|writeTextFile)",
|
|
31
|
+
];
|
|
32
|
+
// Spec rev 6, Q3 item 3: what dangerous inline code is aimed at (re2 patterns, linear time).
|
|
33
|
+
const TREE_DELETE = "\\b(rmtree|removedirs|rm_rf|remove_dir_all|rmdir_p)\\b|\\b(rmSync|rm)\\s*\\(.{0,300}?recursive\\s*:\\s*true|File::Path";
|
|
34
|
+
const HOME_OR_ROOT = "expanduser\\s*\\(\\s*['\"]~|\\bhomedir\\s*\\(|Path\\.home\\s*\\(|\\$ENV\\{\\s*['\"]?HOME|ENV\\[\\s*['\"]HOME|environ\\[\\s*['\"]HOME|process\\.env\\.HOME|getenv\\(\\s*['\"](HOME|USERPROFILE)|['\"](~|/|~/\\*?|/\\*|[A-Za-z]:\\\\?)['\"]";
|
|
35
|
+
const NETWORK = "\\b(socket|urllib|urllib2|urllib3|requests|httpx|aiohttp|fetch|axios|XMLHttpRequest|WebSocket|smtplib|ftplib|paramiko|LWP|IO::Socket|open-uri)\\b|net\\.connect|HTTP::Tiny|Net::HTTP|https?\\.(request|get)\\b";
|
|
36
|
+
const SENSITIVE = "\\.ssh|id_rsa|id_ed25519|\\.aws|credentials|\\.netrc|\\.git-credentials|\\.kube|\\.config/gh|(^|[^.\\w])\\.env\\b|os\\.environ\\s*($|[^\\[.\\s]|\\.(items|copy)\\b)|dict\\(\\s*os\\.environ|process\\.env\\s*($|[^.\\[\\s])|JSON\\.stringify\\(\\s*process\\.env\\b|%ENV\\b|ENV\\.to_h";
|
|
37
|
+
export function analyzeInlineCode(code) {
|
|
38
|
+
const none = { destroysTree: false, homeOrRoot: false, network: false, sensitive: false };
|
|
39
|
+
if (code.length > 16 * 1024)
|
|
40
|
+
return { unanalyzable: "inline code is too long to analyze", dangerous: true, ...none };
|
|
41
|
+
for (const [pattern, label] of MARKERS) {
|
|
42
|
+
if (test(pattern, code))
|
|
43
|
+
return { unanalyzable: `inline code uses an obfuscation marker (${label})`, dangerous: true, ...none };
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
unanalyzable: null,
|
|
47
|
+
dangerous: DANGEROUS.some((p) => test(p, code)),
|
|
48
|
+
destroysTree: test(TREE_DELETE, code),
|
|
49
|
+
homeOrRoot: test(HOME_OR_ROOT, code),
|
|
50
|
+
network: test(NETWORK, code),
|
|
51
|
+
sensitive: test(SENSITIVE, code),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=inline.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type JobKind } from "./schedule.js";
|
|
2
|
+
export interface PathCtx {
|
|
3
|
+
platform: "linux" | "darwin" | "win32";
|
|
4
|
+
homeDir: string;
|
|
5
|
+
cwd: string | null;
|
|
6
|
+
caseInsensitive: boolean;
|
|
7
|
+
glassboxDirs: readonly string[];
|
|
8
|
+
claudeConfigDir?: string | undefined;
|
|
9
|
+
extraProtected: readonly string[];
|
|
10
|
+
extraSensitive: readonly string[];
|
|
11
|
+
secretPaths: readonly string[];
|
|
12
|
+
resolved?: Readonly<Record<string, string>> | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface NormPath {
|
|
15
|
+
/** Normalized absolute path, or null if not resolvable. */
|
|
16
|
+
path: string | null;
|
|
17
|
+
/** Known literal suffix (starts with "/") when the path is only partly known. */
|
|
18
|
+
suffix: string | null;
|
|
19
|
+
/** The path is relative and the cwd is unknown. */
|
|
20
|
+
relativeUnknown: boolean;
|
|
21
|
+
basename: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function fold(s: string, ci: boolean): string;
|
|
24
|
+
export declare function normalizeSlashes(p: string, win: boolean): string;
|
|
25
|
+
export declare function normalizeFull(raw: string, ctx: PathCtx): string | null;
|
|
26
|
+
export declare function normalizePath(raw: string, ctx: PathCtx): NormPath;
|
|
27
|
+
/** A path known only by its literal tail (e.g. "$(…)/.claude/settings.json"). */
|
|
28
|
+
export declare function suffixOnly(tail: string, ctx: PathCtx): NormPath;
|
|
29
|
+
export interface Entry {
|
|
30
|
+
p: string;
|
|
31
|
+
dir: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare const ANYWHERE: string[];
|
|
34
|
+
export declare function entries(ctx: PathCtx): Entry[];
|
|
35
|
+
export declare function readProtectedEntries(ctx: PathCtx): Entry[];
|
|
36
|
+
export declare function isProtected(np: NormPath, ctx: PathCtx): boolean;
|
|
37
|
+
export declare function isProtectedRead(np: NormPath, ctx: PathCtx): boolean;
|
|
38
|
+
/** A directory-wide read rooted at `np` covers a protected-read path. */
|
|
39
|
+
export declare function coversProtectedRead(np: NormPath, ctx: PathCtx): boolean;
|
|
40
|
+
/** A glob pattern (e.g. Glob tool) that could match a protected-read path. */
|
|
41
|
+
export declare function globCoversProtectedRead(pattern: string, base: string | null, ctx: PathCtx): boolean;
|
|
42
|
+
export interface PersistHit {
|
|
43
|
+
kind: "deny" | "ask" | "job";
|
|
44
|
+
label: string;
|
|
45
|
+
job?: JobKind;
|
|
46
|
+
}
|
|
47
|
+
/** Where writing `np` would install persistence or change remote access, else null. */
|
|
48
|
+
export declare function persistenceHit(np: NormPath, ctx: PathCtx): PersistHit | null;
|
|
49
|
+
/**
|
|
50
|
+
* True when deleting `path` recursively would remove the home directory itself, everything in
|
|
51
|
+
* it, or a whole folder one level under it (~/Documents, ~/Desktop, ~/.ssh, C:/Users/u/Pictures),
|
|
52
|
+
* other than a regenerable cache. `path` is a normalized path; null is false.
|
|
53
|
+
*/
|
|
54
|
+
export declare function homeTopLevel(path: string | null, ctx: PathCtx): boolean;
|
|
55
|
+
/** Returns a label if `np` is a sensitive path, else null. */
|
|
56
|
+
export declare function sensitiveLabel(np: NormPath, ctx: PathCtx): string | null;
|
|
57
|
+
export declare function pathCtxFrom(c: {
|
|
58
|
+
platform: PathCtx["platform"];
|
|
59
|
+
homeDir: string;
|
|
60
|
+
cwd: string | null;
|
|
61
|
+
caseInsensitiveFs: boolean;
|
|
62
|
+
glassboxDirs: readonly string[];
|
|
63
|
+
claudeConfigDir?: string | undefined;
|
|
64
|
+
glassboxSecretPaths?: readonly string[] | undefined;
|
|
65
|
+
resolvedPaths?: Readonly<Record<string, string>> | undefined;
|
|
66
|
+
policy?: {
|
|
67
|
+
extraProtectedPaths?: readonly string[] | undefined;
|
|
68
|
+
extraSensitivePaths?: readonly string[] | undefined;
|
|
69
|
+
} | undefined;
|
|
70
|
+
}): PathCtx;
|
|
71
|
+
//# sourceMappingURL=paths.d.ts.map
|