@node9/policy-engine 2.54.1 → 2.55.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +348 -5
- package/dist/index.mjs +348 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -512,7 +512,7 @@ declare function checkValue(settings: CatalogSettings, id: string): Verdict;
|
|
|
512
512
|
* stores this on its config so every reader sees the same answers. */
|
|
513
513
|
declare function resolveCheckMap(settings: CatalogSettings): Record<string, Verdict>;
|
|
514
514
|
|
|
515
|
-
type InlineCodeCategory = 'deletes' | 'writes-outside' | 'sends' | 'listens' | 'runs-commands' | 'reads-protected' | 'builds-code' | 'permissions' | 'monitors' | 'amplifies';
|
|
515
|
+
type InlineCodeCategory = 'deletes' | 'writes-outside' | 'sends' | 'listens' | 'runs-commands' | 'reads-protected' | 'builds-code' | 'permissions' | 'monitors' | 'amplifies' | 'kills-service';
|
|
516
516
|
|
|
517
517
|
/**
|
|
518
518
|
* The POSIX reading of a command. Kept as the single-string API every existing
|
|
@@ -2455,7 +2455,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
|
2455
2455
|
* files changed, this hash must change too, and you must consciously
|
|
2456
2456
|
* decide whether to bump CANONICAL_EXTRACTOR_VERSION."
|
|
2457
2457
|
*/
|
|
2458
|
-
declare const CANONICAL_EXTRACTOR_HASH = "
|
|
2458
|
+
declare const CANONICAL_EXTRACTOR_HASH = "40803f3331f55a36";
|
|
2459
2459
|
declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
|
|
2460
2460
|
declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
|
|
2461
2461
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -512,7 +512,7 @@ declare function checkValue(settings: CatalogSettings, id: string): Verdict;
|
|
|
512
512
|
* stores this on its config so every reader sees the same answers. */
|
|
513
513
|
declare function resolveCheckMap(settings: CatalogSettings): Record<string, Verdict>;
|
|
514
514
|
|
|
515
|
-
type InlineCodeCategory = 'deletes' | 'writes-outside' | 'sends' | 'listens' | 'runs-commands' | 'reads-protected' | 'builds-code' | 'permissions' | 'monitors' | 'amplifies';
|
|
515
|
+
type InlineCodeCategory = 'deletes' | 'writes-outside' | 'sends' | 'listens' | 'runs-commands' | 'reads-protected' | 'builds-code' | 'permissions' | 'monitors' | 'amplifies' | 'kills-service';
|
|
516
516
|
|
|
517
517
|
/**
|
|
518
518
|
* The POSIX reading of a command. Kept as the single-string API every existing
|
|
@@ -2455,7 +2455,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
|
2455
2455
|
* files changed, this hash must change too, and you must consciously
|
|
2456
2456
|
* decide whether to bump CANONICAL_EXTRACTOR_VERSION."
|
|
2457
2457
|
*/
|
|
2458
|
-
declare const CANONICAL_EXTRACTOR_HASH = "
|
|
2458
|
+
declare const CANONICAL_EXTRACTOR_HASH = "40803f3331f55a36";
|
|
2459
2459
|
declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
|
|
2460
2460
|
declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
|
|
2461
2461
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2566,6 +2566,11 @@ var CHECK_TEXT = {
|
|
|
2566
2566
|
example: "/tmp/build-helper --serve",
|
|
2567
2567
|
advice: "Keep Review. Malware often runs from /tmp."
|
|
2568
2568
|
},
|
|
2569
|
+
"commands.system-processes": {
|
|
2570
|
+
plain: "The agent stops or kills a system service: sshd, dockerd, containerd, systemd, kubelet, cron, the firewall, the display server, or a database or web server (nginx, apache, mysql, postgres, redis, mongo). Directly (pkill sshd, systemctl stop docker, kill of pid 1) or through the process list (a script that finds the processes of a name and kills them). Killing a process by its number, pkill node, killall python and systemctl restart are not this check.",
|
|
2571
|
+
example: "ps -eo pid,cmd | grep sshd | awk '{print $1}' | xargs kill -9",
|
|
2572
|
+
advice: "Keep Review: a stopped service takes other people and programs down with it. Set Log on a machine where agents manage local servers all day."
|
|
2573
|
+
},
|
|
2569
2574
|
"commands.disk-destroy": {
|
|
2570
2575
|
plain: "The agent formats, overwrites or securely erases a disk or file.",
|
|
2571
2576
|
example: "dd if=/dev/zero of=/dev/sda",
|
|
@@ -2762,6 +2767,7 @@ var SOFT = {
|
|
|
2762
2767
|
"commands.sql-no-where": "log",
|
|
2763
2768
|
"commands.temp-binary": "log",
|
|
2764
2769
|
"commands.disk-destroy": "log",
|
|
2770
|
+
"commands.system-processes": "log",
|
|
2765
2771
|
"commands.dangerous-word": "log",
|
|
2766
2772
|
"files.system-dirs": "log",
|
|
2767
2773
|
"files.shell-startup": "log",
|
|
@@ -3171,6 +3177,16 @@ var PRODUCT_CHECKS = [
|
|
|
3171
3177
|
defaultValue: "review",
|
|
3172
3178
|
legacy: ["Manual Nuclear Protection"]
|
|
3173
3179
|
},
|
|
3180
|
+
{
|
|
3181
|
+
id: "commands.system-processes",
|
|
3182
|
+
group: "commands",
|
|
3183
|
+
owasp: "ASI02",
|
|
3184
|
+
title: "Stops a system service",
|
|
3185
|
+
catches: "kill, pkill, killall, systemctl stop or kill, service stop or launchctl unload aimed at a system service (sshd, dockerd, systemd, kubelet, cron, a database or web server), or a script that walks the process list for one of those names and kills what it finds",
|
|
3186
|
+
values: ALL,
|
|
3187
|
+
defaultValue: "review",
|
|
3188
|
+
legacy: ["Node9: System Service Stopped"]
|
|
3189
|
+
},
|
|
3174
3190
|
{
|
|
3175
3191
|
id: "commands.dangerous-word",
|
|
3176
3192
|
group: "commands",
|
|
@@ -5067,6 +5083,98 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
5067
5083
|
return out;
|
|
5068
5084
|
}
|
|
5069
5085
|
|
|
5086
|
+
// src/shell/services.ts
|
|
5087
|
+
var INFRASTRUCTURE_SERVICES = [
|
|
5088
|
+
"init",
|
|
5089
|
+
"sshd",
|
|
5090
|
+
"dockerd",
|
|
5091
|
+
"docker-proxy",
|
|
5092
|
+
"containerd",
|
|
5093
|
+
"containerd-shim",
|
|
5094
|
+
"docker-containerd-shim",
|
|
5095
|
+
"runc",
|
|
5096
|
+
"systemd-journald",
|
|
5097
|
+
"journald",
|
|
5098
|
+
"systemd-logind",
|
|
5099
|
+
"systemd-udevd",
|
|
5100
|
+
"udevd",
|
|
5101
|
+
"dbus-daemon",
|
|
5102
|
+
"polkitd",
|
|
5103
|
+
"sssd",
|
|
5104
|
+
"kubelet",
|
|
5105
|
+
"kube-apiserver",
|
|
5106
|
+
"crond",
|
|
5107
|
+
"cron",
|
|
5108
|
+
"atd",
|
|
5109
|
+
"auditd",
|
|
5110
|
+
"rsyslogd",
|
|
5111
|
+
"syslogd",
|
|
5112
|
+
"chronyd",
|
|
5113
|
+
"ntpd",
|
|
5114
|
+
"NetworkManager",
|
|
5115
|
+
"wpa_supplicant",
|
|
5116
|
+
"dhclient",
|
|
5117
|
+
"avahi-daemon",
|
|
5118
|
+
"firewalld",
|
|
5119
|
+
"ufw",
|
|
5120
|
+
"cupsd",
|
|
5121
|
+
"snapd",
|
|
5122
|
+
"bluetoothd",
|
|
5123
|
+
"Xorg",
|
|
5124
|
+
"Xwayland",
|
|
5125
|
+
"gdm",
|
|
5126
|
+
"sddm",
|
|
5127
|
+
"lightdm"
|
|
5128
|
+
];
|
|
5129
|
+
var SERVER_SERVICES = [
|
|
5130
|
+
"nginx",
|
|
5131
|
+
"apache2",
|
|
5132
|
+
"httpd",
|
|
5133
|
+
"mysqld",
|
|
5134
|
+
"mariadbd",
|
|
5135
|
+
"postgres",
|
|
5136
|
+
"postgresql",
|
|
5137
|
+
"redis-server",
|
|
5138
|
+
"mongod"
|
|
5139
|
+
];
|
|
5140
|
+
var SYSTEM_SERVICES = [...INFRASTRUCTURE_SERVICES, ...SERVER_SERVICES];
|
|
5141
|
+
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\-]/g, "\\$&");
|
|
5142
|
+
var SERVICE_WORD_RE = new RegExp(
|
|
5143
|
+
`(?:^|[^A-Za-z0-9_.-])(${SYSTEM_SERVICES.map(escape).join("|")})(?![A-Za-z0-9_.-])`,
|
|
5144
|
+
"i"
|
|
5145
|
+
);
|
|
5146
|
+
var INIT_PATTERN_RE = /(?:["'*])init(?:["'*])/;
|
|
5147
|
+
function serviceNamedIn(text) {
|
|
5148
|
+
const re = new RegExp(SERVICE_WORD_RE.source, "gi");
|
|
5149
|
+
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
5150
|
+
const lower2 = m[1].toLowerCase();
|
|
5151
|
+
if (lower2 === "init" && !INIT_PATTERN_RE.test(text)) continue;
|
|
5152
|
+
return SYSTEM_SERVICES.find((s) => s.toLowerCase() === lower2) ?? m[1];
|
|
5153
|
+
}
|
|
5154
|
+
return null;
|
|
5155
|
+
}
|
|
5156
|
+
var UNIT_ALIASES = {
|
|
5157
|
+
docker: "dockerd",
|
|
5158
|
+
ssh: "sshd",
|
|
5159
|
+
mysql: "mysqld",
|
|
5160
|
+
mariadb: "mariadbd",
|
|
5161
|
+
redis: "redis-server",
|
|
5162
|
+
mongodb: "mongod",
|
|
5163
|
+
apache: "apache2",
|
|
5164
|
+
rsyslog: "rsyslogd",
|
|
5165
|
+
"systemd-networkd": "systemd-udevd",
|
|
5166
|
+
dbus: "dbus-daemon",
|
|
5167
|
+
avahi: "avahi-daemon",
|
|
5168
|
+
bluetooth: "bluetoothd",
|
|
5169
|
+
cups: "cupsd",
|
|
5170
|
+
chrony: "chronyd"
|
|
5171
|
+
};
|
|
5172
|
+
function serviceOf(name) {
|
|
5173
|
+
const leaf = name.replace(/^.*[\\/]/, "").replace(/\.service$/, "").replace(/@.*$/, "");
|
|
5174
|
+
const lower2 = leaf.toLowerCase();
|
|
5175
|
+
return SYSTEM_SERVICES.find((s) => s.toLowerCase() === lower2) ?? UNIT_ALIASES[lower2] ?? null;
|
|
5176
|
+
}
|
|
5177
|
+
|
|
5070
5178
|
// src/shell/inline-code.ts
|
|
5071
5179
|
var MAX_INLINE_CODE = 64 * 1024;
|
|
5072
5180
|
var WHAT = {
|
|
@@ -5079,8 +5187,22 @@ var WHAT = {
|
|
|
5079
5187
|
"builds-code": "runs code it builds at run time",
|
|
5080
5188
|
permissions: "changes permissions or ownership",
|
|
5081
5189
|
monitors: "captures the screen, the clipboard or the keyboard",
|
|
5082
|
-
amplifies: "writes or sends in an endless loop"
|
|
5190
|
+
amplifies: "writes or sends in an endless loop",
|
|
5191
|
+
"kills-service": "stops a system service"
|
|
5083
5192
|
};
|
|
5193
|
+
var KILL_API = {
|
|
5194
|
+
python: /\bos\.kill(?:pg)?\s*\(|\.(?:kill|terminate)\s*\(|\bsignal\.SIGKILL\b/,
|
|
5195
|
+
node: /\bprocess\.kill\s*\(|\.kill\s*\(\s*['"`]?SIG/,
|
|
5196
|
+
perl: /\bkill\s+(?:-?\d+|['"]?[A-Z]+['"]?)\s*,/,
|
|
5197
|
+
ruby: /\bProcess\.kill\b/,
|
|
5198
|
+
php: /\bposix_kill\s*\(/
|
|
5199
|
+
};
|
|
5200
|
+
function killsService(language, code) {
|
|
5201
|
+
const api = KILL_API[language].exec(code);
|
|
5202
|
+
if (!api) return null;
|
|
5203
|
+
const service = serviceNamedIn(code);
|
|
5204
|
+
return service ? `${api[0].trim()} with ${service}` : null;
|
|
5205
|
+
}
|
|
5084
5206
|
var OUTSIDE = String.raw`(?:~|\.\.[\\/]|/(?!(?:tmp|var/tmp)/(?![^'"\n]*\.\.)|dev/(?:null|stdout|stderr)\b))`;
|
|
5085
5207
|
var pyImport = (mods) => new RegExp(String.raw`\b(?:import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*|from\s+)(?:${mods})\b`);
|
|
5086
5208
|
var either = (...res) => new RegExp(res.map((r) => `(?:${r.source})`).join("|"), "m");
|
|
@@ -5370,6 +5492,15 @@ function judgeInlineCode(language, code, isProtected) {
|
|
|
5370
5492
|
return { outcome: "unreadable", what: "is too long for node9 to read" };
|
|
5371
5493
|
}
|
|
5372
5494
|
const text = language === "python" ? resolvePythonAliases(code) : code;
|
|
5495
|
+
const killed = killsService(language, text);
|
|
5496
|
+
if (killed) {
|
|
5497
|
+
return {
|
|
5498
|
+
outcome: "dangerous",
|
|
5499
|
+
what: WHAT["kills-service"],
|
|
5500
|
+
evidence: killed.slice(0, 60),
|
|
5501
|
+
category: "kills-service"
|
|
5502
|
+
};
|
|
5503
|
+
}
|
|
5373
5504
|
for (const [category, re] of TABLES[language]) {
|
|
5374
5505
|
const m = re.exec(text);
|
|
5375
5506
|
if (!m) continue;
|
|
@@ -12858,6 +12989,62 @@ function validateAssignedSecret(raw, before = "") {
|
|
|
12858
12989
|
const mixed = /[0-9]/.test(value) && /[A-Za-z]/.test(value);
|
|
12859
12990
|
return looksGenerated(value, 12, mixed ? 3 : 3.5);
|
|
12860
12991
|
}
|
|
12992
|
+
var INLINE_SECRET_NAMES = /* @__PURE__ */ new Set([
|
|
12993
|
+
"AWS_SECRET_ACCESS_KEY",
|
|
12994
|
+
"AWS_SESSION_TOKEN",
|
|
12995
|
+
"GITHUB_TOKEN",
|
|
12996
|
+
"GH_TOKEN",
|
|
12997
|
+
"NPM_TOKEN",
|
|
12998
|
+
"OPENAI_API_KEY",
|
|
12999
|
+
"ANTHROPIC_API_KEY",
|
|
13000
|
+
"DATABASE_URL"
|
|
13001
|
+
]);
|
|
13002
|
+
var INLINE_SECRET_PARTS_RE = /([A-Z][A-Z0-9_]*)=([\s\S]+)$/;
|
|
13003
|
+
var INLINE_REFERENCE_RE = /[$`]/;
|
|
13004
|
+
var INLINE_FIXTURE_WORDS = /* @__PURE__ */ new Set([
|
|
13005
|
+
...["dummy", "fake", "mock", "stub", "placeholder", "changeme", "redacted", "sample"],
|
|
13006
|
+
...["test", "tests", "testing", "real", "invalid", "bogus", "nonexistent", "notreal"]
|
|
13007
|
+
]);
|
|
13008
|
+
var INLINE_PLACEHOLDER_WORDS = /* @__PURE__ */ new Set([
|
|
13009
|
+
...["pass", "password", "passwd", "pwd", "secret", "token", "key", "apikey", "value"],
|
|
13010
|
+
...["admin", "administrator", "root", "user", "guest", "demo", "default", "letmein", "qwerty"],
|
|
13011
|
+
...["test", "testing", "example", "sample", "dummy", "fake", "mock", "stub", "placeholder"],
|
|
13012
|
+
...["changeme", "change", "replace", "insert", "paste", "fill", "put", "set", "me", "in", "it"],
|
|
13013
|
+
...["your", "my", "the", "a", "here", "goes", "string", "foo", "bar", "baz", "todo", "fixme"],
|
|
13014
|
+
...["redacted", "hidden", "omitted", "removed", "masked", "none", "null", "undefined", "nil"],
|
|
13015
|
+
...["xxx", "postgres", "mysql", "mariadb", "redis", "mongo", "dev", "development", "local"],
|
|
13016
|
+
...["localhost", "docker", "ci", "invalid", "unset", "empty", "missing", "skip", "noop"]
|
|
13017
|
+
]);
|
|
13018
|
+
function isInlinePlaceholder(value) {
|
|
13019
|
+
const lower2 = value.toLowerCase();
|
|
13020
|
+
if (/^(.)\1*$/.test(value)) return true;
|
|
13021
|
+
if (/^<.*>$/.test(value) || /^\[.*\]$/.test(value)) return true;
|
|
13022
|
+
if (BASIC_TEMPLATE_MARKERS.some((m) => lower2.includes(m))) return true;
|
|
13023
|
+
if (hasSequentialRun(value)) return true;
|
|
13024
|
+
const words = lower2.split(/[^a-z]+/).filter(Boolean);
|
|
13025
|
+
if (words.some((w) => INLINE_FIXTURE_WORDS.has(w))) return true;
|
|
13026
|
+
return words.length > 0 && words.every((w) => INLINE_PLACEHOLDER_WORDS.has(w));
|
|
13027
|
+
}
|
|
13028
|
+
function validateInlineSecretAssignment(raw) {
|
|
13029
|
+
const parts = raw.match(INLINE_SECRET_PARTS_RE);
|
|
13030
|
+
if (!parts) return false;
|
|
13031
|
+
const name = parts[1];
|
|
13032
|
+
let value = parts[2];
|
|
13033
|
+
const quote = value.charAt(0);
|
|
13034
|
+
if ((quote === '"' || quote === "'") && value.endsWith(quote)) value = value.slice(1, -1);
|
|
13035
|
+
if (value === "") return false;
|
|
13036
|
+
if (quote !== "'" && INLINE_REFERENCE_RE.test(value)) return false;
|
|
13037
|
+
if (isInlinePlaceholder(value)) return false;
|
|
13038
|
+
if (rejectedByStructuredValidator(value)) return false;
|
|
13039
|
+
if (name === "DATABASE_URL") {
|
|
13040
|
+
const password = capturedValue(value, DB_URL_PASSWORD_RE);
|
|
13041
|
+
return password !== null && !isInlinePlaceholder(password);
|
|
13042
|
+
}
|
|
13043
|
+
if (INLINE_SECRET_NAMES.has(name)) return true;
|
|
13044
|
+
if (!nameHoldsCredential(name)) return false;
|
|
13045
|
+
if (value.length < 8 || IDENTIFIER_VALUE_RE.test(value)) return false;
|
|
13046
|
+
return true;
|
|
13047
|
+
}
|
|
12861
13048
|
var CIPHER_KEY_NAME_RE = /^([A-Za-z_][\w.]{0,40})/;
|
|
12862
13049
|
var CIPHER_NAME_PARTS = /* @__PURE__ */ new Set([
|
|
12863
13050
|
"cipher",
|
|
@@ -13572,6 +13759,26 @@ var DLP_PATTERNS = [
|
|
|
13572
13759
|
keywords: ["pass", "pwd", "secret", "token", "key", "ticket"],
|
|
13573
13760
|
validate: validateAssignedSecret,
|
|
13574
13761
|
argumentsOnly: true
|
|
13762
|
+
},
|
|
13763
|
+
// ── Known secret variable assigned a literal ──────────────────────────────
|
|
13764
|
+
// `AWS_SECRET_ACCESS_KEY=… aws s3 ls`, `export GH_TOKEN=… && gh api`, `env
|
|
13765
|
+
// NPM_TOKEN=… npm publish`, and a `*_SECRET` / `*_TOKEN` / `*_PASSWORD` /
|
|
13766
|
+
// `*_API_KEY` name in the same place. The name starts a shell word (the
|
|
13767
|
+
// start of the text, a space, a newline, `;`, `&`, `|`, `(`), so an
|
|
13768
|
+
// assignment given as an argument (`docker run -e GITHUB_TOKEN=…`) is the
|
|
13769
|
+
// same handoff and counts too; the value is the rest of the word, or a
|
|
13770
|
+
// quoted string. The validator decides by the
|
|
13771
|
+
// name (node9Firewall#451): see validateInlineSecretAssignment. review, as
|
|
13772
|
+
// every name-based finding: the shape of the value is not checked, so a
|
|
13773
|
+
// human confirms rather than the gate deciding alone.
|
|
13774
|
+
{
|
|
13775
|
+
name: "Inline Secret Assignment",
|
|
13776
|
+
regex: /(?:^|[\s;&|(])((?:AWS_SECRET_ACCESS_KEY|AWS_SESSION_TOKEN|GITHUB_TOKEN|GH_TOKEN|NPM_TOKEN|OPENAI_API_KEY|ANTHROPIC_API_KEY|DATABASE_URL)|[A-Z][A-Z0-9_]{0,60}_(?:SECRET|TOKEN|PASSWORD|API_KEY))=("[^"\n]{1,512}"|'[^'\n]{1,512}'|[^\s;&|"'`()<>]{1,512})/,
|
|
13777
|
+
severity: "review",
|
|
13778
|
+
keywords: ["_secret", "_token", "_password", "_api_key", "database_url"],
|
|
13779
|
+
validate: validateInlineSecretAssignment,
|
|
13780
|
+
redactGroup: 2,
|
|
13781
|
+
argumentsOnly: true
|
|
13575
13782
|
}
|
|
13576
13783
|
];
|
|
13577
13784
|
var DLP_PATTERNS_GLOBAL = DLP_PATTERNS.map(
|
|
@@ -13667,12 +13874,14 @@ function assertBuiltinPatternsAreSafe() {
|
|
|
13667
13874
|
}
|
|
13668
13875
|
}
|
|
13669
13876
|
assertBuiltinPatternsAreSafe();
|
|
13670
|
-
function maskSecret(raw, pattern) {
|
|
13877
|
+
function maskSecret(raw, pattern, redactGroup) {
|
|
13671
13878
|
const match = raw.match(pattern);
|
|
13672
13879
|
if (!match) return "****";
|
|
13673
13880
|
const secret = match[0];
|
|
13674
13881
|
if (secret.length < 8) return "****";
|
|
13675
13882
|
const prefix = secret.slice(0, 4);
|
|
13883
|
+
const group = redactGroup !== void 0 ? match[redactGroup] : void 0;
|
|
13884
|
+
if (typeof group === "string" && group.length < 8) return `${prefix}****`;
|
|
13676
13885
|
const suffix = secret.slice(-4);
|
|
13677
13886
|
const stars = "*".repeat(Math.min(secret.length - 8, 12));
|
|
13678
13887
|
return `${prefix}${stars}${suffix}`;
|
|
@@ -13727,7 +13936,7 @@ function matchArgumentText(text, fieldPath, budget) {
|
|
|
13727
13936
|
const match = {
|
|
13728
13937
|
patternName: pattern.name,
|
|
13729
13938
|
fieldPath,
|
|
13730
|
-
redactedSample: maskSecret(raw, pattern.regex),
|
|
13939
|
+
redactedSample: maskSecret(raw, pattern.regex, pattern.redactGroup),
|
|
13731
13940
|
severity
|
|
13732
13941
|
};
|
|
13733
13942
|
if (severity === "block") return match;
|
|
@@ -17482,6 +17691,7 @@ var MAP_GOVERNED = /* @__PURE__ */ new Set([
|
|
|
17482
17691
|
"commands.sql-no-where",
|
|
17483
17692
|
"commands.temp-binary",
|
|
17484
17693
|
"commands.disk-destroy",
|
|
17694
|
+
"commands.system-processes",
|
|
17485
17695
|
"commands.dangerous-word",
|
|
17486
17696
|
"commands.node9-disarm",
|
|
17487
17697
|
"commands.reverse-shell",
|
|
@@ -18193,6 +18403,126 @@ function scanArgumentSecrets(args) {
|
|
|
18193
18403
|
} : null;
|
|
18194
18404
|
}
|
|
18195
18405
|
|
|
18406
|
+
// src/shell/processes.ts
|
|
18407
|
+
var PRESCREEN_RE3 = /\b(?:kill|pkill|killall|systemctl|service|launchctl|xargs)\b/;
|
|
18408
|
+
var KILL_SIGNAL_RE = /^-(?:\d+|s|SIG[A-Z]+|[A-Z]{2,})$/;
|
|
18409
|
+
var SYSTEMCTL_STOP_VERBS = /* @__PURE__ */ new Set(["stop", "kill", "disable", "mask"]);
|
|
18410
|
+
var LAUNCHCTL_UNLOAD_VERBS = /* @__PURE__ */ new Set(["unload", "bootout", "remove"]);
|
|
18411
|
+
var LAUNCH_DAEMONS_RE = /(?:^|\/)(?:System\/)?Library\/LaunchDaemons\//;
|
|
18412
|
+
var MAX_PAYLOAD_DEPTH5 = 3;
|
|
18413
|
+
function shownOf2(words) {
|
|
18414
|
+
return words.map((w) => w ?? "$?").join(" ").slice(0, 80);
|
|
18415
|
+
}
|
|
18416
|
+
function withoutComments(command) {
|
|
18417
|
+
return command.split("\n").map((line) => {
|
|
18418
|
+
for (let i = 0; i < line.length; i++) {
|
|
18419
|
+
if (line[i] === "#" && (i === 0 || line[i - 1] === " " || line[i - 1] === " ")) {
|
|
18420
|
+
return line.slice(0, i);
|
|
18421
|
+
}
|
|
18422
|
+
}
|
|
18423
|
+
return line;
|
|
18424
|
+
}).join("\n");
|
|
18425
|
+
}
|
|
18426
|
+
function detectSystemProcessStop(command, depth = 0) {
|
|
18427
|
+
if (!PRESCREEN_RE3.test(command)) return null;
|
|
18428
|
+
const named = serviceNamedIn(withoutComments(command));
|
|
18429
|
+
let direct = null;
|
|
18430
|
+
let dynamicKill = null;
|
|
18431
|
+
walkCommandScope(command, (node) => {
|
|
18432
|
+
const n = node;
|
|
18433
|
+
if (direct || !n || n.kind !== "CallExpr") return true;
|
|
18434
|
+
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
18435
|
+
if (words.length === 0) return true;
|
|
18436
|
+
if (baseWord(words[0]) === "xargs" && words.some((w) => w !== null && baseWord(w) === "kill")) {
|
|
18437
|
+
dynamicKill ??= shownOf2(words);
|
|
18438
|
+
return true;
|
|
18439
|
+
}
|
|
18440
|
+
if (depth < MAX_PAYLOAD_DEPTH5) {
|
|
18441
|
+
const payload = literalShellPayload(words, baseWord(words[0]));
|
|
18442
|
+
if (payload !== null) {
|
|
18443
|
+
const inner = detectSystemProcessStop(payload, depth + 1);
|
|
18444
|
+
if (inner) direct = inner;
|
|
18445
|
+
return true;
|
|
18446
|
+
}
|
|
18447
|
+
}
|
|
18448
|
+
const head = unwrapCommandHead(words);
|
|
18449
|
+
if (head >= words.length) return true;
|
|
18450
|
+
const name = baseWord(words[head]);
|
|
18451
|
+
const rest = words.slice(head + 1);
|
|
18452
|
+
const shown = shownOf2(words);
|
|
18453
|
+
const viaXargs = words.slice(0, head).some((w) => w !== null && baseWord(w) === "xargs");
|
|
18454
|
+
if (name === "kill") {
|
|
18455
|
+
const targets = [];
|
|
18456
|
+
for (let i = 0; i < rest.length; i++) {
|
|
18457
|
+
const w = rest[i];
|
|
18458
|
+
if (i === 0 && w !== null && KILL_SIGNAL_RE.test(w)) {
|
|
18459
|
+
if (w === "-s") i++;
|
|
18460
|
+
continue;
|
|
18461
|
+
}
|
|
18462
|
+
if (w === "--") continue;
|
|
18463
|
+
targets.push(w);
|
|
18464
|
+
}
|
|
18465
|
+
if (targets.some((t) => t === "1" || t === "-1")) {
|
|
18466
|
+
direct = { service: "init (pid 1)", how: "kills", shown };
|
|
18467
|
+
} else if (viaXargs || targets.some((t) => t === null)) {
|
|
18468
|
+
dynamicKill ??= shown;
|
|
18469
|
+
}
|
|
18470
|
+
return true;
|
|
18471
|
+
}
|
|
18472
|
+
if (name === "pkill" || name === "killall") {
|
|
18473
|
+
let skipValue = false;
|
|
18474
|
+
for (const w of rest) {
|
|
18475
|
+
if (skipValue) {
|
|
18476
|
+
skipValue = false;
|
|
18477
|
+
continue;
|
|
18478
|
+
}
|
|
18479
|
+
if (w !== null && w.startsWith("-")) {
|
|
18480
|
+
if (/^-(?:u|U|g|G|t|P|s|n|o|r|q|-signal|-uid|-user)$/.test(w)) skipValue = true;
|
|
18481
|
+
continue;
|
|
18482
|
+
}
|
|
18483
|
+
if (w === null) {
|
|
18484
|
+
dynamicKill ??= shown;
|
|
18485
|
+
continue;
|
|
18486
|
+
}
|
|
18487
|
+
const service = serviceOf(w) ?? serviceNamedIn(w);
|
|
18488
|
+
if (service) direct = { service, how: "kills", shown };
|
|
18489
|
+
}
|
|
18490
|
+
return true;
|
|
18491
|
+
}
|
|
18492
|
+
if (name === "systemctl") {
|
|
18493
|
+
if (rest.includes("--user")) return true;
|
|
18494
|
+
const verb = rest.find((w) => w !== null && !w.startsWith("-"));
|
|
18495
|
+
if (verb === void 0 || verb === null || !SYSTEMCTL_STOP_VERBS.has(verb)) return true;
|
|
18496
|
+
for (const w of rest.slice(rest.indexOf(verb) + 1)) {
|
|
18497
|
+
const service = w === null ? null : serviceOf(w);
|
|
18498
|
+
if (service) direct = { service, how: verb === "kill" ? "kills" : "stops", shown };
|
|
18499
|
+
}
|
|
18500
|
+
return true;
|
|
18501
|
+
}
|
|
18502
|
+
if (name === "service") {
|
|
18503
|
+
const [unit, verb] = rest;
|
|
18504
|
+
const service = typeof unit === "string" ? serviceOf(unit) : null;
|
|
18505
|
+
if (service && verb === "stop") direct = { service, how: "stops", shown };
|
|
18506
|
+
return true;
|
|
18507
|
+
}
|
|
18508
|
+
if (name === "launchctl") {
|
|
18509
|
+
const verb = rest.find((w) => w !== null && !w.startsWith("-"));
|
|
18510
|
+
if (verb === void 0 || verb === null || !LAUNCHCTL_UNLOAD_VERBS.has(verb)) return true;
|
|
18511
|
+
const daemon = rest.find((w) => w !== null && LAUNCH_DAEMONS_RE.test(w));
|
|
18512
|
+
if (daemon) {
|
|
18513
|
+
direct = { service: daemon.replace(/^.*\//, ""), how: "unloads the system daemon", shown };
|
|
18514
|
+
}
|
|
18515
|
+
return true;
|
|
18516
|
+
}
|
|
18517
|
+
return true;
|
|
18518
|
+
});
|
|
18519
|
+
if (direct) return direct;
|
|
18520
|
+
if (dynamicKill !== null && named) {
|
|
18521
|
+
return { service: named, how: "kills the processes of", shown: dynamicKill };
|
|
18522
|
+
}
|
|
18523
|
+
return null;
|
|
18524
|
+
}
|
|
18525
|
+
|
|
18196
18526
|
// src/shell/node9-disarm.ts
|
|
18197
18527
|
var RULE_NAME2 = "review-node9-disarm";
|
|
18198
18528
|
var DESCRIPTION = "The AI wants to stop node9, remove it, or change its own files. These are your commands to run, not the agent's: with the daemon stopped the outside-content and taint checks are off.";
|
|
@@ -18868,6 +19198,17 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
18868
19198
|
checkId: "commands.eval-dynamic"
|
|
18869
19199
|
});
|
|
18870
19200
|
}
|
|
19201
|
+
const stopped = detectSystemProcessStop(shellCommand);
|
|
19202
|
+
if (stopped) {
|
|
19203
|
+
consider("commands.system-processes", {
|
|
19204
|
+
decision: "review",
|
|
19205
|
+
blockedByLabel: "Node9: System Service Stopped",
|
|
19206
|
+
reason: `The AI ${stopped.how} ${stopped.service}: ${stopped.shown}`,
|
|
19207
|
+
ruleDescription: "The AI stops or kills a system service (sshd, dockerd, systemd, a database or web server). Other people and programs on this machine depend on it; confirm this is intentional.",
|
|
19208
|
+
tier: 3,
|
|
19209
|
+
checkId: "commands.system-processes"
|
|
19210
|
+
});
|
|
19211
|
+
}
|
|
18871
19212
|
const builtin = strictestVerdict(candidates);
|
|
18872
19213
|
if (builtin) return builtin;
|
|
18873
19214
|
{
|
|
@@ -20341,7 +20682,8 @@ function classifyRuleSeverity(name, verdict) {
|
|
|
20341
20682
|
"rebase",
|
|
20342
20683
|
"delete-branch",
|
|
20343
20684
|
"delete-remote",
|
|
20344
|
-
"unknown-registry"
|
|
20685
|
+
"unknown-registry",
|
|
20686
|
+
"system-processes"
|
|
20345
20687
|
];
|
|
20346
20688
|
if (highPatterns.some((p) => n.includes(p))) return "high";
|
|
20347
20689
|
if (verdict === "block") return "high";
|
|
@@ -20381,6 +20723,7 @@ function narrativeRuleLabel(name) {
|
|
|
20381
20723
|
"reverse-shell": "reverse shell",
|
|
20382
20724
|
"env-exfil": "environment sent out",
|
|
20383
20725
|
"unknown-registry": "install from an unknown registry",
|
|
20726
|
+
"system-processes": "system service stopped",
|
|
20384
20727
|
"agent-file-write": "agent instruction file written",
|
|
20385
20728
|
"agent-file-content": "instruction written into an agent file",
|
|
20386
20729
|
"agent-hooks-change": "agent hooks changed",
|
|
@@ -20693,7 +21036,7 @@ function matchCanaryArgs(args, values) {
|
|
|
20693
21036
|
// src/scan/canonical.ts
|
|
20694
21037
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
20695
21038
|
var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
20696
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
21039
|
+
var CANONICAL_EXTRACTOR_HASH = "40803f3331f55a36";
|
|
20697
21040
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
20698
21041
|
function extractCanonicalFindings(call, ctx) {
|
|
20699
21042
|
const out = [];
|
package/dist/index.mjs
CHANGED
|
@@ -2303,6 +2303,11 @@ var CHECK_TEXT = {
|
|
|
2303
2303
|
example: "/tmp/build-helper --serve",
|
|
2304
2304
|
advice: "Keep Review. Malware often runs from /tmp."
|
|
2305
2305
|
},
|
|
2306
|
+
"commands.system-processes": {
|
|
2307
|
+
plain: "The agent stops or kills a system service: sshd, dockerd, containerd, systemd, kubelet, cron, the firewall, the display server, or a database or web server (nginx, apache, mysql, postgres, redis, mongo). Directly (pkill sshd, systemctl stop docker, kill of pid 1) or through the process list (a script that finds the processes of a name and kills them). Killing a process by its number, pkill node, killall python and systemctl restart are not this check.",
|
|
2308
|
+
example: "ps -eo pid,cmd | grep sshd | awk '{print $1}' | xargs kill -9",
|
|
2309
|
+
advice: "Keep Review: a stopped service takes other people and programs down with it. Set Log on a machine where agents manage local servers all day."
|
|
2310
|
+
},
|
|
2306
2311
|
"commands.disk-destroy": {
|
|
2307
2312
|
plain: "The agent formats, overwrites or securely erases a disk or file.",
|
|
2308
2313
|
example: "dd if=/dev/zero of=/dev/sda",
|
|
@@ -2499,6 +2504,7 @@ var SOFT = {
|
|
|
2499
2504
|
"commands.sql-no-where": "log",
|
|
2500
2505
|
"commands.temp-binary": "log",
|
|
2501
2506
|
"commands.disk-destroy": "log",
|
|
2507
|
+
"commands.system-processes": "log",
|
|
2502
2508
|
"commands.dangerous-word": "log",
|
|
2503
2509
|
"files.system-dirs": "log",
|
|
2504
2510
|
"files.shell-startup": "log",
|
|
@@ -2908,6 +2914,16 @@ var PRODUCT_CHECKS = [
|
|
|
2908
2914
|
defaultValue: "review",
|
|
2909
2915
|
legacy: ["Manual Nuclear Protection"]
|
|
2910
2916
|
},
|
|
2917
|
+
{
|
|
2918
|
+
id: "commands.system-processes",
|
|
2919
|
+
group: "commands",
|
|
2920
|
+
owasp: "ASI02",
|
|
2921
|
+
title: "Stops a system service",
|
|
2922
|
+
catches: "kill, pkill, killall, systemctl stop or kill, service stop or launchctl unload aimed at a system service (sshd, dockerd, systemd, kubelet, cron, a database or web server), or a script that walks the process list for one of those names and kills what it finds",
|
|
2923
|
+
values: ALL,
|
|
2924
|
+
defaultValue: "review",
|
|
2925
|
+
legacy: ["Node9: System Service Stopped"]
|
|
2926
|
+
},
|
|
2911
2927
|
{
|
|
2912
2928
|
id: "commands.dangerous-word",
|
|
2913
2929
|
group: "commands",
|
|
@@ -4804,6 +4820,98 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4804
4820
|
return out;
|
|
4805
4821
|
}
|
|
4806
4822
|
|
|
4823
|
+
// src/shell/services.ts
|
|
4824
|
+
var INFRASTRUCTURE_SERVICES = [
|
|
4825
|
+
"init",
|
|
4826
|
+
"sshd",
|
|
4827
|
+
"dockerd",
|
|
4828
|
+
"docker-proxy",
|
|
4829
|
+
"containerd",
|
|
4830
|
+
"containerd-shim",
|
|
4831
|
+
"docker-containerd-shim",
|
|
4832
|
+
"runc",
|
|
4833
|
+
"systemd-journald",
|
|
4834
|
+
"journald",
|
|
4835
|
+
"systemd-logind",
|
|
4836
|
+
"systemd-udevd",
|
|
4837
|
+
"udevd",
|
|
4838
|
+
"dbus-daemon",
|
|
4839
|
+
"polkitd",
|
|
4840
|
+
"sssd",
|
|
4841
|
+
"kubelet",
|
|
4842
|
+
"kube-apiserver",
|
|
4843
|
+
"crond",
|
|
4844
|
+
"cron",
|
|
4845
|
+
"atd",
|
|
4846
|
+
"auditd",
|
|
4847
|
+
"rsyslogd",
|
|
4848
|
+
"syslogd",
|
|
4849
|
+
"chronyd",
|
|
4850
|
+
"ntpd",
|
|
4851
|
+
"NetworkManager",
|
|
4852
|
+
"wpa_supplicant",
|
|
4853
|
+
"dhclient",
|
|
4854
|
+
"avahi-daemon",
|
|
4855
|
+
"firewalld",
|
|
4856
|
+
"ufw",
|
|
4857
|
+
"cupsd",
|
|
4858
|
+
"snapd",
|
|
4859
|
+
"bluetoothd",
|
|
4860
|
+
"Xorg",
|
|
4861
|
+
"Xwayland",
|
|
4862
|
+
"gdm",
|
|
4863
|
+
"sddm",
|
|
4864
|
+
"lightdm"
|
|
4865
|
+
];
|
|
4866
|
+
var SERVER_SERVICES = [
|
|
4867
|
+
"nginx",
|
|
4868
|
+
"apache2",
|
|
4869
|
+
"httpd",
|
|
4870
|
+
"mysqld",
|
|
4871
|
+
"mariadbd",
|
|
4872
|
+
"postgres",
|
|
4873
|
+
"postgresql",
|
|
4874
|
+
"redis-server",
|
|
4875
|
+
"mongod"
|
|
4876
|
+
];
|
|
4877
|
+
var SYSTEM_SERVICES = [...INFRASTRUCTURE_SERVICES, ...SERVER_SERVICES];
|
|
4878
|
+
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\-]/g, "\\$&");
|
|
4879
|
+
var SERVICE_WORD_RE = new RegExp(
|
|
4880
|
+
`(?:^|[^A-Za-z0-9_.-])(${SYSTEM_SERVICES.map(escape).join("|")})(?![A-Za-z0-9_.-])`,
|
|
4881
|
+
"i"
|
|
4882
|
+
);
|
|
4883
|
+
var INIT_PATTERN_RE = /(?:["'*])init(?:["'*])/;
|
|
4884
|
+
function serviceNamedIn(text) {
|
|
4885
|
+
const re = new RegExp(SERVICE_WORD_RE.source, "gi");
|
|
4886
|
+
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
4887
|
+
const lower2 = m[1].toLowerCase();
|
|
4888
|
+
if (lower2 === "init" && !INIT_PATTERN_RE.test(text)) continue;
|
|
4889
|
+
return SYSTEM_SERVICES.find((s) => s.toLowerCase() === lower2) ?? m[1];
|
|
4890
|
+
}
|
|
4891
|
+
return null;
|
|
4892
|
+
}
|
|
4893
|
+
var UNIT_ALIASES = {
|
|
4894
|
+
docker: "dockerd",
|
|
4895
|
+
ssh: "sshd",
|
|
4896
|
+
mysql: "mysqld",
|
|
4897
|
+
mariadb: "mariadbd",
|
|
4898
|
+
redis: "redis-server",
|
|
4899
|
+
mongodb: "mongod",
|
|
4900
|
+
apache: "apache2",
|
|
4901
|
+
rsyslog: "rsyslogd",
|
|
4902
|
+
"systemd-networkd": "systemd-udevd",
|
|
4903
|
+
dbus: "dbus-daemon",
|
|
4904
|
+
avahi: "avahi-daemon",
|
|
4905
|
+
bluetooth: "bluetoothd",
|
|
4906
|
+
cups: "cupsd",
|
|
4907
|
+
chrony: "chronyd"
|
|
4908
|
+
};
|
|
4909
|
+
function serviceOf(name) {
|
|
4910
|
+
const leaf = name.replace(/^.*[\\/]/, "").replace(/\.service$/, "").replace(/@.*$/, "");
|
|
4911
|
+
const lower2 = leaf.toLowerCase();
|
|
4912
|
+
return SYSTEM_SERVICES.find((s) => s.toLowerCase() === lower2) ?? UNIT_ALIASES[lower2] ?? null;
|
|
4913
|
+
}
|
|
4914
|
+
|
|
4807
4915
|
// src/shell/inline-code.ts
|
|
4808
4916
|
var MAX_INLINE_CODE = 64 * 1024;
|
|
4809
4917
|
var WHAT = {
|
|
@@ -4816,8 +4924,22 @@ var WHAT = {
|
|
|
4816
4924
|
"builds-code": "runs code it builds at run time",
|
|
4817
4925
|
permissions: "changes permissions or ownership",
|
|
4818
4926
|
monitors: "captures the screen, the clipboard or the keyboard",
|
|
4819
|
-
amplifies: "writes or sends in an endless loop"
|
|
4927
|
+
amplifies: "writes or sends in an endless loop",
|
|
4928
|
+
"kills-service": "stops a system service"
|
|
4820
4929
|
};
|
|
4930
|
+
var KILL_API = {
|
|
4931
|
+
python: /\bos\.kill(?:pg)?\s*\(|\.(?:kill|terminate)\s*\(|\bsignal\.SIGKILL\b/,
|
|
4932
|
+
node: /\bprocess\.kill\s*\(|\.kill\s*\(\s*['"`]?SIG/,
|
|
4933
|
+
perl: /\bkill\s+(?:-?\d+|['"]?[A-Z]+['"]?)\s*,/,
|
|
4934
|
+
ruby: /\bProcess\.kill\b/,
|
|
4935
|
+
php: /\bposix_kill\s*\(/
|
|
4936
|
+
};
|
|
4937
|
+
function killsService(language, code) {
|
|
4938
|
+
const api = KILL_API[language].exec(code);
|
|
4939
|
+
if (!api) return null;
|
|
4940
|
+
const service = serviceNamedIn(code);
|
|
4941
|
+
return service ? `${api[0].trim()} with ${service}` : null;
|
|
4942
|
+
}
|
|
4821
4943
|
var OUTSIDE = String.raw`(?:~|\.\.[\\/]|/(?!(?:tmp|var/tmp)/(?![^'"\n]*\.\.)|dev/(?:null|stdout|stderr)\b))`;
|
|
4822
4944
|
var pyImport = (mods) => new RegExp(String.raw`\b(?:import\s+(?:[\w.]+(?:\s+as\s+\w+)?\s*,\s*)*|from\s+)(?:${mods})\b`);
|
|
4823
4945
|
var either = (...res) => new RegExp(res.map((r) => `(?:${r.source})`).join("|"), "m");
|
|
@@ -5107,6 +5229,15 @@ function judgeInlineCode(language, code, isProtected) {
|
|
|
5107
5229
|
return { outcome: "unreadable", what: "is too long for node9 to read" };
|
|
5108
5230
|
}
|
|
5109
5231
|
const text = language === "python" ? resolvePythonAliases(code) : code;
|
|
5232
|
+
const killed = killsService(language, text);
|
|
5233
|
+
if (killed) {
|
|
5234
|
+
return {
|
|
5235
|
+
outcome: "dangerous",
|
|
5236
|
+
what: WHAT["kills-service"],
|
|
5237
|
+
evidence: killed.slice(0, 60),
|
|
5238
|
+
category: "kills-service"
|
|
5239
|
+
};
|
|
5240
|
+
}
|
|
5110
5241
|
for (const [category, re] of TABLES[language]) {
|
|
5111
5242
|
const m = re.exec(text);
|
|
5112
5243
|
if (!m) continue;
|
|
@@ -12595,6 +12726,62 @@ function validateAssignedSecret(raw, before = "") {
|
|
|
12595
12726
|
const mixed = /[0-9]/.test(value) && /[A-Za-z]/.test(value);
|
|
12596
12727
|
return looksGenerated(value, 12, mixed ? 3 : 3.5);
|
|
12597
12728
|
}
|
|
12729
|
+
var INLINE_SECRET_NAMES = /* @__PURE__ */ new Set([
|
|
12730
|
+
"AWS_SECRET_ACCESS_KEY",
|
|
12731
|
+
"AWS_SESSION_TOKEN",
|
|
12732
|
+
"GITHUB_TOKEN",
|
|
12733
|
+
"GH_TOKEN",
|
|
12734
|
+
"NPM_TOKEN",
|
|
12735
|
+
"OPENAI_API_KEY",
|
|
12736
|
+
"ANTHROPIC_API_KEY",
|
|
12737
|
+
"DATABASE_URL"
|
|
12738
|
+
]);
|
|
12739
|
+
var INLINE_SECRET_PARTS_RE = /([A-Z][A-Z0-9_]*)=([\s\S]+)$/;
|
|
12740
|
+
var INLINE_REFERENCE_RE = /[$`]/;
|
|
12741
|
+
var INLINE_FIXTURE_WORDS = /* @__PURE__ */ new Set([
|
|
12742
|
+
...["dummy", "fake", "mock", "stub", "placeholder", "changeme", "redacted", "sample"],
|
|
12743
|
+
...["test", "tests", "testing", "real", "invalid", "bogus", "nonexistent", "notreal"]
|
|
12744
|
+
]);
|
|
12745
|
+
var INLINE_PLACEHOLDER_WORDS = /* @__PURE__ */ new Set([
|
|
12746
|
+
...["pass", "password", "passwd", "pwd", "secret", "token", "key", "apikey", "value"],
|
|
12747
|
+
...["admin", "administrator", "root", "user", "guest", "demo", "default", "letmein", "qwerty"],
|
|
12748
|
+
...["test", "testing", "example", "sample", "dummy", "fake", "mock", "stub", "placeholder"],
|
|
12749
|
+
...["changeme", "change", "replace", "insert", "paste", "fill", "put", "set", "me", "in", "it"],
|
|
12750
|
+
...["your", "my", "the", "a", "here", "goes", "string", "foo", "bar", "baz", "todo", "fixme"],
|
|
12751
|
+
...["redacted", "hidden", "omitted", "removed", "masked", "none", "null", "undefined", "nil"],
|
|
12752
|
+
...["xxx", "postgres", "mysql", "mariadb", "redis", "mongo", "dev", "development", "local"],
|
|
12753
|
+
...["localhost", "docker", "ci", "invalid", "unset", "empty", "missing", "skip", "noop"]
|
|
12754
|
+
]);
|
|
12755
|
+
function isInlinePlaceholder(value) {
|
|
12756
|
+
const lower2 = value.toLowerCase();
|
|
12757
|
+
if (/^(.)\1*$/.test(value)) return true;
|
|
12758
|
+
if (/^<.*>$/.test(value) || /^\[.*\]$/.test(value)) return true;
|
|
12759
|
+
if (BASIC_TEMPLATE_MARKERS.some((m) => lower2.includes(m))) return true;
|
|
12760
|
+
if (hasSequentialRun(value)) return true;
|
|
12761
|
+
const words = lower2.split(/[^a-z]+/).filter(Boolean);
|
|
12762
|
+
if (words.some((w) => INLINE_FIXTURE_WORDS.has(w))) return true;
|
|
12763
|
+
return words.length > 0 && words.every((w) => INLINE_PLACEHOLDER_WORDS.has(w));
|
|
12764
|
+
}
|
|
12765
|
+
function validateInlineSecretAssignment(raw) {
|
|
12766
|
+
const parts = raw.match(INLINE_SECRET_PARTS_RE);
|
|
12767
|
+
if (!parts) return false;
|
|
12768
|
+
const name = parts[1];
|
|
12769
|
+
let value = parts[2];
|
|
12770
|
+
const quote = value.charAt(0);
|
|
12771
|
+
if ((quote === '"' || quote === "'") && value.endsWith(quote)) value = value.slice(1, -1);
|
|
12772
|
+
if (value === "") return false;
|
|
12773
|
+
if (quote !== "'" && INLINE_REFERENCE_RE.test(value)) return false;
|
|
12774
|
+
if (isInlinePlaceholder(value)) return false;
|
|
12775
|
+
if (rejectedByStructuredValidator(value)) return false;
|
|
12776
|
+
if (name === "DATABASE_URL") {
|
|
12777
|
+
const password = capturedValue(value, DB_URL_PASSWORD_RE);
|
|
12778
|
+
return password !== null && !isInlinePlaceholder(password);
|
|
12779
|
+
}
|
|
12780
|
+
if (INLINE_SECRET_NAMES.has(name)) return true;
|
|
12781
|
+
if (!nameHoldsCredential(name)) return false;
|
|
12782
|
+
if (value.length < 8 || IDENTIFIER_VALUE_RE.test(value)) return false;
|
|
12783
|
+
return true;
|
|
12784
|
+
}
|
|
12598
12785
|
var CIPHER_KEY_NAME_RE = /^([A-Za-z_][\w.]{0,40})/;
|
|
12599
12786
|
var CIPHER_NAME_PARTS = /* @__PURE__ */ new Set([
|
|
12600
12787
|
"cipher",
|
|
@@ -13309,6 +13496,26 @@ var DLP_PATTERNS = [
|
|
|
13309
13496
|
keywords: ["pass", "pwd", "secret", "token", "key", "ticket"],
|
|
13310
13497
|
validate: validateAssignedSecret,
|
|
13311
13498
|
argumentsOnly: true
|
|
13499
|
+
},
|
|
13500
|
+
// ── Known secret variable assigned a literal ──────────────────────────────
|
|
13501
|
+
// `AWS_SECRET_ACCESS_KEY=… aws s3 ls`, `export GH_TOKEN=… && gh api`, `env
|
|
13502
|
+
// NPM_TOKEN=… npm publish`, and a `*_SECRET` / `*_TOKEN` / `*_PASSWORD` /
|
|
13503
|
+
// `*_API_KEY` name in the same place. The name starts a shell word (the
|
|
13504
|
+
// start of the text, a space, a newline, `;`, `&`, `|`, `(`), so an
|
|
13505
|
+
// assignment given as an argument (`docker run -e GITHUB_TOKEN=…`) is the
|
|
13506
|
+
// same handoff and counts too; the value is the rest of the word, or a
|
|
13507
|
+
// quoted string. The validator decides by the
|
|
13508
|
+
// name (node9Firewall#451): see validateInlineSecretAssignment. review, as
|
|
13509
|
+
// every name-based finding: the shape of the value is not checked, so a
|
|
13510
|
+
// human confirms rather than the gate deciding alone.
|
|
13511
|
+
{
|
|
13512
|
+
name: "Inline Secret Assignment",
|
|
13513
|
+
regex: /(?:^|[\s;&|(])((?:AWS_SECRET_ACCESS_KEY|AWS_SESSION_TOKEN|GITHUB_TOKEN|GH_TOKEN|NPM_TOKEN|OPENAI_API_KEY|ANTHROPIC_API_KEY|DATABASE_URL)|[A-Z][A-Z0-9_]{0,60}_(?:SECRET|TOKEN|PASSWORD|API_KEY))=("[^"\n]{1,512}"|'[^'\n]{1,512}'|[^\s;&|"'`()<>]{1,512})/,
|
|
13514
|
+
severity: "review",
|
|
13515
|
+
keywords: ["_secret", "_token", "_password", "_api_key", "database_url"],
|
|
13516
|
+
validate: validateInlineSecretAssignment,
|
|
13517
|
+
redactGroup: 2,
|
|
13518
|
+
argumentsOnly: true
|
|
13312
13519
|
}
|
|
13313
13520
|
];
|
|
13314
13521
|
var DLP_PATTERNS_GLOBAL = DLP_PATTERNS.map(
|
|
@@ -13404,12 +13611,14 @@ function assertBuiltinPatternsAreSafe() {
|
|
|
13404
13611
|
}
|
|
13405
13612
|
}
|
|
13406
13613
|
assertBuiltinPatternsAreSafe();
|
|
13407
|
-
function maskSecret(raw, pattern) {
|
|
13614
|
+
function maskSecret(raw, pattern, redactGroup) {
|
|
13408
13615
|
const match = raw.match(pattern);
|
|
13409
13616
|
if (!match) return "****";
|
|
13410
13617
|
const secret = match[0];
|
|
13411
13618
|
if (secret.length < 8) return "****";
|
|
13412
13619
|
const prefix = secret.slice(0, 4);
|
|
13620
|
+
const group = redactGroup !== void 0 ? match[redactGroup] : void 0;
|
|
13621
|
+
if (typeof group === "string" && group.length < 8) return `${prefix}****`;
|
|
13413
13622
|
const suffix = secret.slice(-4);
|
|
13414
13623
|
const stars = "*".repeat(Math.min(secret.length - 8, 12));
|
|
13415
13624
|
return `${prefix}${stars}${suffix}`;
|
|
@@ -13464,7 +13673,7 @@ function matchArgumentText(text, fieldPath, budget) {
|
|
|
13464
13673
|
const match = {
|
|
13465
13674
|
patternName: pattern.name,
|
|
13466
13675
|
fieldPath,
|
|
13467
|
-
redactedSample: maskSecret(raw, pattern.regex),
|
|
13676
|
+
redactedSample: maskSecret(raw, pattern.regex, pattern.redactGroup),
|
|
13468
13677
|
severity
|
|
13469
13678
|
};
|
|
13470
13679
|
if (severity === "block") return match;
|
|
@@ -17219,6 +17428,7 @@ var MAP_GOVERNED = /* @__PURE__ */ new Set([
|
|
|
17219
17428
|
"commands.sql-no-where",
|
|
17220
17429
|
"commands.temp-binary",
|
|
17221
17430
|
"commands.disk-destroy",
|
|
17431
|
+
"commands.system-processes",
|
|
17222
17432
|
"commands.dangerous-word",
|
|
17223
17433
|
"commands.node9-disarm",
|
|
17224
17434
|
"commands.reverse-shell",
|
|
@@ -17930,6 +18140,126 @@ function scanArgumentSecrets(args) {
|
|
|
17930
18140
|
} : null;
|
|
17931
18141
|
}
|
|
17932
18142
|
|
|
18143
|
+
// src/shell/processes.ts
|
|
18144
|
+
var PRESCREEN_RE3 = /\b(?:kill|pkill|killall|systemctl|service|launchctl|xargs)\b/;
|
|
18145
|
+
var KILL_SIGNAL_RE = /^-(?:\d+|s|SIG[A-Z]+|[A-Z]{2,})$/;
|
|
18146
|
+
var SYSTEMCTL_STOP_VERBS = /* @__PURE__ */ new Set(["stop", "kill", "disable", "mask"]);
|
|
18147
|
+
var LAUNCHCTL_UNLOAD_VERBS = /* @__PURE__ */ new Set(["unload", "bootout", "remove"]);
|
|
18148
|
+
var LAUNCH_DAEMONS_RE = /(?:^|\/)(?:System\/)?Library\/LaunchDaemons\//;
|
|
18149
|
+
var MAX_PAYLOAD_DEPTH5 = 3;
|
|
18150
|
+
function shownOf2(words) {
|
|
18151
|
+
return words.map((w) => w ?? "$?").join(" ").slice(0, 80);
|
|
18152
|
+
}
|
|
18153
|
+
function withoutComments(command) {
|
|
18154
|
+
return command.split("\n").map((line) => {
|
|
18155
|
+
for (let i = 0; i < line.length; i++) {
|
|
18156
|
+
if (line[i] === "#" && (i === 0 || line[i - 1] === " " || line[i - 1] === " ")) {
|
|
18157
|
+
return line.slice(0, i);
|
|
18158
|
+
}
|
|
18159
|
+
}
|
|
18160
|
+
return line;
|
|
18161
|
+
}).join("\n");
|
|
18162
|
+
}
|
|
18163
|
+
function detectSystemProcessStop(command, depth = 0) {
|
|
18164
|
+
if (!PRESCREEN_RE3.test(command)) return null;
|
|
18165
|
+
const named = serviceNamedIn(withoutComments(command));
|
|
18166
|
+
let direct = null;
|
|
18167
|
+
let dynamicKill = null;
|
|
18168
|
+
walkCommandScope(command, (node) => {
|
|
18169
|
+
const n = node;
|
|
18170
|
+
if (direct || !n || n.kind !== "CallExpr") return true;
|
|
18171
|
+
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
18172
|
+
if (words.length === 0) return true;
|
|
18173
|
+
if (baseWord(words[0]) === "xargs" && words.some((w) => w !== null && baseWord(w) === "kill")) {
|
|
18174
|
+
dynamicKill ??= shownOf2(words);
|
|
18175
|
+
return true;
|
|
18176
|
+
}
|
|
18177
|
+
if (depth < MAX_PAYLOAD_DEPTH5) {
|
|
18178
|
+
const payload = literalShellPayload(words, baseWord(words[0]));
|
|
18179
|
+
if (payload !== null) {
|
|
18180
|
+
const inner = detectSystemProcessStop(payload, depth + 1);
|
|
18181
|
+
if (inner) direct = inner;
|
|
18182
|
+
return true;
|
|
18183
|
+
}
|
|
18184
|
+
}
|
|
18185
|
+
const head = unwrapCommandHead(words);
|
|
18186
|
+
if (head >= words.length) return true;
|
|
18187
|
+
const name = baseWord(words[head]);
|
|
18188
|
+
const rest = words.slice(head + 1);
|
|
18189
|
+
const shown = shownOf2(words);
|
|
18190
|
+
const viaXargs = words.slice(0, head).some((w) => w !== null && baseWord(w) === "xargs");
|
|
18191
|
+
if (name === "kill") {
|
|
18192
|
+
const targets = [];
|
|
18193
|
+
for (let i = 0; i < rest.length; i++) {
|
|
18194
|
+
const w = rest[i];
|
|
18195
|
+
if (i === 0 && w !== null && KILL_SIGNAL_RE.test(w)) {
|
|
18196
|
+
if (w === "-s") i++;
|
|
18197
|
+
continue;
|
|
18198
|
+
}
|
|
18199
|
+
if (w === "--") continue;
|
|
18200
|
+
targets.push(w);
|
|
18201
|
+
}
|
|
18202
|
+
if (targets.some((t) => t === "1" || t === "-1")) {
|
|
18203
|
+
direct = { service: "init (pid 1)", how: "kills", shown };
|
|
18204
|
+
} else if (viaXargs || targets.some((t) => t === null)) {
|
|
18205
|
+
dynamicKill ??= shown;
|
|
18206
|
+
}
|
|
18207
|
+
return true;
|
|
18208
|
+
}
|
|
18209
|
+
if (name === "pkill" || name === "killall") {
|
|
18210
|
+
let skipValue = false;
|
|
18211
|
+
for (const w of rest) {
|
|
18212
|
+
if (skipValue) {
|
|
18213
|
+
skipValue = false;
|
|
18214
|
+
continue;
|
|
18215
|
+
}
|
|
18216
|
+
if (w !== null && w.startsWith("-")) {
|
|
18217
|
+
if (/^-(?:u|U|g|G|t|P|s|n|o|r|q|-signal|-uid|-user)$/.test(w)) skipValue = true;
|
|
18218
|
+
continue;
|
|
18219
|
+
}
|
|
18220
|
+
if (w === null) {
|
|
18221
|
+
dynamicKill ??= shown;
|
|
18222
|
+
continue;
|
|
18223
|
+
}
|
|
18224
|
+
const service = serviceOf(w) ?? serviceNamedIn(w);
|
|
18225
|
+
if (service) direct = { service, how: "kills", shown };
|
|
18226
|
+
}
|
|
18227
|
+
return true;
|
|
18228
|
+
}
|
|
18229
|
+
if (name === "systemctl") {
|
|
18230
|
+
if (rest.includes("--user")) return true;
|
|
18231
|
+
const verb = rest.find((w) => w !== null && !w.startsWith("-"));
|
|
18232
|
+
if (verb === void 0 || verb === null || !SYSTEMCTL_STOP_VERBS.has(verb)) return true;
|
|
18233
|
+
for (const w of rest.slice(rest.indexOf(verb) + 1)) {
|
|
18234
|
+
const service = w === null ? null : serviceOf(w);
|
|
18235
|
+
if (service) direct = { service, how: verb === "kill" ? "kills" : "stops", shown };
|
|
18236
|
+
}
|
|
18237
|
+
return true;
|
|
18238
|
+
}
|
|
18239
|
+
if (name === "service") {
|
|
18240
|
+
const [unit, verb] = rest;
|
|
18241
|
+
const service = typeof unit === "string" ? serviceOf(unit) : null;
|
|
18242
|
+
if (service && verb === "stop") direct = { service, how: "stops", shown };
|
|
18243
|
+
return true;
|
|
18244
|
+
}
|
|
18245
|
+
if (name === "launchctl") {
|
|
18246
|
+
const verb = rest.find((w) => w !== null && !w.startsWith("-"));
|
|
18247
|
+
if (verb === void 0 || verb === null || !LAUNCHCTL_UNLOAD_VERBS.has(verb)) return true;
|
|
18248
|
+
const daemon = rest.find((w) => w !== null && LAUNCH_DAEMONS_RE.test(w));
|
|
18249
|
+
if (daemon) {
|
|
18250
|
+
direct = { service: daemon.replace(/^.*\//, ""), how: "unloads the system daemon", shown };
|
|
18251
|
+
}
|
|
18252
|
+
return true;
|
|
18253
|
+
}
|
|
18254
|
+
return true;
|
|
18255
|
+
});
|
|
18256
|
+
if (direct) return direct;
|
|
18257
|
+
if (dynamicKill !== null && named) {
|
|
18258
|
+
return { service: named, how: "kills the processes of", shown: dynamicKill };
|
|
18259
|
+
}
|
|
18260
|
+
return null;
|
|
18261
|
+
}
|
|
18262
|
+
|
|
17933
18263
|
// src/shell/node9-disarm.ts
|
|
17934
18264
|
var RULE_NAME2 = "review-node9-disarm";
|
|
17935
18265
|
var DESCRIPTION = "The AI wants to stop node9, remove it, or change its own files. These are your commands to run, not the agent's: with the daemon stopped the outside-content and taint checks are off.";
|
|
@@ -18605,6 +18935,17 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
18605
18935
|
checkId: "commands.eval-dynamic"
|
|
18606
18936
|
});
|
|
18607
18937
|
}
|
|
18938
|
+
const stopped = detectSystemProcessStop(shellCommand);
|
|
18939
|
+
if (stopped) {
|
|
18940
|
+
consider("commands.system-processes", {
|
|
18941
|
+
decision: "review",
|
|
18942
|
+
blockedByLabel: "Node9: System Service Stopped",
|
|
18943
|
+
reason: `The AI ${stopped.how} ${stopped.service}: ${stopped.shown}`,
|
|
18944
|
+
ruleDescription: "The AI stops or kills a system service (sshd, dockerd, systemd, a database or web server). Other people and programs on this machine depend on it; confirm this is intentional.",
|
|
18945
|
+
tier: 3,
|
|
18946
|
+
checkId: "commands.system-processes"
|
|
18947
|
+
});
|
|
18948
|
+
}
|
|
18608
18949
|
const builtin = strictestVerdict(candidates);
|
|
18609
18950
|
if (builtin) return builtin;
|
|
18610
18951
|
{
|
|
@@ -20078,7 +20419,8 @@ function classifyRuleSeverity(name, verdict) {
|
|
|
20078
20419
|
"rebase",
|
|
20079
20420
|
"delete-branch",
|
|
20080
20421
|
"delete-remote",
|
|
20081
|
-
"unknown-registry"
|
|
20422
|
+
"unknown-registry",
|
|
20423
|
+
"system-processes"
|
|
20082
20424
|
];
|
|
20083
20425
|
if (highPatterns.some((p) => n.includes(p))) return "high";
|
|
20084
20426
|
if (verdict === "block") return "high";
|
|
@@ -20118,6 +20460,7 @@ function narrativeRuleLabel(name) {
|
|
|
20118
20460
|
"reverse-shell": "reverse shell",
|
|
20119
20461
|
"env-exfil": "environment sent out",
|
|
20120
20462
|
"unknown-registry": "install from an unknown registry",
|
|
20463
|
+
"system-processes": "system service stopped",
|
|
20121
20464
|
"agent-file-write": "agent instruction file written",
|
|
20122
20465
|
"agent-file-content": "instruction written into an agent file",
|
|
20123
20466
|
"agent-hooks-change": "agent hooks changed",
|
|
@@ -20430,7 +20773,7 @@ function matchCanaryArgs(args, values) {
|
|
|
20430
20773
|
// src/scan/canonical.ts
|
|
20431
20774
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
20432
20775
|
var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
20433
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
20776
|
+
var CANONICAL_EXTRACTOR_HASH = "40803f3331f55a36";
|
|
20434
20777
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
20435
20778
|
function extractCanonicalFindings(call, ctx) {
|
|
20436
20779
|
const out = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node9/policy-engine",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.55.1",
|
|
4
4
|
"description": "Shared policy evaluation engine for node9 — DLP, smart rules, AST shell parsing, shields, loop detection. Pure functions, no I/O. Used by both node9-proxy and the node9 SaaS firewall.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://node9.ai",
|