@node9/policy-engine 2.37.1 → 2.39.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 +203 -15
- package/dist/index.d.ts +203 -15
- package/dist/index.js +1682 -441
- package/dist/index.mjs +1656 -440
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
// src/files/protected-access.ts
|
|
2
2
|
import picomatch from "picomatch";
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/utils/regex.ts
|
|
5
5
|
import safeRegex from "safe-regex2";
|
|
6
|
+
var MAX_REGEX_LENGTH = 256;
|
|
7
|
+
var REGEX_CACHE_MAX = 500;
|
|
8
|
+
var regexCache = /* @__PURE__ */ new Map();
|
|
9
|
+
function validateRegex(pattern) {
|
|
10
|
+
if (!pattern) return "Pattern is required";
|
|
11
|
+
if (pattern.length > MAX_REGEX_LENGTH) return `Pattern exceeds max length of ${MAX_REGEX_LENGTH}`;
|
|
12
|
+
try {
|
|
13
|
+
new RegExp(pattern);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return `Invalid regex syntax: ${e.message}`;
|
|
16
|
+
}
|
|
17
|
+
if (/\\\d+[*+{]/.test(pattern)) return "Quantified backreferences are forbidden (ReDoS risk)";
|
|
18
|
+
if (!safeRegex(pattern)) return "Pattern rejected: potential ReDoS vulnerability detected";
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function getCompiledRegex(pattern, flags = "") {
|
|
22
|
+
if (flags && !/^[gimsuy]+$/.test(flags)) return null;
|
|
23
|
+
const key = `${pattern}\0${flags}`;
|
|
24
|
+
if (regexCache.has(key)) {
|
|
25
|
+
const cached = regexCache.get(key);
|
|
26
|
+
regexCache.delete(key);
|
|
27
|
+
regexCache.set(key, cached);
|
|
28
|
+
return cached;
|
|
29
|
+
}
|
|
30
|
+
if (validateRegex(pattern) !== null) return null;
|
|
31
|
+
try {
|
|
32
|
+
const re = new RegExp(pattern, flags);
|
|
33
|
+
if (regexCache.size >= REGEX_CACHE_MAX) {
|
|
34
|
+
const oldest = regexCache.keys().next().value;
|
|
35
|
+
if (oldest) regexCache.delete(oldest);
|
|
36
|
+
}
|
|
37
|
+
regexCache.set(key, re);
|
|
38
|
+
return re;
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
6
43
|
|
|
7
44
|
// src/shields/builtin/aws.json
|
|
8
45
|
var aws_default = {
|
|
@@ -313,79 +350,6 @@ var filesystem_default = {
|
|
|
313
350
|
dangerousWords: ["wipefs"]
|
|
314
351
|
};
|
|
315
352
|
|
|
316
|
-
// src/shields/builtin/finance.json
|
|
317
|
-
var finance_default = {
|
|
318
|
-
name: "finance",
|
|
319
|
-
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.",
|
|
320
|
-
aliases: ["payments", "money"],
|
|
321
|
-
smartRules: [
|
|
322
|
-
{
|
|
323
|
-
name: "shield:finance:review-refund",
|
|
324
|
-
tool: "{,mcp__*__}{create_refund,refund_payment,refund_charge,refund_order,issue_refund}",
|
|
325
|
-
conditions: [],
|
|
326
|
-
verdict: "review",
|
|
327
|
-
reason: "A refund returns money to a customer. node9 asks before money moves, whatever the request said (Finance shield)."
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
name: "shield:finance:review-payout",
|
|
331
|
-
tool: "{,mcp__*__}{create_payout,send_payout,payout,create_payouts_batch}",
|
|
332
|
-
conditions: [],
|
|
333
|
-
verdict: "review",
|
|
334
|
-
reason: "A payout moves the balance to a bank account. node9 asks before money moves (Finance shield)."
|
|
335
|
-
},
|
|
336
|
-
{
|
|
337
|
-
name: "shield:finance:review-transfer",
|
|
338
|
-
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}",
|
|
339
|
-
conditions: [],
|
|
340
|
-
verdict: "review",
|
|
341
|
-
reason: "A transfer moves money between accounts. node9 asks before money moves (Finance shield)."
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
name: "shield:finance:review-charge",
|
|
345
|
-
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}",
|
|
346
|
-
conditions: [],
|
|
347
|
-
verdict: "review",
|
|
348
|
-
reason: "This charges a card or captures a payment. node9 asks before money moves (Finance shield)."
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
name: "shield:finance:review-payment-link",
|
|
352
|
-
tool: "{,mcp__*__}{create_payment_link,create_invoice,finalize_invoice,send_invoice,pay_invoice,create_invoice_item}",
|
|
353
|
-
conditions: [],
|
|
354
|
-
verdict: "review",
|
|
355
|
-
reason: "This bills someone or creates a link that charges a card. node9 asks before money moves (Finance shield)."
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
name: "shield:finance:review-subscription",
|
|
359
|
-
tool: "{,mcp__*__}{create_subscription,cancel_subscription,update_subscription,pause_subscription,resume_subscription}",
|
|
360
|
-
conditions: [],
|
|
361
|
-
verdict: "review",
|
|
362
|
-
reason: "A subscription starts or stops recurring charges. node9 asks before money moves (Finance shield)."
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
name: "shield:finance:review-dispute",
|
|
366
|
-
tool: "{,mcp__*__}{update_dispute,accept_dispute,close_dispute}",
|
|
367
|
-
conditions: [],
|
|
368
|
-
verdict: "review",
|
|
369
|
-
reason: "This answers or concedes a chargeback. node9 asks before money moves (Finance shield)."
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
name: "shield:finance:review-card",
|
|
373
|
-
tool: "{,mcp__*__}{issue_card,create_virtual_card,create_issuing_card,update_card_limit}",
|
|
374
|
-
conditions: [],
|
|
375
|
-
verdict: "review",
|
|
376
|
-
reason: "This issues a card or changes its limit. node9 asks before money moves (Finance shield)."
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
name: "shield:finance:review-withdraw",
|
|
380
|
-
tool: "{,mcp__*__}{withdraw,withdraw_funds,create_withdrawal,request_withdrawal}",
|
|
381
|
-
conditions: [],
|
|
382
|
-
verdict: "review",
|
|
383
|
-
reason: "A withdrawal moves money out. node9 asks before money moves (Finance shield)."
|
|
384
|
-
}
|
|
385
|
-
],
|
|
386
|
-
dangerousWords: []
|
|
387
|
-
};
|
|
388
|
-
|
|
389
353
|
// src/shields/builtin/github.json
|
|
390
354
|
var github_default = {
|
|
391
355
|
name: "github",
|
|
@@ -414,58 +378,6 @@ var github_default = {
|
|
|
414
378
|
dangerousWords: []
|
|
415
379
|
};
|
|
416
380
|
|
|
417
|
-
// src/shields/builtin/identity.json
|
|
418
|
-
var identity_default = {
|
|
419
|
-
name: "identity",
|
|
420
|
-
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.",
|
|
421
|
-
aliases: ["access", "iam"],
|
|
422
|
-
smartRules: [
|
|
423
|
-
{
|
|
424
|
-
name: "shield:identity:review-password",
|
|
425
|
-
tool: "{,mcp__*__}{change_password,update_password,reset_password,set_password,expire_password,force_password_reset}",
|
|
426
|
-
conditions: [],
|
|
427
|
-
verdict: "review",
|
|
428
|
-
reason: "This changes or resets a password. node9 asks before credentials change, whatever the request said (Identity shield)."
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
name: "shield:identity:review-key",
|
|
432
|
-
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}",
|
|
433
|
-
conditions: [],
|
|
434
|
-
verdict: "review",
|
|
435
|
-
reason: "This creates or rotates a key, token or secret. node9 asks before credentials change (Identity shield)."
|
|
436
|
-
},
|
|
437
|
-
{
|
|
438
|
-
name: "shield:identity:review-access",
|
|
439
|
-
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}",
|
|
440
|
-
conditions: [],
|
|
441
|
-
verdict: "review",
|
|
442
|
-
reason: "This grants or revokes access. node9 asks before access changes (Identity shield)."
|
|
443
|
-
},
|
|
444
|
-
{
|
|
445
|
-
name: "shield:identity:review-membership",
|
|
446
|
-
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}",
|
|
447
|
-
conditions: [],
|
|
448
|
-
verdict: "review",
|
|
449
|
-
reason: "This changes who belongs where. node9 asks before membership changes (Identity shield)."
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
name: "shield:identity:review-user",
|
|
453
|
-
tool: "{,mcp__*__}{create_user,delete_user,deactivate_user,suspend_user,activate_user,unlock_user,make_admin,promote_user,demote_user,update_user_role}",
|
|
454
|
-
conditions: [],
|
|
455
|
-
verdict: "review",
|
|
456
|
-
reason: "This creates, removes or promotes an account. node9 asks before accounts change (Identity shield)."
|
|
457
|
-
},
|
|
458
|
-
{
|
|
459
|
-
name: "shield:identity:review-mfa",
|
|
460
|
-
tool: "{,mcp__*__}{reset_mfa,reset_factors,disable_mfa,enroll_factor,deactivate_factor}",
|
|
461
|
-
conditions: [],
|
|
462
|
-
verdict: "review",
|
|
463
|
-
reason: "This changes a second factor. node9 asks before credentials change (Identity shield)."
|
|
464
|
-
}
|
|
465
|
-
],
|
|
466
|
-
dangerousWords: []
|
|
467
|
-
};
|
|
468
|
-
|
|
469
381
|
// src/shields/builtin/k8s.json
|
|
470
382
|
var k8s_default = {
|
|
471
383
|
name: "k8s",
|
|
@@ -725,7 +637,7 @@ var project_jail_default = {
|
|
|
725
637
|
{
|
|
726
638
|
field: "command",
|
|
727
639
|
op: "matches",
|
|
728
|
-
value: "(cat|less|head|tail|bat|more|open|print|nano|vim
|
|
640
|
+
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;&|>)<]|$)",
|
|
729
641
|
flags: "i"
|
|
730
642
|
}
|
|
731
643
|
],
|
|
@@ -739,7 +651,7 @@ var project_jail_default = {
|
|
|
739
651
|
{
|
|
740
652
|
field: "command",
|
|
741
653
|
op: "matches",
|
|
742
|
-
value: "(cat|less|head|tail|bat|more|open|print|nano|vim
|
|
654
|
+
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)",
|
|
743
655
|
flags: "i"
|
|
744
656
|
}
|
|
745
657
|
],
|
|
@@ -806,6 +718,212 @@ var project_jail_default = {
|
|
|
806
718
|
dangerousWords: []
|
|
807
719
|
};
|
|
808
720
|
|
|
721
|
+
// src/shields/builtin/redis.json
|
|
722
|
+
var redis_default = {
|
|
723
|
+
name: "redis",
|
|
724
|
+
description: "Protects Redis instances from destructive AI operations",
|
|
725
|
+
aliases: [],
|
|
726
|
+
_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.",
|
|
727
|
+
smartRules: [
|
|
728
|
+
{
|
|
729
|
+
name: "shield:redis:block-flushall",
|
|
730
|
+
tool: "*",
|
|
731
|
+
conditions: [
|
|
732
|
+
{
|
|
733
|
+
field: "command",
|
|
734
|
+
op: "matches",
|
|
735
|
+
value: "(redis|valkey)-cli.*\\bFLUSHALL\\b|\\bFLUSHALL\\b.*(redis|valkey)-cli|^ ?FLUSHALL\\b|\\.flushall\\s*\\(",
|
|
736
|
+
flags: "i"
|
|
737
|
+
}
|
|
738
|
+
],
|
|
739
|
+
verdict: "block",
|
|
740
|
+
reason: "FLUSHALL deletes every key in every database \u2014 blocked by Redis shield"
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
name: "shield:redis:block-flushdb",
|
|
744
|
+
tool: "*",
|
|
745
|
+
conditions: [
|
|
746
|
+
{
|
|
747
|
+
field: "command",
|
|
748
|
+
op: "matches",
|
|
749
|
+
value: "(redis|valkey)-cli.*\\bFLUSHDB\\b|\\bFLUSHDB\\b.*(redis|valkey)-cli|^ ?FLUSHDB\\b|\\.flushdb\\s*\\(",
|
|
750
|
+
flags: "i"
|
|
751
|
+
}
|
|
752
|
+
],
|
|
753
|
+
verdict: "block",
|
|
754
|
+
reason: "FLUSHDB deletes all keys in the current database \u2014 blocked by Redis shield"
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
name: "shield:redis:block-config-resetstat",
|
|
758
|
+
tool: "*",
|
|
759
|
+
conditions: [
|
|
760
|
+
{
|
|
761
|
+
field: "command",
|
|
762
|
+
op: "matches",
|
|
763
|
+
value: "(redis|valkey)-cli.*CONFIG\\s+RESETSTAT|^ ?CONFIG\\s+RESETSTAT",
|
|
764
|
+
flags: "i"
|
|
765
|
+
}
|
|
766
|
+
],
|
|
767
|
+
verdict: "block",
|
|
768
|
+
reason: "CONFIG RESETSTAT resets server statistics irreversibly \u2014 blocked by Redis shield"
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
name: "shield:redis:review-config-set",
|
|
772
|
+
tool: "*",
|
|
773
|
+
conditions: [
|
|
774
|
+
{
|
|
775
|
+
field: "command",
|
|
776
|
+
op: "matches",
|
|
777
|
+
value: "(redis|valkey)-cli.*\\bCONFIG\\s+SET\\b|\\bCONFIG\\s+SET\\b.*(redis|valkey)-cli|^ ?CONFIG\\s+SET\\b",
|
|
778
|
+
flags: "i"
|
|
779
|
+
}
|
|
780
|
+
],
|
|
781
|
+
verdict: "review",
|
|
782
|
+
reason: "CONFIG SET changes live server configuration and requires human approval (Redis shield)"
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
name: "shield:redis:review-del-wildcard",
|
|
786
|
+
tool: "*",
|
|
787
|
+
conditions: [
|
|
788
|
+
{
|
|
789
|
+
field: "command",
|
|
790
|
+
op: "matches",
|
|
791
|
+
value: "(redis|valkey)-cli.*\\bDEL\\b.*[*?\\[]|^ ?DEL\\b.*[*?\\[]|-cli.*--scan.*xargs.*del",
|
|
792
|
+
flags: "i"
|
|
793
|
+
}
|
|
794
|
+
],
|
|
795
|
+
verdict: "review",
|
|
796
|
+
reason: "Wildcard key deletion requires human approval (Redis shield)"
|
|
797
|
+
}
|
|
798
|
+
],
|
|
799
|
+
dangerousWords: ["FLUSHALL", "FLUSHDB"]
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
// src/shields/builtin/finance.json
|
|
803
|
+
var finance_default = {
|
|
804
|
+
name: "finance",
|
|
805
|
+
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.",
|
|
806
|
+
aliases: ["payments", "money"],
|
|
807
|
+
smartRules: [
|
|
808
|
+
{
|
|
809
|
+
name: "shield:finance:review-refund",
|
|
810
|
+
tool: "{,mcp__*__}{create_refund,refund_payment,refund_charge,refund_order,issue_refund}",
|
|
811
|
+
conditions: [],
|
|
812
|
+
verdict: "review",
|
|
813
|
+
reason: "A refund returns money to a customer. node9 asks before money moves, whatever the request said (Finance shield)."
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
name: "shield:finance:review-payout",
|
|
817
|
+
tool: "{,mcp__*__}{create_payout,send_payout,payout,create_payouts_batch}",
|
|
818
|
+
conditions: [],
|
|
819
|
+
verdict: "review",
|
|
820
|
+
reason: "A payout moves the balance to a bank account. node9 asks before money moves (Finance shield)."
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
name: "shield:finance:review-transfer",
|
|
824
|
+
tool: "{,mcp__*__}{transfer_create,transfer_authorization_create,create_transfer,transfer_money,transfer_funds,send_money,wire_transfer,create_wire,schedule_transaction,update_scheduled_transaction}",
|
|
825
|
+
conditions: [],
|
|
826
|
+
verdict: "review",
|
|
827
|
+
reason: "A transfer moves money between accounts. node9 asks before money moves (Finance shield)."
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
name: "shield:finance:review-charge",
|
|
831
|
+
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}",
|
|
832
|
+
conditions: [],
|
|
833
|
+
verdict: "review",
|
|
834
|
+
reason: "This charges a card or captures a payment. node9 asks before money moves (Finance shield)."
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
name: "shield:finance:review-payment-link",
|
|
838
|
+
tool: "{,mcp__*__}{create_payment_link,create_invoice,finalize_invoice,send_invoice,pay_invoice,create_invoice_item}",
|
|
839
|
+
conditions: [],
|
|
840
|
+
verdict: "review",
|
|
841
|
+
reason: "This bills someone or creates a link that charges a card. node9 asks before money moves (Finance shield)."
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
name: "shield:finance:review-subscription",
|
|
845
|
+
tool: "{,mcp__*__}{create_subscription,cancel_subscription,update_subscription,pause_subscription,resume_subscription}",
|
|
846
|
+
conditions: [],
|
|
847
|
+
verdict: "review",
|
|
848
|
+
reason: "A subscription starts or stops recurring charges. node9 asks before money moves (Finance shield)."
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
name: "shield:finance:review-dispute",
|
|
852
|
+
tool: "{,mcp__*__}{update_dispute,accept_dispute,close_dispute}",
|
|
853
|
+
conditions: [],
|
|
854
|
+
verdict: "review",
|
|
855
|
+
reason: "This answers or concedes a chargeback. node9 asks before money moves (Finance shield)."
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
name: "shield:finance:review-card",
|
|
859
|
+
tool: "{,mcp__*__}{issue_card,create_virtual_card,create_issuing_card,update_card_limit}",
|
|
860
|
+
conditions: [],
|
|
861
|
+
verdict: "review",
|
|
862
|
+
reason: "This issues a card or changes its limit. node9 asks before money moves (Finance shield)."
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
name: "shield:finance:review-withdraw",
|
|
866
|
+
tool: "{,mcp__*__}{withdraw,withdraw_funds,create_withdrawal,request_withdrawal}",
|
|
867
|
+
conditions: [],
|
|
868
|
+
verdict: "review",
|
|
869
|
+
reason: "A withdrawal moves money out. node9 asks before money moves (Finance shield)."
|
|
870
|
+
}
|
|
871
|
+
],
|
|
872
|
+
dangerousWords: []
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/shields/builtin/identity.json
|
|
876
|
+
var identity_default = {
|
|
877
|
+
name: "identity",
|
|
878
|
+
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.",
|
|
879
|
+
aliases: ["access", "iam"],
|
|
880
|
+
smartRules: [
|
|
881
|
+
{
|
|
882
|
+
name: "shield:identity:review-password",
|
|
883
|
+
tool: "{,mcp__*__}{change_password,update_password,reset_password,set_password,expire_password,force_password_reset}",
|
|
884
|
+
conditions: [],
|
|
885
|
+
verdict: "review",
|
|
886
|
+
reason: "This changes or resets a password. node9 asks before credentials change, whatever the request said (Identity shield)."
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
name: "shield:identity:review-key",
|
|
890
|
+
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}",
|
|
891
|
+
conditions: [],
|
|
892
|
+
verdict: "review",
|
|
893
|
+
reason: "This creates or rotates a key, token or secret. node9 asks before credentials change (Identity shield)."
|
|
894
|
+
},
|
|
895
|
+
{
|
|
896
|
+
name: "shield:identity:review-access",
|
|
897
|
+
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}",
|
|
898
|
+
conditions: [],
|
|
899
|
+
verdict: "review",
|
|
900
|
+
reason: "This grants or revokes access. node9 asks before access changes (Identity shield)."
|
|
901
|
+
},
|
|
902
|
+
{
|
|
903
|
+
name: "shield:identity:review-membership",
|
|
904
|
+
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}",
|
|
905
|
+
conditions: [],
|
|
906
|
+
verdict: "review",
|
|
907
|
+
reason: "This changes who belongs where. node9 asks before membership changes (Identity shield)."
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
name: "shield:identity:review-user",
|
|
911
|
+
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}",
|
|
912
|
+
conditions: [],
|
|
913
|
+
verdict: "review",
|
|
914
|
+
reason: "This creates, removes or promotes an account. node9 asks before accounts change (Identity shield)."
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
name: "shield:identity:review-mfa",
|
|
918
|
+
tool: "{,mcp__*__}{reset_mfa,reset_factors,disable_mfa,enroll_factor,deactivate_factor}",
|
|
919
|
+
conditions: [],
|
|
920
|
+
verdict: "review",
|
|
921
|
+
reason: "This changes a second factor. node9 asks before credentials change (Identity shield)."
|
|
922
|
+
}
|
|
923
|
+
],
|
|
924
|
+
dangerousWords: []
|
|
925
|
+
};
|
|
926
|
+
|
|
809
927
|
// src/shields/builtin/publishing.json
|
|
810
928
|
var publishing_default = {
|
|
811
929
|
name: "publishing",
|
|
@@ -977,85 +1095,554 @@ var publishing_default = {
|
|
|
977
1095
|
dangerousWords: []
|
|
978
1096
|
};
|
|
979
1097
|
|
|
980
|
-
// src/shields/
|
|
981
|
-
var
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1098
|
+
// src/shields/apps.ts
|
|
1099
|
+
var ACTION_TEMPLATES = {
|
|
1100
|
+
finance: finance_default.smartRules,
|
|
1101
|
+
identity: identity_default.smartRules,
|
|
1102
|
+
publishing: publishing_default.smartRules
|
|
1103
|
+
};
|
|
1104
|
+
var ACTION_CHECKS = {
|
|
1105
|
+
finance: { checkId: "actions.money", slug: "money", label: "Money check" },
|
|
1106
|
+
identity: { checkId: "actions.access", slug: "access", label: "Accounts and access check" },
|
|
1107
|
+
publishing: { checkId: "actions.publish", slug: "publish", label: "Publishing check" }
|
|
1108
|
+
};
|
|
1109
|
+
function isToolRule(rule) {
|
|
1110
|
+
return rule.tool.startsWith("{,mcp__*__}");
|
|
1111
|
+
}
|
|
1112
|
+
function actionPart(ruleName) {
|
|
1113
|
+
const m = /^shield:[^:]+:(.+)$/.exec(ruleName ?? "");
|
|
1114
|
+
return m ? m[1] : ruleName ?? "rule";
|
|
1115
|
+
}
|
|
1116
|
+
function ownReason(reason, owner) {
|
|
1117
|
+
if (!reason) return reason;
|
|
1118
|
+
return reason.replace(/\((?:Finance|Identity|Publishing) shield\)\.?$/, `(${owner}).`);
|
|
1119
|
+
}
|
|
1120
|
+
var GAP = "[^;&|]{0,200}?";
|
|
1121
|
+
var prog = (alt) => `(?:^|[^\\w-])(?:${alt})(?![\\w-])`;
|
|
1122
|
+
var httpTo = (host2) => prog("curl|wget|http|https|xh") + "[^;&|]{0,400}?" + host2;
|
|
1123
|
+
var httpWrite = (methods) => ({
|
|
1124
|
+
field: "command",
|
|
1125
|
+
op: "matches",
|
|
1126
|
+
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)`
|
|
1127
|
+
});
|
|
1128
|
+
var HTTP_WRITE = httpWrite("POST|DELETE");
|
|
1129
|
+
var HTTP_WRITE_ANY = httpWrite("POST|PUT|PATCH|DELETE");
|
|
1130
|
+
var NOT_STRIPE_TEST = {
|
|
1131
|
+
field: "command",
|
|
1132
|
+
op: "notMatches",
|
|
1133
|
+
value: "\\b[sr]k_test_"
|
|
1134
|
+
};
|
|
1135
|
+
var postTo = (host2) => `\\.post\\(\\s*["'\`][^"'\`]{0,80}${host2}`;
|
|
1136
|
+
var STRIPE_OBJECTS = "refunds|payouts|charges|transfers|payment_intents|payment_links|invoices|subscriptions|topups";
|
|
1137
|
+
var APP_SHIELD_SPECS = [
|
|
1138
|
+
{
|
|
1139
|
+
name: "stripe",
|
|
1140
|
+
label: "Stripe",
|
|
1141
|
+
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.",
|
|
1142
|
+
template: "finance",
|
|
1143
|
+
server: "*stripe*",
|
|
1144
|
+
doors: [
|
|
1145
|
+
{
|
|
1146
|
+
name: "shield:stripe:review-cli",
|
|
1147
|
+
tool: "bash",
|
|
1148
|
+
conditions: [
|
|
1149
|
+
{
|
|
1150
|
+
field: "command",
|
|
1151
|
+
op: "matches",
|
|
1152
|
+
value: prog("stripe") + GAP + `\\s(?:${STRIPE_OBJECTS})\\s+(?:create|cancel|capture|confirm|update|pay|finalize_invoice|send_invoice|void_invoice)(?![\\w-])`,
|
|
1153
|
+
flags: "i"
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
field: "command",
|
|
1157
|
+
op: "matches",
|
|
1158
|
+
// The stripe CLI works in test mode unless told otherwise.
|
|
1159
|
+
value: "\\s--live(?![\\w-])|\\b[sr]k_live_"
|
|
1160
|
+
}
|
|
1161
|
+
],
|
|
1162
|
+
conditionMode: "all",
|
|
1163
|
+
verdict: "review",
|
|
1164
|
+
reason: "The stripe CLI is about to move money. node9 asks before money moves (Stripe)."
|
|
1165
|
+
},
|
|
1166
|
+
{
|
|
1167
|
+
name: "shield:stripe:review-cli-request",
|
|
1168
|
+
tool: "bash",
|
|
1169
|
+
conditions: [
|
|
1170
|
+
{
|
|
1171
|
+
field: "command",
|
|
1172
|
+
op: "matches",
|
|
1173
|
+
value: prog("stripe") + GAP + `\\s(?:post|delete)\\s+/?v1/(?:${STRIPE_OBJECTS})(?![\\w-])`,
|
|
1174
|
+
flags: "i"
|
|
1175
|
+
},
|
|
1176
|
+
{
|
|
1177
|
+
field: "command",
|
|
1178
|
+
op: "matches",
|
|
1179
|
+
// The stripe CLI works in test mode unless told otherwise.
|
|
1180
|
+
value: "\\s--live(?![\\w-])|\\b[sr]k_live_"
|
|
1181
|
+
}
|
|
1182
|
+
],
|
|
1183
|
+
conditionMode: "all",
|
|
1184
|
+
verdict: "review",
|
|
1185
|
+
reason: "A raw stripe CLI request is about to move money. node9 asks before money moves (Stripe)."
|
|
1186
|
+
},
|
|
1187
|
+
{
|
|
1188
|
+
name: "shield:stripe:review-api",
|
|
1189
|
+
tool: "bash",
|
|
1190
|
+
conditions: [
|
|
1191
|
+
{
|
|
1192
|
+
field: "command",
|
|
1193
|
+
op: "matches",
|
|
1194
|
+
value: httpTo(`api\\.stripe\\.com/v1/(?:${STRIPE_OBJECTS})(?![\\w-])`),
|
|
1195
|
+
flags: "i"
|
|
1196
|
+
},
|
|
1197
|
+
HTTP_WRITE,
|
|
1198
|
+
NOT_STRIPE_TEST
|
|
1199
|
+
],
|
|
1200
|
+
conditionMode: "all",
|
|
1201
|
+
verdict: "review",
|
|
1202
|
+
reason: "A request to the Stripe API is about to move money. node9 asks before money moves (Stripe)."
|
|
1203
|
+
},
|
|
1204
|
+
{
|
|
1205
|
+
name: "shield:stripe:review-code",
|
|
1206
|
+
tool: "bash",
|
|
1207
|
+
conditions: [
|
|
1208
|
+
{
|
|
1209
|
+
field: "command",
|
|
1210
|
+
op: "matches",
|
|
1211
|
+
// Python: stripe.Refund.create(...)
|
|
1212
|
+
value: "\\bstripe\\.(?:Refund|Payout|Transfer|Charge|PaymentIntent|PaymentLink|Invoice|Subscription|Topup)\\.(?:create|cancel|capture|confirm|modify|pay|finalize_invoice|send_invoice|void_invoice)\\b"
|
|
1213
|
+
},
|
|
1214
|
+
NOT_STRIPE_TEST
|
|
1215
|
+
],
|
|
1216
|
+
conditionMode: "all",
|
|
1217
|
+
verdict: "review",
|
|
1218
|
+
reason: "This code moves money through the Stripe library. node9 asks before money moves (Stripe)."
|
|
1219
|
+
},
|
|
1220
|
+
{
|
|
1221
|
+
name: "shield:stripe:review-code-node",
|
|
1222
|
+
tool: "bash",
|
|
1223
|
+
conditions: [
|
|
1224
|
+
{
|
|
1225
|
+
field: "command",
|
|
1226
|
+
op: "matches",
|
|
1227
|
+
// Node: stripe.refunds.create(...)
|
|
1228
|
+
value: "\\bstripe\\.(?:refunds|payouts|transfers|charges|paymentIntents|paymentLinks|invoices|subscriptions|topups)\\.(?:create|cancel|capture|confirm|update|pay|finalizeInvoice|sendInvoice|voidInvoice)\\s*\\("
|
|
1229
|
+
},
|
|
1230
|
+
NOT_STRIPE_TEST
|
|
1231
|
+
],
|
|
1232
|
+
conditionMode: "all",
|
|
1233
|
+
verdict: "review",
|
|
1234
|
+
reason: "This code moves money through the Stripe library. node9 asks before money moves (Stripe)."
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
name: "shield:stripe:review-code-http",
|
|
1238
|
+
tool: "bash",
|
|
1239
|
+
conditions: [
|
|
1240
|
+
{
|
|
1241
|
+
field: "command",
|
|
1242
|
+
op: "matches",
|
|
1243
|
+
// requests.post("https://api.stripe.com/v1/refunds", ...)
|
|
1244
|
+
value: `\\.post\\(\\s*["'\`][^"'\`]{0,80}api\\.stripe\\.com/v1/(?:${STRIPE_OBJECTS})`
|
|
1245
|
+
},
|
|
1246
|
+
NOT_STRIPE_TEST
|
|
1247
|
+
],
|
|
1248
|
+
conditionMode: "all",
|
|
1249
|
+
verdict: "review",
|
|
1250
|
+
reason: "This code posts to the Stripe API. node9 asks before money moves (Stripe)."
|
|
1251
|
+
}
|
|
1252
|
+
]
|
|
1253
|
+
},
|
|
1254
|
+
{
|
|
1255
|
+
name: "paypal",
|
|
1256
|
+
label: "PayPal",
|
|
1257
|
+
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.",
|
|
1258
|
+
template: "finance",
|
|
1259
|
+
server: "*paypal*",
|
|
1260
|
+
doors: [
|
|
1261
|
+
{
|
|
1262
|
+
name: "shield:paypal:review-api",
|
|
1263
|
+
tool: "bash",
|
|
1264
|
+
conditions: [
|
|
1265
|
+
{
|
|
1266
|
+
field: "command",
|
|
1267
|
+
op: "matches",
|
|
1268
|
+
// The live hosts only: api.paypal.com and api-m.paypal.com. The
|
|
1269
|
+
// sandbox (api-m.sandbox.paypal.com) moves no money.
|
|
1270
|
+
value: httpTo("api(?:-m)?\\.paypal\\.com/v[12]/"),
|
|
1271
|
+
flags: "i"
|
|
1272
|
+
},
|
|
1273
|
+
{
|
|
1274
|
+
field: "command",
|
|
1275
|
+
op: "matches",
|
|
1276
|
+
// The endpoints that move money.
|
|
1277
|
+
value: "\\.paypal\\.com/v[12]/(?:payments/(?:captures|authorizations|sale|payouts|payment|referenced-payouts)|checkout/orders/[^\\s/]{1,64}/(?:capture|authorize)|invoicing/invoices|billing/subscriptions)",
|
|
1278
|
+
flags: "i"
|
|
1279
|
+
},
|
|
1280
|
+
HTTP_WRITE
|
|
1281
|
+
],
|
|
1282
|
+
conditionMode: "all",
|
|
1283
|
+
verdict: "review",
|
|
1284
|
+
reason: "A request to the PayPal API is about to move money. node9 asks before money moves (PayPal)."
|
|
1285
|
+
},
|
|
1286
|
+
{
|
|
1287
|
+
name: "shield:paypal:review-code",
|
|
1288
|
+
tool: "bash",
|
|
1289
|
+
conditions: [
|
|
1290
|
+
{
|
|
1291
|
+
field: "command",
|
|
1292
|
+
op: "matches",
|
|
1293
|
+
// The Node SDKs (checkout-server-sdk, paypal-server-sdk) and the
|
|
1294
|
+
// Python paypalrestsdk.
|
|
1295
|
+
value: "\\b(?:CapturesRefundRequest|OrdersCaptureRequest|AuthorizationsCaptureRequest|PayoutsPostRequest)\\b|\\b(?:captureOrder|refundCapturedPayment|captureAuthorizedPayment|createBatchPayout)\\s*\\(|\\bpaypalrestsdk\\.(?:Payout|Sale|Capture|Invoice|BillingAgreement)\\b"
|
|
1296
|
+
}
|
|
1297
|
+
],
|
|
1298
|
+
verdict: "review",
|
|
1299
|
+
reason: "This code moves money through PayPal. node9 asks before money moves (PayPal)."
|
|
1300
|
+
},
|
|
1301
|
+
{
|
|
1302
|
+
name: "shield:paypal:review-code-http",
|
|
1303
|
+
tool: "bash",
|
|
1304
|
+
conditions: [
|
|
1305
|
+
{
|
|
1306
|
+
field: "command",
|
|
1307
|
+
op: "matches",
|
|
1308
|
+
// The endpoints that move money; the token call every script
|
|
1309
|
+
// starts with (/v1/oauth2/token) is not one.
|
|
1310
|
+
value: postTo(
|
|
1311
|
+
"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)"
|
|
1312
|
+
)
|
|
1313
|
+
}
|
|
1314
|
+
],
|
|
1315
|
+
verdict: "review",
|
|
1316
|
+
reason: "This code posts to the PayPal API. node9 asks before money moves (PayPal)."
|
|
1317
|
+
}
|
|
1318
|
+
]
|
|
1319
|
+
},
|
|
1320
|
+
{
|
|
1321
|
+
name: "square",
|
|
1322
|
+
label: "Square",
|
|
1323
|
+
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.",
|
|
1324
|
+
template: "finance",
|
|
1325
|
+
// Square's servers, never Squarespace (a website builder).
|
|
1326
|
+
server: "{*square,*square[-_]*,*squareup*}",
|
|
1327
|
+
mcpTools: [
|
|
1328
|
+
{
|
|
1329
|
+
// Square's official MCP server has one tool for every API call; the
|
|
1330
|
+
// service and method name what it does.
|
|
1331
|
+
name: "shield:square:review-mcp-request",
|
|
1332
|
+
tool: "{,mcp__*__}make_api_request",
|
|
1333
|
+
conditions: [
|
|
1334
|
+
{
|
|
1335
|
+
field: "service",
|
|
1336
|
+
op: "matches",
|
|
1337
|
+
value: "^(?:refunds|payments|orders|invoices|subscriptions|disputes|gift_cards|gift_card_activities|checkout|terminal)$",
|
|
1338
|
+
flags: "i"
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
field: "method",
|
|
1342
|
+
op: "notMatches",
|
|
1343
|
+
value: "^(?:list|get|retrieve|search|batch_?retrieve|calculate)",
|
|
1344
|
+
flags: "i"
|
|
1345
|
+
}
|
|
1346
|
+
],
|
|
1347
|
+
conditionMode: "all",
|
|
1348
|
+
verdict: "review",
|
|
1349
|
+
reason: "A request through the Square MCP server is about to move money. node9 asks before money moves (Square)."
|
|
1350
|
+
}
|
|
1351
|
+
],
|
|
1352
|
+
doors: [
|
|
1353
|
+
{
|
|
1354
|
+
name: "shield:square:review-api",
|
|
1355
|
+
tool: "bash",
|
|
1356
|
+
conditions: [
|
|
1357
|
+
{
|
|
1358
|
+
field: "command",
|
|
1359
|
+
op: "matches",
|
|
1360
|
+
// The live host only; the sandbox is connect.squareupsandbox.com.
|
|
1361
|
+
value: httpTo(
|
|
1362
|
+
"connect\\.squareup\\.com/v2/(?:refunds|payments|orders/[^\\s/?]{1,64}/pay|invoices|subscriptions|disputes|gift-cards/activities)(?![\\w-]|/search)"
|
|
1363
|
+
),
|
|
1364
|
+
flags: "i"
|
|
1365
|
+
},
|
|
1366
|
+
HTTP_WRITE_ANY
|
|
1367
|
+
],
|
|
1368
|
+
conditionMode: "all",
|
|
1369
|
+
verdict: "review",
|
|
1370
|
+
reason: "A request to the Square API is about to move money. node9 asks before money moves (Square)."
|
|
1371
|
+
},
|
|
1372
|
+
{
|
|
1373
|
+
name: "shield:square:review-code",
|
|
1374
|
+
tool: "bash",
|
|
1375
|
+
conditions: [
|
|
1376
|
+
{
|
|
1377
|
+
field: "command",
|
|
1378
|
+
op: "matches",
|
|
1379
|
+
// The Square SDK in the script: Node (`square`) or Python (`square`, `squareup`).
|
|
1380
|
+
value: `\\bSquareClient\\b|\\bsquare\\.client\\b|from\\s+square[.\\s]|from\\s+["']square["']|require\\(\\s*["']square["']`
|
|
1381
|
+
},
|
|
1382
|
+
{
|
|
1383
|
+
field: "command",
|
|
1384
|
+
op: "matches",
|
|
1385
|
+
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*\\("
|
|
1386
|
+
}
|
|
1387
|
+
],
|
|
1388
|
+
conditionMode: "all",
|
|
1389
|
+
verdict: "review",
|
|
1390
|
+
reason: "This code moves money through the Square SDK. node9 asks before money moves (Square)."
|
|
1391
|
+
},
|
|
1392
|
+
{
|
|
1393
|
+
name: "shield:square:review-code-http",
|
|
1394
|
+
tool: "bash",
|
|
1395
|
+
conditions: [
|
|
1396
|
+
{
|
|
1397
|
+
field: "command",
|
|
1398
|
+
op: "matches",
|
|
1399
|
+
value: postTo(
|
|
1400
|
+
"connect\\.squareup\\.com/v2/(?:refunds|payments|orders/[^\\s/?\"'`]{1,64}/pay|invoices|subscriptions|disputes|gift-cards/activities)(?![\\w-]|/search)"
|
|
1401
|
+
)
|
|
1402
|
+
}
|
|
1403
|
+
],
|
|
1404
|
+
verdict: "review",
|
|
1405
|
+
reason: "This code posts to the Square API. node9 asks before money moves (Square)."
|
|
1406
|
+
}
|
|
1407
|
+
]
|
|
1408
|
+
},
|
|
1409
|
+
{
|
|
1410
|
+
name: "plaid",
|
|
1411
|
+
label: "Plaid",
|
|
1412
|
+
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.",
|
|
1413
|
+
template: "finance",
|
|
1414
|
+
server: "*plaid*",
|
|
1415
|
+
doors: [
|
|
1416
|
+
{
|
|
1417
|
+
name: "shield:plaid:review-api",
|
|
1418
|
+
tool: "bash",
|
|
1419
|
+
conditions: [
|
|
1420
|
+
{
|
|
1421
|
+
field: "command",
|
|
1422
|
+
op: "matches",
|
|
1423
|
+
// Every Plaid endpoint is a POST, so the path is what tells a
|
|
1424
|
+
// write; the live host only, never sandbox.plaid.com. A script
|
|
1425
|
+
// that posts to the URL meets this door too.
|
|
1426
|
+
value: httpTo(
|
|
1427
|
+
"production\\.plaid\\.com/(?:transfer/(?:create|authorization/create|recurring/create)|payment_initiation/payment/create|bank_transfer/create)(?![\\w-])"
|
|
1428
|
+
),
|
|
1429
|
+
flags: "i"
|
|
1430
|
+
}
|
|
1431
|
+
],
|
|
1432
|
+
verdict: "review",
|
|
1433
|
+
reason: "A request to the Plaid API is about to move money. node9 asks before money moves (Plaid)."
|
|
1434
|
+
},
|
|
1435
|
+
{
|
|
1436
|
+
name: "shield:plaid:review-code",
|
|
1437
|
+
tool: "bash",
|
|
1438
|
+
conditions: [
|
|
1439
|
+
{ field: "command", op: "matches", value: "\\bplaid", flags: "i" },
|
|
1440
|
+
{
|
|
1441
|
+
field: "command",
|
|
1442
|
+
op: "matches",
|
|
1443
|
+
value: "\\b(?:transfer(?:Authorization|Recurring)?Create|paymentInitiationPaymentCreate|bankTransferCreate|transfer_(?:authorization_|recurring_)?create|payment_initiation_payment_create|bank_transfer_create)\\s*\\("
|
|
1444
|
+
}
|
|
1445
|
+
],
|
|
1446
|
+
conditionMode: "all",
|
|
1447
|
+
verdict: "review",
|
|
1448
|
+
reason: "This code moves money through Plaid. node9 asks before money moves (Plaid)."
|
|
1449
|
+
}
|
|
1450
|
+
]
|
|
1451
|
+
},
|
|
1452
|
+
{
|
|
1453
|
+
name: "okta",
|
|
1454
|
+
label: "Okta",
|
|
1455
|
+
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.",
|
|
1456
|
+
template: "identity",
|
|
1457
|
+
server: "*okta*",
|
|
1458
|
+
doors: [
|
|
1459
|
+
{
|
|
1460
|
+
name: "shield:okta:review-api",
|
|
1461
|
+
tool: "bash",
|
|
1462
|
+
conditions: [
|
|
1463
|
+
{
|
|
1464
|
+
field: "command",
|
|
1465
|
+
op: "matches",
|
|
1466
|
+
// The management API only: sign-in (/api/v1/authn, /sessions,
|
|
1467
|
+
// /oauth2) is not under these paths.
|
|
1468
|
+
value: httpTo(
|
|
1469
|
+
"[\\w-]+\\.okta(?:-emea)?\\.com/api/v1/(?:users|groups|apps|iam|api-tokens|idps|authorizationServers|policies)(?![\\w-])"
|
|
1470
|
+
),
|
|
1471
|
+
flags: "i"
|
|
1472
|
+
},
|
|
1473
|
+
HTTP_WRITE_ANY
|
|
1474
|
+
],
|
|
1475
|
+
conditionMode: "all",
|
|
1476
|
+
verdict: "review",
|
|
1477
|
+
reason: "A request to the Okta API is about to change who has access. node9 asks before access changes (Okta)."
|
|
1478
|
+
},
|
|
1479
|
+
{
|
|
1480
|
+
name: "shield:okta:review-code",
|
|
1481
|
+
tool: "bash",
|
|
1482
|
+
conditions: [
|
|
1483
|
+
{
|
|
1484
|
+
field: "command",
|
|
1485
|
+
op: "matches",
|
|
1486
|
+
// The Okta SDK in the script: a method named createUser alone is
|
|
1487
|
+
// in half the applications ever written.
|
|
1488
|
+
value: "@okta/okta-sdk|\\bokta\\.Client\\b|from\\s+okta[.\\s]|\\bimport\\s+okta\\b"
|
|
1489
|
+
},
|
|
1490
|
+
{
|
|
1491
|
+
field: "command",
|
|
1492
|
+
op: "matches",
|
|
1493
|
+
value: "\\b(?:(?:create|delete|deactivate|suspend|unlock|activate)User|(?:reset|expire)Password|resetFactors|(?:assign|unassign)User(?:To|From)Group|assignRoleTo(?:User|Group))\\s*\\("
|
|
1494
|
+
}
|
|
1495
|
+
],
|
|
1496
|
+
conditionMode: "all",
|
|
1497
|
+
verdict: "review",
|
|
1498
|
+
reason: "This code changes who has access in Okta. node9 asks before access changes (Okta)."
|
|
1499
|
+
},
|
|
1500
|
+
{
|
|
1501
|
+
name: "shield:okta:review-code-py",
|
|
1502
|
+
tool: "bash",
|
|
1503
|
+
conditions: [
|
|
1504
|
+
{
|
|
1505
|
+
field: "command",
|
|
1506
|
+
op: "matches",
|
|
1507
|
+
value: "@okta/okta-sdk|\\bokta\\.Client\\b|from\\s+okta[.\\s]|\\bimport\\s+okta\\b"
|
|
1508
|
+
},
|
|
1509
|
+
{
|
|
1510
|
+
field: "command",
|
|
1511
|
+
op: "matches",
|
|
1512
|
+
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*\\("
|
|
1513
|
+
}
|
|
1514
|
+
],
|
|
1515
|
+
conditionMode: "all",
|
|
1516
|
+
verdict: "review",
|
|
1517
|
+
reason: "This code changes who has access in Okta. node9 asks before access changes (Okta)."
|
|
1518
|
+
}
|
|
1519
|
+
]
|
|
1520
|
+
},
|
|
1521
|
+
{
|
|
1522
|
+
name: "auth0",
|
|
1523
|
+
label: "Auth0",
|
|
1524
|
+
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.",
|
|
1525
|
+
template: "identity",
|
|
1526
|
+
server: "*auth0*",
|
|
1527
|
+
mcpTools: [
|
|
1528
|
+
{
|
|
1529
|
+
// Auth0's official MCP server: applications (their secrets and
|
|
1530
|
+
// callbacks), APIs and their scopes, and Actions (code that runs at
|
|
1531
|
+
// every sign-in).
|
|
1532
|
+
name: "shield:auth0:review-tenant-config",
|
|
1533
|
+
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}",
|
|
1534
|
+
conditions: [],
|
|
1535
|
+
verdict: "review",
|
|
1536
|
+
reason: "This changes an Auth0 application, API or sign-in Action. node9 asks before access changes (Auth0)."
|
|
1537
|
+
}
|
|
1538
|
+
],
|
|
1539
|
+
doors: [
|
|
1540
|
+
{
|
|
1541
|
+
name: "shield:auth0:review-cli",
|
|
1542
|
+
tool: "bash",
|
|
1543
|
+
conditions: [
|
|
1544
|
+
{
|
|
1545
|
+
field: "command",
|
|
1546
|
+
op: "matches",
|
|
1547
|
+
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-])",
|
|
1548
|
+
flags: "i"
|
|
1549
|
+
}
|
|
1550
|
+
],
|
|
1551
|
+
verdict: "review",
|
|
1552
|
+
reason: "The auth0 CLI is about to change who has access. node9 asks before access changes (Auth0)."
|
|
1553
|
+
},
|
|
1554
|
+
{
|
|
1555
|
+
name: "shield:auth0:review-api",
|
|
1556
|
+
tool: "bash",
|
|
1557
|
+
conditions: [
|
|
1558
|
+
{
|
|
1559
|
+
field: "command",
|
|
1560
|
+
op: "matches",
|
|
1561
|
+
// The Management API only; /oauth/token is signing in.
|
|
1562
|
+
value: httpTo(
|
|
1563
|
+
"\\.auth0\\.com/api/v2/(?:users|roles|clients|grants|client-grants|organizations|tickets|jobs/users-imports|device-credentials)(?![\\w-])"
|
|
1564
|
+
),
|
|
1565
|
+
flags: "i"
|
|
1566
|
+
},
|
|
1567
|
+
HTTP_WRITE_ANY
|
|
1568
|
+
],
|
|
1569
|
+
conditionMode: "all",
|
|
1570
|
+
verdict: "review",
|
|
1571
|
+
reason: "A request to the Auth0 Management API is about to change who has access. node9 asks before access changes (Auth0)."
|
|
1572
|
+
},
|
|
1573
|
+
{
|
|
1574
|
+
name: "shield:auth0:review-code",
|
|
1575
|
+
tool: "bash",
|
|
1576
|
+
conditions: [
|
|
1577
|
+
{
|
|
1578
|
+
field: "command",
|
|
1579
|
+
op: "matches",
|
|
1580
|
+
// The Auth0 SDK in the script (Node `auth0`, Python `auth0`).
|
|
1581
|
+
value: `\\bManagementClient\\b|from\\s+auth0[.\\s]|from\\s+["']auth0["']|require\\(\\s*["']auth0["']`
|
|
1582
|
+
},
|
|
1583
|
+
{
|
|
1584
|
+
field: "command",
|
|
1585
|
+
op: "matches",
|
|
1586
|
+
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*\\("
|
|
1587
|
+
}
|
|
1588
|
+
],
|
|
1589
|
+
conditionMode: "all",
|
|
1590
|
+
verdict: "review",
|
|
1591
|
+
reason: "This code changes who has access in Auth0. node9 asks before access changes (Auth0)."
|
|
1592
|
+
}
|
|
1593
|
+
]
|
|
1594
|
+
}
|
|
1595
|
+
];
|
|
1596
|
+
function buildAppShield(spec) {
|
|
1597
|
+
const owner = spec.label;
|
|
1598
|
+
const toolRules = ACTION_TEMPLATES[spec.template].filter(isToolRule).map((rule) => ({
|
|
1599
|
+
...rule,
|
|
1600
|
+
name: `shield:${spec.name}:${actionPart(rule.name)}`,
|
|
1601
|
+
server: spec.server,
|
|
1602
|
+
reason: ownReason(rule.reason, owner)
|
|
1603
|
+
}));
|
|
1604
|
+
const ownTools = (spec.mcpTools ?? []).map((rule) => ({
|
|
1605
|
+
...rule,
|
|
1606
|
+
server: spec.server
|
|
1607
|
+
}));
|
|
1608
|
+
return {
|
|
1609
|
+
name: spec.name,
|
|
1610
|
+
description: spec.description,
|
|
1611
|
+
aliases: [],
|
|
1612
|
+
smartRules: [...toolRules, ...ownTools, ...spec.doors],
|
|
1613
|
+
dangerousWords: []
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
var APP_SHIELDS = APP_SHIELD_SPECS.map(buildAppShield);
|
|
1617
|
+
var APP_SHIELD_NAMES = new Set(APP_SHIELD_SPECS.map((s) => s.name));
|
|
1618
|
+
var APP_SERVER_GLOB = `{${APP_SHIELD_SPECS.map((s) => s.server).join(",")}}`;
|
|
1619
|
+
function buildGeneralRules() {
|
|
1620
|
+
const out = [];
|
|
1621
|
+
for (const name of Object.keys(ACTION_TEMPLATES)) {
|
|
1622
|
+
const { slug, label } = ACTION_CHECKS[name];
|
|
1623
|
+
for (const rule of ACTION_TEMPLATES[name].filter(isToolRule)) {
|
|
1624
|
+
const part = actionPart(rule.name).replace(/^review-/, "");
|
|
1625
|
+
out.push({
|
|
1626
|
+
...rule,
|
|
1627
|
+
name: `review-action-${slug}-${part}`,
|
|
1628
|
+
notServer: APP_SERVER_GLOB,
|
|
1629
|
+
reason: ownReason(rule.reason, label)
|
|
1630
|
+
});
|
|
1056
1631
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1632
|
+
}
|
|
1633
|
+
return out;
|
|
1634
|
+
}
|
|
1635
|
+
var GENERAL_ACTION_RULES = buildGeneralRules();
|
|
1636
|
+
function generalActionRuleNames(template) {
|
|
1637
|
+
const { slug } = ACTION_CHECKS[template];
|
|
1638
|
+
return GENERAL_ACTION_RULES.filter((r) => r.name?.startsWith(`review-action-${slug}-`)).map(
|
|
1639
|
+
(r) => r.name
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
var REPLACED_SHIELDS = {
|
|
1643
|
+
finance: "finance is now the Money check (actions.money), on by default. For an app: node9 shield enable stripe (or paypal).",
|
|
1644
|
+
identity: "identity is now the Accounts and access check (actions.access), on by default.",
|
|
1645
|
+
publishing: "publishing is now the Publishing check (actions.publish), on by default."
|
|
1059
1646
|
};
|
|
1060
1647
|
|
|
1061
1648
|
// src/shields/index.ts
|
|
@@ -1100,36 +1687,36 @@ var BUILTIN_SHIELDS = {
|
|
|
1100
1687
|
[bash_safe_default.name]: bash_safe_default,
|
|
1101
1688
|
[docker_default.name]: docker_default,
|
|
1102
1689
|
[filesystem_default.name]: filesystem_default,
|
|
1103
|
-
// Dangerous actions as category shields (node9Firewall#385): an MCP app's
|
|
1104
|
-
// money, credential and publishing tools, asked about whatever the request
|
|
1105
|
-
// said. One glob per rule covers the bare name the gateway sends and the
|
|
1106
|
-
// mcp__<server>__ name the agent hook sends.
|
|
1107
|
-
[finance_default.name]: finance_default,
|
|
1108
1690
|
[github_default.name]: github_default,
|
|
1109
|
-
[identity_default.name]: identity_default,
|
|
1110
1691
|
[k8s_default.name]: k8s_default,
|
|
1111
1692
|
[mongodb_default.name]: mongodb_default,
|
|
1112
1693
|
[postgres_default.name]: postgres_default,
|
|
1113
1694
|
[project_jail_default.name]: project_jail_default,
|
|
1114
|
-
[
|
|
1115
|
-
|
|
1695
|
+
[redis_default.name]: redis_default,
|
|
1696
|
+
// App shields generated from the action templates (node9Firewall#390): one
|
|
1697
|
+
// per app, every door (MCP server, CLI, API, library), off by default.
|
|
1698
|
+
...Object.fromEntries(APP_SHIELDS.map((s) => [s.name, s]))
|
|
1116
1699
|
};
|
|
1117
|
-
var ACTION_SHIELD_NAMES = /* @__PURE__ */ new Set([
|
|
1118
|
-
"finance",
|
|
1119
|
-
"identity",
|
|
1120
|
-
"publishing"
|
|
1121
|
-
]);
|
|
1122
1700
|
function assertBuiltinShieldRegexesAreSafe() {
|
|
1123
|
-
|
|
1701
|
+
const sets = [
|
|
1702
|
+
...Object.values(BUILTIN_SHIELDS).map((sh) => ({
|
|
1703
|
+
name: sh.name,
|
|
1704
|
+
smartRules: sh.smartRules
|
|
1705
|
+
})),
|
|
1706
|
+
...Object.entries(ACTION_TEMPLATES).map(([name, smartRules]) => ({ name, smartRules })),
|
|
1707
|
+
{ name: "general-action-checks", smartRules: GENERAL_ACTION_RULES }
|
|
1708
|
+
];
|
|
1709
|
+
for (const shield of sets) {
|
|
1124
1710
|
for (const rule of shield.smartRules) {
|
|
1125
1711
|
const conditions = rule.conditions ?? [];
|
|
1126
1712
|
for (const cond of conditions) {
|
|
1127
1713
|
if (cond.op !== "matches" && cond.op !== "notMatches") continue;
|
|
1128
1714
|
const pattern = cond.value;
|
|
1129
1715
|
if (!pattern) continue;
|
|
1130
|
-
|
|
1716
|
+
const problem = validateRegex(pattern);
|
|
1717
|
+
if (problem) {
|
|
1131
1718
|
throw new Error(
|
|
1132
|
-
`[node9 engine] Shield '${shield.name}' rule '${rule.name ?? rule.tool}' has
|
|
1719
|
+
`[node9 engine] Shield '${shield.name}' rule '${rule.name ?? rule.tool}' has a regex the runtime refuses (${problem}): ${pattern}`
|
|
1133
1720
|
);
|
|
1134
1721
|
}
|
|
1135
1722
|
}
|
|
@@ -1423,9 +2010,9 @@ var CHECK_TEXT = {
|
|
|
1423
2010
|
},
|
|
1424
2011
|
// ── Commands ──────────────────────────────────────────────────────────────
|
|
1425
2012
|
"commands.inline-exec": {
|
|
1426
|
-
plain: "The agent runs a small program written inside the command itself.",
|
|
2013
|
+
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.",
|
|
1427
2014
|
example: `node -e "require('fs').rmSync('dist', {recursive: true})"`,
|
|
1428
|
-
advice: "
|
|
2015
|
+
advice: "Keep Review. Strict mode reviews every inline call, harmless or not; Log or Off only if inline code never reaches anything that matters."
|
|
1429
2016
|
},
|
|
1430
2017
|
"commands.eval-dynamic": {
|
|
1431
2018
|
plain: "The agent runs code whose content is built at run time, so node9 cannot read it in advance.",
|
|
@@ -1457,6 +2044,21 @@ var CHECK_TEXT = {
|
|
|
1457
2044
|
example: "chmod 777 deploy.sh",
|
|
1458
2045
|
advice: "Keep Review. A narrower permission (755, 644) almost always does the job."
|
|
1459
2046
|
},
|
|
2047
|
+
"actions.money": {
|
|
2048
|
+
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.",
|
|
2049
|
+
example: "refund_order on a server called acme-billing",
|
|
2050
|
+
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."
|
|
2051
|
+
},
|
|
2052
|
+
"actions.access": {
|
|
2053
|
+
plain: "The agent changes a password, a key, a role or who belongs to a team, through an app node9 has no protection for.",
|
|
2054
|
+
example: "invite_user or grant_role on a company admin server",
|
|
2055
|
+
advice: "Keep Review. Set Log on a sandbox workspace where agents manage test users all day."
|
|
2056
|
+
},
|
|
2057
|
+
"actions.publish": {
|
|
2058
|
+
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.",
|
|
2059
|
+
example: "create_release or deploy_to_production on a company MCP server",
|
|
2060
|
+
advice: "Keep Review. Set Log on a release machine whose pipeline publishes on purpose, never on a developer laptop."
|
|
2061
|
+
},
|
|
1460
2062
|
"commands.sudo": {
|
|
1461
2063
|
plain: "The agent runs a command as the administrator (root).",
|
|
1462
2064
|
example: "sudo apt-get install -y nginx",
|
|
@@ -1617,12 +2219,86 @@ var CHECK_TEXT = {
|
|
|
1617
2219
|
advice: "Fixed at Block. A person accepts the change on the machine (node9 mcp pin update)."
|
|
1618
2220
|
},
|
|
1619
2221
|
"loading.malicious-package": {
|
|
1620
|
-
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.",
|
|
2222
|
+
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.",
|
|
1621
2223
|
example: "npm install of a package flagged as malware",
|
|
1622
2224
|
advice: "Keep Block for known-malicious packages; brand-new packages already stop for Review."
|
|
1623
2225
|
}
|
|
1624
2226
|
};
|
|
1625
2227
|
|
|
2228
|
+
// src/levels.ts
|
|
2229
|
+
var LEVELS = ["audit", "soft", "standard", "strict", "block-all"];
|
|
2230
|
+
var MODE_VALUES = ["observe", ...LEVELS];
|
|
2231
|
+
function isModeValue(v) {
|
|
2232
|
+
return typeof v === "string" && MODE_VALUES.includes(v);
|
|
2233
|
+
}
|
|
2234
|
+
function levelOf(mode) {
|
|
2235
|
+
if (mode === "observe") return "audit";
|
|
2236
|
+
return LEVELS.includes(mode ?? "") ? mode : "standard";
|
|
2237
|
+
}
|
|
2238
|
+
function isRecordOnly(mode) {
|
|
2239
|
+
return levelOf(mode) === "audit";
|
|
2240
|
+
}
|
|
2241
|
+
function reviewsEveryInline(mode) {
|
|
2242
|
+
const level = levelOf(mode);
|
|
2243
|
+
return level === "strict" || level === "block-all";
|
|
2244
|
+
}
|
|
2245
|
+
function isBlockAll(mode) {
|
|
2246
|
+
return levelOf(mode) === "block-all";
|
|
2247
|
+
}
|
|
2248
|
+
var SOFT = {
|
|
2249
|
+
"commands.inline-exec": "log",
|
|
2250
|
+
"commands.eval-dynamic": "log",
|
|
2251
|
+
"commands.rm": "log",
|
|
2252
|
+
"commands.chmod": "log",
|
|
2253
|
+
"commands.sudo": "log",
|
|
2254
|
+
"commands.git-destructive": "log",
|
|
2255
|
+
"commands.sql-ddl": "log",
|
|
2256
|
+
"commands.sql-no-where": "log",
|
|
2257
|
+
"commands.temp-binary": "log",
|
|
2258
|
+
"commands.disk-destroy": "log",
|
|
2259
|
+
"commands.dangerous-word": "log",
|
|
2260
|
+
"files.system-dirs": "log",
|
|
2261
|
+
"files.shell-startup": "log",
|
|
2262
|
+
"files.password-hashes": "log",
|
|
2263
|
+
"data.pipe-chain": "log",
|
|
2264
|
+
"behavior.untrusted-content": "log"
|
|
2265
|
+
};
|
|
2266
|
+
var STRICT = {
|
|
2267
|
+
"commands.sql-ddl": "block",
|
|
2268
|
+
"commands.disk-destroy": "block",
|
|
2269
|
+
"commands.node9-disarm": "block",
|
|
2270
|
+
"files.system-dirs": "block",
|
|
2271
|
+
"files.shell-startup": "block",
|
|
2272
|
+
"files.password-hashes": "block",
|
|
2273
|
+
"data.secrets-weak": "block",
|
|
2274
|
+
"data.pipe-chain": "block",
|
|
2275
|
+
"network.unknown-host": "review",
|
|
2276
|
+
"network.internal-addresses": "block",
|
|
2277
|
+
"behavior.prompt-injection": "log",
|
|
2278
|
+
"loading.skill-tamper": "block"
|
|
2279
|
+
};
|
|
2280
|
+
var BLOCK_ALL = {
|
|
2281
|
+
...STRICT,
|
|
2282
|
+
"commands.unknown": "review",
|
|
2283
|
+
"commands.temp-binary": "block"
|
|
2284
|
+
};
|
|
2285
|
+
var LEVEL_CHECKS = {
|
|
2286
|
+
audit: {},
|
|
2287
|
+
soft: SOFT,
|
|
2288
|
+
standard: {},
|
|
2289
|
+
strict: STRICT,
|
|
2290
|
+
"block-all": BLOCK_ALL
|
|
2291
|
+
};
|
|
2292
|
+
function levelCheckValue(mode, id) {
|
|
2293
|
+
return LEVEL_CHECKS[levelOf(mode)][id];
|
|
2294
|
+
}
|
|
2295
|
+
function levelChecks(mode) {
|
|
2296
|
+
return LEVEL_CHECKS[levelOf(mode)];
|
|
2297
|
+
}
|
|
2298
|
+
function levelPackageSignals(mode) {
|
|
2299
|
+
return levelOf(mode) === "soft" ? { newPackage: "off", installScript: "off" } : void 0;
|
|
2300
|
+
}
|
|
2301
|
+
|
|
1626
2302
|
// src/catalog.ts
|
|
1627
2303
|
var VERDICTS = ["off", "log", "review", "block"];
|
|
1628
2304
|
var CHECK_VERDICT_RANK = { off: 0, log: 1, review: 2, block: 3 };
|
|
@@ -1635,7 +2311,8 @@ var CHECK_GROUPS = [
|
|
|
1635
2311
|
{ id: "network", title: "Network" },
|
|
1636
2312
|
{ id: "files", title: "Files" },
|
|
1637
2313
|
{ id: "behavior", title: "Agent behavior" },
|
|
1638
|
-
{ id: "loading", title: "What the agent loads" }
|
|
2314
|
+
{ id: "loading", title: "What the agent loads" },
|
|
2315
|
+
{ id: "actions", title: "Actions in apps" }
|
|
1639
2316
|
];
|
|
1640
2317
|
var ALL = VERDICTS;
|
|
1641
2318
|
var BUILTIN_DANGEROUS_WORDS = ["mkfs", "shred"];
|
|
@@ -1682,7 +2359,7 @@ var PRODUCT_CHECKS = [
|
|
|
1682
2359
|
id: "commands.inline-exec",
|
|
1683
2360
|
group: "commands",
|
|
1684
2361
|
title: "Inline code execution",
|
|
1685
|
-
catches: "
|
|
2362
|
+
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",
|
|
1686
2363
|
values: ALL,
|
|
1687
2364
|
defaultValue: "review",
|
|
1688
2365
|
legacy: ["Node9 Standard (Inline Execution)"]
|
|
@@ -2039,6 +2716,38 @@ var PRODUCT_CHECKS = [
|
|
|
2039
2716
|
values: ALL,
|
|
2040
2717
|
defaultValue: "block",
|
|
2041
2718
|
legacy: ["\u{1F4E6} Node9 Package Check (Malicious)", "\u{1F4E6} Node9 Package Check (Review)"]
|
|
2719
|
+
},
|
|
2720
|
+
// ── Actions in apps (node9Firewall#390) ──────────────────────────────────
|
|
2721
|
+
// The safety net under the app shields: an action that moves money, changes
|
|
2722
|
+
// access or publishes, on an MCP server no app shield claims (an internal
|
|
2723
|
+
// billing server, a vendor with no shield, Zapier). Review by default; the
|
|
2724
|
+
// rules come from the action templates (shields/apps.ts).
|
|
2725
|
+
{
|
|
2726
|
+
id: "actions.money",
|
|
2727
|
+
group: "actions",
|
|
2728
|
+
title: "Money moves",
|
|
2729
|
+
catches: "a refund, payout, transfer, charge or withdrawal through an app with no protection of its own",
|
|
2730
|
+
values: ALL,
|
|
2731
|
+
defaultValue: "review",
|
|
2732
|
+
legacy: generalActionRuleNames("finance")
|
|
2733
|
+
},
|
|
2734
|
+
{
|
|
2735
|
+
id: "actions.access",
|
|
2736
|
+
group: "actions",
|
|
2737
|
+
title: "Accounts and access change",
|
|
2738
|
+
catches: "a password, key, role, permission or user changed through an app with no protection of its own",
|
|
2739
|
+
values: ALL,
|
|
2740
|
+
defaultValue: "review",
|
|
2741
|
+
legacy: generalActionRuleNames("identity")
|
|
2742
|
+
},
|
|
2743
|
+
{
|
|
2744
|
+
id: "actions.publish",
|
|
2745
|
+
group: "actions",
|
|
2746
|
+
title: "Something is published",
|
|
2747
|
+
catches: "a release, package, deploy or public post through an app with no protection of its own",
|
|
2748
|
+
values: ALL,
|
|
2749
|
+
defaultValue: "review",
|
|
2750
|
+
legacy: generalActionRuleNames("publishing")
|
|
2042
2751
|
}
|
|
2043
2752
|
];
|
|
2044
2753
|
var SHIELD_RULE_NAME = /^shield:([^:]+):(block|review|allow)-(.+)$/;
|
|
@@ -2100,7 +2809,7 @@ function ssrfCheckId(tier) {
|
|
|
2100
2809
|
var PROJECT_JAIL_BLOCK_READ = /^shield:project-jail:block-read-(ssh|aws|env)(-any-tool)?$/;
|
|
2101
2810
|
var OVERRIDE_PREFIX = "Override block rule:";
|
|
2102
2811
|
var LABEL_WRAPPERS = ["Smart Rule:", "Node9 (AST):", "project-jail (AST):"];
|
|
2103
|
-
function
|
|
2812
|
+
function ruleNameInLabel(s) {
|
|
2104
2813
|
let rest = s;
|
|
2105
2814
|
const override = rest.lastIndexOf(OVERRIDE_PREFIX);
|
|
2106
2815
|
if (override >= 0) rest = rest.slice(override + OVERRIDE_PREFIX.length).trimStart();
|
|
@@ -2116,7 +2825,7 @@ function checkIdForRule(nameOrLabel) {
|
|
|
2116
2825
|
const s = nameOrLabel.trim();
|
|
2117
2826
|
const exact = LEGACY_TO_ID.get(s);
|
|
2118
2827
|
if (exact) return exact;
|
|
2119
|
-
const unwrapped =
|
|
2828
|
+
const unwrapped = ruleNameInLabel(s);
|
|
2120
2829
|
if (unwrapped !== void 0) return checkIdForRule(unwrapped);
|
|
2121
2830
|
if (s.startsWith("shield:project-jail:")) {
|
|
2122
2831
|
return PROJECT_JAIL_BLOCK_READ.test(s) ? "data.credential-files" : "data.credential-files-other";
|
|
@@ -2196,7 +2905,7 @@ var LEGACY_READERS = {
|
|
|
2196
2905
|
"commands.rm": (s) => knob(s.commandChecks?.rmAdvisory),
|
|
2197
2906
|
"commands.chmod": (s) => knob(s.commandChecks?.chmod),
|
|
2198
2907
|
"commands.sql-ddl": (s) => knob(s.commandChecks?.sqlDdl),
|
|
2199
|
-
"commands.unknown": (s) => s.mode === void 0 ? void 0 : s.mode
|
|
2908
|
+
"commands.unknown": (s) => s.mode === void 0 ? void 0 : isBlockAll(s.mode) ? "review" : "off",
|
|
2200
2909
|
"data.secrets": (s) => enabledOr(s.dlp?.enabled, "block"),
|
|
2201
2910
|
"data.secrets-weak": (s) => {
|
|
2202
2911
|
if (s.dlp?.enabled === false) return "off";
|
|
@@ -2235,19 +2944,21 @@ function resolveCheck(settings, id) {
|
|
|
2235
2944
|
if (!def) return void 0;
|
|
2236
2945
|
if (isLockedCheck(def)) return { id, value: "block", source: "locked" };
|
|
2237
2946
|
const floor = def.floor ? CHECK_VERDICT_RANK[def.floor] : 0;
|
|
2947
|
+
const levelDefault = levelCheckValue(settings.mode, id) ?? def.defaultValue;
|
|
2948
|
+
const sourceOf = (value2) => value2 === levelDefault ? "default" : "configured";
|
|
2238
2949
|
const explicit = settings.checks?.[id];
|
|
2239
2950
|
if (isVerdict(explicit)) {
|
|
2240
2951
|
const value2 = CHECK_VERDICT_RANK[explicit] < floor ? def.floor : explicit;
|
|
2241
|
-
return { id, value: value2, source: value2
|
|
2952
|
+
return { id, value: value2, source: sourceOf(value2) };
|
|
2242
2953
|
}
|
|
2243
2954
|
if (def.pack) {
|
|
2244
2955
|
const on = settings.appliedShields?.includes(def.pack) ?? false;
|
|
2245
2956
|
return { id, value: on ? def.defaultValue : "off", source: "default" };
|
|
2246
2957
|
}
|
|
2247
2958
|
const read = LEGACY_READERS[id]?.(settings);
|
|
2248
|
-
if (read === void 0) return { id, value:
|
|
2959
|
+
if (read === void 0) return { id, value: levelDefault, source: "default" };
|
|
2249
2960
|
const value = CHECK_VERDICT_RANK[read] < floor ? def.floor : read;
|
|
2250
|
-
return { id, value, source: value
|
|
2961
|
+
return { id, value, source: sourceOf(value) };
|
|
2251
2962
|
}
|
|
2252
2963
|
function resolveAllChecks(settings) {
|
|
2253
2964
|
return CHECKS.map((c) => resolveCheck(settings, c.id));
|
|
@@ -2359,45 +3070,356 @@ function looksLikeText(buf) {
|
|
|
2359
3070
|
}
|
|
2360
3071
|
return printable / buf.length >= 0.9;
|
|
2361
3072
|
}
|
|
2362
|
-
var BASE64_RUN_RE = /[A-Za-z0-9+/]{32,}={0,2}|[A-Za-z0-9_-]{32,}/g;
|
|
2363
|
-
function decodeEmbeddedBase64(text) {
|
|
2364
|
-
const out = [];
|
|
2365
|
-
for (const m of text.matchAll(BASE64_RUN_RE)) {
|
|
2366
|
-
if (out.length >= MAX_BLOBS) break;
|
|
2367
|
-
const run = m[0];
|
|
2368
|
-
if (/^[0-9a-fA-F]+$/.test(run)) continue;
|
|
2369
|
-
const buf = Buffer.from(run, "base64");
|
|
2370
|
-
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3073
|
+
var BASE64_RUN_RE = /[A-Za-z0-9+/]{32,}={0,2}|[A-Za-z0-9_-]{32,}/g;
|
|
3074
|
+
function decodeEmbeddedBase64(text) {
|
|
3075
|
+
const out = [];
|
|
3076
|
+
for (const m of text.matchAll(BASE64_RUN_RE)) {
|
|
3077
|
+
if (out.length >= MAX_BLOBS) break;
|
|
3078
|
+
const run = m[0];
|
|
3079
|
+
if (/^[0-9a-fA-F]+$/.test(run)) continue;
|
|
3080
|
+
const buf = Buffer.from(run, "base64");
|
|
3081
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3082
|
+
}
|
|
3083
|
+
return out;
|
|
3084
|
+
}
|
|
3085
|
+
var HEX_RUN_RE = /\b(?:[0-9a-fA-F]{2}){24,}\b/g;
|
|
3086
|
+
var HEX_ESCAPE_RUN_RE = /(?:\\x[0-9a-fA-F]{2}){16,}/g;
|
|
3087
|
+
function decodeEmbeddedHex(text) {
|
|
3088
|
+
const out = [];
|
|
3089
|
+
for (const m of text.matchAll(HEX_RUN_RE)) {
|
|
3090
|
+
if (out.length >= MAX_BLOBS) break;
|
|
3091
|
+
const buf = Buffer.from(m[0], "hex");
|
|
3092
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3093
|
+
}
|
|
3094
|
+
for (const m of text.matchAll(HEX_ESCAPE_RUN_RE)) {
|
|
3095
|
+
if (out.length >= MAX_BLOBS) break;
|
|
3096
|
+
const buf = Buffer.from(m[0].replace(/\\x/g, ""), "hex");
|
|
3097
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3098
|
+
}
|
|
3099
|
+
return out;
|
|
3100
|
+
}
|
|
3101
|
+
function scanViews(text) {
|
|
3102
|
+
const views = [{ kind: "original", text }];
|
|
3103
|
+
const normalized = normalizeForScan(text);
|
|
3104
|
+
if (normalized !== text) views.push({ kind: "normalized", text: normalized });
|
|
3105
|
+
for (const t of decodeEmbeddedBase64(normalized)) {
|
|
3106
|
+
views.push({ kind: "base64", text: normalizeForScan(t) });
|
|
3107
|
+
}
|
|
3108
|
+
for (const t of decodeEmbeddedHex(normalized)) {
|
|
3109
|
+
views.push({ kind: "hex", text: normalizeForScan(t) });
|
|
3110
|
+
}
|
|
3111
|
+
return views;
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
// src/files/paths.ts
|
|
3115
|
+
var SYSTEM_AUTH_FILES = [
|
|
3116
|
+
"/etc/passwd",
|
|
3117
|
+
"/etc/shadow",
|
|
3118
|
+
"/etc/group",
|
|
3119
|
+
"/etc/gshadow",
|
|
3120
|
+
"/etc/sudoers"
|
|
3121
|
+
];
|
|
3122
|
+
var SYSTEM_AUTH_DIRS = ["/etc/security", "/etc/pam.d", "/etc/sudoers.d"];
|
|
3123
|
+
var PASSWORD_HASH_FILES = ["/etc/shadow", "/etc/gshadow"];
|
|
3124
|
+
var STARTUP_NAMES = [".bashrc", ".zshrc", ".profile", ".bash_profile"];
|
|
3125
|
+
var SYSTEM_DIRS = [
|
|
3126
|
+
"/usr",
|
|
3127
|
+
"/etc",
|
|
3128
|
+
"/boot",
|
|
3129
|
+
"/bin",
|
|
3130
|
+
"/sbin",
|
|
3131
|
+
"/lib",
|
|
3132
|
+
"/lib64",
|
|
3133
|
+
"/var/log"
|
|
3134
|
+
];
|
|
3135
|
+
var SYSTEM_DIRS_EXEMPT = ["/usr/local", "/usr/src"];
|
|
3136
|
+
var UPLOAD_SYSTEM_DIRS = [...SYSTEM_DIRS, "/proc", "/sys", "/root"];
|
|
3137
|
+
var AGENT_INSTRUCTION_FILES = [
|
|
3138
|
+
".gitlab-ci.yml",
|
|
3139
|
+
"CLAUDE.md",
|
|
3140
|
+
"AGENTS.md",
|
|
3141
|
+
".cursorrules",
|
|
3142
|
+
".mcp.json",
|
|
3143
|
+
".vscode/settings.json",
|
|
3144
|
+
"package.json"
|
|
3145
|
+
];
|
|
3146
|
+
var AGENT_INSTRUCTION_DIRS = [
|
|
3147
|
+
".github/workflows",
|
|
3148
|
+
".claude",
|
|
3149
|
+
".cursor",
|
|
3150
|
+
".git/hooks",
|
|
3151
|
+
".husky"
|
|
3152
|
+
];
|
|
3153
|
+
function isAgentInstructionPath(absPath, root) {
|
|
3154
|
+
const r = root.replace(/\/$/, "");
|
|
3155
|
+
if (!(absPath === r || absPath.startsWith(r + "/"))) return false;
|
|
3156
|
+
const rel = absPath.slice(r.length + 1);
|
|
3157
|
+
if (AGENT_INSTRUCTION_FILES.includes(rel)) return true;
|
|
3158
|
+
return AGENT_INSTRUCTION_DIRS.some((d) => rel === d || rel.startsWith(d + "/"));
|
|
3159
|
+
}
|
|
3160
|
+
function isInside(root, p) {
|
|
3161
|
+
const r = root.replace(/\/$/, "") || "/";
|
|
3162
|
+
return p === r || p.startsWith(r === "/" ? "/" : r + "/");
|
|
3163
|
+
}
|
|
3164
|
+
var LEGACY_SYSTEM_PATH_RE = /^(?:[a-zA-Z]:)?\/etc\/(?:passwd|shadow|sudoers)$/;
|
|
3165
|
+
function isPasswordHashPath(p) {
|
|
3166
|
+
return PASSWORD_HASH_FILES.includes(p);
|
|
3167
|
+
}
|
|
3168
|
+
function isLegacySystemPath(p) {
|
|
3169
|
+
return LEGACY_SYSTEM_PATH_RE.test(p);
|
|
3170
|
+
}
|
|
3171
|
+
function normalizeFilePath(p, cwd = "", home = "~") {
|
|
3172
|
+
if (!p.startsWith("/") && !p.startsWith("~") && cwd) p = `${cwd}/${p}`;
|
|
3173
|
+
if (p === "~" || p.startsWith("~/")) p = home + p.slice(1);
|
|
3174
|
+
const rooted = p.startsWith("/");
|
|
3175
|
+
const parts = [];
|
|
3176
|
+
for (const part of p.split("/")) {
|
|
3177
|
+
if (!part || part === ".") continue;
|
|
3178
|
+
if (part === ".." && parts.length && parts.at(-1) !== "..") parts.pop();
|
|
3179
|
+
else if (part !== ".." || !rooted) parts.push(part);
|
|
3180
|
+
}
|
|
3181
|
+
return (rooted ? "/" : "") + parts.join("/");
|
|
3182
|
+
}
|
|
3183
|
+
|
|
3184
|
+
// src/shell/inline-code.ts
|
|
3185
|
+
var MAX_INLINE_CODE = 64 * 1024;
|
|
3186
|
+
var WHAT = {
|
|
3187
|
+
deletes: "deletes files",
|
|
3188
|
+
"writes-outside": "writes a file outside the project",
|
|
3189
|
+
sends: "sends data over the network",
|
|
3190
|
+
listens: "opens a listening socket or a shell",
|
|
3191
|
+
"runs-commands": "runs other commands or processes",
|
|
3192
|
+
"reads-protected": "reads a protected file",
|
|
3193
|
+
"builds-code": "runs code it builds at run time",
|
|
3194
|
+
permissions: "changes permissions or ownership",
|
|
3195
|
+
monitors: "captures the screen, the clipboard or the keyboard",
|
|
3196
|
+
amplifies: "writes or sends in an endless loop"
|
|
3197
|
+
};
|
|
3198
|
+
var OUTSIDE = String.raw`(?:~|\.\.[\\/]|/(?!(?:tmp|var/tmp)/(?![^'"\n]*\.\.)|dev/(?:null|stdout|stderr)\b))`;
|
|
3199
|
+
var pyImport = (mods) => new RegExp(String.raw`\b(?:import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*|from\s+)(?:${mods})\b`);
|
|
3200
|
+
var either = (...res) => new RegExp(res.map((r) => `(?:${r.source})`).join("|"), "m");
|
|
3201
|
+
var PYTHON = [
|
|
3202
|
+
[
|
|
3203
|
+
"deletes",
|
|
3204
|
+
/\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/
|
|
3205
|
+
],
|
|
3206
|
+
[
|
|
3207
|
+
"writes-outside",
|
|
3208
|
+
new RegExp(
|
|
3209
|
+
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}`
|
|
3210
|
+
)
|
|
3211
|
+
],
|
|
3212
|
+
[
|
|
3213
|
+
"sends",
|
|
3214
|
+
either(
|
|
3215
|
+
pyImport(
|
|
3216
|
+
String.raw`socket|requests|urllib2|urllib3|http\.client|httplib|smtplib|ftplib|paramiko|telnetlib|aiohttp|httpx|websockets?|xmlrpc|poplib|imaplib|pycurl|scapy`
|
|
3217
|
+
),
|
|
3218
|
+
/\burllib\.request\b|\burlopen\s*\(|\bfrom\s+urllib\s+import\s+[^\n;]*\brequest\b|\basyncio\.open_connection\s*\(/
|
|
3219
|
+
)
|
|
3220
|
+
],
|
|
3221
|
+
[
|
|
3222
|
+
"listens",
|
|
3223
|
+
either(
|
|
3224
|
+
pyImport(String.raw`pty|socketserver|http\.server`),
|
|
3225
|
+
/\bpty\.spawn\s*\(|\.bind\s*\(\s*\(|\basyncio\.start_server\s*\(/
|
|
3226
|
+
)
|
|
3227
|
+
],
|
|
3228
|
+
[
|
|
3229
|
+
"runs-commands",
|
|
3230
|
+
either(
|
|
3231
|
+
pyImport("subprocess|pexpect|commands|psutil"),
|
|
3232
|
+
/\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+\*/
|
|
3233
|
+
)
|
|
3234
|
+
],
|
|
3235
|
+
[
|
|
3236
|
+
"builds-code",
|
|
3237
|
+
/(?<![\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*\[/
|
|
3238
|
+
],
|
|
3239
|
+
[
|
|
3240
|
+
// Spyware shapes: a screenshot, the clipboard, a key logger.
|
|
3241
|
+
"monitors",
|
|
3242
|
+
either(
|
|
3243
|
+
pyImport(String.raw`pyperclip|pynput|keyboard|pyautogui|pyscreenshot|mss|clipboard`),
|
|
3244
|
+
/\bImageGrab\b|\bpyautogui\.screenshot\b|\bscreencapture\b/
|
|
3245
|
+
)
|
|
3246
|
+
],
|
|
3247
|
+
[
|
|
3248
|
+
"permissions",
|
|
3249
|
+
/\bos\.(?:chmod|lchmod|fchmod|chown|lchown|fchown|setuid|setgid|seteuid|setegid|setreuid|setregid|setresuid)\s*\(|\.chmod\s*\(|\bshutil\.chown\s*\(/
|
|
3250
|
+
]
|
|
3251
|
+
];
|
|
3252
|
+
var NODE = [
|
|
3253
|
+
[
|
|
3254
|
+
"deletes",
|
|
3255
|
+
/\.(?:rm|rmSync|rmdir|rmdirSync|unlink|unlinkSync)\s*\(|\brimraf\b|\bDeno\.remove(?:Sync)?\s*\(/
|
|
3256
|
+
],
|
|
3257
|
+
[
|
|
3258
|
+
"writes-outside",
|
|
3259
|
+
new RegExp(
|
|
3260
|
+
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}`
|
|
3261
|
+
)
|
|
3262
|
+
],
|
|
3263
|
+
[
|
|
3264
|
+
"sends",
|
|
3265
|
+
/\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*\(/
|
|
3266
|
+
],
|
|
3267
|
+
["listens", /\bcreateServer\s*\(|\b(?:Deno\.(?:listen\w*|serve)|Bun\.(?:listen|serve))\s*\(/],
|
|
3268
|
+
[
|
|
3269
|
+
"runs-commands",
|
|
3270
|
+
/\bchild_process\b|\bprocess\.(?:binding|dlopen|kill)\s*\(|\bDeno\.(?:run|Command)\b|\bBun\.(?:spawn|spawnSync|\$)\b|\bexecSync\s*\(|\bspawnSync\s*\(/
|
|
3271
|
+
],
|
|
3272
|
+
[
|
|
3273
|
+
"builds-code",
|
|
3274
|
+
/(?<![\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)]/
|
|
3275
|
+
],
|
|
3276
|
+
[
|
|
3277
|
+
"permissions",
|
|
3278
|
+
/\.(?:chmod|chmodSync|chown|chownSync|lchown|lchownSync|fchmod|fchmodSync|fchown|fchownSync)\s*\(|\bprocess\.set(?:e)?[ug]id\s*\(|\bDeno\.(?:chmod|chown)(?:Sync)?\s*\(/
|
|
3279
|
+
]
|
|
3280
|
+
];
|
|
3281
|
+
var PERL = [
|
|
3282
|
+
["deletes", /\b(?:unlink|rmdir|rmtree|remove_tree)\b/],
|
|
3283
|
+
[
|
|
3284
|
+
"writes-outside",
|
|
3285
|
+
new RegExp(
|
|
3286
|
+
String.raw`['"]\s*(?:\+?>>?|\+<)\s*['"]?\s*,?\s*['"]?${OUTSIDE}|\b(?:rename|symlink|link|copy|move)\s*\(?[^;\n]*['"]${OUTSIDE}`
|
|
3287
|
+
)
|
|
3288
|
+
],
|
|
3289
|
+
[
|
|
3290
|
+
"sends",
|
|
3291
|
+
/\b(?:IO::Socket|Socket|LWP|HTTP::Tiny|Net::\w+|Mojo::UserAgent|WWW::Mechanize|IO::Socket::INET)\b/
|
|
3292
|
+
],
|
|
3293
|
+
[
|
|
3294
|
+
"runs-commands",
|
|
3295
|
+
/\b(?:system|exec|fork|kill|syscall)\b|`[^`]*`|\bqx\s*[{([/|!'"]|\bopen\s*\(?[^;\n]*(?:['"]\s*\||\|\s*['"]|['"]-\|['"])/
|
|
3296
|
+
],
|
|
3297
|
+
["builds-code", /\beval\b|\bStorable::thaw\b|\bdo\s+['"]/],
|
|
3298
|
+
["permissions", /\b(?:chmod|chown)\b/]
|
|
3299
|
+
];
|
|
3300
|
+
var RUBY = [
|
|
3301
|
+
[
|
|
3302
|
+
"deletes",
|
|
3303
|
+
/\bFile\.(?:delete|unlink)\b|\bFileUtils\.(?:rm\w*|remove\w*)\b|\bDir\.(?:rmdir|delete|unlink)\b|\.(?:rmtree|delete_all)\b/
|
|
3304
|
+
],
|
|
3305
|
+
[
|
|
3306
|
+
"writes-outside",
|
|
3307
|
+
new RegExp(
|
|
3308
|
+
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}`
|
|
3309
|
+
)
|
|
3310
|
+
],
|
|
3311
|
+
[
|
|
3312
|
+
"sends",
|
|
3313
|
+
/\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)['"]/
|
|
3314
|
+
],
|
|
3315
|
+
["listens", /\b(?:TCPServer|UNIXServer|WEBrick|PTY)\b/],
|
|
3316
|
+
[
|
|
3317
|
+
"runs-commands",
|
|
3318
|
+
/(?<![\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/
|
|
3319
|
+
],
|
|
3320
|
+
[
|
|
3321
|
+
"builds-code",
|
|
3322
|
+
/(?<![\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/
|
|
3323
|
+
],
|
|
3324
|
+
["permissions", /\b(?:File|FileUtils)\.(?:chmod|chown|lchmod|lchown)\w*\b/]
|
|
3325
|
+
];
|
|
3326
|
+
var PHP = [
|
|
3327
|
+
["deletes", /\b(?:unlink|rmdir)\s*\(/],
|
|
3328
|
+
[
|
|
3329
|
+
"writes-outside",
|
|
3330
|
+
new RegExp(
|
|
3331
|
+
String.raw`\b(?:file_put_contents|symlink|link|copy|rename|mkdir|touch)\s*\([^)\n]*['"]${OUTSIDE}|\bfopen\s*\(\s*['"]${OUTSIDE}[^'"\n]*['"]\s*,\s*['"][waxc+]`
|
|
3332
|
+
)
|
|
3333
|
+
],
|
|
3334
|
+
[
|
|
3335
|
+
"sends",
|
|
3336
|
+
/\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):/
|
|
3337
|
+
],
|
|
3338
|
+
["listens", /\b(?:stream_socket_server|socket_bind|socket_listen)\s*\(/],
|
|
3339
|
+
[
|
|
3340
|
+
"runs-commands",
|
|
3341
|
+
/\b(?:system|exec|shell_exec|passthru|proc_open|popen|pcntl_exec|pcntl_fork|posix_kill)\s*\(|`[^`]*`/
|
|
3342
|
+
],
|
|
3343
|
+
[
|
|
3344
|
+
"builds-code",
|
|
3345
|
+
/\b(?:eval|assert|create_function|unserialize|call_user_func(?:_array)?)\s*\(|\bbase64_decode\b/
|
|
3346
|
+
],
|
|
3347
|
+
["permissions", /\b(?:chmod|chown|chgrp|lchown|lchgrp)\s*\(/]
|
|
3348
|
+
];
|
|
3349
|
+
var TABLES = {
|
|
3350
|
+
python: PYTHON,
|
|
3351
|
+
node: NODE,
|
|
3352
|
+
perl: PERL,
|
|
3353
|
+
ruby: RUBY,
|
|
3354
|
+
php: PHP
|
|
3355
|
+
};
|
|
3356
|
+
function inlineLanguageOf(interp) {
|
|
3357
|
+
const i = interp.toLowerCase();
|
|
3358
|
+
if (/^python[\d.]*$/.test(i)) return "python";
|
|
3359
|
+
if (/^(?:node|tsx|ts-node|deno|bun)$/.test(i)) return "node";
|
|
3360
|
+
if (i === "perl") return "perl";
|
|
3361
|
+
if (i === "ruby" || i === "irb") return "ruby";
|
|
3362
|
+
if (i === "php") return "php";
|
|
3363
|
+
return null;
|
|
3364
|
+
}
|
|
3365
|
+
function resolvePythonAliases(code) {
|
|
3366
|
+
const aliases = [...code.matchAll(/\bimport\s+([\w.]+)\s+as\s+(\w+)/g)].slice(0, 32);
|
|
3367
|
+
let out = code;
|
|
3368
|
+
for (const [, mod, alias] of aliases) {
|
|
3369
|
+
if (alias === mod) continue;
|
|
3370
|
+
out = out.replace(new RegExp(String.raw`(?<![\w.])${alias}\b`, "g"), mod);
|
|
2371
3371
|
}
|
|
2372
3372
|
return out;
|
|
2373
3373
|
}
|
|
2374
|
-
var
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
const
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
2382
|
-
}
|
|
2383
|
-
for (const m of text.matchAll(HEX_ESCAPE_RUN_RE)) {
|
|
2384
|
-
if (out.length >= MAX_BLOBS) break;
|
|
2385
|
-
const buf = Buffer.from(m[0].replace(/\\x/g, ""), "hex");
|
|
2386
|
-
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
3374
|
+
var STRING_LITERAL = /(['"`])((?:\\.|(?!\1)[^\\\n]){1,4096})\1/g;
|
|
3375
|
+
function protectedLiteral(code, isProtected) {
|
|
3376
|
+
let n = 0;
|
|
3377
|
+
for (const m of code.matchAll(STRING_LITERAL)) {
|
|
3378
|
+
if (++n > 2048) break;
|
|
3379
|
+
const value = m[2].trim();
|
|
3380
|
+
if (value && isProtected(value)) return value;
|
|
2387
3381
|
}
|
|
2388
|
-
return
|
|
3382
|
+
return null;
|
|
2389
3383
|
}
|
|
2390
|
-
function
|
|
2391
|
-
const
|
|
2392
|
-
const
|
|
2393
|
-
if (
|
|
2394
|
-
|
|
2395
|
-
|
|
3384
|
+
function amplifies(language, code) {
|
|
3385
|
+
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*\)/;
|
|
3386
|
+
const m = loop.exec(code);
|
|
3387
|
+
if (!m) return null;
|
|
3388
|
+
const body = code.slice(m.index);
|
|
3389
|
+
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(
|
|
3390
|
+
body
|
|
3391
|
+
) ? m[0] : null;
|
|
3392
|
+
}
|
|
3393
|
+
function judgeInlineCode(language, code, isProtected) {
|
|
3394
|
+
if (code.length > MAX_INLINE_CODE) {
|
|
3395
|
+
return { outcome: "unreadable", what: "is too long for node9 to read" };
|
|
3396
|
+
}
|
|
3397
|
+
const text = language === "python" ? resolvePythonAliases(code) : code;
|
|
3398
|
+
for (const [category, re] of TABLES[language]) {
|
|
3399
|
+
const m = re.exec(text);
|
|
3400
|
+
if (!m) continue;
|
|
3401
|
+
const evidence = m[0].trim().replace(/\s+/g, " ").slice(0, 60);
|
|
3402
|
+
return {
|
|
3403
|
+
outcome: category === "builds-code" ? "unreadable" : "dangerous",
|
|
3404
|
+
what: WHAT[category],
|
|
3405
|
+
evidence,
|
|
3406
|
+
category
|
|
3407
|
+
};
|
|
2396
3408
|
}
|
|
2397
|
-
|
|
2398
|
-
|
|
3409
|
+
const path = protectedLiteral(text, isProtected);
|
|
3410
|
+
if (path) {
|
|
3411
|
+
return {
|
|
3412
|
+
outcome: "dangerous",
|
|
3413
|
+
what: WHAT["reads-protected"],
|
|
3414
|
+
evidence: path.slice(0, 60),
|
|
3415
|
+
category: "reads-protected"
|
|
3416
|
+
};
|
|
2399
3417
|
}
|
|
2400
|
-
|
|
3418
|
+
const loop = amplifies(language, text);
|
|
3419
|
+
if (loop) {
|
|
3420
|
+
return { outcome: "dangerous", what: WHAT.amplifies, evidence: loop, category: "amplifies" };
|
|
3421
|
+
}
|
|
3422
|
+
return null;
|
|
2401
3423
|
}
|
|
2402
3424
|
|
|
2403
3425
|
// src/shell/index.ts
|
|
@@ -2506,6 +3528,59 @@ function cachedNormalize(command, compute) {
|
|
|
2506
3528
|
function normalizeCommandForPolicy(command) {
|
|
2507
3529
|
return commandReadingsImpl(command).posix;
|
|
2508
3530
|
}
|
|
3531
|
+
var INTERPRETER_LINE = /^#![ \t]*[\w./+-]+(?:[ \t]+[\w./+=:-]+)*[ \t]*\r?(?=\n|$)/;
|
|
3532
|
+
function fileAccessView(command) {
|
|
3533
|
+
const hit = accessViewCache.get(command);
|
|
3534
|
+
if (hit !== void 0) return hit;
|
|
3535
|
+
const view = fileAccessViewImpl(command);
|
|
3536
|
+
if (accessViewCache.size >= ACCESS_VIEW_CACHE_MAX) {
|
|
3537
|
+
const oldest = accessViewCache.keys().next().value;
|
|
3538
|
+
if (oldest !== void 0) accessViewCache.delete(oldest);
|
|
3539
|
+
}
|
|
3540
|
+
accessViewCache.set(command, view);
|
|
3541
|
+
return view;
|
|
3542
|
+
}
|
|
3543
|
+
var PROGRAM_DIR = /^(?:\/usr(?:\/local)?|\/opt\/homebrew|\/home\/linuxbrew\/\.linuxbrew)?\/s?bin\/[^/]+$|^\/snap\/bin\/[^/]+$|^(?![/~\\]|[A-Za-z]:|.*\.\.)/;
|
|
3544
|
+
var ACCESS_VIEW_CACHE_MAX = 1e3;
|
|
3545
|
+
var accessViewCache = /* @__PURE__ */ new Map();
|
|
3546
|
+
function fileAccessViewImpl(command) {
|
|
3547
|
+
const text = command.replace(INTERPRETER_LINE, "");
|
|
3548
|
+
const f = parseShared(text);
|
|
3549
|
+
if (f === PARSE_FAIL) return text;
|
|
3550
|
+
const toCharIndex = byteOffsetToCharIndex(text);
|
|
3551
|
+
const at = (byteOffset) => toCharIndex === null ? byteOffset : toCharIndex(byteOffset);
|
|
3552
|
+
const edits = [];
|
|
3553
|
+
try {
|
|
3554
|
+
syntax.Walk(f, (node) => {
|
|
3555
|
+
if (!node) return false;
|
|
3556
|
+
const n = node;
|
|
3557
|
+
if (syntax.NodeType(n) !== "CallExpr") return true;
|
|
3558
|
+
const args = n.Args || [];
|
|
3559
|
+
const words = args.map((a) => resolveWordLiteral(a));
|
|
3560
|
+
const head = unwrapCommandHead(words);
|
|
3561
|
+
for (const i of /* @__PURE__ */ new Set([0, head])) {
|
|
3562
|
+
const word = words[i];
|
|
3563
|
+
if (i >= args.length || word === null || word === void 0 || !/[\\/]/.test(word)) {
|
|
3564
|
+
continue;
|
|
3565
|
+
}
|
|
3566
|
+
if (!PROGRAM_DIR.test(word)) continue;
|
|
3567
|
+
const name = word.split(/[\\/]/).pop() ?? "";
|
|
3568
|
+
if (!name) continue;
|
|
3569
|
+
const s = at(args[i].Pos().Offset());
|
|
3570
|
+
const e = at(args[i].End().Offset());
|
|
3571
|
+
if (s < 0 || e < 0) continue;
|
|
3572
|
+
edits.push([s, e, name]);
|
|
3573
|
+
}
|
|
3574
|
+
return true;
|
|
3575
|
+
});
|
|
3576
|
+
} catch {
|
|
3577
|
+
return text;
|
|
3578
|
+
}
|
|
3579
|
+
edits.sort((a, b) => b[0] - a[0]);
|
|
3580
|
+
let out = text;
|
|
3581
|
+
for (const [s, e, rep] of edits) out = out.slice(0, s) + rep + out.slice(e);
|
|
3582
|
+
return out;
|
|
3583
|
+
}
|
|
2509
3584
|
function commandReadings(command) {
|
|
2510
3585
|
const r = commandReadingsImpl(command);
|
|
2511
3586
|
const out = /* @__PURE__ */ new Set([r.posix, r.separator, r.folded]);
|
|
@@ -3671,53 +4746,119 @@ function unwrapCommandHead(words, stopAtFind = false, stopAtDynamic = false) {
|
|
|
3671
4746
|
}
|
|
3672
4747
|
return i;
|
|
3673
4748
|
}
|
|
3674
|
-
function
|
|
4749
|
+
function heredocText(word) {
|
|
4750
|
+
const parts = word?.Parts ?? [];
|
|
4751
|
+
let out = "";
|
|
4752
|
+
for (const p of parts) {
|
|
4753
|
+
if (syntax.NodeType(p) !== "Lit") return null;
|
|
4754
|
+
out += p.Value ?? "";
|
|
4755
|
+
}
|
|
4756
|
+
return out;
|
|
4757
|
+
}
|
|
4758
|
+
function stdinCodeOf(redirs) {
|
|
4759
|
+
const heredoc = /* @__PURE__ */ new Set([deriveRedirOp("cat <<X\nX"), deriveRedirOp("cat <<-X\nX")]);
|
|
4760
|
+
const herestring = deriveRedirOp("cat <<< x");
|
|
4761
|
+
for (const r of redirs) {
|
|
4762
|
+
if (!r || !redirStdinOps().has(r.Op)) continue;
|
|
4763
|
+
if (heredoc.has(r.Op)) {
|
|
4764
|
+
const text = heredocText(r.Hdoc);
|
|
4765
|
+
return text === null ? { code: null, source: "variable" } : { code: text };
|
|
4766
|
+
}
|
|
4767
|
+
if (r.Op === herestring) {
|
|
4768
|
+
const text = resolveWordLiteral(r.Word);
|
|
4769
|
+
return text === null ? { code: null, source: "variable" } : { code: text };
|
|
4770
|
+
}
|
|
4771
|
+
return { code: null, source: "file" };
|
|
4772
|
+
}
|
|
4773
|
+
return { code: null, source: "file" };
|
|
4774
|
+
}
|
|
4775
|
+
function attachedCode(interp, flag) {
|
|
4776
|
+
const eq = flag.indexOf("=");
|
|
4777
|
+
if (flag.startsWith("--")) return eq >= 0 ? flag.slice(eq + 1) : null;
|
|
4778
|
+
if (/^(pwsh|powershell)/.test(interp)) return null;
|
|
4779
|
+
const letters = /^(perl|ruby|lua|bun|osascript|rscript|irb)$/.test(interp) ? "e" : /^(node|tsx|ts-node)$/.test(interp) ? "ep" : interp === "php" ? "r" : "c";
|
|
4780
|
+
const body = flag.slice(1);
|
|
4781
|
+
const at = [...body].findIndex((ch) => letters.includes(ch.toLowerCase()));
|
|
4782
|
+
if (at < 0) return null;
|
|
4783
|
+
let rest = body.slice(at + 1);
|
|
4784
|
+
if (letters === "ep" && /^[ep]*$/i.test(rest)) rest = "";
|
|
4785
|
+
return rest === "" ? null : rest;
|
|
4786
|
+
}
|
|
4787
|
+
function inlineExecCall(stmt, pipeFed) {
|
|
3675
4788
|
const cmd = stmt?.Cmd;
|
|
3676
|
-
if (!cmd || syntax.NodeType(cmd) !== "CallExpr") return
|
|
4789
|
+
if (!cmd || syntax.NodeType(cmd) !== "CallExpr") return null;
|
|
3677
4790
|
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
3678
|
-
if (words.length === 0) return
|
|
4791
|
+
if (words.length === 0) return null;
|
|
3679
4792
|
const headIdx = unwrapCommandHead(words);
|
|
3680
4793
|
const rawHead = words[headIdx];
|
|
3681
|
-
if (rawHead == null) return
|
|
4794
|
+
if (rawHead == null) return null;
|
|
3682
4795
|
const interp = (rawHead.split("/").pop() ?? "").toLowerCase();
|
|
3683
|
-
if (!INLINE_INTERPRETER.test(interp)) return
|
|
4796
|
+
if (!INLINE_INTERPRETER.test(interp)) return null;
|
|
3684
4797
|
let args = words.slice(headIdx + 1);
|
|
3685
|
-
if (interp === "deno" && (args[0] ?? "").toLowerCase() === "eval")
|
|
4798
|
+
if (interp === "deno" && (args[0] ?? "").toLowerCase() === "eval") {
|
|
4799
|
+
const code = args[1] ?? null;
|
|
4800
|
+
return { interp, code: [code], source: code === null ? "variable" : void 0 };
|
|
4801
|
+
}
|
|
3686
4802
|
if (INTERP_LEADING_TARGET.has(interp)) {
|
|
3687
4803
|
const firstFlag = args.findIndex((a) => a == null || a.startsWith("-"));
|
|
3688
4804
|
args = firstFlag >= 0 ? args.slice(firstFlag) : [];
|
|
3689
4805
|
}
|
|
4806
|
+
const redirs = stmt.Redirs || cmd.Redirs || [];
|
|
4807
|
+
const stdinFed = redirs.some((r) => r && redirStdinOps().has(r.Op));
|
|
4808
|
+
const fromStdin = () => {
|
|
4809
|
+
if (stdinFed) {
|
|
4810
|
+
const { code, source } = stdinCodeOf(redirs);
|
|
4811
|
+
return { interp, code: [code], source };
|
|
4812
|
+
}
|
|
4813
|
+
return { interp, code: [null], source: "pipe" };
|
|
4814
|
+
};
|
|
3690
4815
|
let positionals2 = 0;
|
|
3691
4816
|
let selectedProgram = false;
|
|
4817
|
+
const codes = [];
|
|
3692
4818
|
for (let i = 0; i < args.length; i++) {
|
|
3693
4819
|
const a = args[i];
|
|
3694
4820
|
if (a == null) {
|
|
4821
|
+
if (codes.length > 0) break;
|
|
3695
4822
|
positionals2++;
|
|
3696
4823
|
selectedProgram = true;
|
|
3697
4824
|
continue;
|
|
3698
4825
|
}
|
|
3699
4826
|
if (!selectedProgram && isInlineCodeFlag(interp, a)) {
|
|
3700
|
-
if (
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
4827
|
+
if (/^(bash|sh|zsh|dash|ksh)$/.test(interp)) {
|
|
4828
|
+
const payload = args[i + 1];
|
|
4829
|
+
if (payload == null) return { interp, code: [null], source: "variable" };
|
|
4830
|
+
return shellPayloadNeedsReview(payload) ? { interp, code: [null], source: "payload" } : null;
|
|
4831
|
+
}
|
|
4832
|
+
const attached = attachedCode(interp, a);
|
|
4833
|
+
if (attached !== null) {
|
|
4834
|
+
codes.push(attached);
|
|
4835
|
+
} else {
|
|
4836
|
+
codes.push(args[i + 1] ?? null);
|
|
4837
|
+
i++;
|
|
4838
|
+
}
|
|
4839
|
+
continue;
|
|
4840
|
+
}
|
|
4841
|
+
if (codes.length > 0) {
|
|
4842
|
+
if (a.startsWith("-")) continue;
|
|
4843
|
+
break;
|
|
3704
4844
|
}
|
|
3705
4845
|
if (a === "-m") {
|
|
3706
4846
|
selectedProgram = true;
|
|
3707
4847
|
continue;
|
|
3708
4848
|
}
|
|
3709
|
-
if (a === "-" && !selectedProgram) return
|
|
4849
|
+
if (a === "-" && !selectedProgram) return fromStdin();
|
|
3710
4850
|
if (!a.startsWith("-")) {
|
|
3711
4851
|
positionals2++;
|
|
3712
4852
|
selectedProgram = true;
|
|
3713
4853
|
}
|
|
3714
4854
|
}
|
|
3715
|
-
|
|
3716
|
-
|
|
4855
|
+
if (codes.length > 0) {
|
|
4856
|
+
return { interp, code: codes, source: codes.includes(null) ? "variable" : void 0 };
|
|
4857
|
+
}
|
|
3717
4858
|
if (positionals2 === 0 && (stdinFed || pipeFed)) {
|
|
3718
|
-
if (!/^(bash|sh|zsh)$/i.test(interp)) return
|
|
4859
|
+
if (!/^(bash|sh|zsh)$/i.test(interp)) return fromStdin();
|
|
3719
4860
|
}
|
|
3720
|
-
return
|
|
4861
|
+
return null;
|
|
3721
4862
|
}
|
|
3722
4863
|
var MAX_PAYLOAD_NESTING = 8;
|
|
3723
4864
|
var payloadNesting = 0;
|
|
@@ -3752,7 +4893,7 @@ function shellPayloadNeedsReview(payload) {
|
|
|
3752
4893
|
payload
|
|
3753
4894
|
))
|
|
3754
4895
|
review = true;
|
|
3755
|
-
if (!review &&
|
|
4896
|
+
if (!review && inlineExecReview(payload) !== null) review = true;
|
|
3756
4897
|
} catch {
|
|
3757
4898
|
review = true;
|
|
3758
4899
|
} finally {
|
|
@@ -3760,35 +4901,85 @@ function shellPayloadNeedsReview(payload) {
|
|
|
3760
4901
|
}
|
|
3761
4902
|
return review;
|
|
3762
4903
|
}
|
|
3763
|
-
|
|
4904
|
+
var MAX_INLINE_CALLS = 16;
|
|
4905
|
+
function inlineExecCalls(command) {
|
|
3764
4906
|
const f = parseShared(command);
|
|
3765
|
-
if (f === PARSE_FAIL)
|
|
3766
|
-
|
|
3767
|
-
command
|
|
3768
|
-
);
|
|
3769
|
-
}
|
|
3770
|
-
let found = false;
|
|
4907
|
+
if (f === PARSE_FAIL) return PARSE_FAIL;
|
|
4908
|
+
const calls = [];
|
|
3771
4909
|
try {
|
|
3772
4910
|
syntax.Walk(f, (node) => {
|
|
3773
|
-
if (!node ||
|
|
4911
|
+
if (!node || calls.length >= MAX_INLINE_CALLS) return false;
|
|
3774
4912
|
const n = node;
|
|
3775
4913
|
const t = syntax.NodeType(n);
|
|
3776
4914
|
if (t === "BinaryCmd" && n.Y && !listOps().has(n.Op)) {
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
return false;
|
|
3780
|
-
}
|
|
4915
|
+
const call = inlineExecCall(n.Y, true);
|
|
4916
|
+
if (call) calls.push(call);
|
|
3781
4917
|
}
|
|
3782
|
-
if (t === "Stmt"
|
|
3783
|
-
|
|
3784
|
-
|
|
4918
|
+
if (t === "Stmt") {
|
|
4919
|
+
const call = inlineExecCall(n, false);
|
|
4920
|
+
if (call) calls.push(call);
|
|
3785
4921
|
}
|
|
3786
4922
|
return true;
|
|
3787
4923
|
});
|
|
3788
4924
|
} catch {
|
|
3789
|
-
return found;
|
|
3790
4925
|
}
|
|
3791
|
-
return
|
|
4926
|
+
return calls;
|
|
4927
|
+
}
|
|
4928
|
+
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;
|
|
4929
|
+
function detectInlineExec(command) {
|
|
4930
|
+
const calls = inlineExecCalls(command);
|
|
4931
|
+
if (calls === PARSE_FAIL) return INLINE_EXEC_FALLBACK.test(command);
|
|
4932
|
+
return calls.length > 0;
|
|
4933
|
+
}
|
|
4934
|
+
var UNREADABLE_SOURCE = {
|
|
4935
|
+
pipe: "reads its code from another program through a pipe",
|
|
4936
|
+
file: "reads its code from a file on stdin",
|
|
4937
|
+
variable: "runs code the shell fills in at run time",
|
|
4938
|
+
payload: "runs a shell payload that evaluates, sources or runs further code"
|
|
4939
|
+
};
|
|
4940
|
+
function isProtectedCodePath(p) {
|
|
4941
|
+
if (matchSensitivePath(p) !== null) return true;
|
|
4942
|
+
return SYSTEM_AUTH_FILES.includes(p) || SYSTEM_AUTH_DIRS.some((d) => p === d || p.startsWith(d + "/"));
|
|
4943
|
+
}
|
|
4944
|
+
function inlineExecDescription(r) {
|
|
4945
|
+
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.";
|
|
4946
|
+
return `${lead} Review the full script below before allowing it to execute.`;
|
|
4947
|
+
}
|
|
4948
|
+
function inlineExecReason(r) {
|
|
4949
|
+
const who = r.interp ? `This inline ${r.interp} code` : "This inline code";
|
|
4950
|
+
return r.evidence ? `${who} ${r.what} (${r.evidence})` : `${who} ${r.what}`;
|
|
4951
|
+
}
|
|
4952
|
+
function inlineExecReview(command) {
|
|
4953
|
+
const calls = inlineExecCalls(command);
|
|
4954
|
+
if (calls === PARSE_FAIL) {
|
|
4955
|
+
return INLINE_EXEC_FALLBACK.test(command) ? { outcome: "unreadable", interp: "", what: "could not be parsed" } : null;
|
|
4956
|
+
}
|
|
4957
|
+
let unreadable = calls.length >= MAX_INLINE_CALLS ? { outcome: "unreadable", interp: "", what: "runs more inline programs than node9 reads" } : null;
|
|
4958
|
+
for (const call of calls) {
|
|
4959
|
+
const language = inlineLanguageOf(call.interp);
|
|
4960
|
+
for (const code of call.code) {
|
|
4961
|
+
let finding = null;
|
|
4962
|
+
if (code === null) {
|
|
4963
|
+
finding = {
|
|
4964
|
+
outcome: "unreadable",
|
|
4965
|
+
interp: call.interp,
|
|
4966
|
+
what: UNREADABLE_SOURCE[call.source ?? "variable"]
|
|
4967
|
+
};
|
|
4968
|
+
} else if (language === null) {
|
|
4969
|
+
finding = {
|
|
4970
|
+
outcome: "unreadable",
|
|
4971
|
+
interp: call.interp,
|
|
4972
|
+
what: `is ${call.interp} code, which node9 does not read`
|
|
4973
|
+
};
|
|
4974
|
+
} else {
|
|
4975
|
+
const judged = judgeInlineCode(language, code, isProtectedCodePath);
|
|
4976
|
+
if (judged) finding = { ...judged, interp: call.interp };
|
|
4977
|
+
}
|
|
4978
|
+
if (finding?.outcome === "dangerous") return finding;
|
|
4979
|
+
if (finding && !unreadable) unreadable = finding;
|
|
4980
|
+
}
|
|
4981
|
+
}
|
|
4982
|
+
return unreadable;
|
|
3792
4983
|
}
|
|
3793
4984
|
function analyzeChmod777(command) {
|
|
3794
4985
|
if (!/chmod/i.test(command.replace(/[\\'"]/g, ""))) return null;
|
|
@@ -5256,46 +6447,6 @@ function analyzeShellCommand(command) {
|
|
|
5256
6447
|
return { actions, paths, allTokens };
|
|
5257
6448
|
}
|
|
5258
6449
|
|
|
5259
|
-
// src/utils/regex.ts
|
|
5260
|
-
import safeRegex2 from "safe-regex2";
|
|
5261
|
-
var MAX_REGEX_LENGTH = 256;
|
|
5262
|
-
var REGEX_CACHE_MAX = 500;
|
|
5263
|
-
var regexCache = /* @__PURE__ */ new Map();
|
|
5264
|
-
function validateRegex(pattern) {
|
|
5265
|
-
if (!pattern) return "Pattern is required";
|
|
5266
|
-
if (pattern.length > MAX_REGEX_LENGTH) return `Pattern exceeds max length of ${MAX_REGEX_LENGTH}`;
|
|
5267
|
-
try {
|
|
5268
|
-
new RegExp(pattern);
|
|
5269
|
-
} catch (e) {
|
|
5270
|
-
return `Invalid regex syntax: ${e.message}`;
|
|
5271
|
-
}
|
|
5272
|
-
if (/\\\d+[*+{]/.test(pattern)) return "Quantified backreferences are forbidden (ReDoS risk)";
|
|
5273
|
-
if (!safeRegex2(pattern)) return "Pattern rejected: potential ReDoS vulnerability detected";
|
|
5274
|
-
return null;
|
|
5275
|
-
}
|
|
5276
|
-
function getCompiledRegex(pattern, flags = "") {
|
|
5277
|
-
if (flags && !/^[gimsuy]+$/.test(flags)) return null;
|
|
5278
|
-
const key = `${pattern}\0${flags}`;
|
|
5279
|
-
if (regexCache.has(key)) {
|
|
5280
|
-
const cached = regexCache.get(key);
|
|
5281
|
-
regexCache.delete(key);
|
|
5282
|
-
regexCache.set(key, cached);
|
|
5283
|
-
return cached;
|
|
5284
|
-
}
|
|
5285
|
-
if (validateRegex(pattern) !== null) return null;
|
|
5286
|
-
try {
|
|
5287
|
-
const re = new RegExp(pattern, flags);
|
|
5288
|
-
if (regexCache.size >= REGEX_CACHE_MAX) {
|
|
5289
|
-
const oldest = regexCache.keys().next().value;
|
|
5290
|
-
if (oldest) regexCache.delete(oldest);
|
|
5291
|
-
}
|
|
5292
|
-
regexCache.set(key, re);
|
|
5293
|
-
return re;
|
|
5294
|
-
} catch {
|
|
5295
|
-
return null;
|
|
5296
|
-
}
|
|
5297
|
-
}
|
|
5298
|
-
|
|
5299
6450
|
// src/rules/index.ts
|
|
5300
6451
|
function matchesPattern(text, patterns) {
|
|
5301
6452
|
const p = Array.isArray(patterns) ? patterns : [patterns];
|
|
@@ -5307,6 +6458,18 @@ function matchesPattern(text, patterns) {
|
|
|
5307
6458
|
const withoutDotSlash = text.replace(/^\.\//, "");
|
|
5308
6459
|
return isMatch(withoutDotSlash) || isMatch(`./${withoutDotSlash}`);
|
|
5309
6460
|
}
|
|
6461
|
+
function mcpServerFromToolName(toolName) {
|
|
6462
|
+
const match = toolName.match(/^mcp__([^_](?:[^_]|_(?!_))*?)__/i);
|
|
6463
|
+
return match?.[1];
|
|
6464
|
+
}
|
|
6465
|
+
function ruleServerMatches(rule, serverLabel) {
|
|
6466
|
+
const label = typeof serverLabel === "string" ? serverLabel.trim().replace(/[\\/]/g, "-") || void 0 : void 0;
|
|
6467
|
+
if (rule.server) {
|
|
6468
|
+
if (!label || !matchesPattern(label, rule.server)) return false;
|
|
6469
|
+
}
|
|
6470
|
+
if (rule.notServer && label && matchesPattern(label, rule.notServer)) return false;
|
|
6471
|
+
return true;
|
|
6472
|
+
}
|
|
5310
6473
|
var FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
5311
6474
|
function getNestedValue(obj, path) {
|
|
5312
6475
|
if (!obj || typeof obj !== "object") return null;
|
|
@@ -5330,23 +6493,26 @@ function evaluateSmartConditions(args, rule) {
|
|
|
5330
6493
|
return val;
|
|
5331
6494
|
};
|
|
5332
6495
|
const readingsCache = /* @__PURE__ */ new Map();
|
|
5333
|
-
const resolveFieldReadings = (field) => {
|
|
5334
|
-
const
|
|
6496
|
+
const resolveFieldReadings = (field, reading) => {
|
|
6497
|
+
const access = reading === "access" && field === "command";
|
|
6498
|
+
const key = access ? `${field}\0access` : field;
|
|
6499
|
+
const cached = readingsCache.get(key);
|
|
5335
6500
|
if (cached) return cached;
|
|
5336
6501
|
const primary = resolveField(field);
|
|
5337
6502
|
if (primary === null) {
|
|
5338
|
-
readingsCache.set(
|
|
6503
|
+
readingsCache.set(key, []);
|
|
5339
6504
|
return [];
|
|
5340
6505
|
}
|
|
5341
6506
|
let out = [primary];
|
|
5342
6507
|
if (field === "command") {
|
|
5343
6508
|
const raw = getNestedValue(args, field);
|
|
5344
6509
|
if (typeof raw === "string") {
|
|
5345
|
-
const
|
|
5346
|
-
|
|
6510
|
+
const text = access ? fileAccessView(raw) : raw;
|
|
6511
|
+
const collapsed = commandReadings(text).map((r) => r.replace(/\s+/g, " ").trim());
|
|
6512
|
+
out = access ? [...new Set(collapsed)] : [.../* @__PURE__ */ new Set([primary, ...collapsed])];
|
|
5347
6513
|
}
|
|
5348
6514
|
}
|
|
5349
|
-
readingsCache.set(
|
|
6515
|
+
readingsCache.set(key, out);
|
|
5350
6516
|
return out;
|
|
5351
6517
|
};
|
|
5352
6518
|
const results = rule.conditions.map((cond) => {
|
|
@@ -5364,14 +6530,14 @@ function evaluateSmartConditions(args, rule) {
|
|
|
5364
6530
|
if (val === null || !cond.value) return false;
|
|
5365
6531
|
const reM = getCompiledRegex(cond.value, cond.flags ?? "");
|
|
5366
6532
|
if (!reM) return false;
|
|
5367
|
-
return resolveFieldReadings(cond.field).some((v) => reM.test(v));
|
|
6533
|
+
return resolveFieldReadings(cond.field, cond.reading).some((v) => reM.test(v));
|
|
5368
6534
|
}
|
|
5369
6535
|
case "notMatches": {
|
|
5370
6536
|
if (!cond.value) return false;
|
|
5371
6537
|
if (val === null) return true;
|
|
5372
6538
|
const reN = getCompiledRegex(cond.value, cond.flags ?? "");
|
|
5373
6539
|
if (!reN) return false;
|
|
5374
|
-
return !resolveFieldReadings(cond.field).some((v) => reN.test(v));
|
|
6540
|
+
return !resolveFieldReadings(cond.field, cond.reading).some((v) => reN.test(v));
|
|
5375
6541
|
}
|
|
5376
6542
|
case "matchesGlob":
|
|
5377
6543
|
return val !== null && cond.value ? pm.isMatch(val, cond.value) : false;
|
|
@@ -6332,76 +7498,6 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
6332
7498
|
return out;
|
|
6333
7499
|
}
|
|
6334
7500
|
|
|
6335
|
-
// src/files/paths.ts
|
|
6336
|
-
var SYSTEM_AUTH_FILES = [
|
|
6337
|
-
"/etc/passwd",
|
|
6338
|
-
"/etc/shadow",
|
|
6339
|
-
"/etc/group",
|
|
6340
|
-
"/etc/gshadow",
|
|
6341
|
-
"/etc/sudoers"
|
|
6342
|
-
];
|
|
6343
|
-
var SYSTEM_AUTH_DIRS = ["/etc/security", "/etc/pam.d", "/etc/sudoers.d"];
|
|
6344
|
-
var PASSWORD_HASH_FILES = ["/etc/shadow", "/etc/gshadow"];
|
|
6345
|
-
var STARTUP_NAMES = [".bashrc", ".zshrc", ".profile", ".bash_profile"];
|
|
6346
|
-
var SYSTEM_DIRS = [
|
|
6347
|
-
"/usr",
|
|
6348
|
-
"/etc",
|
|
6349
|
-
"/boot",
|
|
6350
|
-
"/bin",
|
|
6351
|
-
"/sbin",
|
|
6352
|
-
"/lib",
|
|
6353
|
-
"/lib64",
|
|
6354
|
-
"/var/log"
|
|
6355
|
-
];
|
|
6356
|
-
var SYSTEM_DIRS_EXEMPT = ["/usr/local", "/usr/src"];
|
|
6357
|
-
var UPLOAD_SYSTEM_DIRS = [...SYSTEM_DIRS, "/proc", "/sys", "/root"];
|
|
6358
|
-
var AGENT_INSTRUCTION_FILES = [
|
|
6359
|
-
".gitlab-ci.yml",
|
|
6360
|
-
"CLAUDE.md",
|
|
6361
|
-
"AGENTS.md",
|
|
6362
|
-
".cursorrules",
|
|
6363
|
-
".mcp.json",
|
|
6364
|
-
".vscode/settings.json",
|
|
6365
|
-
"package.json"
|
|
6366
|
-
];
|
|
6367
|
-
var AGENT_INSTRUCTION_DIRS = [
|
|
6368
|
-
".github/workflows",
|
|
6369
|
-
".claude",
|
|
6370
|
-
".cursor",
|
|
6371
|
-
".git/hooks",
|
|
6372
|
-
".husky"
|
|
6373
|
-
];
|
|
6374
|
-
function isAgentInstructionPath(absPath, root) {
|
|
6375
|
-
const r = root.replace(/\/$/, "");
|
|
6376
|
-
if (!(absPath === r || absPath.startsWith(r + "/"))) return false;
|
|
6377
|
-
const rel = absPath.slice(r.length + 1);
|
|
6378
|
-
if (AGENT_INSTRUCTION_FILES.includes(rel)) return true;
|
|
6379
|
-
return AGENT_INSTRUCTION_DIRS.some((d) => rel === d || rel.startsWith(d + "/"));
|
|
6380
|
-
}
|
|
6381
|
-
function isInside(root, p) {
|
|
6382
|
-
const r = root.replace(/\/$/, "") || "/";
|
|
6383
|
-
return p === r || p.startsWith(r === "/" ? "/" : r + "/");
|
|
6384
|
-
}
|
|
6385
|
-
var LEGACY_SYSTEM_PATH_RE = /^(?:[a-zA-Z]:)?\/etc\/(?:passwd|shadow|sudoers)$/;
|
|
6386
|
-
function isPasswordHashPath(p) {
|
|
6387
|
-
return PASSWORD_HASH_FILES.includes(p);
|
|
6388
|
-
}
|
|
6389
|
-
function isLegacySystemPath(p) {
|
|
6390
|
-
return LEGACY_SYSTEM_PATH_RE.test(p);
|
|
6391
|
-
}
|
|
6392
|
-
function normalizeFilePath(p, cwd = "", home = "~") {
|
|
6393
|
-
if (!p.startsWith("/") && !p.startsWith("~") && cwd) p = `${cwd}/${p}`;
|
|
6394
|
-
if (p === "~" || p.startsWith("~/")) p = home + p.slice(1);
|
|
6395
|
-
const rooted = p.startsWith("/");
|
|
6396
|
-
const parts = [];
|
|
6397
|
-
for (const part of p.split("/")) {
|
|
6398
|
-
if (!part || part === ".") continue;
|
|
6399
|
-
if (part === ".." && parts.length && parts.at(-1) !== "..") parts.pop();
|
|
6400
|
-
else if (part !== ".." || !rooted) parts.push(part);
|
|
6401
|
-
}
|
|
6402
|
-
return (rooted ? "/" : "") + parts.join("/");
|
|
6403
|
-
}
|
|
6404
|
-
|
|
6405
7501
|
// src/files/protected-access.ts
|
|
6406
7502
|
function incompleteFileVerdict(operation = "write") {
|
|
6407
7503
|
return {
|
|
@@ -6584,7 +7680,7 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
6584
7680
|
}
|
|
6585
7681
|
|
|
6586
7682
|
// src/dlp/index.ts
|
|
6587
|
-
import
|
|
7683
|
+
import safeRegex2 from "safe-regex2";
|
|
6588
7684
|
|
|
6589
7685
|
// src/dlp/mnemonic.ts
|
|
6590
7686
|
import { createHash } from "crypto";
|
|
@@ -10317,14 +11413,14 @@ var SENSITIVE_PATH_REGEXES = [
|
|
|
10317
11413
|
];
|
|
10318
11414
|
function assertBuiltinPatternsAreSafe() {
|
|
10319
11415
|
for (const p of DLP_PATTERNS) {
|
|
10320
|
-
if (!
|
|
11416
|
+
if (!safeRegex2(p.regex.source)) {
|
|
10321
11417
|
throw new Error(
|
|
10322
11418
|
`[node9 engine] Builtin DLP pattern '${p.name}' is vulnerable to ReDoS: ${p.regex.source}`
|
|
10323
11419
|
);
|
|
10324
11420
|
}
|
|
10325
11421
|
}
|
|
10326
11422
|
for (const re of SENSITIVE_PATH_PATTERNS) {
|
|
10327
|
-
if (!
|
|
11423
|
+
if (!safeRegex2(re.source)) {
|
|
10328
11424
|
throw new Error(
|
|
10329
11425
|
`[node9 engine] Builtin sensitive-path pattern is vulnerable to ReDoS: ${re.source}`
|
|
10330
11426
|
);
|
|
@@ -11657,7 +12753,7 @@ function checksFromLegacyPolicy(policy, mode) {
|
|
|
11657
12753
|
if (uc?.enabled === false) out["behavior.untrusted-content"] = "off";
|
|
11658
12754
|
else if (uc?.enabled === true)
|
|
11659
12755
|
out["behavior.untrusted-content"] = uc.afterExposure === "log-only" ? "log" : "review";
|
|
11660
|
-
if (mode
|
|
12756
|
+
if (isBlockAll(mode)) out["commands.unknown"] = "review";
|
|
11661
12757
|
return out;
|
|
11662
12758
|
}
|
|
11663
12759
|
function checkToLegacyPolicy(policy, id, v) {
|
|
@@ -11749,6 +12845,25 @@ function checkToLegacyPolicy(policy, id, v) {
|
|
|
11749
12845
|
return false;
|
|
11750
12846
|
}
|
|
11751
12847
|
}
|
|
12848
|
+
function knobStatedChecks(policy) {
|
|
12849
|
+
const out = /* @__PURE__ */ new Set();
|
|
12850
|
+
const has = (o, key) => !!o && typeof o === "object" && o[key] !== void 0;
|
|
12851
|
+
const { dlp, egress, loopDetection, injectionScan, skillPinning, packageCheck } = policy;
|
|
12852
|
+
const uc = policy.untrustedContent;
|
|
12853
|
+
if (has(dlp, "enabled")) out.add("data.secrets");
|
|
12854
|
+
if (has(dlp, "reviewAction") || dlp?.enabled === false) out.add("data.secrets-weak");
|
|
12855
|
+
if (has(dlp, "pii")) out.add("data.pii");
|
|
12856
|
+
if (has(egress, "enabled") || has(egress, "mode")) out.add("network.unknown-host");
|
|
12857
|
+
if (has(egress, "ssrfStrict")) out.add("network.internal-addresses");
|
|
12858
|
+
if (has(loopDetection, "enabled")) out.add("behavior.loops");
|
|
12859
|
+
if (has(injectionScan, "enabled")) out.add("behavior.prompt-injection");
|
|
12860
|
+
if (has(skillPinning, "enabled") || has(skillPinning, "mode")) out.add("loading.skill-tamper");
|
|
12861
|
+
if (has(packageCheck, "enabled") || has(packageCheck, "onMalicious"))
|
|
12862
|
+
out.add("loading.malicious-package");
|
|
12863
|
+
if (uc && typeof uc === "object" && (uc.enabled === false || has(uc, "afterExposure")))
|
|
12864
|
+
out.add("behavior.untrusted-content");
|
|
12865
|
+
return out;
|
|
12866
|
+
}
|
|
11752
12867
|
var MAP_GOVERNED = /* @__PURE__ */ new Set([
|
|
11753
12868
|
"files.shell-startup",
|
|
11754
12869
|
"files.password-hashes",
|
|
@@ -11766,7 +12881,11 @@ var MAP_GOVERNED = /* @__PURE__ */ new Set([
|
|
|
11766
12881
|
"commands.disk-destroy",
|
|
11767
12882
|
"commands.dangerous-word",
|
|
11768
12883
|
"commands.node9-disarm",
|
|
11769
|
-
"data.pipe-chain"
|
|
12884
|
+
"data.pipe-chain",
|
|
12885
|
+
// The general action checks (node9Firewall#390): smart rules the map governs.
|
|
12886
|
+
"actions.money",
|
|
12887
|
+
"actions.access",
|
|
12888
|
+
"actions.publish"
|
|
11770
12889
|
]);
|
|
11771
12890
|
var KNOB_GOVERNED = {
|
|
11772
12891
|
"data.secrets": ["off", "block"],
|
|
@@ -12715,11 +13834,15 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
12715
13834
|
};
|
|
12716
13835
|
const ruleCheck = (rule) => {
|
|
12717
13836
|
if (rule.verdict === "allow") return void 0;
|
|
12718
|
-
if (!rule.builtin
|
|
13837
|
+
if (!rule.builtin) return void 0;
|
|
12719
13838
|
const id = checkIdForRule(rule.name);
|
|
12720
13839
|
if (!id) return void 0;
|
|
12721
13840
|
const def = getCheck(id);
|
|
12722
13841
|
if (!def) return void 0;
|
|
13842
|
+
if (rule.pinned) {
|
|
13843
|
+
const explicit = config.policy.checks?.[id];
|
|
13844
|
+
return def.pack && config.policy.checkSources?.[id] === "workspace" && isVerdict(explicit) ? { id, value: explicit } : void 0;
|
|
13845
|
+
}
|
|
12723
13846
|
if (rule.name?.startsWith("shield:") && !def.pack) return void 0;
|
|
12724
13847
|
if (def.pack) {
|
|
12725
13848
|
const explicit = config.policy.checks?.[id];
|
|
@@ -12727,8 +13850,10 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
12727
13850
|
}
|
|
12728
13851
|
return { id, value: cv(id) };
|
|
12729
13852
|
};
|
|
13853
|
+
const serverLabel = context.mcpServer ?? mcpServerFromToolName(toolName);
|
|
12730
13854
|
const matches = config.policy.smartRules.filter((rule) => {
|
|
12731
13855
|
if (!toolMatchesRule(toolName, rule.tool, layers)) return false;
|
|
13856
|
+
if (!ruleServerMatches(rule, serverLabel)) return false;
|
|
12732
13857
|
if (astSuppressed(rule)) return false;
|
|
12733
13858
|
if (rmCleanupWaiver && rule.name === "review-rm" && rule.verdict === "review") return false;
|
|
12734
13859
|
if (!evaluateSmartConditions(shellRuleArgs(toolName, args, rule.tool, layers), rule))
|
|
@@ -12805,11 +13930,13 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
12805
13930
|
if (v?.logged) noteLogged(v);
|
|
12806
13931
|
else if (v) candidates.push(v);
|
|
12807
13932
|
};
|
|
12808
|
-
|
|
13933
|
+
const inline = reviewsEveryInline(config.settings.mode) ? detectInlineExec(shellCommand) ? void 0 : null : inlineExecReview(shellCommand);
|
|
13934
|
+
if (inline !== null) {
|
|
12809
13935
|
consider("commands.inline-exec", {
|
|
12810
13936
|
decision: "review",
|
|
12811
13937
|
blockedByLabel: "Node9 Standard (Inline Execution)",
|
|
12812
|
-
|
|
13938
|
+
...inline ? { reason: inlineExecReason(inline) } : {},
|
|
13939
|
+
ruleDescription: inlineExecDescription(inline),
|
|
12813
13940
|
tier: 3,
|
|
12814
13941
|
checkId: "commands.inline-exec"
|
|
12815
13942
|
});
|
|
@@ -12863,21 +13990,17 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
12863
13990
|
if (firstToken && firstToken.startsWith("/") && checkProvenance) {
|
|
12864
13991
|
const prov = checkProvenance(firstToken, cwd);
|
|
12865
13992
|
if (prov.trustLevel === "suspect") {
|
|
12866
|
-
const
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
{
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
tier: 3,
|
|
12874
|
-
checkId: "commands.temp-binary"
|
|
12875
|
-
}
|
|
12876
|
-
);
|
|
13993
|
+
const v = applyCheckValue(cv("commands.temp-binary"), {
|
|
13994
|
+
decision: "review",
|
|
13995
|
+
blockedByLabel: "Node9: Suspect Binary",
|
|
13996
|
+
reason: `Binary "${firstToken}" resolved to ${prov.resolvedPath} \u2014 ${prov.reason}`,
|
|
13997
|
+
tier: 3,
|
|
13998
|
+
checkId: "commands.temp-binary"
|
|
13999
|
+
});
|
|
12877
14000
|
if (v?.logged) noteLogged(v);
|
|
12878
14001
|
else if (v) return v;
|
|
12879
14002
|
}
|
|
12880
|
-
if (prov.trustLevel === "unknown" && config.settings.mode
|
|
14003
|
+
if (prov.trustLevel === "unknown" && isBlockAll(config.settings.mode)) {
|
|
12881
14004
|
return {
|
|
12882
14005
|
decision: "review",
|
|
12883
14006
|
blockedByLabel: "Node9: Unknown Binary (strict mode)",
|
|
@@ -12968,7 +14091,7 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
12968
14091
|
if (v?.logged) noteLogged(v);
|
|
12969
14092
|
else if (v) return v;
|
|
12970
14093
|
}
|
|
12971
|
-
if (config.settings.mode
|
|
14094
|
+
if (isBlockAll(config.settings.mode)) {
|
|
12972
14095
|
if (activeEnvironment?.requireApproval === false) return allowed();
|
|
12973
14096
|
return {
|
|
12974
14097
|
decision: "review",
|
|
@@ -14024,6 +15147,74 @@ function safeMessage(value, max = 300) {
|
|
|
14024
15147
|
return s.length > max ? s.slice(0, max - 1) + "\u2026" : s;
|
|
14025
15148
|
}
|
|
14026
15149
|
|
|
15150
|
+
// src/suggest.ts
|
|
15151
|
+
function unwrapRuleLabel(label) {
|
|
15152
|
+
return ruleNameInLabel(label.trim()) ?? label.trim();
|
|
15153
|
+
}
|
|
15154
|
+
var SHIELD_RULE = /^shield:([a-z0-9-]+):((?:review|block)-[a-z0-9-]+)$/;
|
|
15155
|
+
var ACTION_RULE = /^review-action-(money|access|publish)-/;
|
|
15156
|
+
function packRowOf(ruleName, shield) {
|
|
15157
|
+
const id = checkIdForRule(ruleName);
|
|
15158
|
+
const def = id ? CHECK_BY_ID.get(id) : void 0;
|
|
15159
|
+
return def?.pack === shield && def.legacy?.includes(ruleName) ? id : void 0;
|
|
15160
|
+
}
|
|
15161
|
+
function suggestFromApprovals(rows, opts = {}) {
|
|
15162
|
+
const minApprovals = opts.minApprovals ?? 3;
|
|
15163
|
+
const minSessions = opts.minSessions ?? 2;
|
|
15164
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
15165
|
+
for (const r of rows) {
|
|
15166
|
+
const ruleName = unwrapRuleLabel(r.ruleName);
|
|
15167
|
+
const action = ACTION_RULE.exec(ruleName);
|
|
15168
|
+
if (action && checkIdForRule(ruleName) !== `actions.${action[1]}`) continue;
|
|
15169
|
+
if (action && !r.server) continue;
|
|
15170
|
+
const key = action ? `server:${r.server.toLowerCase()}:${action[1]}` : `rule:${ruleName}`;
|
|
15171
|
+
const isAction = action !== null;
|
|
15172
|
+
const acc = byKey.get(key) ?? {
|
|
15173
|
+
ruleName,
|
|
15174
|
+
server: isAction ? r.server : void 0,
|
|
15175
|
+
approvals: 0,
|
|
15176
|
+
sessions: /* @__PURE__ */ new Set(),
|
|
15177
|
+
denied: false
|
|
15178
|
+
};
|
|
15179
|
+
if (r.decision === "denied") acc.denied = true;
|
|
15180
|
+
else {
|
|
15181
|
+
acc.approvals += 1;
|
|
15182
|
+
if (r.sessionId) acc.sessions.add(r.sessionId);
|
|
15183
|
+
}
|
|
15184
|
+
byKey.set(key, acc);
|
|
15185
|
+
}
|
|
15186
|
+
const out = [];
|
|
15187
|
+
for (const acc of byKey.values()) {
|
|
15188
|
+
if (acc.denied || acc.approvals < minApprovals || acc.sessions.size < minSessions) continue;
|
|
15189
|
+
const shieldRule = SHIELD_RULE.exec(acc.ruleName);
|
|
15190
|
+
if (shieldRule) {
|
|
15191
|
+
const checkId = packRowOf(acc.ruleName, shieldRule[1]);
|
|
15192
|
+
if (!checkId) continue;
|
|
15193
|
+
out.push({
|
|
15194
|
+
kind: "quiet-rule",
|
|
15195
|
+
ruleName: acc.ruleName,
|
|
15196
|
+
shield: shieldRule[1],
|
|
15197
|
+
rule: shieldRule[2],
|
|
15198
|
+
checkId,
|
|
15199
|
+
approvals: acc.approvals,
|
|
15200
|
+
sessions: acc.sessions.size
|
|
15201
|
+
});
|
|
15202
|
+
continue;
|
|
15203
|
+
}
|
|
15204
|
+
const action = ACTION_RULE.exec(acc.ruleName);
|
|
15205
|
+
if (action && acc.server) {
|
|
15206
|
+
out.push({
|
|
15207
|
+
kind: "link-server",
|
|
15208
|
+
server: acc.server,
|
|
15209
|
+
checkId: `actions.${action[1]}`,
|
|
15210
|
+
approvals: acc.approvals,
|
|
15211
|
+
sessions: acc.sessions.size
|
|
15212
|
+
});
|
|
15213
|
+
}
|
|
15214
|
+
}
|
|
15215
|
+
return out.sort((a, b) => b.approvals - a.approvals);
|
|
15216
|
+
}
|
|
15217
|
+
|
|
14027
15218
|
// src/loop/index.ts
|
|
14028
15219
|
import crypto from "crypto";
|
|
14029
15220
|
var LOOP_MAX_RECORDS = 500;
|
|
@@ -14495,8 +15686,8 @@ function matchCanaryArgs(args, values) {
|
|
|
14495
15686
|
|
|
14496
15687
|
// src/scan/canonical.ts
|
|
14497
15688
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
14498
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
14499
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
15689
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v30";
|
|
15690
|
+
var CANONICAL_EXTRACTOR_HASH = "d55f1f9e5bee7e41";
|
|
14500
15691
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
14501
15692
|
function extractCanonicalFindings(call, ctx) {
|
|
14502
15693
|
const out = [];
|
|
@@ -14866,9 +16057,13 @@ function* stringValues(obj, depth = 0) {
|
|
|
14866
16057
|
// src/index.ts
|
|
14867
16058
|
var ENGINE_VERSION = "1.4.0";
|
|
14868
16059
|
export {
|
|
14869
|
-
|
|
16060
|
+
ACTION_CHECKS,
|
|
16061
|
+
ACTION_TEMPLATES,
|
|
14870
16062
|
AGENT_INSTRUCTION_DIRS,
|
|
14871
16063
|
AGENT_INSTRUCTION_FILES,
|
|
16064
|
+
APP_SERVER_GLOB,
|
|
16065
|
+
APP_SHIELD_NAMES,
|
|
16066
|
+
APP_SHIELD_SPECS,
|
|
14872
16067
|
ARGUMENT_SCAN_LIMITS,
|
|
14873
16068
|
AST_FS_REGEX_RULES,
|
|
14874
16069
|
BASH_TOOL_NAMES,
|
|
@@ -14895,17 +16090,21 @@ export {
|
|
|
14895
16090
|
FILE_TOOLS,
|
|
14896
16091
|
FLAGS_WITH_VALUES,
|
|
14897
16092
|
FS_READ_TOOLS,
|
|
16093
|
+
GENERAL_ACTION_RULES,
|
|
14898
16094
|
KNOB_GOVERNED,
|
|
16095
|
+
LEVELS,
|
|
14899
16096
|
LONG_OUTPUT_THRESHOLD_BYTES,
|
|
14900
16097
|
LOOP_MAX_RECORDS,
|
|
14901
16098
|
LOOP_THRESHOLD_FOR_WASTE,
|
|
14902
16099
|
MAP_GOVERNED,
|
|
14903
16100
|
MAX_BLAST_PATH,
|
|
14904
16101
|
MAX_DESTINATIONS,
|
|
16102
|
+
MODE_VALUES,
|
|
14905
16103
|
NET_BINARIES,
|
|
14906
16104
|
PATTERN_VERB_NAMES,
|
|
14907
16105
|
PRIVILEGE_ESCALATION_RE,
|
|
14908
16106
|
REALTIME_PII_PATTERNS,
|
|
16107
|
+
REPLACED_SHIELDS,
|
|
14909
16108
|
SCAN_SIGNAL_WEIGHTS,
|
|
14910
16109
|
SENSITIVE_PATH_RE,
|
|
14911
16110
|
SENSITIVE_PATH_REGEXES,
|
|
@@ -14966,6 +16165,7 @@ export {
|
|
|
14966
16165
|
extractShellDestTokens,
|
|
14967
16166
|
extractShellDestinations,
|
|
14968
16167
|
extractToolDestinations,
|
|
16168
|
+
fileAccessView,
|
|
14969
16169
|
fileOperandFlagsOf,
|
|
14970
16170
|
fileToolOperation,
|
|
14971
16171
|
foldHomoglyphs,
|
|
@@ -14976,11 +16176,15 @@ export {
|
|
|
14976
16176
|
hashDestination,
|
|
14977
16177
|
hostMatches,
|
|
14978
16178
|
incompleteFileVerdict,
|
|
16179
|
+
inlineExecDescription,
|
|
16180
|
+
inlineExecReason,
|
|
16181
|
+
inlineExecReview,
|
|
14979
16182
|
inspectArgumentSecrets,
|
|
14980
16183
|
inspectionEntry,
|
|
14981
16184
|
inspectionLayers,
|
|
14982
16185
|
isAgentInstructionPath,
|
|
14983
16186
|
isBashTool,
|
|
16187
|
+
isBlockAll,
|
|
14984
16188
|
isDestructiveToolName,
|
|
14985
16189
|
isHashedEntry,
|
|
14986
16190
|
isIgnoredTool,
|
|
@@ -14990,13 +16194,20 @@ export {
|
|
|
14990
16194
|
isLockedCheck,
|
|
14991
16195
|
isLoopbackHost,
|
|
14992
16196
|
isMaskedKind,
|
|
16197
|
+
isModeValue,
|
|
14993
16198
|
isPasswordHashPath,
|
|
14994
16199
|
isPrivateHost,
|
|
14995
16200
|
isProtectedHomePath,
|
|
16201
|
+
isRecordOnly,
|
|
14996
16202
|
isShellShapedTool,
|
|
14997
16203
|
isShieldVerdict,
|
|
14998
16204
|
isStrictGatedTier,
|
|
14999
16205
|
isVerdict,
|
|
16206
|
+
knobStatedChecks,
|
|
16207
|
+
levelCheckValue,
|
|
16208
|
+
levelChecks,
|
|
16209
|
+
levelOf,
|
|
16210
|
+
levelPackageSignals,
|
|
15000
16211
|
maskDestination,
|
|
15001
16212
|
maskPersonalData,
|
|
15002
16213
|
maskPersonalValue,
|
|
@@ -15006,6 +16217,7 @@ export {
|
|
|
15006
16217
|
matchesPattern,
|
|
15007
16218
|
matchesTrustedEntry,
|
|
15008
16219
|
matchesTrustedList,
|
|
16220
|
+
mcpServerFromToolName,
|
|
15009
16221
|
narrativeRuleLabel,
|
|
15010
16222
|
normalizeCommandForPolicy,
|
|
15011
16223
|
normalizeDestination,
|
|
@@ -15026,6 +16238,8 @@ export {
|
|
|
15026
16238
|
resolveCheckMap,
|
|
15027
16239
|
resolvePinned,
|
|
15028
16240
|
resolveShellInput,
|
|
16241
|
+
reviewsEveryInline,
|
|
16242
|
+
ruleServerMatches,
|
|
15029
16243
|
safeMessage,
|
|
15030
16244
|
sampleCopyCommand,
|
|
15031
16245
|
scanArgs,
|
|
@@ -15044,6 +16258,7 @@ export {
|
|
|
15044
16258
|
stripControlChars,
|
|
15045
16259
|
stripInvisible,
|
|
15046
16260
|
stripTerminalEscapes,
|
|
16261
|
+
suggestFromApprovals,
|
|
15047
16262
|
summarizeBlast,
|
|
15048
16263
|
summarizeScan,
|
|
15049
16264
|
toScanFinding,
|
|
@@ -15053,6 +16268,7 @@ export {
|
|
|
15053
16268
|
tuningFromLegacyPolicy,
|
|
15054
16269
|
tuningToLegacyPolicy,
|
|
15055
16270
|
unwrapCommandHead,
|
|
16271
|
+
unwrapRuleLabel,
|
|
15056
16272
|
validateOverrides,
|
|
15057
16273
|
validateRegex,
|
|
15058
16274
|
validateShieldDefinition
|