@node9/policy-engine 2.37.1 → 2.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +161 -14
- package/dist/index.d.ts +161 -14
- package/dist/index.js +1551 -423
- package/dist/index.mjs +1536 -422
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30,9 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
|
|
33
|
+
ACTION_CHECKS: () => ACTION_CHECKS,
|
|
34
|
+
ACTION_TEMPLATES: () => ACTION_TEMPLATES,
|
|
34
35
|
AGENT_INSTRUCTION_DIRS: () => AGENT_INSTRUCTION_DIRS,
|
|
35
36
|
AGENT_INSTRUCTION_FILES: () => AGENT_INSTRUCTION_FILES,
|
|
37
|
+
APP_SERVER_GLOB: () => APP_SERVER_GLOB,
|
|
38
|
+
APP_SHIELD_NAMES: () => APP_SHIELD_NAMES,
|
|
39
|
+
APP_SHIELD_SPECS: () => APP_SHIELD_SPECS,
|
|
36
40
|
ARGUMENT_SCAN_LIMITS: () => ARGUMENT_SCAN_LIMITS,
|
|
37
41
|
AST_FS_REGEX_RULES: () => AST_FS_REGEX_RULES,
|
|
38
42
|
BASH_TOOL_NAMES: () => BASH_TOOL_NAMES,
|
|
@@ -59,6 +63,7 @@ __export(src_exports, {
|
|
|
59
63
|
FILE_TOOLS: () => FILE_TOOLS,
|
|
60
64
|
FLAGS_WITH_VALUES: () => FLAGS_WITH_VALUES,
|
|
61
65
|
FS_READ_TOOLS: () => FS_READ_TOOLS,
|
|
66
|
+
GENERAL_ACTION_RULES: () => GENERAL_ACTION_RULES,
|
|
62
67
|
KNOB_GOVERNED: () => KNOB_GOVERNED,
|
|
63
68
|
LONG_OUTPUT_THRESHOLD_BYTES: () => LONG_OUTPUT_THRESHOLD_BYTES,
|
|
64
69
|
LOOP_MAX_RECORDS: () => LOOP_MAX_RECORDS,
|
|
@@ -70,6 +75,7 @@ __export(src_exports, {
|
|
|
70
75
|
PATTERN_VERB_NAMES: () => PATTERN_VERB_NAMES,
|
|
71
76
|
PRIVILEGE_ESCALATION_RE: () => PRIVILEGE_ESCALATION_RE,
|
|
72
77
|
REALTIME_PII_PATTERNS: () => REALTIME_PII_PATTERNS,
|
|
78
|
+
REPLACED_SHIELDS: () => REPLACED_SHIELDS,
|
|
73
79
|
SCAN_SIGNAL_WEIGHTS: () => SCAN_SIGNAL_WEIGHTS,
|
|
74
80
|
SENSITIVE_PATH_RE: () => SENSITIVE_PATH_RE,
|
|
75
81
|
SENSITIVE_PATH_REGEXES: () => SENSITIVE_PATH_REGEXES,
|
|
@@ -130,6 +136,7 @@ __export(src_exports, {
|
|
|
130
136
|
extractShellDestTokens: () => extractShellDestTokens,
|
|
131
137
|
extractShellDestinations: () => extractShellDestinations,
|
|
132
138
|
extractToolDestinations: () => extractToolDestinations,
|
|
139
|
+
fileAccessView: () => fileAccessView,
|
|
133
140
|
fileOperandFlagsOf: () => fileOperandFlagsOf,
|
|
134
141
|
fileToolOperation: () => fileToolOperation,
|
|
135
142
|
foldHomoglyphs: () => foldHomoglyphs,
|
|
@@ -140,6 +147,9 @@ __export(src_exports, {
|
|
|
140
147
|
hashDestination: () => hashDestination,
|
|
141
148
|
hostMatches: () => hostMatches,
|
|
142
149
|
incompleteFileVerdict: () => incompleteFileVerdict,
|
|
150
|
+
inlineExecDescription: () => inlineExecDescription,
|
|
151
|
+
inlineExecReason: () => inlineExecReason,
|
|
152
|
+
inlineExecReview: () => inlineExecReview,
|
|
143
153
|
inspectArgumentSecrets: () => inspectArgumentSecrets,
|
|
144
154
|
inspectionEntry: () => inspectionEntry,
|
|
145
155
|
inspectionLayers: () => inspectionLayers,
|
|
@@ -170,6 +180,7 @@ __export(src_exports, {
|
|
|
170
180
|
matchesPattern: () => matchesPattern,
|
|
171
181
|
matchesTrustedEntry: () => matchesTrustedEntry,
|
|
172
182
|
matchesTrustedList: () => matchesTrustedList,
|
|
183
|
+
mcpServerFromToolName: () => mcpServerFromToolName,
|
|
173
184
|
narrativeRuleLabel: () => narrativeRuleLabel,
|
|
174
185
|
normalizeCommandForPolicy: () => normalizeCommandForPolicy,
|
|
175
186
|
normalizeDestination: () => normalizeDestination,
|
|
@@ -190,6 +201,7 @@ __export(src_exports, {
|
|
|
190
201
|
resolveCheckMap: () => resolveCheckMap,
|
|
191
202
|
resolvePinned: () => resolvePinned,
|
|
192
203
|
resolveShellInput: () => resolveShellInput,
|
|
204
|
+
ruleServerMatches: () => ruleServerMatches,
|
|
193
205
|
safeMessage: () => safeMessage,
|
|
194
206
|
sampleCopyCommand: () => sampleCopyCommand,
|
|
195
207
|
scanArgs: () => scanArgs,
|
|
@@ -208,6 +220,7 @@ __export(src_exports, {
|
|
|
208
220
|
stripControlChars: () => stripControlChars,
|
|
209
221
|
stripInvisible: () => stripInvisible,
|
|
210
222
|
stripTerminalEscapes: () => stripTerminalEscapes,
|
|
223
|
+
suggestFromApprovals: () => suggestFromApprovals,
|
|
211
224
|
summarizeBlast: () => summarizeBlast,
|
|
212
225
|
summarizeScan: () => summarizeScan,
|
|
213
226
|
toScanFinding: () => toScanFinding,
|
|
@@ -217,6 +230,7 @@ __export(src_exports, {
|
|
|
217
230
|
tuningFromLegacyPolicy: () => tuningFromLegacyPolicy,
|
|
218
231
|
tuningToLegacyPolicy: () => tuningToLegacyPolicy,
|
|
219
232
|
unwrapCommandHead: () => unwrapCommandHead,
|
|
233
|
+
unwrapRuleLabel: () => unwrapRuleLabel,
|
|
220
234
|
validateOverrides: () => validateOverrides,
|
|
221
235
|
validateRegex: () => validateRegex,
|
|
222
236
|
validateShieldDefinition: () => validateShieldDefinition
|
|
@@ -226,8 +240,45 @@ module.exports = __toCommonJS(src_exports);
|
|
|
226
240
|
// src/files/protected-access.ts
|
|
227
241
|
var import_picomatch2 = __toESM(require("picomatch"));
|
|
228
242
|
|
|
229
|
-
// src/
|
|
243
|
+
// src/utils/regex.ts
|
|
230
244
|
var import_safe_regex2 = __toESM(require("safe-regex2"));
|
|
245
|
+
var MAX_REGEX_LENGTH = 256;
|
|
246
|
+
var REGEX_CACHE_MAX = 500;
|
|
247
|
+
var regexCache = /* @__PURE__ */ new Map();
|
|
248
|
+
function validateRegex(pattern) {
|
|
249
|
+
if (!pattern) return "Pattern is required";
|
|
250
|
+
if (pattern.length > MAX_REGEX_LENGTH) return `Pattern exceeds max length of ${MAX_REGEX_LENGTH}`;
|
|
251
|
+
try {
|
|
252
|
+
new RegExp(pattern);
|
|
253
|
+
} catch (e) {
|
|
254
|
+
return `Invalid regex syntax: ${e.message}`;
|
|
255
|
+
}
|
|
256
|
+
if (/\\\d+[*+{]/.test(pattern)) return "Quantified backreferences are forbidden (ReDoS risk)";
|
|
257
|
+
if (!(0, import_safe_regex2.default)(pattern)) return "Pattern rejected: potential ReDoS vulnerability detected";
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
function getCompiledRegex(pattern, flags = "") {
|
|
261
|
+
if (flags && !/^[gimsuy]+$/.test(flags)) return null;
|
|
262
|
+
const key = `${pattern}\0${flags}`;
|
|
263
|
+
if (regexCache.has(key)) {
|
|
264
|
+
const cached = regexCache.get(key);
|
|
265
|
+
regexCache.delete(key);
|
|
266
|
+
regexCache.set(key, cached);
|
|
267
|
+
return cached;
|
|
268
|
+
}
|
|
269
|
+
if (validateRegex(pattern) !== null) return null;
|
|
270
|
+
try {
|
|
271
|
+
const re = new RegExp(pattern, flags);
|
|
272
|
+
if (regexCache.size >= REGEX_CACHE_MAX) {
|
|
273
|
+
const oldest = regexCache.keys().next().value;
|
|
274
|
+
if (oldest) regexCache.delete(oldest);
|
|
275
|
+
}
|
|
276
|
+
regexCache.set(key, re);
|
|
277
|
+
return re;
|
|
278
|
+
} catch {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
231
282
|
|
|
232
283
|
// src/shields/builtin/aws.json
|
|
233
284
|
var aws_default = {
|
|
@@ -538,79 +589,6 @@ var filesystem_default = {
|
|
|
538
589
|
dangerousWords: ["wipefs"]
|
|
539
590
|
};
|
|
540
591
|
|
|
541
|
-
// src/shields/builtin/finance.json
|
|
542
|
-
var finance_default = {
|
|
543
|
-
name: "finance",
|
|
544
|
-
description: "Asks before money moves through a payment or banking app (refunds, payouts, transfers, charges, invoices), whatever the request said. Reads are never asked about.",
|
|
545
|
-
aliases: ["payments", "money"],
|
|
546
|
-
smartRules: [
|
|
547
|
-
{
|
|
548
|
-
name: "shield:finance:review-refund",
|
|
549
|
-
tool: "{,mcp__*__}{create_refund,refund_payment,refund_charge,refund_order,issue_refund}",
|
|
550
|
-
conditions: [],
|
|
551
|
-
verdict: "review",
|
|
552
|
-
reason: "A refund returns money to a customer. node9 asks before money moves, whatever the request said (Finance shield)."
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
name: "shield:finance:review-payout",
|
|
556
|
-
tool: "{,mcp__*__}{create_payout,send_payout,payout,create_payouts_batch}",
|
|
557
|
-
conditions: [],
|
|
558
|
-
verdict: "review",
|
|
559
|
-
reason: "A payout moves the balance to a bank account. node9 asks before money moves (Finance shield)."
|
|
560
|
-
},
|
|
561
|
-
{
|
|
562
|
-
name: "shield:finance:review-transfer",
|
|
563
|
-
tool: "{,mcp__*__}{transfer_create,transfer_authorization_create,create_transfer,transfer_money,transfer_funds,send_money,wire_transfer,create_wire,schedule_transaction,update_scheduled_transaction,create_transaction}",
|
|
564
|
-
conditions: [],
|
|
565
|
-
verdict: "review",
|
|
566
|
-
reason: "A transfer moves money between accounts. node9 asks before money moves (Finance shield)."
|
|
567
|
-
},
|
|
568
|
-
{
|
|
569
|
-
name: "shield:finance:review-charge",
|
|
570
|
-
tool: "{,mcp__*__}{create_payment_intent,confirm_payment_intent,capture_payment_intent,create_charge,create_payment,capture_payment,capture_order,create_order,authorize_order,create_checkout_session}",
|
|
571
|
-
conditions: [],
|
|
572
|
-
verdict: "review",
|
|
573
|
-
reason: "This charges a card or captures a payment. node9 asks before money moves (Finance shield)."
|
|
574
|
-
},
|
|
575
|
-
{
|
|
576
|
-
name: "shield:finance:review-payment-link",
|
|
577
|
-
tool: "{,mcp__*__}{create_payment_link,create_invoice,finalize_invoice,send_invoice,pay_invoice,create_invoice_item}",
|
|
578
|
-
conditions: [],
|
|
579
|
-
verdict: "review",
|
|
580
|
-
reason: "This bills someone or creates a link that charges a card. node9 asks before money moves (Finance shield)."
|
|
581
|
-
},
|
|
582
|
-
{
|
|
583
|
-
name: "shield:finance:review-subscription",
|
|
584
|
-
tool: "{,mcp__*__}{create_subscription,cancel_subscription,update_subscription,pause_subscription,resume_subscription}",
|
|
585
|
-
conditions: [],
|
|
586
|
-
verdict: "review",
|
|
587
|
-
reason: "A subscription starts or stops recurring charges. node9 asks before money moves (Finance shield)."
|
|
588
|
-
},
|
|
589
|
-
{
|
|
590
|
-
name: "shield:finance:review-dispute",
|
|
591
|
-
tool: "{,mcp__*__}{update_dispute,accept_dispute,close_dispute}",
|
|
592
|
-
conditions: [],
|
|
593
|
-
verdict: "review",
|
|
594
|
-
reason: "This answers or concedes a chargeback. node9 asks before money moves (Finance shield)."
|
|
595
|
-
},
|
|
596
|
-
{
|
|
597
|
-
name: "shield:finance:review-card",
|
|
598
|
-
tool: "{,mcp__*__}{issue_card,create_virtual_card,create_issuing_card,update_card_limit}",
|
|
599
|
-
conditions: [],
|
|
600
|
-
verdict: "review",
|
|
601
|
-
reason: "This issues a card or changes its limit. node9 asks before money moves (Finance shield)."
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
name: "shield:finance:review-withdraw",
|
|
605
|
-
tool: "{,mcp__*__}{withdraw,withdraw_funds,create_withdrawal,request_withdrawal}",
|
|
606
|
-
conditions: [],
|
|
607
|
-
verdict: "review",
|
|
608
|
-
reason: "A withdrawal moves money out. node9 asks before money moves (Finance shield)."
|
|
609
|
-
}
|
|
610
|
-
],
|
|
611
|
-
dangerousWords: []
|
|
612
|
-
};
|
|
613
|
-
|
|
614
592
|
// src/shields/builtin/github.json
|
|
615
593
|
var github_default = {
|
|
616
594
|
name: "github",
|
|
@@ -639,58 +617,6 @@ var github_default = {
|
|
|
639
617
|
dangerousWords: []
|
|
640
618
|
};
|
|
641
619
|
|
|
642
|
-
// src/shields/builtin/identity.json
|
|
643
|
-
var identity_default = {
|
|
644
|
-
name: "identity",
|
|
645
|
-
description: "Asks before a password, a key, a token, a role or a user changes in an identity or admin app, whatever the request said. Reads are never asked about.",
|
|
646
|
-
aliases: ["access", "iam"],
|
|
647
|
-
smartRules: [
|
|
648
|
-
{
|
|
649
|
-
name: "shield:identity:review-password",
|
|
650
|
-
tool: "{,mcp__*__}{change_password,update_password,reset_password,set_password,expire_password,force_password_reset}",
|
|
651
|
-
conditions: [],
|
|
652
|
-
verdict: "review",
|
|
653
|
-
reason: "This changes or resets a password. node9 asks before credentials change, whatever the request said (Identity shield)."
|
|
654
|
-
},
|
|
655
|
-
{
|
|
656
|
-
name: "shield:identity:review-key",
|
|
657
|
-
tool: "{,mcp__*__}{rotate_key,rotate_api_key,create_api_key,create_token,create_access_token,create_personal_access_token,regenerate_secret,rotate_secret,create_service_account_key,create_credential}",
|
|
658
|
-
conditions: [],
|
|
659
|
-
verdict: "review",
|
|
660
|
-
reason: "This creates or rotates a key, token or secret. node9 asks before credentials change (Identity shield)."
|
|
661
|
-
},
|
|
662
|
-
{
|
|
663
|
-
name: "shield:identity:review-access",
|
|
664
|
-
tool: "{,mcp__*__}{grant_access,grant_permission,grant_role,revoke_access,revoke_permission,revoke_role,revoke_token,set_permission,set_permissions,set_role,assign_role,update_role,add_permission,remove_permission,attach_policy,detach_policy}",
|
|
665
|
-
conditions: [],
|
|
666
|
-
verdict: "review",
|
|
667
|
-
reason: "This grants or revokes access. node9 asks before access changes (Identity shield)."
|
|
668
|
-
},
|
|
669
|
-
{
|
|
670
|
-
name: "shield:identity:review-membership",
|
|
671
|
-
tool: "{,mcp__*__}{add_member,remove_member,add_user_to_group,remove_user_from_group,add_collaborator,remove_collaborator,invite_user,invite_member,invite_user_to_slack,invite_users,add_org_member,remove_org_member,add_team_member,remove_team_member}",
|
|
672
|
-
conditions: [],
|
|
673
|
-
verdict: "review",
|
|
674
|
-
reason: "This changes who belongs where. node9 asks before membership changes (Identity shield)."
|
|
675
|
-
},
|
|
676
|
-
{
|
|
677
|
-
name: "shield:identity:review-user",
|
|
678
|
-
tool: "{,mcp__*__}{create_user,delete_user,deactivate_user,suspend_user,activate_user,unlock_user,make_admin,promote_user,demote_user,update_user_role}",
|
|
679
|
-
conditions: [],
|
|
680
|
-
verdict: "review",
|
|
681
|
-
reason: "This creates, removes or promotes an account. node9 asks before accounts change (Identity shield)."
|
|
682
|
-
},
|
|
683
|
-
{
|
|
684
|
-
name: "shield:identity:review-mfa",
|
|
685
|
-
tool: "{,mcp__*__}{reset_mfa,reset_factors,disable_mfa,enroll_factor,deactivate_factor}",
|
|
686
|
-
conditions: [],
|
|
687
|
-
verdict: "review",
|
|
688
|
-
reason: "This changes a second factor. node9 asks before credentials change (Identity shield)."
|
|
689
|
-
}
|
|
690
|
-
],
|
|
691
|
-
dangerousWords: []
|
|
692
|
-
};
|
|
693
|
-
|
|
694
620
|
// src/shields/builtin/k8s.json
|
|
695
621
|
var k8s_default = {
|
|
696
622
|
name: "k8s",
|
|
@@ -950,7 +876,7 @@ var project_jail_default = {
|
|
|
950
876
|
{
|
|
951
877
|
field: "command",
|
|
952
878
|
op: "matches",
|
|
953
|
-
value: "(cat|less|head|tail|bat|more|open|print|nano|vim
|
|
879
|
+
value: "(cat|less|head|tail|bat|more|open|print|nano|vim?|emacs|code|type|[ef]?grep|rg|ag|ack|g?awk|sed|cut|tr|[jy]q|od|xxd|hexdump|strings|base64|sort|uniq|tac|nl|dd)\\s+.*?\\.env(\\.(local|production|staging|development)){0,2}(?=[\\s;&|>)<]|$)",
|
|
954
880
|
flags: "i"
|
|
955
881
|
}
|
|
956
882
|
],
|
|
@@ -964,7 +890,7 @@ var project_jail_default = {
|
|
|
964
890
|
{
|
|
965
891
|
field: "command",
|
|
966
892
|
op: "matches",
|
|
967
|
-
value: "(cat|less|head|tail|bat|more|open|print|nano|vim
|
|
893
|
+
value: "(cat|less|head|tail|bat|more|open|print|nano|vim?|emacs|code|type|[ef]?grep|rg|ag|ack|g?awk|sed|cut|tr|[jy]q|od|xxd|hexdump|strings|base64|sort|uniq|tac|nl|dd)\\s+.*(credentials\\.json|\\.netrc|\\.npmrc|\\.docker[\\/\\\\]config\\.json|gcloud[\\/\\\\]credentials)",
|
|
968
894
|
flags: "i"
|
|
969
895
|
}
|
|
970
896
|
],
|
|
@@ -1031,6 +957,212 @@ var project_jail_default = {
|
|
|
1031
957
|
dangerousWords: []
|
|
1032
958
|
};
|
|
1033
959
|
|
|
960
|
+
// src/shields/builtin/redis.json
|
|
961
|
+
var redis_default = {
|
|
962
|
+
name: "redis",
|
|
963
|
+
description: "Protects Redis instances from destructive AI operations",
|
|
964
|
+
aliases: [],
|
|
965
|
+
_scopeNote: "Every rule requires Redis to actually be involved: a client in the command (redis-cli / valkey-cli, in either order \u2014 `redis-cli FLUSHALL` and `echo FLUSHALL | redis-cli` are both real), OR the command field holding the bare keyword, which is what the MCP redis_command tool sends ({ command: 'FLUSHALL', args: [] }). Without the client requirement these rules matched the WORD anywhere \u2014 including prose in a heredoc writing a file \u2014 which produced two observed false positives: a test fixture describing the shield, and a commit message naming the rule. Every other builtin shield already scopes this way (aws s3, docker system prune, kubectl delete, gh repo delete). See redis-scope.spec.ts.",
|
|
966
|
+
smartRules: [
|
|
967
|
+
{
|
|
968
|
+
name: "shield:redis:block-flushall",
|
|
969
|
+
tool: "*",
|
|
970
|
+
conditions: [
|
|
971
|
+
{
|
|
972
|
+
field: "command",
|
|
973
|
+
op: "matches",
|
|
974
|
+
value: "(redis|valkey)-cli.*\\bFLUSHALL\\b|\\bFLUSHALL\\b.*(redis|valkey)-cli|^ ?FLUSHALL\\b|\\.flushall\\s*\\(",
|
|
975
|
+
flags: "i"
|
|
976
|
+
}
|
|
977
|
+
],
|
|
978
|
+
verdict: "block",
|
|
979
|
+
reason: "FLUSHALL deletes every key in every database \u2014 blocked by Redis shield"
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
name: "shield:redis:block-flushdb",
|
|
983
|
+
tool: "*",
|
|
984
|
+
conditions: [
|
|
985
|
+
{
|
|
986
|
+
field: "command",
|
|
987
|
+
op: "matches",
|
|
988
|
+
value: "(redis|valkey)-cli.*\\bFLUSHDB\\b|\\bFLUSHDB\\b.*(redis|valkey)-cli|^ ?FLUSHDB\\b|\\.flushdb\\s*\\(",
|
|
989
|
+
flags: "i"
|
|
990
|
+
}
|
|
991
|
+
],
|
|
992
|
+
verdict: "block",
|
|
993
|
+
reason: "FLUSHDB deletes all keys in the current database \u2014 blocked by Redis shield"
|
|
994
|
+
},
|
|
995
|
+
{
|
|
996
|
+
name: "shield:redis:block-config-resetstat",
|
|
997
|
+
tool: "*",
|
|
998
|
+
conditions: [
|
|
999
|
+
{
|
|
1000
|
+
field: "command",
|
|
1001
|
+
op: "matches",
|
|
1002
|
+
value: "(redis|valkey)-cli.*CONFIG\\s+RESETSTAT|^ ?CONFIG\\s+RESETSTAT",
|
|
1003
|
+
flags: "i"
|
|
1004
|
+
}
|
|
1005
|
+
],
|
|
1006
|
+
verdict: "block",
|
|
1007
|
+
reason: "CONFIG RESETSTAT resets server statistics irreversibly \u2014 blocked by Redis shield"
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
name: "shield:redis:review-config-set",
|
|
1011
|
+
tool: "*",
|
|
1012
|
+
conditions: [
|
|
1013
|
+
{
|
|
1014
|
+
field: "command",
|
|
1015
|
+
op: "matches",
|
|
1016
|
+
value: "(redis|valkey)-cli.*\\bCONFIG\\s+SET\\b|\\bCONFIG\\s+SET\\b.*(redis|valkey)-cli|^ ?CONFIG\\s+SET\\b",
|
|
1017
|
+
flags: "i"
|
|
1018
|
+
}
|
|
1019
|
+
],
|
|
1020
|
+
verdict: "review",
|
|
1021
|
+
reason: "CONFIG SET changes live server configuration and requires human approval (Redis shield)"
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
name: "shield:redis:review-del-wildcard",
|
|
1025
|
+
tool: "*",
|
|
1026
|
+
conditions: [
|
|
1027
|
+
{
|
|
1028
|
+
field: "command",
|
|
1029
|
+
op: "matches",
|
|
1030
|
+
value: "(redis|valkey)-cli.*\\bDEL\\b.*[*?\\[]|^ ?DEL\\b.*[*?\\[]|-cli.*--scan.*xargs.*del",
|
|
1031
|
+
flags: "i"
|
|
1032
|
+
}
|
|
1033
|
+
],
|
|
1034
|
+
verdict: "review",
|
|
1035
|
+
reason: "Wildcard key deletion requires human approval (Redis shield)"
|
|
1036
|
+
}
|
|
1037
|
+
],
|
|
1038
|
+
dangerousWords: ["FLUSHALL", "FLUSHDB"]
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
// src/shields/builtin/finance.json
|
|
1042
|
+
var finance_default = {
|
|
1043
|
+
name: "finance",
|
|
1044
|
+
description: "Asks before money moves through a payment or banking app (refunds, payouts, transfers, charges, invoices), whatever the request said. Reads are never asked about.",
|
|
1045
|
+
aliases: ["payments", "money"],
|
|
1046
|
+
smartRules: [
|
|
1047
|
+
{
|
|
1048
|
+
name: "shield:finance:review-refund",
|
|
1049
|
+
tool: "{,mcp__*__}{create_refund,refund_payment,refund_charge,refund_order,issue_refund}",
|
|
1050
|
+
conditions: [],
|
|
1051
|
+
verdict: "review",
|
|
1052
|
+
reason: "A refund returns money to a customer. node9 asks before money moves, whatever the request said (Finance shield)."
|
|
1053
|
+
},
|
|
1054
|
+
{
|
|
1055
|
+
name: "shield:finance:review-payout",
|
|
1056
|
+
tool: "{,mcp__*__}{create_payout,send_payout,payout,create_payouts_batch}",
|
|
1057
|
+
conditions: [],
|
|
1058
|
+
verdict: "review",
|
|
1059
|
+
reason: "A payout moves the balance to a bank account. node9 asks before money moves (Finance shield)."
|
|
1060
|
+
},
|
|
1061
|
+
{
|
|
1062
|
+
name: "shield:finance:review-transfer",
|
|
1063
|
+
tool: "{,mcp__*__}{transfer_create,transfer_authorization_create,create_transfer,transfer_money,transfer_funds,send_money,wire_transfer,create_wire,schedule_transaction,update_scheduled_transaction}",
|
|
1064
|
+
conditions: [],
|
|
1065
|
+
verdict: "review",
|
|
1066
|
+
reason: "A transfer moves money between accounts. node9 asks before money moves (Finance shield)."
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
name: "shield:finance:review-charge",
|
|
1070
|
+
tool: "{,mcp__*__}{create_payment_intent,confirm_payment_intent,capture_payment_intent,create_charge,create_payment,capture_payment,capture_order,create_order,authorize_order,create_checkout_session}",
|
|
1071
|
+
conditions: [],
|
|
1072
|
+
verdict: "review",
|
|
1073
|
+
reason: "This charges a card or captures a payment. node9 asks before money moves (Finance shield)."
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
name: "shield:finance:review-payment-link",
|
|
1077
|
+
tool: "{,mcp__*__}{create_payment_link,create_invoice,finalize_invoice,send_invoice,pay_invoice,create_invoice_item}",
|
|
1078
|
+
conditions: [],
|
|
1079
|
+
verdict: "review",
|
|
1080
|
+
reason: "This bills someone or creates a link that charges a card. node9 asks before money moves (Finance shield)."
|
|
1081
|
+
},
|
|
1082
|
+
{
|
|
1083
|
+
name: "shield:finance:review-subscription",
|
|
1084
|
+
tool: "{,mcp__*__}{create_subscription,cancel_subscription,update_subscription,pause_subscription,resume_subscription}",
|
|
1085
|
+
conditions: [],
|
|
1086
|
+
verdict: "review",
|
|
1087
|
+
reason: "A subscription starts or stops recurring charges. node9 asks before money moves (Finance shield)."
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
name: "shield:finance:review-dispute",
|
|
1091
|
+
tool: "{,mcp__*__}{update_dispute,accept_dispute,close_dispute}",
|
|
1092
|
+
conditions: [],
|
|
1093
|
+
verdict: "review",
|
|
1094
|
+
reason: "This answers or concedes a chargeback. node9 asks before money moves (Finance shield)."
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
name: "shield:finance:review-card",
|
|
1098
|
+
tool: "{,mcp__*__}{issue_card,create_virtual_card,create_issuing_card,update_card_limit}",
|
|
1099
|
+
conditions: [],
|
|
1100
|
+
verdict: "review",
|
|
1101
|
+
reason: "This issues a card or changes its limit. node9 asks before money moves (Finance shield)."
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
name: "shield:finance:review-withdraw",
|
|
1105
|
+
tool: "{,mcp__*__}{withdraw,withdraw_funds,create_withdrawal,request_withdrawal}",
|
|
1106
|
+
conditions: [],
|
|
1107
|
+
verdict: "review",
|
|
1108
|
+
reason: "A withdrawal moves money out. node9 asks before money moves (Finance shield)."
|
|
1109
|
+
}
|
|
1110
|
+
],
|
|
1111
|
+
dangerousWords: []
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
// src/shields/builtin/identity.json
|
|
1115
|
+
var identity_default = {
|
|
1116
|
+
name: "identity",
|
|
1117
|
+
description: "Asks before a password, a key, a token, a role or a user changes in an identity or admin app, whatever the request said. Reads are never asked about.",
|
|
1118
|
+
aliases: ["access", "iam"],
|
|
1119
|
+
smartRules: [
|
|
1120
|
+
{
|
|
1121
|
+
name: "shield:identity:review-password",
|
|
1122
|
+
tool: "{,mcp__*__}{change_password,update_password,reset_password,set_password,expire_password,force_password_reset}",
|
|
1123
|
+
conditions: [],
|
|
1124
|
+
verdict: "review",
|
|
1125
|
+
reason: "This changes or resets a password. node9 asks before credentials change, whatever the request said (Identity shield)."
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
name: "shield:identity:review-key",
|
|
1129
|
+
tool: "{,mcp__*__}{rotate_key,rotate_api_key,create_api_key,create_token,create_access_token,create_personal_access_token,regenerate_secret,rotate_secret,create_service_account_key,create_credential}",
|
|
1130
|
+
conditions: [],
|
|
1131
|
+
verdict: "review",
|
|
1132
|
+
reason: "This creates or rotates a key, token or secret. node9 asks before credentials change (Identity shield)."
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
name: "shield:identity:review-access",
|
|
1136
|
+
tool: "{,mcp__*__}{grant_access,grant_permission,grant_role,revoke_access,revoke_permission,revoke_role,revoke_token,set_permission,set_permissions,set_role,assign_role,update_role,add_permission,remove_permission,attach_policy,detach_policy,share_file}",
|
|
1137
|
+
conditions: [],
|
|
1138
|
+
verdict: "review",
|
|
1139
|
+
reason: "This grants or revokes access. node9 asks before access changes (Identity shield)."
|
|
1140
|
+
},
|
|
1141
|
+
{
|
|
1142
|
+
name: "shield:identity:review-membership",
|
|
1143
|
+
tool: "{,mcp__*__}{add_member,remove_member,add_user_to_group,remove_user_from_group,add_collaborator,remove_collaborator,invite_user,invite_member,invite_user_to_slack,invite_users,add_org_member,remove_org_member,add_team_member,remove_team_member,add_user_to_channel,remove_user_from_slack}",
|
|
1144
|
+
conditions: [],
|
|
1145
|
+
verdict: "review",
|
|
1146
|
+
reason: "This changes who belongs where. node9 asks before membership changes (Identity shield)."
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
name: "shield:identity:review-user",
|
|
1150
|
+
tool: "{,mcp__*__}{create_user,delete_user,delete_deactivated_user,deactivate_user,suspend_user,activate_user,unlock_user,make_admin,promote_user,demote_user,update_user_role}",
|
|
1151
|
+
conditions: [],
|
|
1152
|
+
verdict: "review",
|
|
1153
|
+
reason: "This creates, removes or promotes an account. node9 asks before accounts change (Identity shield)."
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
name: "shield:identity:review-mfa",
|
|
1157
|
+
tool: "{,mcp__*__}{reset_mfa,reset_factors,disable_mfa,enroll_factor,deactivate_factor}",
|
|
1158
|
+
conditions: [],
|
|
1159
|
+
verdict: "review",
|
|
1160
|
+
reason: "This changes a second factor. node9 asks before credentials change (Identity shield)."
|
|
1161
|
+
}
|
|
1162
|
+
],
|
|
1163
|
+
dangerousWords: []
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1034
1166
|
// src/shields/builtin/publishing.json
|
|
1035
1167
|
var publishing_default = {
|
|
1036
1168
|
name: "publishing",
|
|
@@ -1202,85 +1334,554 @@ var publishing_default = {
|
|
|
1202
1334
|
dangerousWords: []
|
|
1203
1335
|
};
|
|
1204
1336
|
|
|
1205
|
-
// src/shields/
|
|
1206
|
-
var
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1337
|
+
// src/shields/apps.ts
|
|
1338
|
+
var ACTION_TEMPLATES = {
|
|
1339
|
+
finance: finance_default.smartRules,
|
|
1340
|
+
identity: identity_default.smartRules,
|
|
1341
|
+
publishing: publishing_default.smartRules
|
|
1342
|
+
};
|
|
1343
|
+
var ACTION_CHECKS = {
|
|
1344
|
+
finance: { checkId: "actions.money", slug: "money", label: "Money check" },
|
|
1345
|
+
identity: { checkId: "actions.access", slug: "access", label: "Accounts and access check" },
|
|
1346
|
+
publishing: { checkId: "actions.publish", slug: "publish", label: "Publishing check" }
|
|
1347
|
+
};
|
|
1348
|
+
function isToolRule(rule) {
|
|
1349
|
+
return rule.tool.startsWith("{,mcp__*__}");
|
|
1350
|
+
}
|
|
1351
|
+
function actionPart(ruleName) {
|
|
1352
|
+
const m = /^shield:[^:]+:(.+)$/.exec(ruleName ?? "");
|
|
1353
|
+
return m ? m[1] : ruleName ?? "rule";
|
|
1354
|
+
}
|
|
1355
|
+
function ownReason(reason, owner) {
|
|
1356
|
+
if (!reason) return reason;
|
|
1357
|
+
return reason.replace(/\((?:Finance|Identity|Publishing) shield\)\.?$/, `(${owner}).`);
|
|
1358
|
+
}
|
|
1359
|
+
var GAP = "[^;&|]{0,200}?";
|
|
1360
|
+
var prog = (alt) => `(?:^|[^\\w-])(?:${alt})(?![\\w-])`;
|
|
1361
|
+
var httpTo = (host2) => prog("curl|wget|http|https|xh") + "[^;&|]{0,400}?" + host2;
|
|
1362
|
+
var httpWrite = (methods) => ({
|
|
1363
|
+
field: "command",
|
|
1364
|
+
op: "matches",
|
|
1365
|
+
value: `-X\\s*(?:${methods})|--(?:request|method)[=\\s]+(?:${methods})|--post-(?:data|file)|\\s(?:${methods}|${methods.toLowerCase()})\\s|^(?!.*\\s(?:-[a-zA-Z]*G|--get)(?![\\w-])).*(?:\\s-d[\\s'"@]|\\s--data|\\s--json\\s|\\s-F\\s|\\s--form\\s)`
|
|
1366
|
+
});
|
|
1367
|
+
var HTTP_WRITE = httpWrite("POST|DELETE");
|
|
1368
|
+
var HTTP_WRITE_ANY = httpWrite("POST|PUT|PATCH|DELETE");
|
|
1369
|
+
var NOT_STRIPE_TEST = {
|
|
1370
|
+
field: "command",
|
|
1371
|
+
op: "notMatches",
|
|
1372
|
+
value: "\\b[sr]k_test_"
|
|
1373
|
+
};
|
|
1374
|
+
var postTo = (host2) => `\\.post\\(\\s*["'\`][^"'\`]{0,80}${host2}`;
|
|
1375
|
+
var STRIPE_OBJECTS = "refunds|payouts|charges|transfers|payment_intents|payment_links|invoices|subscriptions|topups";
|
|
1376
|
+
var APP_SHIELD_SPECS = [
|
|
1377
|
+
{
|
|
1378
|
+
name: "stripe",
|
|
1379
|
+
label: "Stripe",
|
|
1380
|
+
description: "Asks before money moves in Stripe (refunds, payouts, charges, invoices, subscriptions), whether the agent uses the Stripe MCP server, the stripe CLI, the API or the Stripe library in a script. Reads are never asked about.",
|
|
1381
|
+
template: "finance",
|
|
1382
|
+
server: "*stripe*",
|
|
1383
|
+
doors: [
|
|
1384
|
+
{
|
|
1385
|
+
name: "shield:stripe:review-cli",
|
|
1386
|
+
tool: "bash",
|
|
1387
|
+
conditions: [
|
|
1388
|
+
{
|
|
1389
|
+
field: "command",
|
|
1390
|
+
op: "matches",
|
|
1391
|
+
value: prog("stripe") + GAP + `\\s(?:${STRIPE_OBJECTS})\\s+(?:create|cancel|capture|confirm|update|pay|finalize_invoice|send_invoice|void_invoice)(?![\\w-])`,
|
|
1392
|
+
flags: "i"
|
|
1393
|
+
},
|
|
1394
|
+
{
|
|
1395
|
+
field: "command",
|
|
1396
|
+
op: "matches",
|
|
1397
|
+
// The stripe CLI works in test mode unless told otherwise.
|
|
1398
|
+
value: "\\s--live(?![\\w-])|\\b[sr]k_live_"
|
|
1399
|
+
}
|
|
1400
|
+
],
|
|
1401
|
+
conditionMode: "all",
|
|
1402
|
+
verdict: "review",
|
|
1403
|
+
reason: "The stripe CLI is about to move money. node9 asks before money moves (Stripe)."
|
|
1404
|
+
},
|
|
1405
|
+
{
|
|
1406
|
+
name: "shield:stripe:review-cli-request",
|
|
1407
|
+
tool: "bash",
|
|
1408
|
+
conditions: [
|
|
1409
|
+
{
|
|
1410
|
+
field: "command",
|
|
1411
|
+
op: "matches",
|
|
1412
|
+
value: prog("stripe") + GAP + `\\s(?:post|delete)\\s+/?v1/(?:${STRIPE_OBJECTS})(?![\\w-])`,
|
|
1413
|
+
flags: "i"
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
field: "command",
|
|
1417
|
+
op: "matches",
|
|
1418
|
+
// The stripe CLI works in test mode unless told otherwise.
|
|
1419
|
+
value: "\\s--live(?![\\w-])|\\b[sr]k_live_"
|
|
1420
|
+
}
|
|
1421
|
+
],
|
|
1422
|
+
conditionMode: "all",
|
|
1423
|
+
verdict: "review",
|
|
1424
|
+
reason: "A raw stripe CLI request is about to move money. node9 asks before money moves (Stripe)."
|
|
1425
|
+
},
|
|
1426
|
+
{
|
|
1427
|
+
name: "shield:stripe:review-api",
|
|
1428
|
+
tool: "bash",
|
|
1429
|
+
conditions: [
|
|
1430
|
+
{
|
|
1431
|
+
field: "command",
|
|
1432
|
+
op: "matches",
|
|
1433
|
+
value: httpTo(`api\\.stripe\\.com/v1/(?:${STRIPE_OBJECTS})(?![\\w-])`),
|
|
1434
|
+
flags: "i"
|
|
1435
|
+
},
|
|
1436
|
+
HTTP_WRITE,
|
|
1437
|
+
NOT_STRIPE_TEST
|
|
1438
|
+
],
|
|
1439
|
+
conditionMode: "all",
|
|
1440
|
+
verdict: "review",
|
|
1441
|
+
reason: "A request to the Stripe API is about to move money. node9 asks before money moves (Stripe)."
|
|
1442
|
+
},
|
|
1443
|
+
{
|
|
1444
|
+
name: "shield:stripe:review-code",
|
|
1445
|
+
tool: "bash",
|
|
1446
|
+
conditions: [
|
|
1447
|
+
{
|
|
1448
|
+
field: "command",
|
|
1449
|
+
op: "matches",
|
|
1450
|
+
// Python: stripe.Refund.create(...)
|
|
1451
|
+
value: "\\bstripe\\.(?:Refund|Payout|Transfer|Charge|PaymentIntent|PaymentLink|Invoice|Subscription|Topup)\\.(?:create|cancel|capture|confirm|modify|pay|finalize_invoice|send_invoice|void_invoice)\\b"
|
|
1452
|
+
},
|
|
1453
|
+
NOT_STRIPE_TEST
|
|
1454
|
+
],
|
|
1455
|
+
conditionMode: "all",
|
|
1456
|
+
verdict: "review",
|
|
1457
|
+
reason: "This code moves money through the Stripe library. node9 asks before money moves (Stripe)."
|
|
1458
|
+
},
|
|
1459
|
+
{
|
|
1460
|
+
name: "shield:stripe:review-code-node",
|
|
1461
|
+
tool: "bash",
|
|
1462
|
+
conditions: [
|
|
1463
|
+
{
|
|
1464
|
+
field: "command",
|
|
1465
|
+
op: "matches",
|
|
1466
|
+
// Node: stripe.refunds.create(...)
|
|
1467
|
+
value: "\\bstripe\\.(?:refunds|payouts|transfers|charges|paymentIntents|paymentLinks|invoices|subscriptions|topups)\\.(?:create|cancel|capture|confirm|update|pay|finalizeInvoice|sendInvoice|voidInvoice)\\s*\\("
|
|
1468
|
+
},
|
|
1469
|
+
NOT_STRIPE_TEST
|
|
1470
|
+
],
|
|
1471
|
+
conditionMode: "all",
|
|
1472
|
+
verdict: "review",
|
|
1473
|
+
reason: "This code moves money through the Stripe library. node9 asks before money moves (Stripe)."
|
|
1474
|
+
},
|
|
1475
|
+
{
|
|
1476
|
+
name: "shield:stripe:review-code-http",
|
|
1477
|
+
tool: "bash",
|
|
1478
|
+
conditions: [
|
|
1479
|
+
{
|
|
1480
|
+
field: "command",
|
|
1481
|
+
op: "matches",
|
|
1482
|
+
// requests.post("https://api.stripe.com/v1/refunds", ...)
|
|
1483
|
+
value: `\\.post\\(\\s*["'\`][^"'\`]{0,80}api\\.stripe\\.com/v1/(?:${STRIPE_OBJECTS})`
|
|
1484
|
+
},
|
|
1485
|
+
NOT_STRIPE_TEST
|
|
1486
|
+
],
|
|
1487
|
+
conditionMode: "all",
|
|
1488
|
+
verdict: "review",
|
|
1489
|
+
reason: "This code posts to the Stripe API. node9 asks before money moves (Stripe)."
|
|
1490
|
+
}
|
|
1491
|
+
]
|
|
1492
|
+
},
|
|
1493
|
+
{
|
|
1494
|
+
name: "paypal",
|
|
1495
|
+
label: "PayPal",
|
|
1496
|
+
description: "Asks before money moves in PayPal (refunds, payouts, captured orders, invoices, subscriptions), whether the agent uses a PayPal MCP server, the API or the PayPal SDK in a script. The sandbox is never asked about, and neither are reads.",
|
|
1497
|
+
template: "finance",
|
|
1498
|
+
server: "*paypal*",
|
|
1499
|
+
doors: [
|
|
1500
|
+
{
|
|
1501
|
+
name: "shield:paypal:review-api",
|
|
1502
|
+
tool: "bash",
|
|
1503
|
+
conditions: [
|
|
1504
|
+
{
|
|
1505
|
+
field: "command",
|
|
1506
|
+
op: "matches",
|
|
1507
|
+
// The live hosts only: api.paypal.com and api-m.paypal.com. The
|
|
1508
|
+
// sandbox (api-m.sandbox.paypal.com) moves no money.
|
|
1509
|
+
value: httpTo("api(?:-m)?\\.paypal\\.com/v[12]/"),
|
|
1510
|
+
flags: "i"
|
|
1511
|
+
},
|
|
1512
|
+
{
|
|
1513
|
+
field: "command",
|
|
1514
|
+
op: "matches",
|
|
1515
|
+
// The endpoints that move money.
|
|
1516
|
+
value: "\\.paypal\\.com/v[12]/(?:payments/(?:captures|authorizations|sale|payouts|payment|referenced-payouts)|checkout/orders/[^\\s/]{1,64}/(?:capture|authorize)|invoicing/invoices|billing/subscriptions)",
|
|
1517
|
+
flags: "i"
|
|
1518
|
+
},
|
|
1519
|
+
HTTP_WRITE
|
|
1520
|
+
],
|
|
1521
|
+
conditionMode: "all",
|
|
1522
|
+
verdict: "review",
|
|
1523
|
+
reason: "A request to the PayPal API is about to move money. node9 asks before money moves (PayPal)."
|
|
1524
|
+
},
|
|
1525
|
+
{
|
|
1526
|
+
name: "shield:paypal:review-code",
|
|
1527
|
+
tool: "bash",
|
|
1528
|
+
conditions: [
|
|
1529
|
+
{
|
|
1530
|
+
field: "command",
|
|
1531
|
+
op: "matches",
|
|
1532
|
+
// The Node SDKs (checkout-server-sdk, paypal-server-sdk) and the
|
|
1533
|
+
// Python paypalrestsdk.
|
|
1534
|
+
value: "\\b(?:CapturesRefundRequest|OrdersCaptureRequest|AuthorizationsCaptureRequest|PayoutsPostRequest)\\b|\\b(?:captureOrder|refundCapturedPayment|captureAuthorizedPayment|createBatchPayout)\\s*\\(|\\bpaypalrestsdk\\.(?:Payout|Sale|Capture|Invoice|BillingAgreement)\\b"
|
|
1535
|
+
}
|
|
1536
|
+
],
|
|
1537
|
+
verdict: "review",
|
|
1538
|
+
reason: "This code moves money through PayPal. node9 asks before money moves (PayPal)."
|
|
1539
|
+
},
|
|
1540
|
+
{
|
|
1541
|
+
name: "shield:paypal:review-code-http",
|
|
1542
|
+
tool: "bash",
|
|
1543
|
+
conditions: [
|
|
1544
|
+
{
|
|
1545
|
+
field: "command",
|
|
1546
|
+
op: "matches",
|
|
1547
|
+
// The endpoints that move money; the token call every script
|
|
1548
|
+
// starts with (/v1/oauth2/token) is not one.
|
|
1549
|
+
value: postTo(
|
|
1550
|
+
"api(?:-m)?\\.paypal\\.com/v[12]/(?:payments/(?:captures|authorizations|sale|payouts|payment|referenced-payouts)|checkout/orders/[^\\s/\"'`]{1,64}/(?:capture|authorize)|invoicing/invoices|billing/subscriptions)"
|
|
1551
|
+
)
|
|
1552
|
+
}
|
|
1553
|
+
],
|
|
1554
|
+
verdict: "review",
|
|
1555
|
+
reason: "This code posts to the PayPal API. node9 asks before money moves (PayPal)."
|
|
1556
|
+
}
|
|
1557
|
+
]
|
|
1558
|
+
},
|
|
1559
|
+
{
|
|
1560
|
+
name: "square",
|
|
1561
|
+
label: "Square",
|
|
1562
|
+
description: "Asks before money moves in Square (refunds, payments, paid orders, invoices, subscriptions), whether the agent uses a Square MCP server, the API or the Square SDK in a script. The sandbox host is never asked about, and neither are reads.",
|
|
1563
|
+
template: "finance",
|
|
1564
|
+
// Square's servers, never Squarespace (a website builder).
|
|
1565
|
+
server: "{*square,*square[-_]*,*squareup*}",
|
|
1566
|
+
mcpTools: [
|
|
1567
|
+
{
|
|
1568
|
+
// Square's official MCP server has one tool for every API call; the
|
|
1569
|
+
// service and method name what it does.
|
|
1570
|
+
name: "shield:square:review-mcp-request",
|
|
1571
|
+
tool: "{,mcp__*__}make_api_request",
|
|
1572
|
+
conditions: [
|
|
1573
|
+
{
|
|
1574
|
+
field: "service",
|
|
1575
|
+
op: "matches",
|
|
1576
|
+
value: "^(?:refunds|payments|orders|invoices|subscriptions|disputes|gift_cards|gift_card_activities|checkout|terminal)$",
|
|
1577
|
+
flags: "i"
|
|
1578
|
+
},
|
|
1579
|
+
{
|
|
1580
|
+
field: "method",
|
|
1581
|
+
op: "notMatches",
|
|
1582
|
+
value: "^(?:list|get|retrieve|search|batch_?retrieve|calculate)",
|
|
1583
|
+
flags: "i"
|
|
1584
|
+
}
|
|
1585
|
+
],
|
|
1586
|
+
conditionMode: "all",
|
|
1587
|
+
verdict: "review",
|
|
1588
|
+
reason: "A request through the Square MCP server is about to move money. node9 asks before money moves (Square)."
|
|
1589
|
+
}
|
|
1590
|
+
],
|
|
1591
|
+
doors: [
|
|
1592
|
+
{
|
|
1593
|
+
name: "shield:square:review-api",
|
|
1594
|
+
tool: "bash",
|
|
1595
|
+
conditions: [
|
|
1596
|
+
{
|
|
1597
|
+
field: "command",
|
|
1598
|
+
op: "matches",
|
|
1599
|
+
// The live host only; the sandbox is connect.squareupsandbox.com.
|
|
1600
|
+
value: httpTo(
|
|
1601
|
+
"connect\\.squareup\\.com/v2/(?:refunds|payments|orders/[^\\s/?]{1,64}/pay|invoices|subscriptions|disputes|gift-cards/activities)(?![\\w-]|/search)"
|
|
1602
|
+
),
|
|
1603
|
+
flags: "i"
|
|
1604
|
+
},
|
|
1605
|
+
HTTP_WRITE_ANY
|
|
1606
|
+
],
|
|
1607
|
+
conditionMode: "all",
|
|
1608
|
+
verdict: "review",
|
|
1609
|
+
reason: "A request to the Square API is about to move money. node9 asks before money moves (Square)."
|
|
1610
|
+
},
|
|
1611
|
+
{
|
|
1612
|
+
name: "shield:square:review-code",
|
|
1613
|
+
tool: "bash",
|
|
1614
|
+
conditions: [
|
|
1615
|
+
{
|
|
1616
|
+
field: "command",
|
|
1617
|
+
op: "matches",
|
|
1618
|
+
// The Square SDK in the script: Node (`square`) or Python (`square`, `squareup`).
|
|
1619
|
+
value: `\\bSquareClient\\b|\\bsquare\\.client\\b|from\\s+square[.\\s]|from\\s+["']square["']|require\\(\\s*["']square["']`
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
field: "command",
|
|
1623
|
+
op: "matches",
|
|
1624
|
+
value: "\\.refunds(?:Api)?\\.refund(?:Payment|_payment)\\s*\\(|\\.payments(?:Api)?\\.(?:create|complete)(?:Payment|_payment)?\\s*\\(|\\.orders(?:Api)?\\.pay(?:Order|_order)?\\s*\\(|\\.invoices(?:Api)?\\.publish(?:Invoice|_invoice)?\\s*\\("
|
|
1625
|
+
}
|
|
1626
|
+
],
|
|
1627
|
+
conditionMode: "all",
|
|
1628
|
+
verdict: "review",
|
|
1629
|
+
reason: "This code moves money through the Square SDK. node9 asks before money moves (Square)."
|
|
1630
|
+
},
|
|
1631
|
+
{
|
|
1632
|
+
name: "shield:square:review-code-http",
|
|
1633
|
+
tool: "bash",
|
|
1634
|
+
conditions: [
|
|
1635
|
+
{
|
|
1636
|
+
field: "command",
|
|
1637
|
+
op: "matches",
|
|
1638
|
+
value: postTo(
|
|
1639
|
+
"connect\\.squareup\\.com/v2/(?:refunds|payments|orders/[^\\s/?\"'`]{1,64}/pay|invoices|subscriptions|disputes|gift-cards/activities)(?![\\w-]|/search)"
|
|
1640
|
+
)
|
|
1641
|
+
}
|
|
1642
|
+
],
|
|
1643
|
+
verdict: "review",
|
|
1644
|
+
reason: "This code posts to the Square API. node9 asks before money moves (Square)."
|
|
1645
|
+
}
|
|
1646
|
+
]
|
|
1647
|
+
},
|
|
1648
|
+
{
|
|
1649
|
+
name: "plaid",
|
|
1650
|
+
label: "Plaid",
|
|
1651
|
+
description: "Asks before money moves through Plaid (transfers, transfer authorizations, payment initiation), whether the agent uses a Plaid MCP server, the API or the Plaid SDK in a script. The sandbox host is never asked about, and neither are reads such as balances or transactions.",
|
|
1652
|
+
template: "finance",
|
|
1653
|
+
server: "*plaid*",
|
|
1654
|
+
doors: [
|
|
1655
|
+
{
|
|
1656
|
+
name: "shield:plaid:review-api",
|
|
1657
|
+
tool: "bash",
|
|
1658
|
+
conditions: [
|
|
1659
|
+
{
|
|
1660
|
+
field: "command",
|
|
1661
|
+
op: "matches",
|
|
1662
|
+
// Every Plaid endpoint is a POST, so the path is what tells a
|
|
1663
|
+
// write; the live host only, never sandbox.plaid.com. A script
|
|
1664
|
+
// that posts to the URL meets this door too.
|
|
1665
|
+
value: httpTo(
|
|
1666
|
+
"production\\.plaid\\.com/(?:transfer/(?:create|authorization/create|recurring/create)|payment_initiation/payment/create|bank_transfer/create)(?![\\w-])"
|
|
1667
|
+
),
|
|
1668
|
+
flags: "i"
|
|
1669
|
+
}
|
|
1670
|
+
],
|
|
1671
|
+
verdict: "review",
|
|
1672
|
+
reason: "A request to the Plaid API is about to move money. node9 asks before money moves (Plaid)."
|
|
1673
|
+
},
|
|
1674
|
+
{
|
|
1675
|
+
name: "shield:plaid:review-code",
|
|
1676
|
+
tool: "bash",
|
|
1677
|
+
conditions: [
|
|
1678
|
+
{ field: "command", op: "matches", value: "\\bplaid", flags: "i" },
|
|
1679
|
+
{
|
|
1680
|
+
field: "command",
|
|
1681
|
+
op: "matches",
|
|
1682
|
+
value: "\\b(?:transfer(?:Authorization|Recurring)?Create|paymentInitiationPaymentCreate|bankTransferCreate|transfer_(?:authorization_|recurring_)?create|payment_initiation_payment_create|bank_transfer_create)\\s*\\("
|
|
1683
|
+
}
|
|
1684
|
+
],
|
|
1685
|
+
conditionMode: "all",
|
|
1686
|
+
verdict: "review",
|
|
1687
|
+
reason: "This code moves money through Plaid. node9 asks before money moves (Plaid)."
|
|
1688
|
+
}
|
|
1689
|
+
]
|
|
1690
|
+
},
|
|
1691
|
+
{
|
|
1692
|
+
name: "okta",
|
|
1693
|
+
label: "Okta",
|
|
1694
|
+
description: "Asks before a user, a group member, a role, a password or a key changes in Okta, whether the agent uses an Okta MCP server, the API or the Okta SDK in a script. Reads and signing in are never asked about.",
|
|
1695
|
+
template: "identity",
|
|
1696
|
+
server: "*okta*",
|
|
1697
|
+
doors: [
|
|
1698
|
+
{
|
|
1699
|
+
name: "shield:okta:review-api",
|
|
1700
|
+
tool: "bash",
|
|
1701
|
+
conditions: [
|
|
1702
|
+
{
|
|
1703
|
+
field: "command",
|
|
1704
|
+
op: "matches",
|
|
1705
|
+
// The management API only: sign-in (/api/v1/authn, /sessions,
|
|
1706
|
+
// /oauth2) is not under these paths.
|
|
1707
|
+
value: httpTo(
|
|
1708
|
+
"[\\w-]+\\.okta(?:-emea)?\\.com/api/v1/(?:users|groups|apps|iam|api-tokens|idps|authorizationServers|policies)(?![\\w-])"
|
|
1709
|
+
),
|
|
1710
|
+
flags: "i"
|
|
1711
|
+
},
|
|
1712
|
+
HTTP_WRITE_ANY
|
|
1713
|
+
],
|
|
1714
|
+
conditionMode: "all",
|
|
1715
|
+
verdict: "review",
|
|
1716
|
+
reason: "A request to the Okta API is about to change who has access. node9 asks before access changes (Okta)."
|
|
1717
|
+
},
|
|
1718
|
+
{
|
|
1719
|
+
name: "shield:okta:review-code",
|
|
1720
|
+
tool: "bash",
|
|
1721
|
+
conditions: [
|
|
1722
|
+
{
|
|
1723
|
+
field: "command",
|
|
1724
|
+
op: "matches",
|
|
1725
|
+
// The Okta SDK in the script: a method named createUser alone is
|
|
1726
|
+
// in half the applications ever written.
|
|
1727
|
+
value: "@okta/okta-sdk|\\bokta\\.Client\\b|from\\s+okta[.\\s]|\\bimport\\s+okta\\b"
|
|
1728
|
+
},
|
|
1729
|
+
{
|
|
1730
|
+
field: "command",
|
|
1731
|
+
op: "matches",
|
|
1732
|
+
value: "\\b(?:(?:create|delete|deactivate|suspend|unlock|activate)User|(?:reset|expire)Password|resetFactors|(?:assign|unassign)User(?:To|From)Group|assignRoleTo(?:User|Group))\\s*\\("
|
|
1733
|
+
}
|
|
1734
|
+
],
|
|
1735
|
+
conditionMode: "all",
|
|
1736
|
+
verdict: "review",
|
|
1737
|
+
reason: "This code changes who has access in Okta. node9 asks before access changes (Okta)."
|
|
1738
|
+
},
|
|
1739
|
+
{
|
|
1740
|
+
name: "shield:okta:review-code-py",
|
|
1741
|
+
tool: "bash",
|
|
1742
|
+
conditions: [
|
|
1743
|
+
{
|
|
1744
|
+
field: "command",
|
|
1745
|
+
op: "matches",
|
|
1746
|
+
value: "@okta/okta-sdk|\\bokta\\.Client\\b|from\\s+okta[.\\s]|\\bimport\\s+okta\\b"
|
|
1747
|
+
},
|
|
1748
|
+
{
|
|
1749
|
+
field: "command",
|
|
1750
|
+
op: "matches",
|
|
1751
|
+
value: "\\b(?:(?:create|delete|deactivate|deactivate_or_delete|suspend|unlock|activate)_user|(?:reset|expire)_password|reset_factors|(?:add|remove)_user_(?:to|from)_group|assign_role_to_(?:user|group))\\s*\\("
|
|
1752
|
+
}
|
|
1753
|
+
],
|
|
1754
|
+
conditionMode: "all",
|
|
1755
|
+
verdict: "review",
|
|
1756
|
+
reason: "This code changes who has access in Okta. node9 asks before access changes (Okta)."
|
|
1757
|
+
}
|
|
1758
|
+
]
|
|
1759
|
+
},
|
|
1760
|
+
{
|
|
1761
|
+
name: "auth0",
|
|
1762
|
+
label: "Auth0",
|
|
1763
|
+
description: "Asks before a user, a role, an application or its permissions change in Auth0, whether the agent uses an Auth0 MCP server, the auth0 CLI, the Management API or the Auth0 SDK in a script. Reads and signing in are never asked about.",
|
|
1764
|
+
template: "identity",
|
|
1765
|
+
server: "*auth0*",
|
|
1766
|
+
mcpTools: [
|
|
1767
|
+
{
|
|
1768
|
+
// Auth0's official MCP server: applications (their secrets and
|
|
1769
|
+
// callbacks), APIs and their scopes, and Actions (code that runs at
|
|
1770
|
+
// every sign-in).
|
|
1771
|
+
name: "shield:auth0:review-tenant-config",
|
|
1772
|
+
tool: "{,mcp__*__}{auth0_create_application,auth0_update_application,auth0_create_resource_server,auth0_update_resource_server,auth0_create_action,auth0_update_action,auth0_deploy_action}",
|
|
1773
|
+
conditions: [],
|
|
1774
|
+
verdict: "review",
|
|
1775
|
+
reason: "This changes an Auth0 application, API or sign-in Action. node9 asks before access changes (Auth0)."
|
|
1776
|
+
}
|
|
1777
|
+
],
|
|
1778
|
+
doors: [
|
|
1779
|
+
{
|
|
1780
|
+
name: "shield:auth0:review-cli",
|
|
1781
|
+
tool: "bash",
|
|
1782
|
+
conditions: [
|
|
1783
|
+
{
|
|
1784
|
+
field: "command",
|
|
1785
|
+
op: "matches",
|
|
1786
|
+
value: prog("auth0") + GAP + "\\s(?:(?:users|roles|apps|orgs)\\s+(?:create|update|delete|rm)|users\\s+roles\\s+(?:assign|add|remove|rm)|roles\\s+permissions\\s+(?:add|remove|rm)|users\\s+blocks\\s+unblock|api\\s+(?:post|put|patch|delete))(?![\\w-])",
|
|
1787
|
+
flags: "i"
|
|
1788
|
+
}
|
|
1789
|
+
],
|
|
1790
|
+
verdict: "review",
|
|
1791
|
+
reason: "The auth0 CLI is about to change who has access. node9 asks before access changes (Auth0)."
|
|
1792
|
+
},
|
|
1793
|
+
{
|
|
1794
|
+
name: "shield:auth0:review-api",
|
|
1795
|
+
tool: "bash",
|
|
1796
|
+
conditions: [
|
|
1797
|
+
{
|
|
1798
|
+
field: "command",
|
|
1799
|
+
op: "matches",
|
|
1800
|
+
// The Management API only; /oauth/token is signing in.
|
|
1801
|
+
value: httpTo(
|
|
1802
|
+
"\\.auth0\\.com/api/v2/(?:users|roles|clients|grants|client-grants|organizations|tickets|jobs/users-imports|device-credentials)(?![\\w-])"
|
|
1803
|
+
),
|
|
1804
|
+
flags: "i"
|
|
1805
|
+
},
|
|
1806
|
+
HTTP_WRITE_ANY
|
|
1807
|
+
],
|
|
1808
|
+
conditionMode: "all",
|
|
1809
|
+
verdict: "review",
|
|
1810
|
+
reason: "A request to the Auth0 Management API is about to change who has access. node9 asks before access changes (Auth0)."
|
|
1811
|
+
},
|
|
1812
|
+
{
|
|
1813
|
+
name: "shield:auth0:review-code",
|
|
1814
|
+
tool: "bash",
|
|
1815
|
+
conditions: [
|
|
1816
|
+
{
|
|
1817
|
+
field: "command",
|
|
1818
|
+
op: "matches",
|
|
1819
|
+
// The Auth0 SDK in the script (Node `auth0`, Python `auth0`).
|
|
1820
|
+
value: `\\bManagementClient\\b|from\\s+auth0[.\\s]|from\\s+["']auth0["']|require\\(\\s*["']auth0["']`
|
|
1821
|
+
},
|
|
1822
|
+
{
|
|
1823
|
+
field: "command",
|
|
1824
|
+
op: "matches",
|
|
1825
|
+
value: "\\.(?:users|roles|organizations|clients)\\.(?:create|delete|update|assignRoles|deleteRoles|assignUsers|addPermissions|deletePermissions|addMembers|deleteMembers|add_roles|remove_roles|add_users|add_permissions|remove_permissions)\\s*\\("
|
|
1826
|
+
}
|
|
1827
|
+
],
|
|
1828
|
+
conditionMode: "all",
|
|
1829
|
+
verdict: "review",
|
|
1830
|
+
reason: "This code changes who has access in Auth0. node9 asks before access changes (Auth0)."
|
|
1831
|
+
}
|
|
1832
|
+
]
|
|
1833
|
+
}
|
|
1834
|
+
];
|
|
1835
|
+
function buildAppShield(spec) {
|
|
1836
|
+
const owner = spec.label;
|
|
1837
|
+
const toolRules = ACTION_TEMPLATES[spec.template].filter(isToolRule).map((rule) => ({
|
|
1838
|
+
...rule,
|
|
1839
|
+
name: `shield:${spec.name}:${actionPart(rule.name)}`,
|
|
1840
|
+
server: spec.server,
|
|
1841
|
+
reason: ownReason(rule.reason, owner)
|
|
1842
|
+
}));
|
|
1843
|
+
const ownTools = (spec.mcpTools ?? []).map((rule) => ({
|
|
1844
|
+
...rule,
|
|
1845
|
+
server: spec.server
|
|
1846
|
+
}));
|
|
1847
|
+
return {
|
|
1848
|
+
name: spec.name,
|
|
1849
|
+
description: spec.description,
|
|
1850
|
+
aliases: [],
|
|
1851
|
+
smartRules: [...toolRules, ...ownTools, ...spec.doors],
|
|
1852
|
+
dangerousWords: []
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
var APP_SHIELDS = APP_SHIELD_SPECS.map(buildAppShield);
|
|
1856
|
+
var APP_SHIELD_NAMES = new Set(APP_SHIELD_SPECS.map((s) => s.name));
|
|
1857
|
+
var APP_SERVER_GLOB = `{${APP_SHIELD_SPECS.map((s) => s.server).join(",")}}`;
|
|
1858
|
+
function buildGeneralRules() {
|
|
1859
|
+
const out = [];
|
|
1860
|
+
for (const name of Object.keys(ACTION_TEMPLATES)) {
|
|
1861
|
+
const { slug, label } = ACTION_CHECKS[name];
|
|
1862
|
+
for (const rule of ACTION_TEMPLATES[name].filter(isToolRule)) {
|
|
1863
|
+
const part = actionPart(rule.name).replace(/^review-/, "");
|
|
1864
|
+
out.push({
|
|
1865
|
+
...rule,
|
|
1866
|
+
name: `review-action-${slug}-${part}`,
|
|
1867
|
+
notServer: APP_SERVER_GLOB,
|
|
1868
|
+
reason: ownReason(rule.reason, label)
|
|
1869
|
+
});
|
|
1281
1870
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1871
|
+
}
|
|
1872
|
+
return out;
|
|
1873
|
+
}
|
|
1874
|
+
var GENERAL_ACTION_RULES = buildGeneralRules();
|
|
1875
|
+
function generalActionRuleNames(template) {
|
|
1876
|
+
const { slug } = ACTION_CHECKS[template];
|
|
1877
|
+
return GENERAL_ACTION_RULES.filter((r) => r.name?.startsWith(`review-action-${slug}-`)).map(
|
|
1878
|
+
(r) => r.name
|
|
1879
|
+
);
|
|
1880
|
+
}
|
|
1881
|
+
var REPLACED_SHIELDS = {
|
|
1882
|
+
finance: "finance is now the Money check (actions.money), on by default. For an app: node9 shield enable stripe (or paypal).",
|
|
1883
|
+
identity: "identity is now the Accounts and access check (actions.access), on by default.",
|
|
1884
|
+
publishing: "publishing is now the Publishing check (actions.publish), on by default."
|
|
1284
1885
|
};
|
|
1285
1886
|
|
|
1286
1887
|
// src/shields/index.ts
|
|
@@ -1325,36 +1926,36 @@ var BUILTIN_SHIELDS = {
|
|
|
1325
1926
|
[bash_safe_default.name]: bash_safe_default,
|
|
1326
1927
|
[docker_default.name]: docker_default,
|
|
1327
1928
|
[filesystem_default.name]: filesystem_default,
|
|
1328
|
-
// Dangerous actions as category shields (node9Firewall#385): an MCP app's
|
|
1329
|
-
// money, credential and publishing tools, asked about whatever the request
|
|
1330
|
-
// said. One glob per rule covers the bare name the gateway sends and the
|
|
1331
|
-
// mcp__<server>__ name the agent hook sends.
|
|
1332
|
-
[finance_default.name]: finance_default,
|
|
1333
1929
|
[github_default.name]: github_default,
|
|
1334
|
-
[identity_default.name]: identity_default,
|
|
1335
1930
|
[k8s_default.name]: k8s_default,
|
|
1336
1931
|
[mongodb_default.name]: mongodb_default,
|
|
1337
1932
|
[postgres_default.name]: postgres_default,
|
|
1338
1933
|
[project_jail_default.name]: project_jail_default,
|
|
1339
|
-
[
|
|
1340
|
-
|
|
1934
|
+
[redis_default.name]: redis_default,
|
|
1935
|
+
// App shields generated from the action templates (node9Firewall#390): one
|
|
1936
|
+
// per app, every door (MCP server, CLI, API, library), off by default.
|
|
1937
|
+
...Object.fromEntries(APP_SHIELDS.map((s) => [s.name, s]))
|
|
1341
1938
|
};
|
|
1342
|
-
var ACTION_SHIELD_NAMES = /* @__PURE__ */ new Set([
|
|
1343
|
-
"finance",
|
|
1344
|
-
"identity",
|
|
1345
|
-
"publishing"
|
|
1346
|
-
]);
|
|
1347
1939
|
function assertBuiltinShieldRegexesAreSafe() {
|
|
1348
|
-
|
|
1940
|
+
const sets = [
|
|
1941
|
+
...Object.values(BUILTIN_SHIELDS).map((sh) => ({
|
|
1942
|
+
name: sh.name,
|
|
1943
|
+
smartRules: sh.smartRules
|
|
1944
|
+
})),
|
|
1945
|
+
...Object.entries(ACTION_TEMPLATES).map(([name, smartRules]) => ({ name, smartRules })),
|
|
1946
|
+
{ name: "general-action-checks", smartRules: GENERAL_ACTION_RULES }
|
|
1947
|
+
];
|
|
1948
|
+
for (const shield of sets) {
|
|
1349
1949
|
for (const rule of shield.smartRules) {
|
|
1350
1950
|
const conditions = rule.conditions ?? [];
|
|
1351
1951
|
for (const cond of conditions) {
|
|
1352
1952
|
if (cond.op !== "matches" && cond.op !== "notMatches") continue;
|
|
1353
1953
|
const pattern = cond.value;
|
|
1354
1954
|
if (!pattern) continue;
|
|
1355
|
-
|
|
1955
|
+
const problem = validateRegex(pattern);
|
|
1956
|
+
if (problem) {
|
|
1356
1957
|
throw new Error(
|
|
1357
|
-
`[node9 engine] Shield '${shield.name}' rule '${rule.name ?? rule.tool}' has
|
|
1958
|
+
`[node9 engine] Shield '${shield.name}' rule '${rule.name ?? rule.tool}' has a regex the runtime refuses (${problem}): ${pattern}`
|
|
1358
1959
|
);
|
|
1359
1960
|
}
|
|
1360
1961
|
}
|
|
@@ -1648,9 +2249,9 @@ var CHECK_TEXT = {
|
|
|
1648
2249
|
},
|
|
1649
2250
|
// ── Commands ──────────────────────────────────────────────────────────────
|
|
1650
2251
|
"commands.inline-exec": {
|
|
1651
|
-
plain: "The agent runs a small program written inside the command itself.",
|
|
2252
|
+
plain: "The agent runs a small program written inside the command itself, and node9 reads it: ordinary code runs, code that deletes, sends data out, runs other commands or reads protected files is held, and so is code node9 cannot read.",
|
|
1652
2253
|
example: `node -e "require('fs').rmSync('dist', {recursive: true})"`,
|
|
1653
|
-
advice: "
|
|
2254
|
+
advice: "Keep Review. Strict mode reviews every inline call, harmless or not; Log or Off only if inline code never reaches anything that matters."
|
|
1654
2255
|
},
|
|
1655
2256
|
"commands.eval-dynamic": {
|
|
1656
2257
|
plain: "The agent runs code whose content is built at run time, so node9 cannot read it in advance.",
|
|
@@ -1682,6 +2283,21 @@ var CHECK_TEXT = {
|
|
|
1682
2283
|
example: "chmod 777 deploy.sh",
|
|
1683
2284
|
advice: "Keep Review. A narrower permission (755, 644) almost always does the job."
|
|
1684
2285
|
},
|
|
2286
|
+
"actions.money": {
|
|
2287
|
+
plain: "The agent moves money (a refund, a payout, a transfer, a charge) through an app node9 has no protection for, such as an internal billing server.",
|
|
2288
|
+
example: "refund_order on a server called acme-billing",
|
|
2289
|
+
advice: "Keep Review. When the app is Stripe or PayPal, turn on its own protection instead: it covers the CLI, the API and scripts too, and a call from it no longer comes here."
|
|
2290
|
+
},
|
|
2291
|
+
"actions.access": {
|
|
2292
|
+
plain: "The agent changes a password, a key, a role or who belongs to a team, through an app node9 has no protection for.",
|
|
2293
|
+
example: "invite_user or grant_role on a company admin server",
|
|
2294
|
+
advice: "Keep Review. Set Log on a sandbox workspace where agents manage test users all day."
|
|
2295
|
+
},
|
|
2296
|
+
"actions.publish": {
|
|
2297
|
+
plain: "The agent publishes something outside the organisation (a release, a package, a deploy, a public post) through an app node9 has no protection for.",
|
|
2298
|
+
example: "create_release or deploy_to_production on a company MCP server",
|
|
2299
|
+
advice: "Keep Review. Set Log on a release machine whose pipeline publishes on purpose, never on a developer laptop."
|
|
2300
|
+
},
|
|
1685
2301
|
"commands.sudo": {
|
|
1686
2302
|
plain: "The agent runs a command as the administrator (root).",
|
|
1687
2303
|
example: "sudo apt-get install -y nginx",
|
|
@@ -1842,7 +2458,7 @@ var CHECK_TEXT = {
|
|
|
1842
2458
|
advice: "Fixed at Block. A person accepts the change on the machine (node9 mcp pin update)."
|
|
1843
2459
|
},
|
|
1844
2460
|
"loading.malicious-package": {
|
|
1845
|
-
plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago. Covers npm, PyPI, RubyGems, crates.io, Go, NuGet, Maven, Packagist and VS Code extensions; the publish-age and install-script signals are npm and PyPI only.",
|
|
2461
|
+
plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago. Covers npm, PyPI, RubyGems, crates.io, Go, NuGet, Maven, Packagist and VS Code extensions; the publish-age and install-script signals are npm and PyPI only. A new release built from the same repository as the one before it (registry provenance) and an install script the package has always run do not stop; a release that lost the provenance its previous release had does.",
|
|
1846
2462
|
example: "npm install of a package flagged as malware",
|
|
1847
2463
|
advice: "Keep Block for known-malicious packages; brand-new packages already stop for Review."
|
|
1848
2464
|
}
|
|
@@ -1860,7 +2476,8 @@ var CHECK_GROUPS = [
|
|
|
1860
2476
|
{ id: "network", title: "Network" },
|
|
1861
2477
|
{ id: "files", title: "Files" },
|
|
1862
2478
|
{ id: "behavior", title: "Agent behavior" },
|
|
1863
|
-
{ id: "loading", title: "What the agent loads" }
|
|
2479
|
+
{ id: "loading", title: "What the agent loads" },
|
|
2480
|
+
{ id: "actions", title: "Actions in apps" }
|
|
1864
2481
|
];
|
|
1865
2482
|
var ALL = VERDICTS;
|
|
1866
2483
|
var BUILTIN_DANGEROUS_WORDS = ["mkfs", "shred"];
|
|
@@ -1907,7 +2524,7 @@ var PRODUCT_CHECKS = [
|
|
|
1907
2524
|
id: "commands.inline-exec",
|
|
1908
2525
|
group: "commands",
|
|
1909
2526
|
title: "Inline code execution",
|
|
1910
|
-
catches: "
|
|
2527
|
+
catches: "inline code (python -c, node -e, a heredoc into an interpreter) that deletes, sends, opens a socket, runs commands, reads protected files or decodes and runs; unreadable inline code",
|
|
1911
2528
|
values: ALL,
|
|
1912
2529
|
defaultValue: "review",
|
|
1913
2530
|
legacy: ["Node9 Standard (Inline Execution)"]
|
|
@@ -2264,6 +2881,38 @@ var PRODUCT_CHECKS = [
|
|
|
2264
2881
|
values: ALL,
|
|
2265
2882
|
defaultValue: "block",
|
|
2266
2883
|
legacy: ["\u{1F4E6} Node9 Package Check (Malicious)", "\u{1F4E6} Node9 Package Check (Review)"]
|
|
2884
|
+
},
|
|
2885
|
+
// ── Actions in apps (node9Firewall#390) ──────────────────────────────────
|
|
2886
|
+
// The safety net under the app shields: an action that moves money, changes
|
|
2887
|
+
// access or publishes, on an MCP server no app shield claims (an internal
|
|
2888
|
+
// billing server, a vendor with no shield, Zapier). Review by default; the
|
|
2889
|
+
// rules come from the action templates (shields/apps.ts).
|
|
2890
|
+
{
|
|
2891
|
+
id: "actions.money",
|
|
2892
|
+
group: "actions",
|
|
2893
|
+
title: "Money moves",
|
|
2894
|
+
catches: "a refund, payout, transfer, charge or withdrawal through an app with no protection of its own",
|
|
2895
|
+
values: ALL,
|
|
2896
|
+
defaultValue: "review",
|
|
2897
|
+
legacy: generalActionRuleNames("finance")
|
|
2898
|
+
},
|
|
2899
|
+
{
|
|
2900
|
+
id: "actions.access",
|
|
2901
|
+
group: "actions",
|
|
2902
|
+
title: "Accounts and access change",
|
|
2903
|
+
catches: "a password, key, role, permission or user changed through an app with no protection of its own",
|
|
2904
|
+
values: ALL,
|
|
2905
|
+
defaultValue: "review",
|
|
2906
|
+
legacy: generalActionRuleNames("identity")
|
|
2907
|
+
},
|
|
2908
|
+
{
|
|
2909
|
+
id: "actions.publish",
|
|
2910
|
+
group: "actions",
|
|
2911
|
+
title: "Something is published",
|
|
2912
|
+
catches: "a release, package, deploy or public post through an app with no protection of its own",
|
|
2913
|
+
values: ALL,
|
|
2914
|
+
defaultValue: "review",
|
|
2915
|
+
legacy: generalActionRuleNames("publishing")
|
|
2267
2916
|
}
|
|
2268
2917
|
];
|
|
2269
2918
|
var SHIELD_RULE_NAME = /^shield:([^:]+):(block|review|allow)-(.+)$/;
|
|
@@ -2325,7 +2974,7 @@ function ssrfCheckId(tier) {
|
|
|
2325
2974
|
var PROJECT_JAIL_BLOCK_READ = /^shield:project-jail:block-read-(ssh|aws|env)(-any-tool)?$/;
|
|
2326
2975
|
var OVERRIDE_PREFIX = "Override block rule:";
|
|
2327
2976
|
var LABEL_WRAPPERS = ["Smart Rule:", "Node9 (AST):", "project-jail (AST):"];
|
|
2328
|
-
function
|
|
2977
|
+
function ruleNameInLabel(s) {
|
|
2329
2978
|
let rest = s;
|
|
2330
2979
|
const override = rest.lastIndexOf(OVERRIDE_PREFIX);
|
|
2331
2980
|
if (override >= 0) rest = rest.slice(override + OVERRIDE_PREFIX.length).trimStart();
|
|
@@ -2341,7 +2990,7 @@ function checkIdForRule(nameOrLabel) {
|
|
|
2341
2990
|
const s = nameOrLabel.trim();
|
|
2342
2991
|
const exact = LEGACY_TO_ID.get(s);
|
|
2343
2992
|
if (exact) return exact;
|
|
2344
|
-
const unwrapped =
|
|
2993
|
+
const unwrapped = ruleNameInLabel(s);
|
|
2345
2994
|
if (unwrapped !== void 0) return checkIdForRule(unwrapped);
|
|
2346
2995
|
if (s.startsWith("shield:project-jail:")) {
|
|
2347
2996
|
return PROJECT_JAIL_BLOCK_READ.test(s) ? "data.credential-files" : "data.credential-files-other";
|
|
@@ -2584,45 +3233,356 @@ function looksLikeText(buf) {
|
|
|
2584
3233
|
}
|
|
2585
3234
|
return printable / buf.length >= 0.9;
|
|
2586
3235
|
}
|
|
2587
|
-
var BASE64_RUN_RE = /[A-Za-z0-9+/]{32,}={0,2}|[A-Za-z0-9_-]{32,}/g;
|
|
2588
|
-
function decodeEmbeddedBase64(text) {
|
|
2589
|
-
const out = [];
|
|
2590
|
-
for (const m of text.matchAll(BASE64_RUN_RE)) {
|
|
2591
|
-
if (out.length >= MAX_BLOBS) break;
|
|
2592
|
-
const run = m[0];
|
|
2593
|
-
if (/^[0-9a-fA-F]+$/.test(run)) continue;
|
|
2594
|
-
const buf = Buffer.from(run, "base64");
|
|
2595
|
-
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3236
|
+
var BASE64_RUN_RE = /[A-Za-z0-9+/]{32,}={0,2}|[A-Za-z0-9_-]{32,}/g;
|
|
3237
|
+
function decodeEmbeddedBase64(text) {
|
|
3238
|
+
const out = [];
|
|
3239
|
+
for (const m of text.matchAll(BASE64_RUN_RE)) {
|
|
3240
|
+
if (out.length >= MAX_BLOBS) break;
|
|
3241
|
+
const run = m[0];
|
|
3242
|
+
if (/^[0-9a-fA-F]+$/.test(run)) continue;
|
|
3243
|
+
const buf = Buffer.from(run, "base64");
|
|
3244
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3245
|
+
}
|
|
3246
|
+
return out;
|
|
3247
|
+
}
|
|
3248
|
+
var HEX_RUN_RE = /\b(?:[0-9a-fA-F]{2}){24,}\b/g;
|
|
3249
|
+
var HEX_ESCAPE_RUN_RE = /(?:\\x[0-9a-fA-F]{2}){16,}/g;
|
|
3250
|
+
function decodeEmbeddedHex(text) {
|
|
3251
|
+
const out = [];
|
|
3252
|
+
for (const m of text.matchAll(HEX_RUN_RE)) {
|
|
3253
|
+
if (out.length >= MAX_BLOBS) break;
|
|
3254
|
+
const buf = Buffer.from(m[0], "hex");
|
|
3255
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3256
|
+
}
|
|
3257
|
+
for (const m of text.matchAll(HEX_ESCAPE_RUN_RE)) {
|
|
3258
|
+
if (out.length >= MAX_BLOBS) break;
|
|
3259
|
+
const buf = Buffer.from(m[0].replace(/\\x/g, ""), "hex");
|
|
3260
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3261
|
+
}
|
|
3262
|
+
return out;
|
|
3263
|
+
}
|
|
3264
|
+
function scanViews(text) {
|
|
3265
|
+
const views = [{ kind: "original", text }];
|
|
3266
|
+
const normalized = normalizeForScan(text);
|
|
3267
|
+
if (normalized !== text) views.push({ kind: "normalized", text: normalized });
|
|
3268
|
+
for (const t of decodeEmbeddedBase64(normalized)) {
|
|
3269
|
+
views.push({ kind: "base64", text: normalizeForScan(t) });
|
|
3270
|
+
}
|
|
3271
|
+
for (const t of decodeEmbeddedHex(normalized)) {
|
|
3272
|
+
views.push({ kind: "hex", text: normalizeForScan(t) });
|
|
3273
|
+
}
|
|
3274
|
+
return views;
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
// src/files/paths.ts
|
|
3278
|
+
var SYSTEM_AUTH_FILES = [
|
|
3279
|
+
"/etc/passwd",
|
|
3280
|
+
"/etc/shadow",
|
|
3281
|
+
"/etc/group",
|
|
3282
|
+
"/etc/gshadow",
|
|
3283
|
+
"/etc/sudoers"
|
|
3284
|
+
];
|
|
3285
|
+
var SYSTEM_AUTH_DIRS = ["/etc/security", "/etc/pam.d", "/etc/sudoers.d"];
|
|
3286
|
+
var PASSWORD_HASH_FILES = ["/etc/shadow", "/etc/gshadow"];
|
|
3287
|
+
var STARTUP_NAMES = [".bashrc", ".zshrc", ".profile", ".bash_profile"];
|
|
3288
|
+
var SYSTEM_DIRS = [
|
|
3289
|
+
"/usr",
|
|
3290
|
+
"/etc",
|
|
3291
|
+
"/boot",
|
|
3292
|
+
"/bin",
|
|
3293
|
+
"/sbin",
|
|
3294
|
+
"/lib",
|
|
3295
|
+
"/lib64",
|
|
3296
|
+
"/var/log"
|
|
3297
|
+
];
|
|
3298
|
+
var SYSTEM_DIRS_EXEMPT = ["/usr/local", "/usr/src"];
|
|
3299
|
+
var UPLOAD_SYSTEM_DIRS = [...SYSTEM_DIRS, "/proc", "/sys", "/root"];
|
|
3300
|
+
var AGENT_INSTRUCTION_FILES = [
|
|
3301
|
+
".gitlab-ci.yml",
|
|
3302
|
+
"CLAUDE.md",
|
|
3303
|
+
"AGENTS.md",
|
|
3304
|
+
".cursorrules",
|
|
3305
|
+
".mcp.json",
|
|
3306
|
+
".vscode/settings.json",
|
|
3307
|
+
"package.json"
|
|
3308
|
+
];
|
|
3309
|
+
var AGENT_INSTRUCTION_DIRS = [
|
|
3310
|
+
".github/workflows",
|
|
3311
|
+
".claude",
|
|
3312
|
+
".cursor",
|
|
3313
|
+
".git/hooks",
|
|
3314
|
+
".husky"
|
|
3315
|
+
];
|
|
3316
|
+
function isAgentInstructionPath(absPath, root) {
|
|
3317
|
+
const r = root.replace(/\/$/, "");
|
|
3318
|
+
if (!(absPath === r || absPath.startsWith(r + "/"))) return false;
|
|
3319
|
+
const rel = absPath.slice(r.length + 1);
|
|
3320
|
+
if (AGENT_INSTRUCTION_FILES.includes(rel)) return true;
|
|
3321
|
+
return AGENT_INSTRUCTION_DIRS.some((d) => rel === d || rel.startsWith(d + "/"));
|
|
3322
|
+
}
|
|
3323
|
+
function isInside(root, p) {
|
|
3324
|
+
const r = root.replace(/\/$/, "") || "/";
|
|
3325
|
+
return p === r || p.startsWith(r === "/" ? "/" : r + "/");
|
|
3326
|
+
}
|
|
3327
|
+
var LEGACY_SYSTEM_PATH_RE = /^(?:[a-zA-Z]:)?\/etc\/(?:passwd|shadow|sudoers)$/;
|
|
3328
|
+
function isPasswordHashPath(p) {
|
|
3329
|
+
return PASSWORD_HASH_FILES.includes(p);
|
|
3330
|
+
}
|
|
3331
|
+
function isLegacySystemPath(p) {
|
|
3332
|
+
return LEGACY_SYSTEM_PATH_RE.test(p);
|
|
3333
|
+
}
|
|
3334
|
+
function normalizeFilePath(p, cwd = "", home = "~") {
|
|
3335
|
+
if (!p.startsWith("/") && !p.startsWith("~") && cwd) p = `${cwd}/${p}`;
|
|
3336
|
+
if (p === "~" || p.startsWith("~/")) p = home + p.slice(1);
|
|
3337
|
+
const rooted = p.startsWith("/");
|
|
3338
|
+
const parts = [];
|
|
3339
|
+
for (const part of p.split("/")) {
|
|
3340
|
+
if (!part || part === ".") continue;
|
|
3341
|
+
if (part === ".." && parts.length && parts.at(-1) !== "..") parts.pop();
|
|
3342
|
+
else if (part !== ".." || !rooted) parts.push(part);
|
|
3343
|
+
}
|
|
3344
|
+
return (rooted ? "/" : "") + parts.join("/");
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
// src/shell/inline-code.ts
|
|
3348
|
+
var MAX_INLINE_CODE = 64 * 1024;
|
|
3349
|
+
var WHAT = {
|
|
3350
|
+
deletes: "deletes files",
|
|
3351
|
+
"writes-outside": "writes a file outside the project",
|
|
3352
|
+
sends: "sends data over the network",
|
|
3353
|
+
listens: "opens a listening socket or a shell",
|
|
3354
|
+
"runs-commands": "runs other commands or processes",
|
|
3355
|
+
"reads-protected": "reads a protected file",
|
|
3356
|
+
"builds-code": "runs code it builds at run time",
|
|
3357
|
+
permissions: "changes permissions or ownership",
|
|
3358
|
+
monitors: "captures the screen, the clipboard or the keyboard",
|
|
3359
|
+
amplifies: "writes or sends in an endless loop"
|
|
3360
|
+
};
|
|
3361
|
+
var OUTSIDE = String.raw`(?:~|\.\.[\\/]|/(?!(?:tmp|var/tmp)/(?![^'"\n]*\.\.)|dev/(?:null|stdout|stderr)\b))`;
|
|
3362
|
+
var pyImport = (mods) => new RegExp(String.raw`\b(?:import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*|from\s+)(?:${mods})\b`);
|
|
3363
|
+
var either = (...res) => new RegExp(res.map((r) => `(?:${r.source})`).join("|"), "m");
|
|
3364
|
+
var PYTHON = [
|
|
3365
|
+
[
|
|
3366
|
+
"deletes",
|
|
3367
|
+
/\bos\.(?:remove|unlink|rmdir|removedirs)\s*\(|\bshutil\.rmtree\s*\(|\.(?:unlink|rmdir)\s*\(|\bfrom\s+(?:os|shutil)\s+import\s+[^\n]*\b(?:remove|unlink|rmdir|removedirs|rmtree)\b/
|
|
3368
|
+
],
|
|
3369
|
+
[
|
|
3370
|
+
"writes-outside",
|
|
3371
|
+
new RegExp(
|
|
3372
|
+
String.raw`\bopen\s*\(\s*[rRbBuU]?['"]${OUTSIDE}[^'"\n]*['"]\s*,\s*(?:mode\s*=\s*)?[rRbB]?['"][^'"\n]*[wax+]|\bPath\s*\(\s*[rR]?['"]${OUTSIDE}[^'"\n]*['"]\s*\)\s*\.(?:write_text|write_bytes|touch|mkdir|symlink_to)\s*\(|\bshutil\.(?:copy\w*|move)\s*\([^)\n]*['"]${OUTSIDE}|\bos\.(?:rename|replace|symlink|link|truncate|makedirs|mkdir)\s*\([^)\n]*['"]${OUTSIDE}`
|
|
3373
|
+
)
|
|
3374
|
+
],
|
|
3375
|
+
[
|
|
3376
|
+
"sends",
|
|
3377
|
+
either(
|
|
3378
|
+
pyImport(
|
|
3379
|
+
String.raw`socket|requests|urllib2|urllib3|http\.client|httplib|smtplib|ftplib|paramiko|telnetlib|aiohttp|httpx|websockets?|xmlrpc|poplib|imaplib|pycurl|scapy`
|
|
3380
|
+
),
|
|
3381
|
+
/\burllib\.request\b|\burlopen\s*\(|\bfrom\s+urllib\s+import\s+[^\n;]*\brequest\b|\basyncio\.open_connection\s*\(/
|
|
3382
|
+
)
|
|
3383
|
+
],
|
|
3384
|
+
[
|
|
3385
|
+
"listens",
|
|
3386
|
+
either(
|
|
3387
|
+
pyImport(String.raw`pty|socketserver|http\.server`),
|
|
3388
|
+
/\bpty\.spawn\s*\(|\.bind\s*\(\s*\(|\basyncio\.start_server\s*\(/
|
|
3389
|
+
)
|
|
3390
|
+
],
|
|
3391
|
+
[
|
|
3392
|
+
"runs-commands",
|
|
3393
|
+
either(
|
|
3394
|
+
pyImport("subprocess|pexpect|commands|psutil"),
|
|
3395
|
+
/\bos\.(?:system|popen|exec\w*|spawn\w*|posix_spawn\w*|fork|forkpty|kill|killpg)\s*\(|\bfrom\s+os\s+import\s+[^\n;]*\b(?:system|popen|exec\w*|spawn\w*|fork|kill)\b|\bfrom\s+(?:os|shutil|pty|ctypes)\s+import\s+\*/
|
|
3396
|
+
)
|
|
3397
|
+
],
|
|
3398
|
+
[
|
|
3399
|
+
"builds-code",
|
|
3400
|
+
/(?<![\w.])(?:exec|eval|compile|execfile)\s*\(|\b__import__\s*\(|\bimportlib\b|\b(?:c?pickle|dill|marshal|shelve)\.loads?\s*\(|\byaml\.(?:unsafe_)?load\s*\((?![^)\n]*SafeLoader)|\bctypes\b|\b(?:getattr|vars)\s*\(\s*(?:os|subprocess|shutil|socket|sys|pty|builtins|__builtins__)\b|\b(?:os|subprocess|shutil|socket|sys|pty|builtins)\.__dict__\b|\b__builtins__\b|\bsys\.modules\b|\bglobals\s*\(\s*\)\s*\[/
|
|
3401
|
+
],
|
|
3402
|
+
[
|
|
3403
|
+
// Spyware shapes: a screenshot, the clipboard, a key logger.
|
|
3404
|
+
"monitors",
|
|
3405
|
+
either(
|
|
3406
|
+
pyImport(String.raw`pyperclip|pynput|keyboard|pyautogui|pyscreenshot|mss|clipboard`),
|
|
3407
|
+
/\bImageGrab\b|\bpyautogui\.screenshot\b|\bscreencapture\b/
|
|
3408
|
+
)
|
|
3409
|
+
],
|
|
3410
|
+
[
|
|
3411
|
+
"permissions",
|
|
3412
|
+
/\bos\.(?:chmod|lchmod|fchmod|chown|lchown|fchown|setuid|setgid|seteuid|setegid|setreuid|setregid|setresuid)\s*\(|\.chmod\s*\(|\bshutil\.chown\s*\(/
|
|
3413
|
+
]
|
|
3414
|
+
];
|
|
3415
|
+
var NODE = [
|
|
3416
|
+
[
|
|
3417
|
+
"deletes",
|
|
3418
|
+
/\.(?:rm|rmSync|rmdir|rmdirSync|unlink|unlinkSync)\s*\(|\brimraf\b|\bDeno\.remove(?:Sync)?\s*\(/
|
|
3419
|
+
],
|
|
3420
|
+
[
|
|
3421
|
+
"writes-outside",
|
|
3422
|
+
new RegExp(
|
|
3423
|
+
String.raw`(?:\.(?:writeFile|writeFileSync|appendFile|appendFileSync|createWriteStream|copyFile|copyFileSync|cp|cpSync|rename|renameSync|truncate|truncateSync|symlink|symlinkSync|mkdir|mkdirSync)|\bDeno\.(?:writeTextFile|writeFile|rename|mkdir)(?:Sync)?|\bBun\.write)\s*\(\s*['"\x60]${OUTSIDE}`
|
|
3424
|
+
)
|
|
3425
|
+
],
|
|
3426
|
+
[
|
|
3427
|
+
"sends",
|
|
3428
|
+
/\bfetch\s*\(|(?:\brequire\s*\(\s*|\bfrom\s+|\bimport\s+)['"\x60](?:node:)?(?:http|https|http2|net|dgram|tls|axios|node-fetch|ws|request|got|undici|nodemailer)['"\x60]|\bnew\s+WebSocket\b|\bXMLHttpRequest\b|\b(?:Deno|Bun)\.connect\w*\s*\(/
|
|
3429
|
+
],
|
|
3430
|
+
["listens", /\bcreateServer\s*\(|\b(?:Deno\.(?:listen\w*|serve)|Bun\.(?:listen|serve))\s*\(/],
|
|
3431
|
+
[
|
|
3432
|
+
"runs-commands",
|
|
3433
|
+
/\bchild_process\b|\bprocess\.(?:binding|dlopen|kill)\s*\(|\bDeno\.(?:run|Command)\b|\bBun\.(?:spawn|spawnSync|\$)\b|\bexecSync\s*\(|\bspawnSync\s*\(/
|
|
3434
|
+
],
|
|
3435
|
+
[
|
|
3436
|
+
"builds-code",
|
|
3437
|
+
/(?<![\w.])eval\s*\(|\bnew\s+Function\s*\(|(?<![\w.])Function\s*\(|(?:\brequire\s*\(\s*|\bfrom\s+)['"\x60](?:node:)?vm['"\x60]|\bvm\.\w+|\brequire\s*\(\s*[^'"\x60\s)]|\bimport\s*\(\s*[^'"\x60\s)]/
|
|
3438
|
+
],
|
|
3439
|
+
[
|
|
3440
|
+
"permissions",
|
|
3441
|
+
/\.(?:chmod|chmodSync|chown|chownSync|lchown|lchownSync|fchmod|fchmodSync|fchown|fchownSync)\s*\(|\bprocess\.set(?:e)?[ug]id\s*\(|\bDeno\.(?:chmod|chown)(?:Sync)?\s*\(/
|
|
3442
|
+
]
|
|
3443
|
+
];
|
|
3444
|
+
var PERL = [
|
|
3445
|
+
["deletes", /\b(?:unlink|rmdir|rmtree|remove_tree)\b/],
|
|
3446
|
+
[
|
|
3447
|
+
"writes-outside",
|
|
3448
|
+
new RegExp(
|
|
3449
|
+
String.raw`['"]\s*(?:\+?>>?|\+<)\s*['"]?\s*,?\s*['"]?${OUTSIDE}|\b(?:rename|symlink|link|copy|move)\s*\(?[^;\n]*['"]${OUTSIDE}`
|
|
3450
|
+
)
|
|
3451
|
+
],
|
|
3452
|
+
[
|
|
3453
|
+
"sends",
|
|
3454
|
+
/\b(?:IO::Socket|Socket|LWP|HTTP::Tiny|Net::\w+|Mojo::UserAgent|WWW::Mechanize|IO::Socket::INET)\b/
|
|
3455
|
+
],
|
|
3456
|
+
[
|
|
3457
|
+
"runs-commands",
|
|
3458
|
+
/\b(?:system|exec|fork|kill|syscall)\b|`[^`]*`|\bqx\s*[{([/|!'"]|\bopen\s*\(?[^;\n]*(?:['"]\s*\||\|\s*['"]|['"]-\|['"])/
|
|
3459
|
+
],
|
|
3460
|
+
["builds-code", /\beval\b|\bStorable::thaw\b|\bdo\s+['"]/],
|
|
3461
|
+
["permissions", /\b(?:chmod|chown)\b/]
|
|
3462
|
+
];
|
|
3463
|
+
var RUBY = [
|
|
3464
|
+
[
|
|
3465
|
+
"deletes",
|
|
3466
|
+
/\bFile\.(?:delete|unlink)\b|\bFileUtils\.(?:rm\w*|remove\w*)\b|\bDir\.(?:rmdir|delete|unlink)\b|\.(?:rmtree|delete_all)\b/
|
|
3467
|
+
],
|
|
3468
|
+
[
|
|
3469
|
+
"writes-outside",
|
|
3470
|
+
new RegExp(
|
|
3471
|
+
String.raw`\bFile\.(?:write|binwrite|symlink|rename)\s*\(?\s*['"]${OUTSIDE}|\bFile\.open\s*\(?\s*['"]${OUTSIDE}[^'"\n]*['"]\s*,\s*['"][wa+]|\bFileUtils\.(?:cp\w*|mv|install|ln\w*|mkdir_p|touch)\s*\(?[^\n]*['"]${OUTSIDE}`
|
|
3472
|
+
)
|
|
3473
|
+
],
|
|
3474
|
+
[
|
|
3475
|
+
"sends",
|
|
3476
|
+
/\bNet::\w+|\b(?:TCPSocket|UDPSocket|UNIXSocket|Socket)\b|\bopen-uri\b|\bURI\.open\b|\b(?:HTTParty|Faraday|RestClient|Excon|Typhoeus)\b|\brequire\s+['"](?:socket|net\/\w+|open-uri)['"]/
|
|
3477
|
+
],
|
|
3478
|
+
["listens", /\b(?:TCPServer|UNIXServer|WEBrick|PTY)\b/],
|
|
3479
|
+
[
|
|
3480
|
+
"runs-commands",
|
|
3481
|
+
/(?<![\w.])(?:system|exec|spawn|fork)\b|`[^`]*`|%x[{([|!]|(?<![\w.])open\s*\(?\s*['"]\||\bIO\.popen\b|\bOpen3\b|\bProcess\.(?:spawn|kill|exec)\b|\bKernel\.(?:system|exec|spawn|open)\b/
|
|
3482
|
+
],
|
|
3483
|
+
[
|
|
3484
|
+
"builds-code",
|
|
3485
|
+
/(?<![\w.])eval\b|\b(?:instance|class|module)_eval\b|\b(?:send|public_send)\s*\(?\s*:?['"]?(?:system|eval|exec|spawn)\b|\bMarshal\.load\b|\bYAML\.(?:unsafe_)?load\b|\bconst_get\b/
|
|
3486
|
+
],
|
|
3487
|
+
["permissions", /\b(?:File|FileUtils)\.(?:chmod|chown|lchmod|lchown)\w*\b/]
|
|
3488
|
+
];
|
|
3489
|
+
var PHP = [
|
|
3490
|
+
["deletes", /\b(?:unlink|rmdir)\s*\(/],
|
|
3491
|
+
[
|
|
3492
|
+
"writes-outside",
|
|
3493
|
+
new RegExp(
|
|
3494
|
+
String.raw`\b(?:file_put_contents|symlink|link|copy|rename|mkdir|touch)\s*\([^)\n]*['"]${OUTSIDE}|\bfopen\s*\(\s*['"]${OUTSIDE}[^'"\n]*['"]\s*,\s*['"][waxc+]`
|
|
3495
|
+
)
|
|
3496
|
+
],
|
|
3497
|
+
[
|
|
3498
|
+
"sends",
|
|
3499
|
+
/\b(?:curl_exec|curl_init|fsockopen|pfsockopen|stream_socket_client|socket_create|socket_connect|mail|ftp_connect)\s*\(|\b(?:file_get_contents|fopen|file|readfile)\s*\(\s*['"](?:https?|ftp):/
|
|
3500
|
+
],
|
|
3501
|
+
["listens", /\b(?:stream_socket_server|socket_bind|socket_listen)\s*\(/],
|
|
3502
|
+
[
|
|
3503
|
+
"runs-commands",
|
|
3504
|
+
/\b(?:system|exec|shell_exec|passthru|proc_open|popen|pcntl_exec|pcntl_fork|posix_kill)\s*\(|`[^`]*`/
|
|
3505
|
+
],
|
|
3506
|
+
[
|
|
3507
|
+
"builds-code",
|
|
3508
|
+
/\b(?:eval|assert|create_function|unserialize|call_user_func(?:_array)?)\s*\(|\bbase64_decode\b/
|
|
3509
|
+
],
|
|
3510
|
+
["permissions", /\b(?:chmod|chown|chgrp|lchown|lchgrp)\s*\(/]
|
|
3511
|
+
];
|
|
3512
|
+
var TABLES = {
|
|
3513
|
+
python: PYTHON,
|
|
3514
|
+
node: NODE,
|
|
3515
|
+
perl: PERL,
|
|
3516
|
+
ruby: RUBY,
|
|
3517
|
+
php: PHP
|
|
3518
|
+
};
|
|
3519
|
+
function inlineLanguageOf(interp) {
|
|
3520
|
+
const i = interp.toLowerCase();
|
|
3521
|
+
if (/^python[\d.]*$/.test(i)) return "python";
|
|
3522
|
+
if (/^(?:node|tsx|ts-node|deno|bun)$/.test(i)) return "node";
|
|
3523
|
+
if (i === "perl") return "perl";
|
|
3524
|
+
if (i === "ruby" || i === "irb") return "ruby";
|
|
3525
|
+
if (i === "php") return "php";
|
|
3526
|
+
return null;
|
|
3527
|
+
}
|
|
3528
|
+
function resolvePythonAliases(code) {
|
|
3529
|
+
const aliases = [...code.matchAll(/\bimport\s+([\w.]+)\s+as\s+(\w+)/g)].slice(0, 32);
|
|
3530
|
+
let out = code;
|
|
3531
|
+
for (const [, mod, alias] of aliases) {
|
|
3532
|
+
if (alias === mod) continue;
|
|
3533
|
+
out = out.replace(new RegExp(String.raw`(?<![\w.])${alias}\b`, "g"), mod);
|
|
2596
3534
|
}
|
|
2597
3535
|
return out;
|
|
2598
3536
|
}
|
|
2599
|
-
var
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
const
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
2607
|
-
}
|
|
2608
|
-
for (const m of text.matchAll(HEX_ESCAPE_RUN_RE)) {
|
|
2609
|
-
if (out.length >= MAX_BLOBS) break;
|
|
2610
|
-
const buf = Buffer.from(m[0].replace(/\\x/g, ""), "hex");
|
|
2611
|
-
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3537
|
+
var STRING_LITERAL = /(['"`])((?:\\.|(?!\1)[^\\\n]){1,4096})\1/g;
|
|
3538
|
+
function protectedLiteral(code, isProtected) {
|
|
3539
|
+
let n = 0;
|
|
3540
|
+
for (const m of code.matchAll(STRING_LITERAL)) {
|
|
3541
|
+
if (++n > 2048) break;
|
|
3542
|
+
const value = m[2].trim();
|
|
3543
|
+
if (value && isProtected(value)) return value;
|
|
2612
3544
|
}
|
|
2613
|
-
return
|
|
3545
|
+
return null;
|
|
2614
3546
|
}
|
|
2615
|
-
function
|
|
2616
|
-
const
|
|
2617
|
-
const
|
|
2618
|
-
if (
|
|
2619
|
-
|
|
2620
|
-
|
|
3547
|
+
function amplifies(language, code) {
|
|
3548
|
+
const loop = language === "python" ? /\bwhile\s+(?:True|1)\s*:/ : language === "node" ? /\bwhile\s*\(\s*(?:true|1)\s*\)|\bfor\s*\(\s*;\s*;\s*\)|\bsetInterval\s*\(/ : /\bwhile\s*\(?\s*(?:1|true)\s*\)?|\bloop\s+do\b|\bfor\s*\(\s*;\s*;\s*\)/;
|
|
3549
|
+
const m = loop.exec(code);
|
|
3550
|
+
if (!m) return null;
|
|
3551
|
+
const body = code.slice(m.index);
|
|
3552
|
+
return /\.write\s*\(|\.(?:append|write)File(?:Sync)?\s*\(|\bopen\s*\(|\bprint\s*\(\s*[^)\n]*\bfile\s*=|\.send(?:all|to)?\s*\(|\bfwrite\s*\(|\bfile_put_contents\s*\(|\bsyswrite\b/.test(
|
|
3553
|
+
body
|
|
3554
|
+
) ? m[0] : null;
|
|
3555
|
+
}
|
|
3556
|
+
function judgeInlineCode(language, code, isProtected) {
|
|
3557
|
+
if (code.length > MAX_INLINE_CODE) {
|
|
3558
|
+
return { outcome: "unreadable", what: "is too long for node9 to read" };
|
|
3559
|
+
}
|
|
3560
|
+
const text = language === "python" ? resolvePythonAliases(code) : code;
|
|
3561
|
+
for (const [category, re] of TABLES[language]) {
|
|
3562
|
+
const m = re.exec(text);
|
|
3563
|
+
if (!m) continue;
|
|
3564
|
+
const evidence = m[0].trim().replace(/\s+/g, " ").slice(0, 60);
|
|
3565
|
+
return {
|
|
3566
|
+
outcome: category === "builds-code" ? "unreadable" : "dangerous",
|
|
3567
|
+
what: WHAT[category],
|
|
3568
|
+
evidence,
|
|
3569
|
+
category
|
|
3570
|
+
};
|
|
2621
3571
|
}
|
|
2622
|
-
|
|
2623
|
-
|
|
3572
|
+
const path = protectedLiteral(text, isProtected);
|
|
3573
|
+
if (path) {
|
|
3574
|
+
return {
|
|
3575
|
+
outcome: "dangerous",
|
|
3576
|
+
what: WHAT["reads-protected"],
|
|
3577
|
+
evidence: path.slice(0, 60),
|
|
3578
|
+
category: "reads-protected"
|
|
3579
|
+
};
|
|
2624
3580
|
}
|
|
2625
|
-
|
|
3581
|
+
const loop = amplifies(language, text);
|
|
3582
|
+
if (loop) {
|
|
3583
|
+
return { outcome: "dangerous", what: WHAT.amplifies, evidence: loop, category: "amplifies" };
|
|
3584
|
+
}
|
|
3585
|
+
return null;
|
|
2626
3586
|
}
|
|
2627
3587
|
|
|
2628
3588
|
// src/shell/index.ts
|
|
@@ -2731,6 +3691,59 @@ function cachedNormalize(command, compute) {
|
|
|
2731
3691
|
function normalizeCommandForPolicy(command) {
|
|
2732
3692
|
return commandReadingsImpl(command).posix;
|
|
2733
3693
|
}
|
|
3694
|
+
var INTERPRETER_LINE = /^#![ \t]*[\w./+-]+(?:[ \t]+[\w./+=:-]+)*[ \t]*\r?(?=\n|$)/;
|
|
3695
|
+
function fileAccessView(command) {
|
|
3696
|
+
const hit = accessViewCache.get(command);
|
|
3697
|
+
if (hit !== void 0) return hit;
|
|
3698
|
+
const view = fileAccessViewImpl(command);
|
|
3699
|
+
if (accessViewCache.size >= ACCESS_VIEW_CACHE_MAX) {
|
|
3700
|
+
const oldest = accessViewCache.keys().next().value;
|
|
3701
|
+
if (oldest !== void 0) accessViewCache.delete(oldest);
|
|
3702
|
+
}
|
|
3703
|
+
accessViewCache.set(command, view);
|
|
3704
|
+
return view;
|
|
3705
|
+
}
|
|
3706
|
+
var PROGRAM_DIR = /^(?:\/usr(?:\/local)?|\/opt\/homebrew|\/home\/linuxbrew\/\.linuxbrew)?\/s?bin\/[^/]+$|^\/snap\/bin\/[^/]+$|^(?![/~\\]|[A-Za-z]:|.*\.\.)/;
|
|
3707
|
+
var ACCESS_VIEW_CACHE_MAX = 1e3;
|
|
3708
|
+
var accessViewCache = /* @__PURE__ */ new Map();
|
|
3709
|
+
function fileAccessViewImpl(command) {
|
|
3710
|
+
const text = command.replace(INTERPRETER_LINE, "");
|
|
3711
|
+
const f = parseShared(text);
|
|
3712
|
+
if (f === PARSE_FAIL) return text;
|
|
3713
|
+
const toCharIndex = byteOffsetToCharIndex(text);
|
|
3714
|
+
const at = (byteOffset) => toCharIndex === null ? byteOffset : toCharIndex(byteOffset);
|
|
3715
|
+
const edits = [];
|
|
3716
|
+
try {
|
|
3717
|
+
syntax.Walk(f, (node) => {
|
|
3718
|
+
if (!node) return false;
|
|
3719
|
+
const n = node;
|
|
3720
|
+
if (syntax.NodeType(n) !== "CallExpr") return true;
|
|
3721
|
+
const args = n.Args || [];
|
|
3722
|
+
const words = args.map((a) => resolveWordLiteral(a));
|
|
3723
|
+
const head = unwrapCommandHead(words);
|
|
3724
|
+
for (const i of /* @__PURE__ */ new Set([0, head])) {
|
|
3725
|
+
const word = words[i];
|
|
3726
|
+
if (i >= args.length || word === null || word === void 0 || !/[\\/]/.test(word)) {
|
|
3727
|
+
continue;
|
|
3728
|
+
}
|
|
3729
|
+
if (!PROGRAM_DIR.test(word)) continue;
|
|
3730
|
+
const name = word.split(/[\\/]/).pop() ?? "";
|
|
3731
|
+
if (!name) continue;
|
|
3732
|
+
const s = at(args[i].Pos().Offset());
|
|
3733
|
+
const e = at(args[i].End().Offset());
|
|
3734
|
+
if (s < 0 || e < 0) continue;
|
|
3735
|
+
edits.push([s, e, name]);
|
|
3736
|
+
}
|
|
3737
|
+
return true;
|
|
3738
|
+
});
|
|
3739
|
+
} catch {
|
|
3740
|
+
return text;
|
|
3741
|
+
}
|
|
3742
|
+
edits.sort((a, b) => b[0] - a[0]);
|
|
3743
|
+
let out = text;
|
|
3744
|
+
for (const [s, e, rep] of edits) out = out.slice(0, s) + rep + out.slice(e);
|
|
3745
|
+
return out;
|
|
3746
|
+
}
|
|
2734
3747
|
function commandReadings(command) {
|
|
2735
3748
|
const r = commandReadingsImpl(command);
|
|
2736
3749
|
const out = /* @__PURE__ */ new Set([r.posix, r.separator, r.folded]);
|
|
@@ -3896,53 +4909,119 @@ function unwrapCommandHead(words, stopAtFind = false, stopAtDynamic = false) {
|
|
|
3896
4909
|
}
|
|
3897
4910
|
return i;
|
|
3898
4911
|
}
|
|
3899
|
-
function
|
|
4912
|
+
function heredocText(word) {
|
|
4913
|
+
const parts = word?.Parts ?? [];
|
|
4914
|
+
let out = "";
|
|
4915
|
+
for (const p of parts) {
|
|
4916
|
+
if (syntax.NodeType(p) !== "Lit") return null;
|
|
4917
|
+
out += p.Value ?? "";
|
|
4918
|
+
}
|
|
4919
|
+
return out;
|
|
4920
|
+
}
|
|
4921
|
+
function stdinCodeOf(redirs) {
|
|
4922
|
+
const heredoc = /* @__PURE__ */ new Set([deriveRedirOp("cat <<X\nX"), deriveRedirOp("cat <<-X\nX")]);
|
|
4923
|
+
const herestring = deriveRedirOp("cat <<< x");
|
|
4924
|
+
for (const r of redirs) {
|
|
4925
|
+
if (!r || !redirStdinOps().has(r.Op)) continue;
|
|
4926
|
+
if (heredoc.has(r.Op)) {
|
|
4927
|
+
const text = heredocText(r.Hdoc);
|
|
4928
|
+
return text === null ? { code: null, source: "variable" } : { code: text };
|
|
4929
|
+
}
|
|
4930
|
+
if (r.Op === herestring) {
|
|
4931
|
+
const text = resolveWordLiteral(r.Word);
|
|
4932
|
+
return text === null ? { code: null, source: "variable" } : { code: text };
|
|
4933
|
+
}
|
|
4934
|
+
return { code: null, source: "file" };
|
|
4935
|
+
}
|
|
4936
|
+
return { code: null, source: "file" };
|
|
4937
|
+
}
|
|
4938
|
+
function attachedCode(interp, flag) {
|
|
4939
|
+
const eq = flag.indexOf("=");
|
|
4940
|
+
if (flag.startsWith("--")) return eq >= 0 ? flag.slice(eq + 1) : null;
|
|
4941
|
+
if (/^(pwsh|powershell)/.test(interp)) return null;
|
|
4942
|
+
const letters = /^(perl|ruby|lua|bun|osascript|rscript|irb)$/.test(interp) ? "e" : /^(node|tsx|ts-node)$/.test(interp) ? "ep" : interp === "php" ? "r" : "c";
|
|
4943
|
+
const body = flag.slice(1);
|
|
4944
|
+
const at = [...body].findIndex((ch) => letters.includes(ch.toLowerCase()));
|
|
4945
|
+
if (at < 0) return null;
|
|
4946
|
+
let rest = body.slice(at + 1);
|
|
4947
|
+
if (letters === "ep" && /^[ep]*$/i.test(rest)) rest = "";
|
|
4948
|
+
return rest === "" ? null : rest;
|
|
4949
|
+
}
|
|
4950
|
+
function inlineExecCall(stmt, pipeFed) {
|
|
3900
4951
|
const cmd = stmt?.Cmd;
|
|
3901
|
-
if (!cmd || syntax.NodeType(cmd) !== "CallExpr") return
|
|
4952
|
+
if (!cmd || syntax.NodeType(cmd) !== "CallExpr") return null;
|
|
3902
4953
|
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
3903
|
-
if (words.length === 0) return
|
|
4954
|
+
if (words.length === 0) return null;
|
|
3904
4955
|
const headIdx = unwrapCommandHead(words);
|
|
3905
4956
|
const rawHead = words[headIdx];
|
|
3906
|
-
if (rawHead == null) return
|
|
4957
|
+
if (rawHead == null) return null;
|
|
3907
4958
|
const interp = (rawHead.split("/").pop() ?? "").toLowerCase();
|
|
3908
|
-
if (!INLINE_INTERPRETER.test(interp)) return
|
|
4959
|
+
if (!INLINE_INTERPRETER.test(interp)) return null;
|
|
3909
4960
|
let args = words.slice(headIdx + 1);
|
|
3910
|
-
if (interp === "deno" && (args[0] ?? "").toLowerCase() === "eval")
|
|
4961
|
+
if (interp === "deno" && (args[0] ?? "").toLowerCase() === "eval") {
|
|
4962
|
+
const code = args[1] ?? null;
|
|
4963
|
+
return { interp, code: [code], source: code === null ? "variable" : void 0 };
|
|
4964
|
+
}
|
|
3911
4965
|
if (INTERP_LEADING_TARGET.has(interp)) {
|
|
3912
4966
|
const firstFlag = args.findIndex((a) => a == null || a.startsWith("-"));
|
|
3913
4967
|
args = firstFlag >= 0 ? args.slice(firstFlag) : [];
|
|
3914
4968
|
}
|
|
4969
|
+
const redirs = stmt.Redirs || cmd.Redirs || [];
|
|
4970
|
+
const stdinFed = redirs.some((r) => r && redirStdinOps().has(r.Op));
|
|
4971
|
+
const fromStdin = () => {
|
|
4972
|
+
if (stdinFed) {
|
|
4973
|
+
const { code, source } = stdinCodeOf(redirs);
|
|
4974
|
+
return { interp, code: [code], source };
|
|
4975
|
+
}
|
|
4976
|
+
return { interp, code: [null], source: "pipe" };
|
|
4977
|
+
};
|
|
3915
4978
|
let positionals2 = 0;
|
|
3916
4979
|
let selectedProgram = false;
|
|
4980
|
+
const codes = [];
|
|
3917
4981
|
for (let i = 0; i < args.length; i++) {
|
|
3918
4982
|
const a = args[i];
|
|
3919
4983
|
if (a == null) {
|
|
4984
|
+
if (codes.length > 0) break;
|
|
3920
4985
|
positionals2++;
|
|
3921
4986
|
selectedProgram = true;
|
|
3922
4987
|
continue;
|
|
3923
4988
|
}
|
|
3924
4989
|
if (!selectedProgram && isInlineCodeFlag(interp, a)) {
|
|
3925
|
-
if (
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
4990
|
+
if (/^(bash|sh|zsh|dash|ksh)$/.test(interp)) {
|
|
4991
|
+
const payload = args[i + 1];
|
|
4992
|
+
if (payload == null) return { interp, code: [null], source: "variable" };
|
|
4993
|
+
return shellPayloadNeedsReview(payload) ? { interp, code: [null], source: "payload" } : null;
|
|
4994
|
+
}
|
|
4995
|
+
const attached = attachedCode(interp, a);
|
|
4996
|
+
if (attached !== null) {
|
|
4997
|
+
codes.push(attached);
|
|
4998
|
+
} else {
|
|
4999
|
+
codes.push(args[i + 1] ?? null);
|
|
5000
|
+
i++;
|
|
5001
|
+
}
|
|
5002
|
+
continue;
|
|
5003
|
+
}
|
|
5004
|
+
if (codes.length > 0) {
|
|
5005
|
+
if (a.startsWith("-")) continue;
|
|
5006
|
+
break;
|
|
3929
5007
|
}
|
|
3930
5008
|
if (a === "-m") {
|
|
3931
5009
|
selectedProgram = true;
|
|
3932
5010
|
continue;
|
|
3933
5011
|
}
|
|
3934
|
-
if (a === "-" && !selectedProgram) return
|
|
5012
|
+
if (a === "-" && !selectedProgram) return fromStdin();
|
|
3935
5013
|
if (!a.startsWith("-")) {
|
|
3936
5014
|
positionals2++;
|
|
3937
5015
|
selectedProgram = true;
|
|
3938
5016
|
}
|
|
3939
5017
|
}
|
|
3940
|
-
|
|
3941
|
-
|
|
5018
|
+
if (codes.length > 0) {
|
|
5019
|
+
return { interp, code: codes, source: codes.includes(null) ? "variable" : void 0 };
|
|
5020
|
+
}
|
|
3942
5021
|
if (positionals2 === 0 && (stdinFed || pipeFed)) {
|
|
3943
|
-
if (!/^(bash|sh|zsh)$/i.test(interp)) return
|
|
5022
|
+
if (!/^(bash|sh|zsh)$/i.test(interp)) return fromStdin();
|
|
3944
5023
|
}
|
|
3945
|
-
return
|
|
5024
|
+
return null;
|
|
3946
5025
|
}
|
|
3947
5026
|
var MAX_PAYLOAD_NESTING = 8;
|
|
3948
5027
|
var payloadNesting = 0;
|
|
@@ -3977,7 +5056,7 @@ function shellPayloadNeedsReview(payload) {
|
|
|
3977
5056
|
payload
|
|
3978
5057
|
))
|
|
3979
5058
|
review = true;
|
|
3980
|
-
if (!review &&
|
|
5059
|
+
if (!review && inlineExecReview(payload) !== null) review = true;
|
|
3981
5060
|
} catch {
|
|
3982
5061
|
review = true;
|
|
3983
5062
|
} finally {
|
|
@@ -3985,35 +5064,85 @@ function shellPayloadNeedsReview(payload) {
|
|
|
3985
5064
|
}
|
|
3986
5065
|
return review;
|
|
3987
5066
|
}
|
|
3988
|
-
|
|
5067
|
+
var MAX_INLINE_CALLS = 16;
|
|
5068
|
+
function inlineExecCalls(command) {
|
|
3989
5069
|
const f = parseShared(command);
|
|
3990
|
-
if (f === PARSE_FAIL)
|
|
3991
|
-
|
|
3992
|
-
command
|
|
3993
|
-
);
|
|
3994
|
-
}
|
|
3995
|
-
let found = false;
|
|
5070
|
+
if (f === PARSE_FAIL) return PARSE_FAIL;
|
|
5071
|
+
const calls = [];
|
|
3996
5072
|
try {
|
|
3997
5073
|
syntax.Walk(f, (node) => {
|
|
3998
|
-
if (!node ||
|
|
5074
|
+
if (!node || calls.length >= MAX_INLINE_CALLS) return false;
|
|
3999
5075
|
const n = node;
|
|
4000
5076
|
const t = syntax.NodeType(n);
|
|
4001
5077
|
if (t === "BinaryCmd" && n.Y && !listOps().has(n.Op)) {
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
return false;
|
|
4005
|
-
}
|
|
5078
|
+
const call = inlineExecCall(n.Y, true);
|
|
5079
|
+
if (call) calls.push(call);
|
|
4006
5080
|
}
|
|
4007
|
-
if (t === "Stmt"
|
|
4008
|
-
|
|
4009
|
-
|
|
5081
|
+
if (t === "Stmt") {
|
|
5082
|
+
const call = inlineExecCall(n, false);
|
|
5083
|
+
if (call) calls.push(call);
|
|
4010
5084
|
}
|
|
4011
5085
|
return true;
|
|
4012
5086
|
});
|
|
4013
5087
|
} catch {
|
|
4014
|
-
return found;
|
|
4015
5088
|
}
|
|
4016
|
-
return
|
|
5089
|
+
return calls;
|
|
5090
|
+
}
|
|
5091
|
+
var INLINE_EXEC_FALLBACK = /(^|[|;&]|&&)\s*(?:[\w./-]*\/)?(python[\d.]*|perl|ruby|node|php|lua|deno|bun|pwsh|osascript|rscript|bash|sh|zsh)\s+-{1,2}[a-z]*[ceEr]/i;
|
|
5092
|
+
function detectInlineExec(command) {
|
|
5093
|
+
const calls = inlineExecCalls(command);
|
|
5094
|
+
if (calls === PARSE_FAIL) return INLINE_EXEC_FALLBACK.test(command);
|
|
5095
|
+
return calls.length > 0;
|
|
5096
|
+
}
|
|
5097
|
+
var UNREADABLE_SOURCE = {
|
|
5098
|
+
pipe: "reads its code from another program through a pipe",
|
|
5099
|
+
file: "reads its code from a file on stdin",
|
|
5100
|
+
variable: "runs code the shell fills in at run time",
|
|
5101
|
+
payload: "runs a shell payload that evaluates, sources or runs further code"
|
|
5102
|
+
};
|
|
5103
|
+
function isProtectedCodePath(p) {
|
|
5104
|
+
if (matchSensitivePath(p) !== null) return true;
|
|
5105
|
+
return SYSTEM_AUTH_FILES.includes(p) || SYSTEM_AUTH_DIRS.some((d) => p === d || p.startsWith(d + "/"));
|
|
5106
|
+
}
|
|
5107
|
+
function inlineExecDescription(r) {
|
|
5108
|
+
const lead = r ? `The AI is running code directly from the command line: ${inlineExecReason(r).replace(/^This/, "this")}.` : "The AI is running code directly from the command line.";
|
|
5109
|
+
return `${lead} Review the full script below before allowing it to execute.`;
|
|
5110
|
+
}
|
|
5111
|
+
function inlineExecReason(r) {
|
|
5112
|
+
const who = r.interp ? `This inline ${r.interp} code` : "This inline code";
|
|
5113
|
+
return r.evidence ? `${who} ${r.what} (${r.evidence})` : `${who} ${r.what}`;
|
|
5114
|
+
}
|
|
5115
|
+
function inlineExecReview(command) {
|
|
5116
|
+
const calls = inlineExecCalls(command);
|
|
5117
|
+
if (calls === PARSE_FAIL) {
|
|
5118
|
+
return INLINE_EXEC_FALLBACK.test(command) ? { outcome: "unreadable", interp: "", what: "could not be parsed" } : null;
|
|
5119
|
+
}
|
|
5120
|
+
let unreadable = calls.length >= MAX_INLINE_CALLS ? { outcome: "unreadable", interp: "", what: "runs more inline programs than node9 reads" } : null;
|
|
5121
|
+
for (const call of calls) {
|
|
5122
|
+
const language = inlineLanguageOf(call.interp);
|
|
5123
|
+
for (const code of call.code) {
|
|
5124
|
+
let finding = null;
|
|
5125
|
+
if (code === null) {
|
|
5126
|
+
finding = {
|
|
5127
|
+
outcome: "unreadable",
|
|
5128
|
+
interp: call.interp,
|
|
5129
|
+
what: UNREADABLE_SOURCE[call.source ?? "variable"]
|
|
5130
|
+
};
|
|
5131
|
+
} else if (language === null) {
|
|
5132
|
+
finding = {
|
|
5133
|
+
outcome: "unreadable",
|
|
5134
|
+
interp: call.interp,
|
|
5135
|
+
what: `is ${call.interp} code, which node9 does not read`
|
|
5136
|
+
};
|
|
5137
|
+
} else {
|
|
5138
|
+
const judged = judgeInlineCode(language, code, isProtectedCodePath);
|
|
5139
|
+
if (judged) finding = { ...judged, interp: call.interp };
|
|
5140
|
+
}
|
|
5141
|
+
if (finding?.outcome === "dangerous") return finding;
|
|
5142
|
+
if (finding && !unreadable) unreadable = finding;
|
|
5143
|
+
}
|
|
5144
|
+
}
|
|
5145
|
+
return unreadable;
|
|
4017
5146
|
}
|
|
4018
5147
|
function analyzeChmod777(command) {
|
|
4019
5148
|
if (!/chmod/i.test(command.replace(/[\\'"]/g, ""))) return null;
|
|
@@ -5481,46 +6610,6 @@ function analyzeShellCommand(command) {
|
|
|
5481
6610
|
return { actions, paths, allTokens };
|
|
5482
6611
|
}
|
|
5483
6612
|
|
|
5484
|
-
// src/utils/regex.ts
|
|
5485
|
-
var import_safe_regex22 = __toESM(require("safe-regex2"));
|
|
5486
|
-
var MAX_REGEX_LENGTH = 256;
|
|
5487
|
-
var REGEX_CACHE_MAX = 500;
|
|
5488
|
-
var regexCache = /* @__PURE__ */ new Map();
|
|
5489
|
-
function validateRegex(pattern) {
|
|
5490
|
-
if (!pattern) return "Pattern is required";
|
|
5491
|
-
if (pattern.length > MAX_REGEX_LENGTH) return `Pattern exceeds max length of ${MAX_REGEX_LENGTH}`;
|
|
5492
|
-
try {
|
|
5493
|
-
new RegExp(pattern);
|
|
5494
|
-
} catch (e) {
|
|
5495
|
-
return `Invalid regex syntax: ${e.message}`;
|
|
5496
|
-
}
|
|
5497
|
-
if (/\\\d+[*+{]/.test(pattern)) return "Quantified backreferences are forbidden (ReDoS risk)";
|
|
5498
|
-
if (!(0, import_safe_regex22.default)(pattern)) return "Pattern rejected: potential ReDoS vulnerability detected";
|
|
5499
|
-
return null;
|
|
5500
|
-
}
|
|
5501
|
-
function getCompiledRegex(pattern, flags = "") {
|
|
5502
|
-
if (flags && !/^[gimsuy]+$/.test(flags)) return null;
|
|
5503
|
-
const key = `${pattern}\0${flags}`;
|
|
5504
|
-
if (regexCache.has(key)) {
|
|
5505
|
-
const cached = regexCache.get(key);
|
|
5506
|
-
regexCache.delete(key);
|
|
5507
|
-
regexCache.set(key, cached);
|
|
5508
|
-
return cached;
|
|
5509
|
-
}
|
|
5510
|
-
if (validateRegex(pattern) !== null) return null;
|
|
5511
|
-
try {
|
|
5512
|
-
const re = new RegExp(pattern, flags);
|
|
5513
|
-
if (regexCache.size >= REGEX_CACHE_MAX) {
|
|
5514
|
-
const oldest = regexCache.keys().next().value;
|
|
5515
|
-
if (oldest) regexCache.delete(oldest);
|
|
5516
|
-
}
|
|
5517
|
-
regexCache.set(key, re);
|
|
5518
|
-
return re;
|
|
5519
|
-
} catch {
|
|
5520
|
-
return null;
|
|
5521
|
-
}
|
|
5522
|
-
}
|
|
5523
|
-
|
|
5524
6613
|
// src/rules/index.ts
|
|
5525
6614
|
function matchesPattern(text, patterns) {
|
|
5526
6615
|
const p = Array.isArray(patterns) ? patterns : [patterns];
|
|
@@ -5532,6 +6621,18 @@ function matchesPattern(text, patterns) {
|
|
|
5532
6621
|
const withoutDotSlash = text.replace(/^\.\//, "");
|
|
5533
6622
|
return isMatch(withoutDotSlash) || isMatch(`./${withoutDotSlash}`);
|
|
5534
6623
|
}
|
|
6624
|
+
function mcpServerFromToolName(toolName) {
|
|
6625
|
+
const match = toolName.match(/^mcp__([^_](?:[^_]|_(?!_))*?)__/i);
|
|
6626
|
+
return match?.[1];
|
|
6627
|
+
}
|
|
6628
|
+
function ruleServerMatches(rule, serverLabel) {
|
|
6629
|
+
const label = typeof serverLabel === "string" ? serverLabel.trim().replace(/[\\/]/g, "-") || void 0 : void 0;
|
|
6630
|
+
if (rule.server) {
|
|
6631
|
+
if (!label || !matchesPattern(label, rule.server)) return false;
|
|
6632
|
+
}
|
|
6633
|
+
if (rule.notServer && label && matchesPattern(label, rule.notServer)) return false;
|
|
6634
|
+
return true;
|
|
6635
|
+
}
|
|
5535
6636
|
var FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
5536
6637
|
function getNestedValue(obj, path) {
|
|
5537
6638
|
if (!obj || typeof obj !== "object") return null;
|
|
@@ -5555,23 +6656,26 @@ function evaluateSmartConditions(args, rule) {
|
|
|
5555
6656
|
return val;
|
|
5556
6657
|
};
|
|
5557
6658
|
const readingsCache = /* @__PURE__ */ new Map();
|
|
5558
|
-
const resolveFieldReadings = (field) => {
|
|
5559
|
-
const
|
|
6659
|
+
const resolveFieldReadings = (field, reading) => {
|
|
6660
|
+
const access = reading === "access" && field === "command";
|
|
6661
|
+
const key = access ? `${field}\0access` : field;
|
|
6662
|
+
const cached = readingsCache.get(key);
|
|
5560
6663
|
if (cached) return cached;
|
|
5561
6664
|
const primary = resolveField(field);
|
|
5562
6665
|
if (primary === null) {
|
|
5563
|
-
readingsCache.set(
|
|
6666
|
+
readingsCache.set(key, []);
|
|
5564
6667
|
return [];
|
|
5565
6668
|
}
|
|
5566
6669
|
let out = [primary];
|
|
5567
6670
|
if (field === "command") {
|
|
5568
6671
|
const raw = getNestedValue(args, field);
|
|
5569
6672
|
if (typeof raw === "string") {
|
|
5570
|
-
const
|
|
5571
|
-
|
|
6673
|
+
const text = access ? fileAccessView(raw) : raw;
|
|
6674
|
+
const collapsed = commandReadings(text).map((r) => r.replace(/\s+/g, " ").trim());
|
|
6675
|
+
out = access ? [...new Set(collapsed)] : [.../* @__PURE__ */ new Set([primary, ...collapsed])];
|
|
5572
6676
|
}
|
|
5573
6677
|
}
|
|
5574
|
-
readingsCache.set(
|
|
6678
|
+
readingsCache.set(key, out);
|
|
5575
6679
|
return out;
|
|
5576
6680
|
};
|
|
5577
6681
|
const results = rule.conditions.map((cond) => {
|
|
@@ -5589,14 +6693,14 @@ function evaluateSmartConditions(args, rule) {
|
|
|
5589
6693
|
if (val === null || !cond.value) return false;
|
|
5590
6694
|
const reM = getCompiledRegex(cond.value, cond.flags ?? "");
|
|
5591
6695
|
if (!reM) return false;
|
|
5592
|
-
return resolveFieldReadings(cond.field).some((v) => reM.test(v));
|
|
6696
|
+
return resolveFieldReadings(cond.field, cond.reading).some((v) => reM.test(v));
|
|
5593
6697
|
}
|
|
5594
6698
|
case "notMatches": {
|
|
5595
6699
|
if (!cond.value) return false;
|
|
5596
6700
|
if (val === null) return true;
|
|
5597
6701
|
const reN = getCompiledRegex(cond.value, cond.flags ?? "");
|
|
5598
6702
|
if (!reN) return false;
|
|
5599
|
-
return !resolveFieldReadings(cond.field).some((v) => reN.test(v));
|
|
6703
|
+
return !resolveFieldReadings(cond.field, cond.reading).some((v) => reN.test(v));
|
|
5600
6704
|
}
|
|
5601
6705
|
case "matchesGlob":
|
|
5602
6706
|
return val !== null && cond.value ? import_picomatch.default.isMatch(val, cond.value) : false;
|
|
@@ -6557,76 +7661,6 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
6557
7661
|
return out;
|
|
6558
7662
|
}
|
|
6559
7663
|
|
|
6560
|
-
// src/files/paths.ts
|
|
6561
|
-
var SYSTEM_AUTH_FILES = [
|
|
6562
|
-
"/etc/passwd",
|
|
6563
|
-
"/etc/shadow",
|
|
6564
|
-
"/etc/group",
|
|
6565
|
-
"/etc/gshadow",
|
|
6566
|
-
"/etc/sudoers"
|
|
6567
|
-
];
|
|
6568
|
-
var SYSTEM_AUTH_DIRS = ["/etc/security", "/etc/pam.d", "/etc/sudoers.d"];
|
|
6569
|
-
var PASSWORD_HASH_FILES = ["/etc/shadow", "/etc/gshadow"];
|
|
6570
|
-
var STARTUP_NAMES = [".bashrc", ".zshrc", ".profile", ".bash_profile"];
|
|
6571
|
-
var SYSTEM_DIRS = [
|
|
6572
|
-
"/usr",
|
|
6573
|
-
"/etc",
|
|
6574
|
-
"/boot",
|
|
6575
|
-
"/bin",
|
|
6576
|
-
"/sbin",
|
|
6577
|
-
"/lib",
|
|
6578
|
-
"/lib64",
|
|
6579
|
-
"/var/log"
|
|
6580
|
-
];
|
|
6581
|
-
var SYSTEM_DIRS_EXEMPT = ["/usr/local", "/usr/src"];
|
|
6582
|
-
var UPLOAD_SYSTEM_DIRS = [...SYSTEM_DIRS, "/proc", "/sys", "/root"];
|
|
6583
|
-
var AGENT_INSTRUCTION_FILES = [
|
|
6584
|
-
".gitlab-ci.yml",
|
|
6585
|
-
"CLAUDE.md",
|
|
6586
|
-
"AGENTS.md",
|
|
6587
|
-
".cursorrules",
|
|
6588
|
-
".mcp.json",
|
|
6589
|
-
".vscode/settings.json",
|
|
6590
|
-
"package.json"
|
|
6591
|
-
];
|
|
6592
|
-
var AGENT_INSTRUCTION_DIRS = [
|
|
6593
|
-
".github/workflows",
|
|
6594
|
-
".claude",
|
|
6595
|
-
".cursor",
|
|
6596
|
-
".git/hooks",
|
|
6597
|
-
".husky"
|
|
6598
|
-
];
|
|
6599
|
-
function isAgentInstructionPath(absPath, root) {
|
|
6600
|
-
const r = root.replace(/\/$/, "");
|
|
6601
|
-
if (!(absPath === r || absPath.startsWith(r + "/"))) return false;
|
|
6602
|
-
const rel = absPath.slice(r.length + 1);
|
|
6603
|
-
if (AGENT_INSTRUCTION_FILES.includes(rel)) return true;
|
|
6604
|
-
return AGENT_INSTRUCTION_DIRS.some((d) => rel === d || rel.startsWith(d + "/"));
|
|
6605
|
-
}
|
|
6606
|
-
function isInside(root, p) {
|
|
6607
|
-
const r = root.replace(/\/$/, "") || "/";
|
|
6608
|
-
return p === r || p.startsWith(r === "/" ? "/" : r + "/");
|
|
6609
|
-
}
|
|
6610
|
-
var LEGACY_SYSTEM_PATH_RE = /^(?:[a-zA-Z]:)?\/etc\/(?:passwd|shadow|sudoers)$/;
|
|
6611
|
-
function isPasswordHashPath(p) {
|
|
6612
|
-
return PASSWORD_HASH_FILES.includes(p);
|
|
6613
|
-
}
|
|
6614
|
-
function isLegacySystemPath(p) {
|
|
6615
|
-
return LEGACY_SYSTEM_PATH_RE.test(p);
|
|
6616
|
-
}
|
|
6617
|
-
function normalizeFilePath(p, cwd = "", home = "~") {
|
|
6618
|
-
if (!p.startsWith("/") && !p.startsWith("~") && cwd) p = `${cwd}/${p}`;
|
|
6619
|
-
if (p === "~" || p.startsWith("~/")) p = home + p.slice(1);
|
|
6620
|
-
const rooted = p.startsWith("/");
|
|
6621
|
-
const parts = [];
|
|
6622
|
-
for (const part of p.split("/")) {
|
|
6623
|
-
if (!part || part === ".") continue;
|
|
6624
|
-
if (part === ".." && parts.length && parts.at(-1) !== "..") parts.pop();
|
|
6625
|
-
else if (part !== ".." || !rooted) parts.push(part);
|
|
6626
|
-
}
|
|
6627
|
-
return (rooted ? "/" : "") + parts.join("/");
|
|
6628
|
-
}
|
|
6629
|
-
|
|
6630
7664
|
// src/files/protected-access.ts
|
|
6631
7665
|
function incompleteFileVerdict(operation = "write") {
|
|
6632
7666
|
return {
|
|
@@ -6809,7 +7843,7 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
6809
7843
|
}
|
|
6810
7844
|
|
|
6811
7845
|
// src/dlp/index.ts
|
|
6812
|
-
var
|
|
7846
|
+
var import_safe_regex22 = __toESM(require("safe-regex2"));
|
|
6813
7847
|
|
|
6814
7848
|
// src/dlp/mnemonic.ts
|
|
6815
7849
|
var import_node_crypto = require("crypto");
|
|
@@ -10542,14 +11576,14 @@ var SENSITIVE_PATH_REGEXES = [
|
|
|
10542
11576
|
];
|
|
10543
11577
|
function assertBuiltinPatternsAreSafe() {
|
|
10544
11578
|
for (const p of DLP_PATTERNS) {
|
|
10545
|
-
if (!(0,
|
|
11579
|
+
if (!(0, import_safe_regex22.default)(p.regex.source)) {
|
|
10546
11580
|
throw new Error(
|
|
10547
11581
|
`[node9 engine] Builtin DLP pattern '${p.name}' is vulnerable to ReDoS: ${p.regex.source}`
|
|
10548
11582
|
);
|
|
10549
11583
|
}
|
|
10550
11584
|
}
|
|
10551
11585
|
for (const re of SENSITIVE_PATH_PATTERNS) {
|
|
10552
|
-
if (!(0,
|
|
11586
|
+
if (!(0, import_safe_regex22.default)(re.source)) {
|
|
10553
11587
|
throw new Error(
|
|
10554
11588
|
`[node9 engine] Builtin sensitive-path pattern is vulnerable to ReDoS: ${re.source}`
|
|
10555
11589
|
);
|
|
@@ -11991,7 +13025,11 @@ var MAP_GOVERNED = /* @__PURE__ */ new Set([
|
|
|
11991
13025
|
"commands.disk-destroy",
|
|
11992
13026
|
"commands.dangerous-word",
|
|
11993
13027
|
"commands.node9-disarm",
|
|
11994
|
-
"data.pipe-chain"
|
|
13028
|
+
"data.pipe-chain",
|
|
13029
|
+
// The general action checks (node9Firewall#390): smart rules the map governs.
|
|
13030
|
+
"actions.money",
|
|
13031
|
+
"actions.access",
|
|
13032
|
+
"actions.publish"
|
|
11995
13033
|
]);
|
|
11996
13034
|
var KNOB_GOVERNED = {
|
|
11997
13035
|
"data.secrets": ["off", "block"],
|
|
@@ -12940,11 +13978,15 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
12940
13978
|
};
|
|
12941
13979
|
const ruleCheck = (rule) => {
|
|
12942
13980
|
if (rule.verdict === "allow") return void 0;
|
|
12943
|
-
if (!rule.builtin
|
|
13981
|
+
if (!rule.builtin) return void 0;
|
|
12944
13982
|
const id = checkIdForRule(rule.name);
|
|
12945
13983
|
if (!id) return void 0;
|
|
12946
13984
|
const def = getCheck(id);
|
|
12947
13985
|
if (!def) return void 0;
|
|
13986
|
+
if (rule.pinned) {
|
|
13987
|
+
const explicit = config.policy.checks?.[id];
|
|
13988
|
+
return def.pack && config.policy.checkSources?.[id] === "workspace" && isVerdict(explicit) ? { id, value: explicit } : void 0;
|
|
13989
|
+
}
|
|
12948
13990
|
if (rule.name?.startsWith("shield:") && !def.pack) return void 0;
|
|
12949
13991
|
if (def.pack) {
|
|
12950
13992
|
const explicit = config.policy.checks?.[id];
|
|
@@ -12952,8 +13994,10 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
12952
13994
|
}
|
|
12953
13995
|
return { id, value: cv(id) };
|
|
12954
13996
|
};
|
|
13997
|
+
const serverLabel = context.mcpServer ?? mcpServerFromToolName(toolName);
|
|
12955
13998
|
const matches = config.policy.smartRules.filter((rule) => {
|
|
12956
13999
|
if (!toolMatchesRule(toolName, rule.tool, layers)) return false;
|
|
14000
|
+
if (!ruleServerMatches(rule, serverLabel)) return false;
|
|
12957
14001
|
if (astSuppressed(rule)) return false;
|
|
12958
14002
|
if (rmCleanupWaiver && rule.name === "review-rm" && rule.verdict === "review") return false;
|
|
12959
14003
|
if (!evaluateSmartConditions(shellRuleArgs(toolName, args, rule.tool, layers), rule))
|
|
@@ -13030,11 +14074,13 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
13030
14074
|
if (v?.logged) noteLogged(v);
|
|
13031
14075
|
else if (v) candidates.push(v);
|
|
13032
14076
|
};
|
|
13033
|
-
|
|
14077
|
+
const inline = config.settings.mode === "strict" ? detectInlineExec(shellCommand) ? void 0 : null : inlineExecReview(shellCommand);
|
|
14078
|
+
if (inline !== null) {
|
|
13034
14079
|
consider("commands.inline-exec", {
|
|
13035
14080
|
decision: "review",
|
|
13036
14081
|
blockedByLabel: "Node9 Standard (Inline Execution)",
|
|
13037
|
-
|
|
14082
|
+
...inline ? { reason: inlineExecReason(inline) } : {},
|
|
14083
|
+
ruleDescription: inlineExecDescription(inline),
|
|
13038
14084
|
tier: 3,
|
|
13039
14085
|
checkId: "commands.inline-exec"
|
|
13040
14086
|
});
|
|
@@ -14249,6 +15295,74 @@ function safeMessage(value, max = 300) {
|
|
|
14249
15295
|
return s.length > max ? s.slice(0, max - 1) + "\u2026" : s;
|
|
14250
15296
|
}
|
|
14251
15297
|
|
|
15298
|
+
// src/suggest.ts
|
|
15299
|
+
function unwrapRuleLabel(label) {
|
|
15300
|
+
return ruleNameInLabel(label.trim()) ?? label.trim();
|
|
15301
|
+
}
|
|
15302
|
+
var SHIELD_RULE = /^shield:([a-z0-9-]+):((?:review|block)-[a-z0-9-]+)$/;
|
|
15303
|
+
var ACTION_RULE = /^review-action-(money|access|publish)-/;
|
|
15304
|
+
function packRowOf(ruleName, shield) {
|
|
15305
|
+
const id = checkIdForRule(ruleName);
|
|
15306
|
+
const def = id ? CHECK_BY_ID.get(id) : void 0;
|
|
15307
|
+
return def?.pack === shield && def.legacy?.includes(ruleName) ? id : void 0;
|
|
15308
|
+
}
|
|
15309
|
+
function suggestFromApprovals(rows, opts = {}) {
|
|
15310
|
+
const minApprovals = opts.minApprovals ?? 3;
|
|
15311
|
+
const minSessions = opts.minSessions ?? 2;
|
|
15312
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
15313
|
+
for (const r of rows) {
|
|
15314
|
+
const ruleName = unwrapRuleLabel(r.ruleName);
|
|
15315
|
+
const action = ACTION_RULE.exec(ruleName);
|
|
15316
|
+
if (action && checkIdForRule(ruleName) !== `actions.${action[1]}`) continue;
|
|
15317
|
+
if (action && !r.server) continue;
|
|
15318
|
+
const key = action ? `server:${r.server.toLowerCase()}:${action[1]}` : `rule:${ruleName}`;
|
|
15319
|
+
const isAction = action !== null;
|
|
15320
|
+
const acc = byKey.get(key) ?? {
|
|
15321
|
+
ruleName,
|
|
15322
|
+
server: isAction ? r.server : void 0,
|
|
15323
|
+
approvals: 0,
|
|
15324
|
+
sessions: /* @__PURE__ */ new Set(),
|
|
15325
|
+
denied: false
|
|
15326
|
+
};
|
|
15327
|
+
if (r.decision === "denied") acc.denied = true;
|
|
15328
|
+
else {
|
|
15329
|
+
acc.approvals += 1;
|
|
15330
|
+
if (r.sessionId) acc.sessions.add(r.sessionId);
|
|
15331
|
+
}
|
|
15332
|
+
byKey.set(key, acc);
|
|
15333
|
+
}
|
|
15334
|
+
const out = [];
|
|
15335
|
+
for (const acc of byKey.values()) {
|
|
15336
|
+
if (acc.denied || acc.approvals < minApprovals || acc.sessions.size < minSessions) continue;
|
|
15337
|
+
const shieldRule = SHIELD_RULE.exec(acc.ruleName);
|
|
15338
|
+
if (shieldRule) {
|
|
15339
|
+
const checkId = packRowOf(acc.ruleName, shieldRule[1]);
|
|
15340
|
+
if (!checkId) continue;
|
|
15341
|
+
out.push({
|
|
15342
|
+
kind: "quiet-rule",
|
|
15343
|
+
ruleName: acc.ruleName,
|
|
15344
|
+
shield: shieldRule[1],
|
|
15345
|
+
rule: shieldRule[2],
|
|
15346
|
+
checkId,
|
|
15347
|
+
approvals: acc.approvals,
|
|
15348
|
+
sessions: acc.sessions.size
|
|
15349
|
+
});
|
|
15350
|
+
continue;
|
|
15351
|
+
}
|
|
15352
|
+
const action = ACTION_RULE.exec(acc.ruleName);
|
|
15353
|
+
if (action && acc.server) {
|
|
15354
|
+
out.push({
|
|
15355
|
+
kind: "link-server",
|
|
15356
|
+
server: acc.server,
|
|
15357
|
+
checkId: `actions.${action[1]}`,
|
|
15358
|
+
approvals: acc.approvals,
|
|
15359
|
+
sessions: acc.sessions.size
|
|
15360
|
+
});
|
|
15361
|
+
}
|
|
15362
|
+
}
|
|
15363
|
+
return out.sort((a, b) => b.approvals - a.approvals);
|
|
15364
|
+
}
|
|
15365
|
+
|
|
14252
15366
|
// src/loop/index.ts
|
|
14253
15367
|
var import_crypto3 = __toESM(require("crypto"));
|
|
14254
15368
|
var LOOP_MAX_RECORDS = 500;
|
|
@@ -14720,8 +15834,8 @@ function matchCanaryArgs(args, values) {
|
|
|
14720
15834
|
|
|
14721
15835
|
// src/scan/canonical.ts
|
|
14722
15836
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
14723
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
14724
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
15837
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v30";
|
|
15838
|
+
var CANONICAL_EXTRACTOR_HASH = "d55f1f9e5bee7e41";
|
|
14725
15839
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
14726
15840
|
function extractCanonicalFindings(call, ctx) {
|
|
14727
15841
|
const out = [];
|
|
@@ -15092,9 +16206,13 @@ function* stringValues(obj, depth = 0) {
|
|
|
15092
16206
|
var ENGINE_VERSION = "1.4.0";
|
|
15093
16207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
15094
16208
|
0 && (module.exports = {
|
|
15095
|
-
|
|
16209
|
+
ACTION_CHECKS,
|
|
16210
|
+
ACTION_TEMPLATES,
|
|
15096
16211
|
AGENT_INSTRUCTION_DIRS,
|
|
15097
16212
|
AGENT_INSTRUCTION_FILES,
|
|
16213
|
+
APP_SERVER_GLOB,
|
|
16214
|
+
APP_SHIELD_NAMES,
|
|
16215
|
+
APP_SHIELD_SPECS,
|
|
15098
16216
|
ARGUMENT_SCAN_LIMITS,
|
|
15099
16217
|
AST_FS_REGEX_RULES,
|
|
15100
16218
|
BASH_TOOL_NAMES,
|
|
@@ -15121,6 +16239,7 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
15121
16239
|
FILE_TOOLS,
|
|
15122
16240
|
FLAGS_WITH_VALUES,
|
|
15123
16241
|
FS_READ_TOOLS,
|
|
16242
|
+
GENERAL_ACTION_RULES,
|
|
15124
16243
|
KNOB_GOVERNED,
|
|
15125
16244
|
LONG_OUTPUT_THRESHOLD_BYTES,
|
|
15126
16245
|
LOOP_MAX_RECORDS,
|
|
@@ -15132,6 +16251,7 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
15132
16251
|
PATTERN_VERB_NAMES,
|
|
15133
16252
|
PRIVILEGE_ESCALATION_RE,
|
|
15134
16253
|
REALTIME_PII_PATTERNS,
|
|
16254
|
+
REPLACED_SHIELDS,
|
|
15135
16255
|
SCAN_SIGNAL_WEIGHTS,
|
|
15136
16256
|
SENSITIVE_PATH_RE,
|
|
15137
16257
|
SENSITIVE_PATH_REGEXES,
|
|
@@ -15192,6 +16312,7 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
15192
16312
|
extractShellDestTokens,
|
|
15193
16313
|
extractShellDestinations,
|
|
15194
16314
|
extractToolDestinations,
|
|
16315
|
+
fileAccessView,
|
|
15195
16316
|
fileOperandFlagsOf,
|
|
15196
16317
|
fileToolOperation,
|
|
15197
16318
|
foldHomoglyphs,
|
|
@@ -15202,6 +16323,9 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
15202
16323
|
hashDestination,
|
|
15203
16324
|
hostMatches,
|
|
15204
16325
|
incompleteFileVerdict,
|
|
16326
|
+
inlineExecDescription,
|
|
16327
|
+
inlineExecReason,
|
|
16328
|
+
inlineExecReview,
|
|
15205
16329
|
inspectArgumentSecrets,
|
|
15206
16330
|
inspectionEntry,
|
|
15207
16331
|
inspectionLayers,
|
|
@@ -15232,6 +16356,7 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
15232
16356
|
matchesPattern,
|
|
15233
16357
|
matchesTrustedEntry,
|
|
15234
16358
|
matchesTrustedList,
|
|
16359
|
+
mcpServerFromToolName,
|
|
15235
16360
|
narrativeRuleLabel,
|
|
15236
16361
|
normalizeCommandForPolicy,
|
|
15237
16362
|
normalizeDestination,
|
|
@@ -15252,6 +16377,7 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
15252
16377
|
resolveCheckMap,
|
|
15253
16378
|
resolvePinned,
|
|
15254
16379
|
resolveShellInput,
|
|
16380
|
+
ruleServerMatches,
|
|
15255
16381
|
safeMessage,
|
|
15256
16382
|
sampleCopyCommand,
|
|
15257
16383
|
scanArgs,
|
|
@@ -15270,6 +16396,7 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
15270
16396
|
stripControlChars,
|
|
15271
16397
|
stripInvisible,
|
|
15272
16398
|
stripTerminalEscapes,
|
|
16399
|
+
suggestFromApprovals,
|
|
15273
16400
|
summarizeBlast,
|
|
15274
16401
|
summarizeScan,
|
|
15275
16402
|
toScanFinding,
|
|
@@ -15279,6 +16406,7 @@ var ENGINE_VERSION = "1.4.0";
|
|
|
15279
16406
|
tuningFromLegacyPolicy,
|
|
15280
16407
|
tuningToLegacyPolicy,
|
|
15281
16408
|
unwrapCommandHead,
|
|
16409
|
+
unwrapRuleLabel,
|
|
15282
16410
|
validateOverrides,
|
|
15283
16411
|
validateRegex,
|
|
15284
16412
|
validateShieldDefinition
|