@node9/policy-engine 2.65.7 → 2.65.8
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 +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +647 -109
- package/dist/index.mjs +644 -109
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -675,13 +675,27 @@ var project_jail_default = {
|
|
|
675
675
|
{
|
|
676
676
|
field: "file_path",
|
|
677
677
|
op: "matches",
|
|
678
|
-
value: "([\\/\\\\]\\.ssh([\\/\\\\]
|
|
678
|
+
value: "([\\/\\\\]\\.ssh(?:$|[\\/\\\\](?!(?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$))|^\\.ssh[\\/\\\\](?!(?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$))",
|
|
679
679
|
flags: "i"
|
|
680
680
|
}
|
|
681
681
|
],
|
|
682
682
|
verdict: "block",
|
|
683
683
|
reason: "Reading SSH private keys is blocked by project-jail shield"
|
|
684
684
|
},
|
|
685
|
+
{
|
|
686
|
+
name: "shield:project-jail:block-write-ssh-trust-files",
|
|
687
|
+
tool: "!(read|read_file|grep|grep_search)",
|
|
688
|
+
conditions: [
|
|
689
|
+
{
|
|
690
|
+
field: "file_path",
|
|
691
|
+
op: "matches",
|
|
692
|
+
value: "(?:^|[\\/\\\\])\\.ssh[\\/\\\\](?:known_hosts(?:\\.old)?|authorized_keys2?|[^\\\\/]+\\.pub)$",
|
|
693
|
+
flags: "i"
|
|
694
|
+
}
|
|
695
|
+
],
|
|
696
|
+
verdict: "block",
|
|
697
|
+
reason: "Changing SSH keys and trusted hosts is blocked by project-jail shield"
|
|
698
|
+
},
|
|
685
699
|
{
|
|
686
700
|
name: "shield:project-jail:block-read-aws-any-tool",
|
|
687
701
|
tool: "*",
|
|
@@ -2122,15 +2136,15 @@ function ssrfExemptMatches(entries, normalized) {
|
|
|
2122
2136
|
continue;
|
|
2123
2137
|
}
|
|
2124
2138
|
if (!target) continue;
|
|
2125
|
-
const
|
|
2139
|
+
const base4 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
|
|
2126
2140
|
const prefixText = entry.slice(slash + 1);
|
|
2127
2141
|
const prefix = /^\d+$/.test(prefixText) ? Number(prefixText) : NaN;
|
|
2128
|
-
if (!
|
|
2142
|
+
if (!base4 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
|
|
2129
2143
|
// differ, so `0.0.0.0/0` does not release `::1`.
|
|
2130
|
-
|
|
2144
|
+
base4.length !== target.length || prefix > base4.length) {
|
|
2131
2145
|
continue;
|
|
2132
2146
|
}
|
|
2133
|
-
if (
|
|
2147
|
+
if (base4.slice(0, prefix) === target.slice(0, prefix)) return true;
|
|
2134
2148
|
}
|
|
2135
2149
|
return false;
|
|
2136
2150
|
}
|
|
@@ -3411,7 +3425,7 @@ var LEGACY_TO_ID = new Map(
|
|
|
3411
3425
|
function ssrfCheckId(tier) {
|
|
3412
3426
|
return isStrictGatedTier(tier) ? "network.internal-addresses" : "network.metadata";
|
|
3413
3427
|
}
|
|
3414
|
-
var PROJECT_JAIL_BLOCK_READ = /^shield:project-jail:block-read-(ssh|aws|env)(-any-tool)
|
|
3428
|
+
var PROJECT_JAIL_BLOCK_READ = /^shield:project-jail:(?:block-read-(ssh|aws|env)(-any-tool)?|block-write-ssh-trust-files)$/;
|
|
3415
3429
|
var OVERRIDE_PREFIX = "Override block rule:";
|
|
3416
3430
|
var LABEL_WRAPPERS = ["Smart Rule:", "Node9 (AST):", "project-jail (AST):"];
|
|
3417
3431
|
function ruleNameInLabel(s) {
|
|
@@ -3929,6 +3943,14 @@ function normalizeFilePath(p, cwd = "", home = "~") {
|
|
|
3929
3943
|
}
|
|
3930
3944
|
return (rooted ? "/" : "") + parts.join("/");
|
|
3931
3945
|
}
|
|
3946
|
+
var PUBLIC_SSH_NAME_SOURCE = String.raw`(?:known_hosts(?:\.old)?|authorized_keys2?|[^\\/]+\.pub)`;
|
|
3947
|
+
var PUBLIC_SSH_PATH_RE = new RegExp(
|
|
3948
|
+
String.raw`(?:^|[\\/])\.ssh[\\/]${PUBLIC_SSH_NAME_SOURCE}$`,
|
|
3949
|
+
"i"
|
|
3950
|
+
);
|
|
3951
|
+
function isPublicSshMaterial(p) {
|
|
3952
|
+
return PUBLIC_SSH_PATH_RE.test(p);
|
|
3953
|
+
}
|
|
3932
3954
|
|
|
3933
3955
|
// src/shell/index.ts
|
|
3934
3956
|
import picomatch from "picomatch";
|
|
@@ -4163,7 +4185,7 @@ function sedSubstitutions(script) {
|
|
|
4163
4185
|
}
|
|
4164
4186
|
return out.length > 0 ? out : null;
|
|
4165
4187
|
}
|
|
4166
|
-
function collectShellFileAccesses(command, context = {}) {
|
|
4188
|
+
function collectShellFileAccesses(command, context = {}, report) {
|
|
4167
4189
|
const out = [];
|
|
4168
4190
|
let payloads = 256;
|
|
4169
4191
|
const functions = /* @__PURE__ */ new Map();
|
|
@@ -4189,7 +4211,11 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4189
4211
|
});
|
|
4190
4212
|
}
|
|
4191
4213
|
function nestedPayload(payload, state, depth) {
|
|
4192
|
-
if (payload === null
|
|
4214
|
+
if (payload === null) return;
|
|
4215
|
+
if (depth >= MAX_PAYLOAD_DEPTH || payloads-- <= 0) {
|
|
4216
|
+
if (report) report.exhausted = true;
|
|
4217
|
+
return;
|
|
4218
|
+
}
|
|
4193
4219
|
const f = parseShared(payload);
|
|
4194
4220
|
if (typeof f !== "symbol") statements(f.Stmts ?? [], state, depth + 1);
|
|
4195
4221
|
}
|
|
@@ -4768,8 +4794,107 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4768
4794
|
}
|
|
4769
4795
|
return null;
|
|
4770
4796
|
}
|
|
4797
|
+
function heredocScript(word) {
|
|
4798
|
+
let text = "";
|
|
4799
|
+
for (const part of word?.Parts ?? []) {
|
|
4800
|
+
if (part?.kind === "Lit") {
|
|
4801
|
+
text += part.Value ?? "";
|
|
4802
|
+
continue;
|
|
4803
|
+
}
|
|
4804
|
+
text += resolveWordLiteral({ Parts: [part] }) ?? "$N9_UNRESOLVED";
|
|
4805
|
+
}
|
|
4806
|
+
return text;
|
|
4807
|
+
}
|
|
4808
|
+
function stdinScriptText(stmt) {
|
|
4809
|
+
for (const redir of stmt?.Redirs ?? []) {
|
|
4810
|
+
if (redir.Hdoc) return heredocScript(redir.Hdoc);
|
|
4811
|
+
if (redir.Op === ops().HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
4812
|
+
}
|
|
4813
|
+
return null;
|
|
4814
|
+
}
|
|
4815
|
+
function printfText(stmt) {
|
|
4816
|
+
const cmd = stmt?.Cmd;
|
|
4817
|
+
if (!cmd || cmd.kind !== "CallExpr") return null;
|
|
4818
|
+
const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
4819
|
+
if (words.some((w) => w === null)) return null;
|
|
4820
|
+
const head = unwrapCommandHead(words);
|
|
4821
|
+
if (base(words[head]) !== "printf") return null;
|
|
4822
|
+
const rest = words.slice(head + 1);
|
|
4823
|
+
if (rest[0] === "--") rest.shift();
|
|
4824
|
+
if (rest.length === 0 || rest[0].startsWith("-")) return null;
|
|
4825
|
+
const [format, ...args] = rest;
|
|
4826
|
+
const directive = /%(?:%|[-+ #0]*(?:\d+|\*)?(?:\.(?:\d+|\*))?[a-zA-Z])/g;
|
|
4827
|
+
let text = "";
|
|
4828
|
+
let next = 0;
|
|
4829
|
+
for (let round = 0; round < 64; round++) {
|
|
4830
|
+
let used = false;
|
|
4831
|
+
text += format.replace(directive, (d) => {
|
|
4832
|
+
if (d === "%%") return "%";
|
|
4833
|
+
used = true;
|
|
4834
|
+
return args[next++] ?? "";
|
|
4835
|
+
});
|
|
4836
|
+
if (!used || next >= args.length) break;
|
|
4837
|
+
}
|
|
4838
|
+
return text;
|
|
4839
|
+
}
|
|
4840
|
+
function soleStatement(stmt) {
|
|
4841
|
+
let cur = stmt;
|
|
4842
|
+
for (let i = 0; i < 8; i++) {
|
|
4843
|
+
const cmd = cur?.Cmd;
|
|
4844
|
+
if (!cmd || cmd.kind !== "Subshell" && cmd.kind !== "Block") break;
|
|
4845
|
+
if ((cur.Redirs ?? []).length > 0 || (cmd.Stmts ?? []).length !== 1) break;
|
|
4846
|
+
cur = cmd.Stmts[0];
|
|
4847
|
+
}
|
|
4848
|
+
return cur;
|
|
4849
|
+
}
|
|
4850
|
+
function passesStdinThrough(stmt, depth = 0) {
|
|
4851
|
+
const cmd = stmt?.Cmd;
|
|
4852
|
+
if (cmd && (cmd.kind === "Subshell" || cmd.kind === "Block"))
|
|
4853
|
+
return depth <= 4 && (stmt.Redirs ?? []).length === 0 && (cmd.Stmts ?? []).some((inner) => passesStdinThrough(inner, depth + 1));
|
|
4854
|
+
if (!cmd || cmd.kind !== "CallExpr") return false;
|
|
4855
|
+
const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
4856
|
+
const head = unwrapCommandHead(words);
|
|
4857
|
+
const name = base(words[head]);
|
|
4858
|
+
const rest = words.slice(head + 1);
|
|
4859
|
+
if (name === "tee") return true;
|
|
4860
|
+
return name === "cat" && rest.every((w) => w === "-" || w !== null && /^-[A-Za-z]+$/.test(w));
|
|
4861
|
+
}
|
|
4862
|
+
function producedScripts(stmt, depth = 0) {
|
|
4863
|
+
const cmd = stmt?.Cmd;
|
|
4864
|
+
if (!cmd) return [];
|
|
4865
|
+
if (cmd.kind === "Subshell" || cmd.kind === "Block") {
|
|
4866
|
+
if (depth > 4 || (stmt.Redirs ?? []).length > 0) return [];
|
|
4867
|
+
const first = [];
|
|
4868
|
+
const last = [];
|
|
4869
|
+
for (const inner of cmd.Stmts ?? []) {
|
|
4870
|
+
const readings = producedScripts(inner, depth + 1);
|
|
4871
|
+
if (readings.length === 0) continue;
|
|
4872
|
+
first.push(readings[0]);
|
|
4873
|
+
last.push(readings[readings.length - 1]);
|
|
4874
|
+
}
|
|
4875
|
+
if (first.length === 0) return [];
|
|
4876
|
+
const a = first.join("\n");
|
|
4877
|
+
const b = last.join("\n");
|
|
4878
|
+
return a === b ? [a] : [a, b];
|
|
4879
|
+
}
|
|
4880
|
+
if (cmd.kind !== "CallExpr") return [];
|
|
4881
|
+
const words = (cmd.Args ?? []).map((w) => resolveWordLiteral(w));
|
|
4882
|
+
if (words.length === 1 && base(words[0]) === "cat") {
|
|
4883
|
+
const text2 = stdinScriptText(stmt);
|
|
4884
|
+
return text2 === null ? [] : [text2];
|
|
4885
|
+
}
|
|
4886
|
+
const formatted = printfText(stmt);
|
|
4887
|
+
if (formatted !== null) return [decodeAnsiC(formatted)];
|
|
4888
|
+
const text = producedText(stmt);
|
|
4889
|
+
if (text === null) return [];
|
|
4890
|
+
if (!text.includes("\\")) return [text];
|
|
4891
|
+
const head = unwrapCommandHead(words);
|
|
4892
|
+
const decodes = words.slice(head + 1).some((w) => w !== null && /^-[neE]+$/.test(w) && w.includes("e"));
|
|
4893
|
+
const decoded = decodeAnsiC(text);
|
|
4894
|
+
return decodes || decoded === text ? [decoded] : [text, decoded];
|
|
4895
|
+
}
|
|
4771
4896
|
function stdinScript(stmt, state, depth) {
|
|
4772
|
-
if (readsScriptFromStdin(stmt)) nestedPayload(
|
|
4897
|
+
if (readsScriptFromStdin(stmt)) nestedPayload(stdinScriptText(stmt), clone(state), depth);
|
|
4773
4898
|
}
|
|
4774
4899
|
function statement(stmt, state, depth) {
|
|
4775
4900
|
if (!stmt || depth > MAX_DEPTH) return;
|
|
@@ -4824,18 +4949,23 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4824
4949
|
}
|
|
4825
4950
|
const seen = clone(state);
|
|
4826
4951
|
let pureAnd = true;
|
|
4952
|
+
let flowing = [];
|
|
4827
4953
|
segments2.forEach(({ op, part }, i) => {
|
|
4828
4954
|
if (op === ops().AND || op === ops().OR) {
|
|
4829
4955
|
if (i > 0 && op === ops().AND && pureAnd && state.onSuccess)
|
|
4830
4956
|
state.cwd = state.onSuccess;
|
|
4831
4957
|
if (i > 0 && op === ops().OR) merge(state, seen);
|
|
4958
|
+
flowing = [];
|
|
4832
4959
|
statement(part, state, depth + 1);
|
|
4833
4960
|
} else {
|
|
4834
4961
|
const fed = i > 0 ? producedText(segments2[i - 1].part) : null;
|
|
4835
4962
|
if (fed !== null) pipedStdin.set(part, fed);
|
|
4836
4963
|
statement(part, clone(state), depth + 1);
|
|
4837
|
-
|
|
4838
|
-
|
|
4964
|
+
const incoming = i > 0 ? flowing : [];
|
|
4965
|
+
if (i > 0 && readsScriptFromStdin(soleStatement(part)))
|
|
4966
|
+
for (const script of incoming) nestedPayload(script, clone(state), depth);
|
|
4967
|
+
const own = producedScripts(part);
|
|
4968
|
+
flowing = [...passesStdinThrough(part) ? incoming : [], ...own].slice(0, 4);
|
|
4839
4969
|
if (fed !== null) nestedPayload(xargsPayload(part, fed), clone(state), depth);
|
|
4840
4970
|
}
|
|
4841
4971
|
if (i > 0 && op !== ops().AND) pureAnd = false;
|
|
@@ -4915,6 +5045,140 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4915
5045
|
return out;
|
|
4916
5046
|
}
|
|
4917
5047
|
|
|
5048
|
+
// src/shell/dotenv-cli.ts
|
|
5049
|
+
var base2 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
|
|
5050
|
+
var FILE_FLAGS = /* @__PURE__ */ new Set(["-f", "--file", "-e", "--env-file"]);
|
|
5051
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
5052
|
+
"-q",
|
|
5053
|
+
"--quote",
|
|
5054
|
+
"-v",
|
|
5055
|
+
"--env",
|
|
5056
|
+
"-fk",
|
|
5057
|
+
"--env-keys-file",
|
|
5058
|
+
"--convention",
|
|
5059
|
+
"--log-level"
|
|
5060
|
+
]);
|
|
5061
|
+
var QUIET_SUBCOMMANDS = /* @__PURE__ */ new Set([
|
|
5062
|
+
"set",
|
|
5063
|
+
"unset",
|
|
5064
|
+
"encrypt",
|
|
5065
|
+
"ls",
|
|
5066
|
+
"help",
|
|
5067
|
+
"version",
|
|
5068
|
+
"rotate",
|
|
5069
|
+
"genexample",
|
|
5070
|
+
"gitignore",
|
|
5071
|
+
"prebuild",
|
|
5072
|
+
"precommit",
|
|
5073
|
+
"keypair",
|
|
5074
|
+
"ext"
|
|
5075
|
+
]);
|
|
5076
|
+
function filesAfter(words, from, files) {
|
|
5077
|
+
for (let j = from; j < words.length; j++) {
|
|
5078
|
+
const w = words[j];
|
|
5079
|
+
if (w === null) continue;
|
|
5080
|
+
if (FILE_FLAGS.has(w)) {
|
|
5081
|
+
if (words[j + 1] !== void 0) files.push(words[j + 1]);
|
|
5082
|
+
j++;
|
|
5083
|
+
continue;
|
|
5084
|
+
}
|
|
5085
|
+
const joined = /^(?:--file|--env-file)=(.*)$/.exec(w);
|
|
5086
|
+
if (joined) files.push(joined[1]);
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
function dotenvArgsStart(words, head) {
|
|
5090
|
+
const name = base2(words[head]);
|
|
5091
|
+
if (name === "dotenv" || name === "dotenv-cli" || name === "dotenvx") return head + 1;
|
|
5092
|
+
if (name === "bundle" && words[head + 1] === "exec" && base2(words[head + 2]) === "dotenv")
|
|
5093
|
+
return head + 3;
|
|
5094
|
+
if (/^(?:python[\d.]*|py)$/.test(name)) {
|
|
5095
|
+
for (let i = head + 1; i < words.length; i++) {
|
|
5096
|
+
const w = words[i];
|
|
5097
|
+
if (w === null || !w.startsWith("-")) return -1;
|
|
5098
|
+
if (w === "-m") return words[i + 1] === "dotenv" ? i + 2 : -1;
|
|
5099
|
+
if (w === "-c") return -1;
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
return -1;
|
|
5103
|
+
}
|
|
5104
|
+
function readDotenvCli(words, head) {
|
|
5105
|
+
const start = dotenvArgsStart(words, head);
|
|
5106
|
+
if (start < 0) return null;
|
|
5107
|
+
const files = [];
|
|
5108
|
+
let print = false;
|
|
5109
|
+
let sawRun = false;
|
|
5110
|
+
let inner = -1;
|
|
5111
|
+
let i = start;
|
|
5112
|
+
while (i < words.length) {
|
|
5113
|
+
const w = words[i];
|
|
5114
|
+
if (w === null) {
|
|
5115
|
+
inner = i;
|
|
5116
|
+
break;
|
|
5117
|
+
}
|
|
5118
|
+
if (w === "--") {
|
|
5119
|
+
inner = i + 1;
|
|
5120
|
+
break;
|
|
5121
|
+
}
|
|
5122
|
+
if (FILE_FLAGS.has(w)) {
|
|
5123
|
+
const value = words[i + 1];
|
|
5124
|
+
if (!(w === "-e" && (value === "true" || value === "false")) && value !== void 0)
|
|
5125
|
+
files.push(value);
|
|
5126
|
+
i += 2;
|
|
5127
|
+
continue;
|
|
5128
|
+
}
|
|
5129
|
+
const joined = /^(?:--file|--env-file)=(.*)$/.exec(w);
|
|
5130
|
+
if (joined) {
|
|
5131
|
+
files.push(joined[1]);
|
|
5132
|
+
i++;
|
|
5133
|
+
continue;
|
|
5134
|
+
}
|
|
5135
|
+
if (w === "-p" || w === "--print") {
|
|
5136
|
+
print = true;
|
|
5137
|
+
i += 2;
|
|
5138
|
+
continue;
|
|
5139
|
+
}
|
|
5140
|
+
if (VALUE_FLAGS.has(w)) {
|
|
5141
|
+
i += 2;
|
|
5142
|
+
continue;
|
|
5143
|
+
}
|
|
5144
|
+
if (w === "-c" || w === "--cascade") {
|
|
5145
|
+
const value = words[i + 1];
|
|
5146
|
+
const after = words[i + 2];
|
|
5147
|
+
const takes = typeof value === "string" && !value.startsWith("-") && typeof after === "string" && after.startsWith("-");
|
|
5148
|
+
i += takes ? 2 : 1;
|
|
5149
|
+
continue;
|
|
5150
|
+
}
|
|
5151
|
+
if (w.startsWith("-")) {
|
|
5152
|
+
i++;
|
|
5153
|
+
continue;
|
|
5154
|
+
}
|
|
5155
|
+
if (!sawRun) {
|
|
5156
|
+
if (w === "list" || w === "get") {
|
|
5157
|
+
print = true;
|
|
5158
|
+
filesAfter(words, i + 1, files);
|
|
5159
|
+
break;
|
|
5160
|
+
}
|
|
5161
|
+
if (w === "run") {
|
|
5162
|
+
sawRun = true;
|
|
5163
|
+
i++;
|
|
5164
|
+
continue;
|
|
5165
|
+
}
|
|
5166
|
+
if (w === "decrypt") {
|
|
5167
|
+
print = words.slice(i + 1).some((x) => x === "--stdout");
|
|
5168
|
+
filesAfter(words, i + 1, files);
|
|
5169
|
+
break;
|
|
5170
|
+
}
|
|
5171
|
+
if (QUIET_SUBCOMMANDS.has(w)) return null;
|
|
5172
|
+
}
|
|
5173
|
+
inner = i;
|
|
5174
|
+
break;
|
|
5175
|
+
}
|
|
5176
|
+
const loaded = files.length > 0 ? files : [".env"];
|
|
5177
|
+
if (print) return { files: loaded, mode: "print", inner: -1 };
|
|
5178
|
+
if (inner >= 0 && inner < words.length) return { files: loaded, mode: "run", inner };
|
|
5179
|
+
return null;
|
|
5180
|
+
}
|
|
5181
|
+
|
|
4918
5182
|
// src/shell/services.ts
|
|
4919
5183
|
var INFRASTRUCTURE_SERVICES = [
|
|
4920
5184
|
"init",
|
|
@@ -5274,8 +5538,19 @@ var DOTENV = {
|
|
|
5274
5538
|
values: /\b(?:dotenv_values|get_key)\s*\(/,
|
|
5275
5539
|
env: /\b(?:environ|getenv)\b/,
|
|
5276
5540
|
literalPath: /\b(?:load_dotenv|dotenv_values)\s*\(\s*(?:dotenv_path\s*=\s*)?[rRbBuU]?['"]/
|
|
5541
|
+
},
|
|
5542
|
+
// Ruby's dotenv gem (node9Firewall#443): `require "dotenv/load"` loads on
|
|
5543
|
+
// require; `require "dotenv"` alone does not, it needs Dotenv.load.
|
|
5544
|
+
ruby: {
|
|
5545
|
+
load: /\brequire\s*\(?\s*['"]dotenv\/load['"]|\bDotenv\s*\.\s*(?:load|overload|parse)\b/,
|
|
5546
|
+
values: /\bDotenv\s*\.\s*parse\b/,
|
|
5547
|
+
env: /\bENV\b/,
|
|
5548
|
+
literalPath: /\bDotenv\s*\.\s*(?:load|overload|parse)\s*\(?\s*['"]/
|
|
5277
5549
|
}
|
|
5278
5550
|
};
|
|
5551
|
+
function inlineReadsEnvironment(language, code) {
|
|
5552
|
+
return language === "python" || language === "node" || language === "ruby" ? DOTENV[language].env.test(code) : false;
|
|
5553
|
+
}
|
|
5279
5554
|
var DOTENV_PATH_OPTION = /\bconfig\s*\(\s*\{[^)]*\bpath\s*:\s*$/;
|
|
5280
5555
|
function inlineReadPaths(language, code, preload = {}) {
|
|
5281
5556
|
const out = [];
|
|
@@ -5301,7 +5576,7 @@ function inlineReadPaths(language, code, preload = {}) {
|
|
|
5301
5576
|
for (const m of code.matchAll(OPENED_NAME[language])) opened.add(m[1] ?? m[2]);
|
|
5302
5577
|
for (const [name, values] of assigned) if (opened.has(name)) out.push(...values);
|
|
5303
5578
|
}
|
|
5304
|
-
if (language === "python" || language === "node") {
|
|
5579
|
+
if (language === "python" || language === "node" || language === "ruby") {
|
|
5305
5580
|
const d = DOTENV[language];
|
|
5306
5581
|
const readsEnv = d.env.test(code);
|
|
5307
5582
|
const loads = /dotenv/.test(code) && d.load.test(code) && !d.literalPath.test(code);
|
|
@@ -6580,7 +6855,12 @@ var SENSITIVE_PATH_RULES = [
|
|
|
6580
6855
|
{
|
|
6581
6856
|
rule: "shield:project-jail:block-read-ssh",
|
|
6582
6857
|
reason: "Reading SSH private keys is blocked by project-jail shield",
|
|
6583
|
-
|
|
6858
|
+
// Public material is not a key (JAIL-16): `known_hosts`, `authorized_keys`
|
|
6859
|
+
// and `*.pub` are readable. Because the exemption lives in the rule itself,
|
|
6860
|
+
// the copy tier sees `x.pub` as a destination OUTSIDE the jail, so
|
|
6861
|
+
// `cp ~/.ssh/id_rsa ~/.ssh/x.pub` is a reviewed copy, not a quiet rename
|
|
6862
|
+
// followed by an allowed read.
|
|
6863
|
+
match: (p) => /([\\/]\.ssh[\\/]|^\.ssh[\\/]|^(?:[~/]|[A-Za-z]:).*[\\/]\.ssh$)/i.test(p) && !isPublicSshMaterial(p)
|
|
6584
6864
|
},
|
|
6585
6865
|
{
|
|
6586
6866
|
rule: "shield:project-jail:block-read-aws",
|
|
@@ -6949,6 +7229,7 @@ function attachedCode(interp, flag) {
|
|
|
6949
7229
|
return rest === "" ? null : rest;
|
|
6950
7230
|
}
|
|
6951
7231
|
var NODE_VALUE_FLAG = /^(-r|--require|--import|--loader|--experimental-loader|--env-file|--env-file-if-exists|--input-type|-C|--conditions)(?:=(.*))?$/;
|
|
7232
|
+
var RUBY_VALUE_FLAG = /^-([rI])(.*)$/;
|
|
6952
7233
|
function inlineExecCall(stmt, pipeFed) {
|
|
6953
7234
|
const cmd = stmt?.Cmd;
|
|
6954
7235
|
if (!cmd || cmd.kind !== "CallExpr") return null;
|
|
@@ -6982,6 +7263,7 @@ function inlineExecCall(stmt, pipeFed) {
|
|
|
6982
7263
|
const codes = [];
|
|
6983
7264
|
const preload = {};
|
|
6984
7265
|
const nodeFamily = inlineLanguageOf(interp) === "node";
|
|
7266
|
+
const rubyFamily = inlineLanguageOf(interp) === "ruby";
|
|
6985
7267
|
for (let i = 0; i < args.length; i++) {
|
|
6986
7268
|
const a = args[i];
|
|
6987
7269
|
if (nodeFamily && !selectedProgram && codes.length === 0 && a != null) {
|
|
@@ -6991,10 +7273,21 @@ function inlineExecCall(stmt, pipeFed) {
|
|
|
6991
7273
|
if (value != null) {
|
|
6992
7274
|
if (/^--env-file/.test(flag[1])) (preload.envFiles ??= []).push(value);
|
|
6993
7275
|
else if (/^dotenv\/config(?:\.js)?$/.test(value)) preload.dotenv = true;
|
|
7276
|
+
} else if (/^--env-file/.test(flag[1])) {
|
|
7277
|
+
preload.unknownEnvFile = true;
|
|
6994
7278
|
}
|
|
6995
7279
|
continue;
|
|
6996
7280
|
}
|
|
6997
7281
|
}
|
|
7282
|
+
if (rubyFamily && !selectedProgram && codes.length === 0 && a != null) {
|
|
7283
|
+
const flag = RUBY_VALUE_FLAG.exec(a);
|
|
7284
|
+
if (flag) {
|
|
7285
|
+
const value = flag[2] !== "" ? flag[2] : args[++i];
|
|
7286
|
+
if (flag[1] === "r" && value != null && /^dotenv\/load(?:\.rb)?$/.test(value))
|
|
7287
|
+
preload.dotenv = true;
|
|
7288
|
+
continue;
|
|
7289
|
+
}
|
|
7290
|
+
}
|
|
6998
7291
|
if (a == null) {
|
|
6999
7292
|
if (codes.length > 0) break;
|
|
7000
7293
|
positionals2++;
|
|
@@ -7333,7 +7626,7 @@ var NET_BINARIES = /* @__PURE__ */ new Set([
|
|
|
7333
7626
|
"netcat",
|
|
7334
7627
|
"rsync"
|
|
7335
7628
|
]);
|
|
7336
|
-
var
|
|
7629
|
+
var VALUE_FLAGS2 = {
|
|
7337
7630
|
// rsync 3.2.7, its own --help: every flag whose operand could be mistaken for
|
|
7338
7631
|
// a host. `-e ssh` is the one that matters most (`ssh` is not the destination).
|
|
7339
7632
|
rsync: /* @__PURE__ */ new Set([
|
|
@@ -7903,7 +8196,7 @@ function parseDestHost(token) {
|
|
|
7903
8196
|
return null;
|
|
7904
8197
|
}
|
|
7905
8198
|
function destTokensForBinary(binary, args) {
|
|
7906
|
-
const valueFlags =
|
|
8199
|
+
const valueFlags = VALUE_FLAGS2[binary] ?? /* @__PURE__ */ new Set();
|
|
7907
8200
|
const positionals2 = [];
|
|
7908
8201
|
const urlFlagValues = [];
|
|
7909
8202
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -8055,7 +8348,9 @@ var FS_OP_CACHE_MAX = 5e3;
|
|
|
8055
8348
|
var fsOpCache = /* @__PURE__ */ new Map();
|
|
8056
8349
|
function analyzeFsOperation(command) {
|
|
8057
8350
|
const normalized = normalizeCommandForPolicy(command);
|
|
8058
|
-
|
|
8351
|
+
const stdinShell = feedsShellStdin(command) || feedsShellStdin(normalized);
|
|
8352
|
+
const dotenvCli = DOTENV_CLI_PRESCREEN_RE.test(command) || DOTENV_CLI_PRESCREEN_RE.test(normalized);
|
|
8353
|
+
if (!FS_OP_PRESCREEN_RE.test(normalized) && !FS_OP_PRESCREEN_RE.test(command) && !SOURCES_FILE_RE.test(command) && !runsInlineInterpreter(command, normalized) && !stdinShell && !dotenvCli)
|
|
8059
8354
|
return null;
|
|
8060
8355
|
if (fsOpCache.has(command)) {
|
|
8061
8356
|
const hit = fsOpCache.get(command) ?? null;
|
|
@@ -8063,8 +8358,10 @@ function analyzeFsOperation(command) {
|
|
|
8063
8358
|
fsOpCache.set(command, hit);
|
|
8064
8359
|
return hit;
|
|
8065
8360
|
}
|
|
8066
|
-
const
|
|
8067
|
-
const
|
|
8361
|
+
const own = analyzeFsOperationImpl(command);
|
|
8362
|
+
const direct = stdinShell && own?.verdict !== "block" ? stricter(own, structuralJailRead(command)) : own ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
|
|
8363
|
+
const withInline = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
|
|
8364
|
+
const computed = withInline?.verdict === "block" || !dotenvCli ? withInline : stricter(withInline, dotenvCliJailRead(command));
|
|
8068
8365
|
if (fsOpCache.size >= FS_OP_CACHE_MAX) {
|
|
8069
8366
|
const oldest = fsOpCache.keys().next().value;
|
|
8070
8367
|
if (oldest !== void 0) fsOpCache.delete(oldest);
|
|
@@ -8074,8 +8371,8 @@ function analyzeFsOperation(command) {
|
|
|
8074
8371
|
}
|
|
8075
8372
|
var stripDotSlash = (p) => p.replace(/^\.\//, "");
|
|
8076
8373
|
function isSensitiveCleanupName(p) {
|
|
8077
|
-
const
|
|
8078
|
-
return /^\.env(\.|$)/i.test(
|
|
8374
|
+
const base4 = p.replace(/^.*[\\/]/, "");
|
|
8375
|
+
return /^\.env(\.|$)/i.test(base4) || /(?:^|[\\/])\.(?:ssh|aws|gnupg|git)(?:[\\/]|$)/i.test(p) || /\.(?:pem|key|p12|pfx|crt)$/i.test(base4) || /^\.?(?:netrc|npmrc|pgpass|htpasswd)$/i.test(base4) || /^id_(?:rsa|dsa|ecdsa|ed25519)/i.test(base4) || /credential/i.test(p) || /secret/i.test(base4);
|
|
8079
8376
|
}
|
|
8080
8377
|
function isWaivableCleanupTarget(p) {
|
|
8081
8378
|
if (/^[/~]/.test(p) || /^\$/.test(p)) return false;
|
|
@@ -8530,6 +8827,11 @@ function matchSensitivePath(p) {
|
|
|
8530
8827
|
return null;
|
|
8531
8828
|
}
|
|
8532
8829
|
var INDIRECT_SHAPE_RE = /\b(?:for|while|until|find|xargs|set|source)\b|\$\{?PWD\b|[*?[]|(?:^|[;&|(\s])\.\s/;
|
|
8830
|
+
var STDIN_SHELL_WORD_RE = new RegExp(
|
|
8831
|
+
`(?:^|[\\s;&|(/\\\\])(?:${[...SHELL_INTERPRETERS].map((name) => name.replace(/[.*+?^\${}()|[\]\\]/g, "\\$&")).join("|")})(?=$|[\\s;&|)<])`,
|
|
8832
|
+
"i"
|
|
8833
|
+
);
|
|
8834
|
+
var feedsShellStdin = (command) => /\||<</.test(command) && STDIN_SHELL_WORD_RE.test(command);
|
|
8533
8835
|
var SOURCES_FILE_RE = /(?:^|[;&|(\s])(?:source|\.)\s/;
|
|
8534
8836
|
function printsEnvironment(words) {
|
|
8535
8837
|
const [name, ...rest] = words;
|
|
@@ -8802,8 +9104,17 @@ function analyzeUnknownCredentialReads(command) {
|
|
|
8802
9104
|
}
|
|
8803
9105
|
return !hit;
|
|
8804
9106
|
});
|
|
8805
|
-
|
|
8806
|
-
|
|
9107
|
+
if (hit)
|
|
9108
|
+
return {
|
|
9109
|
+
reason: "Files are read by names a listing produces when the command runs, and the listing can include credential files"
|
|
9110
|
+
};
|
|
9111
|
+
let unknownEnvFile = false;
|
|
9112
|
+
try {
|
|
9113
|
+
unknownEnvFile = readsUnknownEnvFile(command) || dotenvCliReads(command).unknown;
|
|
9114
|
+
} catch {
|
|
9115
|
+
}
|
|
9116
|
+
return unknownEnvFile ? {
|
|
9117
|
+
reason: "An environment file is loaded and its values are shown, and its name is not known until the command runs: it can be a credential file"
|
|
8807
9118
|
} : null;
|
|
8808
9119
|
}
|
|
8809
9120
|
var JAILED_GLOB_NAMES = [
|
|
@@ -8829,6 +9140,7 @@ function matchSensitiveGlob(glob, dotGlob) {
|
|
|
8829
9140
|
}
|
|
8830
9141
|
});
|
|
8831
9142
|
glob = parts.join("/");
|
|
9143
|
+
if (isPublicSshMaterial(glob)) return null;
|
|
8832
9144
|
const first = parts.findIndex((seg) => GLOB_META.test(seg));
|
|
8833
9145
|
if (first < 0) return matchSensitivePath(glob);
|
|
8834
9146
|
const prefix = parts.slice(0, first).join("/");
|
|
@@ -8855,8 +9167,9 @@ function matchSensitiveGlob(glob, dotGlob) {
|
|
|
8855
9167
|
}
|
|
8856
9168
|
function structuralJailRead(command) {
|
|
8857
9169
|
let accesses;
|
|
9170
|
+
const report = { exhausted: false };
|
|
8858
9171
|
try {
|
|
8859
|
-
accesses = collectShellFileAccesses(command);
|
|
9172
|
+
accesses = collectShellFileAccesses(command, {}, report);
|
|
8860
9173
|
} catch {
|
|
8861
9174
|
return null;
|
|
8862
9175
|
}
|
|
@@ -8872,7 +9185,7 @@ function structuralJailRead(command) {
|
|
|
8872
9185
|
if (hit?.verdict === "block") return hit;
|
|
8873
9186
|
review ??= hit;
|
|
8874
9187
|
}
|
|
8875
|
-
return review;
|
|
9188
|
+
return report.exhausted ? stricter(review, UNANALYSABLE_NESTING) : review;
|
|
8876
9189
|
}
|
|
8877
9190
|
var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
|
|
8878
9191
|
var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
|
|
@@ -8894,6 +9207,77 @@ function inlineCodeJailRead(command) {
|
|
|
8894
9207
|
}
|
|
8895
9208
|
return review;
|
|
8896
9209
|
}
|
|
9210
|
+
var DOTENV_CLI_PRESCREEN_RE = /\bdotenvx?\b/i;
|
|
9211
|
+
var MAX_DOTENV_PAYLOAD_DEPTH = 3;
|
|
9212
|
+
function dotenvCliReads(command, depth = 0) {
|
|
9213
|
+
const out = { paths: [], unknown: false };
|
|
9214
|
+
if (depth > MAX_DOTENV_PAYLOAD_DEPTH || !DOTENV_CLI_PRESCREEN_RE.test(command)) return out;
|
|
9215
|
+
const bytes = new TextEncoder().encode(command);
|
|
9216
|
+
const sourceOf = (from, to) => typeof from === "number" && typeof to === "number" && from >= 0 && to > from ? new TextDecoder().decode(bytes.subarray(from, to)) : "";
|
|
9217
|
+
walkCommandScope(command, (node) => {
|
|
9218
|
+
const n = node;
|
|
9219
|
+
if (!n || n.kind !== "CallExpr") return true;
|
|
9220
|
+
const args = n.Args || [];
|
|
9221
|
+
const words = args.map((a) => resolveWordLiteral(a));
|
|
9222
|
+
if (words.length === 0) return true;
|
|
9223
|
+
const call = readDotenvCli(words, unwrapCommandHead(words));
|
|
9224
|
+
if (!call) {
|
|
9225
|
+
const payload = literalShellPayload(words, baseWord(words[0]));
|
|
9226
|
+
if (payload !== null) {
|
|
9227
|
+
const inner = dotenvCliReads(payload, depth + 1);
|
|
9228
|
+
out.paths.push(...inner.paths);
|
|
9229
|
+
out.unknown ||= inner.unknown;
|
|
9230
|
+
}
|
|
9231
|
+
return true;
|
|
9232
|
+
}
|
|
9233
|
+
let shown = call.mode === "print";
|
|
9234
|
+
if (!shown) {
|
|
9235
|
+
const inner = words.slice(call.inner);
|
|
9236
|
+
const literal = (ws) => ws.length > 0 && ws.every((w) => w !== null);
|
|
9237
|
+
const plain = inner.slice(unwrapCommandHead(inner));
|
|
9238
|
+
shown = literal(inner) && printsEnvironment(inner) || literal(plain) && printsEnvironment(plain);
|
|
9239
|
+
const payload = shown ? null : literalShellPayload(inner, baseWord(inner[0]));
|
|
9240
|
+
if (payload !== null && sourcedAndPrinted(`. .env
|
|
9241
|
+
${payload}`) !== null) shown = true;
|
|
9242
|
+
if (!shown) {
|
|
9243
|
+
const text = sourceOf(args[call.inner]?.pos, args[args.length - 1]?.end);
|
|
9244
|
+
const calls = text ? inlineExecCalls(text) : [];
|
|
9245
|
+
if (calls !== PARSE_FAIL)
|
|
9246
|
+
shown = calls.some((c) => {
|
|
9247
|
+
const language = inlineLanguageOf(c.interp);
|
|
9248
|
+
return language !== null && c.code.some((code) => code !== null && inlineReadsEnvironment(language, code));
|
|
9249
|
+
});
|
|
9250
|
+
}
|
|
9251
|
+
}
|
|
9252
|
+
if (!shown) return true;
|
|
9253
|
+
for (const file of call.files) {
|
|
9254
|
+
if (file === null) out.unknown = true;
|
|
9255
|
+
else out.paths.push(file);
|
|
9256
|
+
}
|
|
9257
|
+
return true;
|
|
9258
|
+
});
|
|
9259
|
+
return out;
|
|
9260
|
+
}
|
|
9261
|
+
function dotenvCliJailRead(command) {
|
|
9262
|
+
let result = null;
|
|
9263
|
+
try {
|
|
9264
|
+
for (const p of dotenvCliReads(command).paths) {
|
|
9265
|
+
result = stricter(result, matchSensitivePath(p));
|
|
9266
|
+
if (result?.verdict === "block") break;
|
|
9267
|
+
}
|
|
9268
|
+
} catch {
|
|
9269
|
+
}
|
|
9270
|
+
return result;
|
|
9271
|
+
}
|
|
9272
|
+
function readsUnknownEnvFile(command) {
|
|
9273
|
+
if (!/--env-file/.test(command)) return false;
|
|
9274
|
+
const calls = inlineExecCalls(command);
|
|
9275
|
+
if (calls === PARSE_FAIL) return false;
|
|
9276
|
+
return calls.some((c) => {
|
|
9277
|
+
const language = inlineLanguageOf(c.interp);
|
|
9278
|
+
return c.preload?.unknownEnvFile === true && language !== null && c.code.some((code) => code !== null && inlineReadsEnvironment(language, code));
|
|
9279
|
+
});
|
|
9280
|
+
}
|
|
8897
9281
|
function baseWord(w) {
|
|
8898
9282
|
return (w ?? "").split("/").pop()?.toLowerCase() ?? "";
|
|
8899
9283
|
}
|
|
@@ -12033,6 +12417,120 @@ function secretViews(text, budget) {
|
|
|
12033
12417
|
return out;
|
|
12034
12418
|
}
|
|
12035
12419
|
|
|
12420
|
+
// src/dlp/placeholder.ts
|
|
12421
|
+
var TEMPLATE_RE = /\$\{|\{\{|%\{|<[^<>\s]{1,80}>/;
|
|
12422
|
+
var RUN_RE = /(.)\1{7}/;
|
|
12423
|
+
var DOMINANT_SHARE = 0.6;
|
|
12424
|
+
var DOC_WORDS = ["example", "sample", "fake", "dummy", "placeholder", "changeme", "redacted"];
|
|
12425
|
+
var STANDALONE_WORDS = /* @__PURE__ */ new Set([...DOC_WORDS, "your", "here", "insert", "replace"]);
|
|
12426
|
+
var DOC_EDGE_RE = new RegExp(
|
|
12427
|
+
`^(?:${DOC_WORDS.join("|")})|(?:${DOC_WORDS.join("|")})(?:[_-]?(?:key|token|secret))?$`
|
|
12428
|
+
);
|
|
12429
|
+
var VOCABULARY = [
|
|
12430
|
+
...DOC_WORDS,
|
|
12431
|
+
"your",
|
|
12432
|
+
"here",
|
|
12433
|
+
"insert",
|
|
12434
|
+
"replace",
|
|
12435
|
+
"put",
|
|
12436
|
+
"change",
|
|
12437
|
+
"goes",
|
|
12438
|
+
"with",
|
|
12439
|
+
"this",
|
|
12440
|
+
"please",
|
|
12441
|
+
"real",
|
|
12442
|
+
"actual",
|
|
12443
|
+
"me",
|
|
12444
|
+
"my",
|
|
12445
|
+
"the",
|
|
12446
|
+
"an",
|
|
12447
|
+
"key",
|
|
12448
|
+
"token",
|
|
12449
|
+
"secret",
|
|
12450
|
+
"password",
|
|
12451
|
+
"passwd",
|
|
12452
|
+
"api",
|
|
12453
|
+
"apikey",
|
|
12454
|
+
"access",
|
|
12455
|
+
"auth",
|
|
12456
|
+
"test",
|
|
12457
|
+
"value",
|
|
12458
|
+
"xxx"
|
|
12459
|
+
];
|
|
12460
|
+
var VOCABULARY_SET = new Set(VOCABULARY);
|
|
12461
|
+
var MAX_COMPOSED_SEGMENT = 48;
|
|
12462
|
+
function madeOfVocabulary(segment) {
|
|
12463
|
+
if (VOCABULARY_SET.has(segment)) return true;
|
|
12464
|
+
if (segment.length > MAX_COMPOSED_SEGMENT) return false;
|
|
12465
|
+
const reachable = new Array(segment.length + 1).fill(false);
|
|
12466
|
+
reachable[0] = true;
|
|
12467
|
+
for (let i = 0; i < segment.length; i++) {
|
|
12468
|
+
if (!reachable[i]) continue;
|
|
12469
|
+
for (const word of VOCABULARY) {
|
|
12470
|
+
if (segment.startsWith(word, i)) reachable[i + word.length] = true;
|
|
12471
|
+
}
|
|
12472
|
+
}
|
|
12473
|
+
return reachable[segment.length];
|
|
12474
|
+
}
|
|
12475
|
+
var isUpper = (c) => c >= 65 && c <= 90;
|
|
12476
|
+
var isLower = (c) => c >= 97 && c <= 122;
|
|
12477
|
+
function alphabeticSegments(token) {
|
|
12478
|
+
const segments2 = [];
|
|
12479
|
+
let start = -1;
|
|
12480
|
+
const close = (end) => {
|
|
12481
|
+
if (start >= 0) segments2.push(token.slice(start, end).toLowerCase());
|
|
12482
|
+
start = -1;
|
|
12483
|
+
};
|
|
12484
|
+
for (let i = 0; i < token.length; i++) {
|
|
12485
|
+
const c = token.charCodeAt(i);
|
|
12486
|
+
if (!isUpper(c) && !isLower(c)) {
|
|
12487
|
+
close(i);
|
|
12488
|
+
continue;
|
|
12489
|
+
}
|
|
12490
|
+
if (start >= 0 && isUpper(c)) {
|
|
12491
|
+
const prev = token.charCodeAt(i - 1);
|
|
12492
|
+
const next = i + 1 < token.length ? token.charCodeAt(i + 1) : 0;
|
|
12493
|
+
if (isLower(prev) || isUpper(prev) && isLower(next)) close(i);
|
|
12494
|
+
}
|
|
12495
|
+
if (start < 0) start = i;
|
|
12496
|
+
}
|
|
12497
|
+
close(token.length);
|
|
12498
|
+
return segments2;
|
|
12499
|
+
}
|
|
12500
|
+
function dominatedByOneChar(s) {
|
|
12501
|
+
if (s.length < 4) return false;
|
|
12502
|
+
const counts = /* @__PURE__ */ new Map();
|
|
12503
|
+
let top = 0;
|
|
12504
|
+
for (const ch of s) {
|
|
12505
|
+
const n = (counts.get(ch) ?? 0) + 1;
|
|
12506
|
+
counts.set(ch, n);
|
|
12507
|
+
if (n > top) top = n;
|
|
12508
|
+
}
|
|
12509
|
+
return top / s.length >= DOMINANT_SHARE;
|
|
12510
|
+
}
|
|
12511
|
+
var MAX_PHRASE_LENGTH = 160;
|
|
12512
|
+
function builtFromVocabulary(token) {
|
|
12513
|
+
if (token.length > MAX_PHRASE_LENGTH) return false;
|
|
12514
|
+
const segments2 = alphabeticSegments(token);
|
|
12515
|
+
if (segments2.length === 0 || !segments2.every(madeOfVocabulary)) return false;
|
|
12516
|
+
const letters = token.replace(/[^A-Za-z]/g, "").length;
|
|
12517
|
+
const alphanumerics = token.replace(/[^A-Za-z0-9]/g, "").length;
|
|
12518
|
+
return letters * 2 >= alphanumerics;
|
|
12519
|
+
}
|
|
12520
|
+
var PHRASE_RE = /^[a-z]{1,20}(?:[-_.][a-z]{1,20}){2,}$/;
|
|
12521
|
+
function isPhrase(secret) {
|
|
12522
|
+
return PHRASE_RE.test(secret);
|
|
12523
|
+
}
|
|
12524
|
+
function isPlaceholder(secret) {
|
|
12525
|
+
if (secret.length === 0) return false;
|
|
12526
|
+
if (TEMPLATE_RE.test(secret)) return true;
|
|
12527
|
+
if (RUN_RE.test(secret) || dominatedByOneChar(secret)) return true;
|
|
12528
|
+
const lower2 = secret.toLowerCase();
|
|
12529
|
+
if (lower2.split(/[^a-z0-9]+/).some((part) => STANDALONE_WORDS.has(part))) return true;
|
|
12530
|
+
if (DOC_EDGE_RE.test(lower2)) return true;
|
|
12531
|
+
return builtFromVocabulary(secret);
|
|
12532
|
+
}
|
|
12533
|
+
|
|
12036
12534
|
// src/scan/checksums.ts
|
|
12037
12535
|
import { createHash as createHash2 } from "crypto";
|
|
12038
12536
|
function validateLuhn(digits) {
|
|
@@ -12155,12 +12653,19 @@ var IBAN_LENGTH = {
|
|
|
12155
12653
|
YE: 30
|
|
12156
12654
|
};
|
|
12157
12655
|
var IBAN_BBAN_SHAPE = {
|
|
12656
|
+
// AD, AE, BA, EE: the registered countries whose code is two hex letters
|
|
12657
|
+
// and that had no shape here, so a hex id with that prefix and a lucky
|
|
12658
|
+
// mod-97 read as an IBAN (node9Firewall#369).
|
|
12659
|
+
AD: /^\d{8}[A-Z0-9]{12}$/,
|
|
12660
|
+
AE: /^\d{19}$/,
|
|
12158
12661
|
AT: /^\d{16}$/,
|
|
12662
|
+
BA: /^\d{16}$/,
|
|
12159
12663
|
BE: /^\d{12}$/,
|
|
12160
12664
|
CH: /^\d{5}[A-Z0-9]{12}$/,
|
|
12161
12665
|
CZ: /^\d{20}$/,
|
|
12162
12666
|
DE: /^\d{18}$/,
|
|
12163
12667
|
DK: /^\d{14}$/,
|
|
12668
|
+
EE: /^\d{16}$/,
|
|
12164
12669
|
ES: /^\d{20}$/,
|
|
12165
12670
|
FI: /^\d{14}$/,
|
|
12166
12671
|
FR: /^\d{10}[A-Z0-9]{11}\d{2}$/,
|
|
@@ -12580,9 +13085,9 @@ function validateBelgianNationalNumber(raw) {
|
|
|
12580
13085
|
if (!/^\d{11}$/.test(d)) return false;
|
|
12581
13086
|
const month = Number(d.slice(2, 4)) % 20;
|
|
12582
13087
|
if (month !== 0 && !plausibleDate(String(month).padStart(2, "0"), d.slice(4, 6))) return false;
|
|
12583
|
-
const
|
|
13088
|
+
const base4 = Number(d.slice(0, 9));
|
|
12584
13089
|
const check = Number(d.slice(9, 11));
|
|
12585
|
-
return 97 -
|
|
13090
|
+
return 97 - base4 % 97 === check || 97 - (2e9 + base4) % 97 === check;
|
|
12586
13091
|
}
|
|
12587
13092
|
function validateCuit(raw) {
|
|
12588
13093
|
const d = raw.replace(/-/g, "");
|
|
@@ -12709,32 +13214,6 @@ function shannonEntropy(s) {
|
|
|
12709
13214
|
}
|
|
12710
13215
|
return h;
|
|
12711
13216
|
}
|
|
12712
|
-
var DLP_STOPWORDS = [
|
|
12713
|
-
"example",
|
|
12714
|
-
"placeholder",
|
|
12715
|
-
"changeme",
|
|
12716
|
-
"your_key",
|
|
12717
|
-
"your_token",
|
|
12718
|
-
"your_secret",
|
|
12719
|
-
"replace_me",
|
|
12720
|
-
"insert_key",
|
|
12721
|
-
"put_your",
|
|
12722
|
-
"fake",
|
|
12723
|
-
"dummy",
|
|
12724
|
-
"sample",
|
|
12725
|
-
"xxxxxxxx",
|
|
12726
|
-
"aaaaaa",
|
|
12727
|
-
"bbbbbb",
|
|
12728
|
-
"00000000",
|
|
12729
|
-
"${",
|
|
12730
|
-
"{{",
|
|
12731
|
-
"%{",
|
|
12732
|
-
"<your",
|
|
12733
|
-
"test_key",
|
|
12734
|
-
"test_token",
|
|
12735
|
-
"your",
|
|
12736
|
-
"here"
|
|
12737
|
-
];
|
|
12738
13217
|
function capturedValue(raw, pattern) {
|
|
12739
13218
|
const m = raw.match(pattern);
|
|
12740
13219
|
return m?.[1] ?? null;
|
|
@@ -12767,8 +13246,7 @@ function rejectedByStructuredValidator(value) {
|
|
|
12767
13246
|
}
|
|
12768
13247
|
function looksGenerated(value, minLength, minEntropy, lettersOnlyAllowed = false) {
|
|
12769
13248
|
if (value.length < minLength) return false;
|
|
12770
|
-
|
|
12771
|
-
if (DLP_STOPWORDS.some((sw) => lower2.includes(sw))) return false;
|
|
13249
|
+
if (isPlaceholder(value)) return false;
|
|
12772
13250
|
if (REFERENCE_VALUE_RE.test(value)) return false;
|
|
12773
13251
|
if (!lettersOnlyAllowed && IDENTIFIER_VALUE_RE.test(value)) return false;
|
|
12774
13252
|
if (EMAIL_VALUE_RE.test(value)) return false;
|
|
@@ -12919,9 +13397,7 @@ var SQL_PASSWORD_VALUE_RE = /['"]([^'"\s]{8,128})['"]$/;
|
|
|
12919
13397
|
function validateSqlPassword(raw) {
|
|
12920
13398
|
const value = capturedValue(raw, SQL_PASSWORD_VALUE_RE);
|
|
12921
13399
|
if (value === null) return false;
|
|
12922
|
-
|
|
12923
|
-
if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || REFERENCE_VALUE_RE.test(value))
|
|
12924
|
-
return false;
|
|
13400
|
+
if (isPlaceholder(value) || REFERENCE_VALUE_RE.test(value)) return false;
|
|
12925
13401
|
if (/^[a-z]+$/i.test(value) && value.length < 12) return false;
|
|
12926
13402
|
return shannonEntropy(value) >= 2.5 && !hasSequentialRun(value);
|
|
12927
13403
|
}
|
|
@@ -12956,8 +13432,7 @@ function validateBasicCredential(raw, before = "") {
|
|
|
12956
13432
|
if (!pair) return false;
|
|
12957
13433
|
const password = pair[2];
|
|
12958
13434
|
if (!/[0-9]/.test(password) || !/[A-Za-z]/.test(password)) return false;
|
|
12959
|
-
|
|
12960
|
-
if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || hasSequentialRun(password)) return false;
|
|
13435
|
+
if (isPlaceholder(password) || hasSequentialRun(password)) return false;
|
|
12961
13436
|
return shannonEntropy(password) >= 3;
|
|
12962
13437
|
}
|
|
12963
13438
|
function headerPairIsCredential(text) {
|
|
@@ -12975,7 +13450,7 @@ function validateDropboxSecret(raw) {
|
|
|
12975
13450
|
const value = capturedValue(raw, DROPBOX_SECRET_RE);
|
|
12976
13451
|
if (value === null || value !== value.toLowerCase()) return false;
|
|
12977
13452
|
if (!/[0-9]/.test(value) || !/[a-z]/.test(value)) return false;
|
|
12978
|
-
if (
|
|
13453
|
+
if (isPlaceholder(value) || hasSequentialRun(value)) return false;
|
|
12979
13454
|
return shannonEntropy(value) >= 3;
|
|
12980
13455
|
}
|
|
12981
13456
|
var OTP_CAPTURE_RE = /["']([A-Z2-7]{16,128}=*)["']$/i;
|
|
@@ -12983,8 +13458,7 @@ var DB_URL_PASSWORD_RE = /:\/\/[^:/\s@]*:([^@\s]{4,})@/;
|
|
|
12983
13458
|
function validateDbConnectionString(raw) {
|
|
12984
13459
|
const password = capturedValue(raw, DB_URL_PASSWORD_RE);
|
|
12985
13460
|
if (password === null) return false;
|
|
12986
|
-
|
|
12987
|
-
if (DLP_STOPWORDS.some((sw) => lower2.includes(sw))) return false;
|
|
13461
|
+
if (isPlaceholder(password)) return false;
|
|
12988
13462
|
return shannonEntropy(raw) >= 3;
|
|
12989
13463
|
}
|
|
12990
13464
|
function validateOtpSecret(raw) {
|
|
@@ -13197,8 +13671,9 @@ var DLP_PATTERNS = [
|
|
|
13197
13671
|
// ── NPM ───────────────────────────────────────────────────────────────────
|
|
13198
13672
|
{
|
|
13199
13673
|
name: "NPM Auth Token",
|
|
13200
|
-
regex: /_authToken\s*=\s*[A-Za-z0-9_-]{20,}/,
|
|
13674
|
+
regex: /_authToken\s*=\s*([A-Za-z0-9_-]{20,})/,
|
|
13201
13675
|
severity: "block",
|
|
13676
|
+
secretGroup: 1,
|
|
13202
13677
|
keywords: ["_authtoken"]
|
|
13203
13678
|
},
|
|
13204
13679
|
// ── JWT ───────────────────────────────────────────────────────────────────
|
|
@@ -13315,7 +13790,11 @@ var DLP_PATTERNS = [
|
|
|
13315
13790
|
// ── PyPI ──────────────────────────────────────────────────────────────────
|
|
13316
13791
|
{
|
|
13317
13792
|
name: "PyPI Upload Token",
|
|
13318
|
-
|
|
13793
|
+
// A PyPI token is a macaroon whose base64 body always starts with the
|
|
13794
|
+
// same bytes: `pypi-AgEIcHlwaS5vcmc` (pypi.org), `pypi-AgENdGVzdC5weXBp`
|
|
13795
|
+
// (test.pypi.org). Without the `AgE` anchor any `pypi-<long-slug>` in a
|
|
13796
|
+
// URL matched (node9Firewall#374).
|
|
13797
|
+
regex: /\bpypi-AgE[A-Za-z0-9_-]{50,}\b/,
|
|
13319
13798
|
severity: "block",
|
|
13320
13799
|
keywords: ["pypi-"],
|
|
13321
13800
|
minEntropy: 3
|
|
@@ -13324,11 +13803,12 @@ var DLP_PATTERNS = [
|
|
|
13324
13803
|
// contextBoost: promoted to block when assigned (e.g. AUTH_TOKEN=Bearer eyJ...)
|
|
13325
13804
|
{
|
|
13326
13805
|
name: "Bearer Token",
|
|
13327
|
-
regex: /Bearer\s+[a-zA-Z0-9\-._~+/]{20,}=*/i,
|
|
13806
|
+
regex: /Bearer\s+([a-zA-Z0-9\-._~+/]{20,})=*/i,
|
|
13328
13807
|
severity: "review",
|
|
13329
13808
|
keywords: ["bearer"],
|
|
13330
13809
|
contextBoost: true,
|
|
13331
|
-
minEntropy: 3
|
|
13810
|
+
minEntropy: 3,
|
|
13811
|
+
secretGroup: 1
|
|
13332
13812
|
},
|
|
13333
13813
|
// ── HTTP Basic credential ─────────────────────────────────────────────────
|
|
13334
13814
|
// `Authorization: Basic <base64 of user:password>`, or the bare scheme in a
|
|
@@ -13398,8 +13878,9 @@ var DLP_PATTERNS = [
|
|
|
13398
13878
|
// ── Cloudinary ────────────────────────────────────────────────────────────
|
|
13399
13879
|
{
|
|
13400
13880
|
name: "Cloudinary URL",
|
|
13401
|
-
regex: /\bcloudinary:\/\/[0-9]+:[a-zA-Z0-9_-]
|
|
13881
|
+
regex: /\bcloudinary:\/\/[0-9]+:([a-zA-Z0-9_-]+)@[a-zA-Z0-9_-]+/,
|
|
13402
13882
|
severity: "block",
|
|
13883
|
+
secretGroup: 1,
|
|
13403
13884
|
keywords: ["cloudinary://"]
|
|
13404
13885
|
},
|
|
13405
13886
|
// ── Airtable ──────────────────────────────────────────────────────────────
|
|
@@ -13663,6 +14144,7 @@ var SENSITIVE_PATH_PATTERNS = [
|
|
|
13663
14144
|
];
|
|
13664
14145
|
function matchSensitivePath2(resolvedPath, originalPath, options = {}) {
|
|
13665
14146
|
const normalised = resolvedPath.replace(/\\/g, "/");
|
|
14147
|
+
if (options.readOnly && isPublicSshMaterial(normalised)) return null;
|
|
13666
14148
|
if (!options.systemAccessHandled && isLegacySystemPath(normalised))
|
|
13667
14149
|
return sensitivePathMatch(originalPath);
|
|
13668
14150
|
for (const pattern of SENSITIVE_PATH_PATTERNS) {
|
|
@@ -13697,6 +14179,16 @@ function assertBuiltinPatternsAreSafe() {
|
|
|
13697
14179
|
);
|
|
13698
14180
|
}
|
|
13699
14181
|
}
|
|
14182
|
+
for (const p of DLP_PATTERNS) {
|
|
14183
|
+
const groups = (new RegExp(`${p.regex.source}|`).exec("")?.length ?? 1) - 1;
|
|
14184
|
+
for (const index of [p.secretGroup, p.redactGroup]) {
|
|
14185
|
+
if (index !== void 0 && (index < 1 || index > groups)) {
|
|
14186
|
+
throw new Error(
|
|
14187
|
+
`[node9 engine] Builtin DLP pattern '${p.name}' names group ${index} of ${groups}`
|
|
14188
|
+
);
|
|
14189
|
+
}
|
|
14190
|
+
}
|
|
14191
|
+
}
|
|
13700
14192
|
for (const re of SENSITIVE_PATH_PATTERNS) {
|
|
13701
14193
|
if (!safeRegex2(re.source)) {
|
|
13702
14194
|
throw new Error(
|
|
@@ -13728,7 +14220,8 @@ var DLP_SCAN_LIMITS = {
|
|
|
13728
14220
|
/** Max nesting depth walked; anything deeper is NOT scanned. */
|
|
13729
14221
|
maxDepth: MAX_DEPTH2
|
|
13730
14222
|
};
|
|
13731
|
-
function suppressed(pattern,
|
|
14223
|
+
function suppressed(pattern, m, before = "") {
|
|
14224
|
+
const raw = m[0];
|
|
13732
14225
|
if (pattern.validate) {
|
|
13733
14226
|
let ok;
|
|
13734
14227
|
try {
|
|
@@ -13738,8 +14231,14 @@ function suppressed(pattern, raw, before = "") {
|
|
|
13738
14231
|
}
|
|
13739
14232
|
return !ok;
|
|
13740
14233
|
}
|
|
13741
|
-
|
|
13742
|
-
|
|
14234
|
+
const group = pattern.secretGroup !== void 0 ? m[pattern.secretGroup] : void 0;
|
|
14235
|
+
const secret = typeof group === "string" && group.length > 0 ? group : raw;
|
|
14236
|
+
if (isPlaceholder(secret) || isPhrase(secret)) return true;
|
|
14237
|
+
const lower2 = secret.toLowerCase();
|
|
14238
|
+
const prefix = pattern.keywords?.find((kw) => lower2.startsWith(kw.toLowerCase()));
|
|
14239
|
+
const body = prefix ? secret.slice(prefix.length) : "";
|
|
14240
|
+
if (prefix && (isPlaceholder(body) || isPhrase(body))) return true;
|
|
14241
|
+
if (pattern.minEntropy !== void 0 && shannonEntropy(secret) < pattern.minEntropy) return true;
|
|
13743
14242
|
return false;
|
|
13744
14243
|
}
|
|
13745
14244
|
function firstAcceptedMatch(pattern, text) {
|
|
@@ -13751,7 +14250,7 @@ function firstAcceptedMatch(pattern, text) {
|
|
|
13751
14250
|
re.lastIndex = m.index + 1;
|
|
13752
14251
|
continue;
|
|
13753
14252
|
}
|
|
13754
|
-
if (!suppressed(pattern, m
|
|
14253
|
+
if (!suppressed(pattern, m, text.slice(Math.max(0, m.index - 64), m.index))) return m[0];
|
|
13755
14254
|
}
|
|
13756
14255
|
return null;
|
|
13757
14256
|
}
|
|
@@ -13917,7 +14416,7 @@ function redactText(text) {
|
|
|
13917
14416
|
continue;
|
|
13918
14417
|
}
|
|
13919
14418
|
result = result.replace(globalRegex, (match, ...rest) => {
|
|
13920
|
-
if (suppressed(pattern, match)) return match;
|
|
14419
|
+
if (suppressed(pattern, [match, ...rest])) return match;
|
|
13921
14420
|
if (!found.includes(pattern.name)) found.push(pattern.name);
|
|
13922
14421
|
const marker = `[node9-redacted:${pattern.name}]`;
|
|
13923
14422
|
const group = pattern.redactGroup !== void 0 && typeof rest[pattern.redactGroup - 1] === "string" ? rest[pattern.redactGroup - 1] : void 0;
|
|
@@ -14268,9 +14767,9 @@ var GitWalk = class {
|
|
|
14268
14767
|
const name = n.Name.Value;
|
|
14269
14768
|
if (n.Append) {
|
|
14270
14769
|
const prev = this.appended.has(name) ? this.appended.get(name) : resolveWordLiteral(n.Value) === null ? null : void 0;
|
|
14271
|
-
const
|
|
14770
|
+
const base4 = prev === void 0 ? recordedExpansion(name) : prev;
|
|
14272
14771
|
const piece = resolveWordLiteral(n.Value);
|
|
14273
|
-
this.appended.set(name, typeof
|
|
14772
|
+
this.appended.set(name, typeof base4 === "string" && piece !== null ? base4 + piece : null);
|
|
14274
14773
|
this.treeTopVars.delete(name);
|
|
14275
14774
|
return true;
|
|
14276
14775
|
}
|
|
@@ -15310,9 +15809,9 @@ var INSTRUCTION_NAMES = /* @__PURE__ */ new Set([
|
|
|
15310
15809
|
var SETTINGS_RE = /\/(?:\.claude\/settings(?:\.local)?\.json|\.gemini\/settings\.json|\.codex\/hooks\.json|\.cursor\/hooks\.json)$/i;
|
|
15311
15810
|
function agentFileKind(p) {
|
|
15312
15811
|
const lower2 = p.toLowerCase();
|
|
15313
|
-
const
|
|
15314
|
-
if (INSTRUCTION_NAMES.has(
|
|
15315
|
-
if (
|
|
15812
|
+
const base4 = lower2.slice(lower2.lastIndexOf("/") + 1);
|
|
15813
|
+
if (INSTRUCTION_NAMES.has(base4)) return "instructions";
|
|
15814
|
+
if (base4 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base4))
|
|
15316
15815
|
return "instructions";
|
|
15317
15816
|
if (/\/\.cursor\/rules(?:\/|$)/.test(lower2)) return "instructions";
|
|
15318
15817
|
if (/\/\.claude\/projects\/[^/]+\/memory(?:\/|$)/.test(lower2)) return "memory";
|
|
@@ -15482,7 +15981,7 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
|
|
|
15482
15981
|
skills: "agent skill",
|
|
15483
15982
|
settings: "agent settings"
|
|
15484
15983
|
};
|
|
15485
|
-
const
|
|
15984
|
+
const base4 = `${kindLabel[kind]} written: ${access.path}`;
|
|
15486
15985
|
if (!signal && !every) {
|
|
15487
15986
|
return {
|
|
15488
15987
|
decision: "allow",
|
|
@@ -15492,14 +15991,14 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
|
|
|
15492
15991
|
path: access.path,
|
|
15493
15992
|
operation: access.operation,
|
|
15494
15993
|
kind,
|
|
15495
|
-
reason:
|
|
15994
|
+
reason: base4,
|
|
15496
15995
|
ruleDescription: "The AI writes to a file every later agent session loads as instructions.",
|
|
15497
|
-
blockedByLabel: `Node9 Files: ${
|
|
15996
|
+
blockedByLabel: `Node9 Files: ${base4}`,
|
|
15498
15997
|
tier: 2
|
|
15499
15998
|
};
|
|
15500
15999
|
}
|
|
15501
16000
|
const ruleName = signal === "content" ? "review-agent-file-content" : signal === "hooks" ? "review-agent-hooks-change" : "review-agent-file-write";
|
|
15502
|
-
const reason = signal ? `${
|
|
16001
|
+
const reason = signal ? `${base4} (${detail})` : base4;
|
|
15503
16002
|
const description = signal === "content" ? "The AI writes an instruction into a file every later agent session loads: to hide something from you, to skip approvals or the guard, or to read or send a secret. It would persist past this session; confirm it is yours." : signal === "hooks" ? "The AI changes the hooks in the agent's settings. Hooks are how node9 and your other checks run before each tool call; a change here can disarm them." : "The AI writes to a file every later agent session loads as instructions (CLAUDE.md, AGENTS.md, memory, agents, commands). Confirm the change is yours.";
|
|
15504
16003
|
return {
|
|
15505
16004
|
decision: value === "log" ? "allow" : value,
|
|
@@ -17766,6 +18265,7 @@ var SENSITIVE_PATTERNS = [
|
|
|
17766
18265
|
// generic credentials files
|
|
17767
18266
|
];
|
|
17768
18267
|
function isSensitivePath(p) {
|
|
18268
|
+
if (isPublicSshMaterial(p)) return false;
|
|
17769
18269
|
return isPasswordHashPath(p) || SENSITIVE_PATTERNS.some((re) => re.test(p));
|
|
17770
18270
|
}
|
|
17771
18271
|
function splitOnPipe(cmd) {
|
|
@@ -18409,7 +18909,9 @@ var DAEMON_CMDLINES = [
|
|
|
18409
18909
|
"node9 daemon start"
|
|
18410
18910
|
];
|
|
18411
18911
|
var DAEMON_NAMES = ["node", "node9"];
|
|
18412
|
-
var KILLALL_NAMES = /* @__PURE__ */ new Set(["
|
|
18912
|
+
var KILLALL_NAMES = /* @__PURE__ */ new Set(["node9", "node9.exe"]);
|
|
18913
|
+
var ORDINARY_NODE_CMDLINES = ["node server.js"];
|
|
18914
|
+
var ORDINARY_NODE_NAMES = ["node"];
|
|
18413
18915
|
var STOP_SYSTEMCTL = /* @__PURE__ */ new Set(["stop", "disable", "mask", "kill"]);
|
|
18414
18916
|
var STOP_LAUNCHCTL = /* @__PURE__ */ new Set(["unload", "bootout", "remove", "stop", "kill", "disable"]);
|
|
18415
18917
|
var PKILL_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
@@ -18439,11 +18941,16 @@ function patternSelects(pattern, targets) {
|
|
|
18439
18941
|
if (pieces.length === 0) return false;
|
|
18440
18942
|
return targets.some((t) => pieces.every((p) => t.includes(p)));
|
|
18441
18943
|
}
|
|
18944
|
+
function aimedAtDaemon(pattern, full) {
|
|
18945
|
+
return pattern.split("|").some(
|
|
18946
|
+
(alternative) => patternSelects(alternative, full ? DAEMON_CMDLINES : DAEMON_NAMES) && !patternSelects(alternative, full ? ORDINARY_NODE_CMDLINES : ORDINARY_NODE_NAMES)
|
|
18947
|
+
);
|
|
18948
|
+
}
|
|
18442
18949
|
function sourceText(bytes, pos, end) {
|
|
18443
18950
|
if (typeof pos !== "number" || typeof end !== "number" || pos < 0 || end < pos) return "";
|
|
18444
18951
|
return new TextDecoder().decode(bytes.subarray(pos, end));
|
|
18445
18952
|
}
|
|
18446
|
-
var
|
|
18953
|
+
var base3 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
|
|
18447
18954
|
function nextOperand(words, from) {
|
|
18448
18955
|
for (let i = from; i < words.length; i++) {
|
|
18449
18956
|
const w = words[i];
|
|
@@ -18453,7 +18960,7 @@ function nextOperand(words, from) {
|
|
|
18453
18960
|
return -1;
|
|
18454
18961
|
}
|
|
18455
18962
|
function node9Command(words, h) {
|
|
18456
|
-
const head =
|
|
18963
|
+
const head = base3(words[h]);
|
|
18457
18964
|
if (head !== "node9" && head !== "node9.cmd" && words[h] !== "@node9/proxy") return null;
|
|
18458
18965
|
const s = nextOperand(words, h + 1);
|
|
18459
18966
|
const sub = s < 0 ? "" : (words[s] ?? "").toLowerCase();
|
|
@@ -18465,7 +18972,7 @@ function node9Command(words, h) {
|
|
|
18465
18972
|
}
|
|
18466
18973
|
var HOME_PID_FILE_RE = /(?:^|[\s"'(=`])(?:~|\$HOME|\$\{HOME\}|\/home\/[^/\s]+|\/Users\/[^/\s]+|\/root)\/\.node9\/daemon\.pid/;
|
|
18467
18974
|
function killsDaemon(words, texts, h, daemonPid) {
|
|
18468
|
-
const head =
|
|
18975
|
+
const head = base3(words[h]);
|
|
18469
18976
|
const args = words.slice(h + 1);
|
|
18470
18977
|
if (head === "kill") {
|
|
18471
18978
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -18499,13 +19006,13 @@ function killsDaemon(words, texts, h, daemonPid) {
|
|
|
18499
19006
|
pattern = w;
|
|
18500
19007
|
}
|
|
18501
19008
|
if (pattern === null) return null;
|
|
18502
|
-
return
|
|
19009
|
+
return aimedAtDaemon(pattern, full) ? `pkill ${full ? "-f " : ""}${pattern}` : null;
|
|
18503
19010
|
}
|
|
18504
19011
|
if (head === "killall") {
|
|
18505
19012
|
const regex = args.some((w) => w === "-r" || w === "--regexp");
|
|
18506
19013
|
for (const w of args) {
|
|
18507
19014
|
if (w === null || w.startsWith("-")) continue;
|
|
18508
|
-
if (regex ?
|
|
19015
|
+
if (regex ? aimedAtDaemon(w, false) : KILLALL_NAMES.has(w.toLowerCase()))
|
|
18509
19016
|
return `killall ${w}`;
|
|
18510
19017
|
}
|
|
18511
19018
|
return null;
|
|
@@ -18523,7 +19030,7 @@ function killsDaemon(words, texts, h, daemonPid) {
|
|
|
18523
19030
|
return null;
|
|
18524
19031
|
}
|
|
18525
19032
|
function stopsService(words, h) {
|
|
18526
|
-
const head =
|
|
19033
|
+
const head = base3(words[h]);
|
|
18527
19034
|
const args = words.slice(h + 1).map((w) => (w ?? "").toLowerCase());
|
|
18528
19035
|
if (head === "systemctl") {
|
|
18529
19036
|
const action = args.find((w) => STOP_SYSTEMCTL.has(w));
|
|
@@ -18552,7 +19059,7 @@ function analyzeNode9Disarm(command, daemonPid = null, depth = 0) {
|
|
|
18552
19059
|
const h = unwrapCommandHead(words);
|
|
18553
19060
|
shown = node9Command(words, h) ?? killsDaemon(words, texts, h, daemonPid) ?? stopsService(words, h);
|
|
18554
19061
|
if (shown === null) {
|
|
18555
|
-
const payload = literalShellPayload(words,
|
|
19062
|
+
const payload = literalShellPayload(words, base3(words[0]));
|
|
18556
19063
|
if (payload) {
|
|
18557
19064
|
const inner = analyzeNode9Disarm(payload, daemonPid, depth + 1);
|
|
18558
19065
|
if (inner) shown = inner.reason.replace(/^node9 switched off by the agent: /, "");
|
|
@@ -19247,7 +19754,15 @@ var MAX_DESTINATIONS = 200;
|
|
|
19247
19754
|
var MAX_SCAN_CHARS = 1e5;
|
|
19248
19755
|
var EMAIL_RE = /[\p{L}\p{N}._%+-]+@[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?(?:\.[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?)*\.\p{L}{2,}/gu;
|
|
19249
19756
|
var URL_RE = /\b(?:[a-z][a-z0-9+.-]*:\/\/|www\.)[^\s<>"'`){}]+/gi;
|
|
19250
|
-
var IBAN_RE = /\b[A-Z]{2}\d{2}(?:[ -]?[A-Z0-9]{4}){2,7}(?:[ -]?[A-Z0-9]{1,4})?\b/
|
|
19757
|
+
var IBAN_RE = /\b[A-Z]{2}\d{2}(?:[ -]?[A-Z0-9]{4}){2,7}(?:[ -]?[A-Z0-9]{1,4})?\b/gi;
|
|
19758
|
+
var ACCOUNT_SHAPE_RE = /^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/;
|
|
19759
|
+
function accountOf(written) {
|
|
19760
|
+
if (written !== written.toUpperCase()) return null;
|
|
19761
|
+
const groups = written.split(/[ -]+/);
|
|
19762
|
+
const printed = groups.length > 1 && groups.slice(0, -1).every((g) => g.length === 4);
|
|
19763
|
+
const compact = printed ? groups.join("") : groups[0];
|
|
19764
|
+
return ACCOUNT_SHAPE_RE.test(compact) ? compact : null;
|
|
19765
|
+
}
|
|
19251
19766
|
var RECIPIENT_KEYS = /* @__PURE__ */ new Set([
|
|
19252
19767
|
"to",
|
|
19253
19768
|
"cc",
|
|
@@ -19292,11 +19807,28 @@ function hostOfUrl(value) {
|
|
|
19292
19807
|
return null;
|
|
19293
19808
|
}
|
|
19294
19809
|
}
|
|
19810
|
+
function ibanOf(written) {
|
|
19811
|
+
const compact = written.replace(/[ -]/g, "").toUpperCase();
|
|
19812
|
+
if (!validateIban(compact)) return null;
|
|
19813
|
+
const length = IBAN_LENGTH[compact.slice(0, 2)];
|
|
19814
|
+
const iban = compact.slice(0, length);
|
|
19815
|
+
if (written === written.toUpperCase()) return iban;
|
|
19816
|
+
let at = 0;
|
|
19817
|
+
for (const group of written.split(/[ -]+/)) {
|
|
19818
|
+
at += group.length;
|
|
19819
|
+
if (at === length) return iban;
|
|
19820
|
+
if (at > length) break;
|
|
19821
|
+
}
|
|
19822
|
+
return null;
|
|
19823
|
+
}
|
|
19295
19824
|
function addIbans(text, out) {
|
|
19296
|
-
for (const m of text.
|
|
19297
|
-
const
|
|
19298
|
-
if (
|
|
19299
|
-
else
|
|
19825
|
+
for (const m of text.matchAll(IBAN_RE)) {
|
|
19826
|
+
const iban = ibanOf(m[0]);
|
|
19827
|
+
if (iban) out.add(`iban:${iban}`);
|
|
19828
|
+
else {
|
|
19829
|
+
const account = accountOf(m[0]);
|
|
19830
|
+
if (account) out.add(`account:${account}`);
|
|
19831
|
+
}
|
|
19300
19832
|
if (out.size >= MAX_DESTINATIONS) return;
|
|
19301
19833
|
}
|
|
19302
19834
|
}
|
|
@@ -19344,8 +19876,8 @@ function walk2(value, key, out, depth) {
|
|
|
19344
19876
|
s.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").replace(/^\/\//, "").split(/[/?#]/)[0].replace(/:\d+$/, "")
|
|
19345
19877
|
);
|
|
19346
19878
|
if (h && (h.includes(":") || /\.\p{L}{2,}$/u.test(h))) out.add(`host:${h}`);
|
|
19347
|
-
const acct = s.replace(/[ .-]/g, "")
|
|
19348
|
-
if (
|
|
19879
|
+
const acct = s.replace(/[ .-]/g, "");
|
|
19880
|
+
if (acct === acct.toUpperCase() && ACCOUNT_SHAPE_RE.test(acct) && !validateIban(acct))
|
|
19349
19881
|
out.add(`account:${acct}`);
|
|
19350
19882
|
}
|
|
19351
19883
|
return;
|
|
@@ -19548,8 +20080,8 @@ function hasRoutingNumber(text) {
|
|
|
19548
20080
|
return false;
|
|
19549
20081
|
}
|
|
19550
20082
|
var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
|
|
19551
|
-
function* validCardRuns(text,
|
|
19552
|
-
const re = new RegExp(
|
|
20083
|
+
function* validCardRuns(text, base4, exemptFractions = true) {
|
|
20084
|
+
const re = new RegExp(base4.source, "g");
|
|
19553
20085
|
let m;
|
|
19554
20086
|
while ((m = re.exec(text)) !== null) {
|
|
19555
20087
|
const digits = m[0].replace(/\D/g, "");
|
|
@@ -19562,17 +20094,17 @@ function* validCardRuns(text, base3, exemptFractions = true) {
|
|
|
19562
20094
|
}
|
|
19563
20095
|
}
|
|
19564
20096
|
function hasValidCard(text) {
|
|
19565
|
-
for (const
|
|
19566
|
-
if (!validCardRuns(text,
|
|
20097
|
+
for (const base4 of CARD_PATTERNS) {
|
|
20098
|
+
if (!validCardRuns(text, base4).next().done) return true;
|
|
19567
20099
|
}
|
|
19568
20100
|
return false;
|
|
19569
20101
|
}
|
|
19570
20102
|
function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
|
|
19571
20103
|
let out = text;
|
|
19572
|
-
for (const
|
|
20104
|
+
for (const base4 of CARD_PATTERNS) {
|
|
19573
20105
|
let res = "";
|
|
19574
20106
|
let last = 0;
|
|
19575
|
-
for (const run of validCardRuns(out,
|
|
20107
|
+
for (const run of validCardRuns(out, base4, exemptFractions)) {
|
|
19576
20108
|
res += out.slice(last, run.index) + replace(run.digits);
|
|
19577
20109
|
last = run.index + run.length;
|
|
19578
20110
|
}
|
|
@@ -19861,9 +20393,9 @@ function maskLeaf(value, key, depth) {
|
|
|
19861
20393
|
const used = /* @__PURE__ */ new Set();
|
|
19862
20394
|
return Object.fromEntries(
|
|
19863
20395
|
Object.entries(value).map(([k, v]) => {
|
|
19864
|
-
const
|
|
19865
|
-
let name =
|
|
19866
|
-
for (let n = 2; used.has(name); n++) name = `${
|
|
20396
|
+
const base4 = maskPersonalData(k);
|
|
20397
|
+
let name = base4;
|
|
20398
|
+
for (let n = 2; used.has(name); n++) name = `${base4}#${n}`;
|
|
19867
20399
|
used.add(name);
|
|
19868
20400
|
return [name, maskLeaf(v, k, depth + 1)];
|
|
19869
20401
|
})
|
|
@@ -20105,7 +20637,7 @@ function classifyCall(head, args, prefixes, env, state, out) {
|
|
|
20105
20637
|
}
|
|
20106
20638
|
case "scp":
|
|
20107
20639
|
case "rsync": {
|
|
20108
|
-
const pos = positionals(args,
|
|
20640
|
+
const pos = positionals(args, VALUE_FLAGS2[head] ?? /* @__PURE__ */ new Set()).filter(
|
|
20109
20641
|
(p) => p !== null
|
|
20110
20642
|
);
|
|
20111
20643
|
if (pos.length < 2) return;
|
|
@@ -20727,7 +21259,7 @@ function summarizeBlast(result, opts = {}) {
|
|
|
20727
21259
|
// src/scan/destructive-regex.ts
|
|
20728
21260
|
var DESTRUCTIVE_OP_RE = /\brm\s+-[rRf]+\b|\bDROP\s+(TABLE|DATABASE|COLLECTION|SCHEMA)\b|\bTRUNCATE\s+TABLE\b|\bgit\s+push\s+(--force|-f)\b|\bFLUSHALL\b|\bFLUSHDB\b|\bkubectl\s+delete\b|\bhelm\s+uninstall\b/i;
|
|
20729
21261
|
var PRIVILEGE_ESCALATION_RE = /\bchmod\s+(0?777|\+x)\b|\bchown\s+root\b/i;
|
|
20730
|
-
var SENSITIVE_PATH_RE = /[\\/]\.aws(?:[\\/]|$)|^\.aws[\\/]|[\\/]\.ssh(
|
|
21262
|
+
var SENSITIVE_PATH_RE = /[\\/]\.aws(?:[\\/]|$)|^\.aws[\\/]|[\\/]\.ssh(?:$|[\\/](?!(?:known_hosts(?:\.old)?|authorized_keys2?|[^\\/]+\.pub)$))|^\.ssh[\\/](?!(?:known_hosts(?:\.old)?|authorized_keys2?|[^\\/]+\.pub)$)|(?:^|[\\/])\.env(?![\w-])(?:[\w.-]*\.local$|(?!\.(?:example|sample|template)\b)(?!\.test$)[\w.-]*$)|\.config\/gcloud\/credentials\.db\b|\.docker\/config\.json\b|\.netrc\b|\.npmrc\b|\.node9\/credentials\.json\b/i;
|
|
20731
21263
|
var FILE_TOOLS = /* @__PURE__ */ new Set([
|
|
20732
21264
|
"read",
|
|
20733
21265
|
"read_file",
|
|
@@ -20930,8 +21462,8 @@ function matchCanaryArgs(args, values) {
|
|
|
20930
21462
|
|
|
20931
21463
|
// src/scan/canonical.ts
|
|
20932
21464
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
20933
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
20934
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
21465
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v40";
|
|
21466
|
+
var CANONICAL_EXTRACTOR_HASH = "0981d8f2268c7d69";
|
|
20935
21467
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
20936
21468
|
function extractCanonicalFindings(call, ctx) {
|
|
20937
21469
|
const out = [];
|
|
@@ -21433,12 +21965,14 @@ export {
|
|
|
21433
21965
|
PATTERN_VERB_NAMES,
|
|
21434
21966
|
POSTURE_CATEGORY_OWASP,
|
|
21435
21967
|
PRIVILEGE_ESCALATION_RE,
|
|
21968
|
+
PUBLIC_SSH_NAME_SOURCE,
|
|
21436
21969
|
REALTIME_PII_PATTERNS,
|
|
21437
21970
|
REPLACED_SHIELDS,
|
|
21438
21971
|
SCAN_REPO_RULES_WITHOUT_RISK,
|
|
21439
21972
|
SCAN_SIGNAL_WEIGHTS,
|
|
21440
21973
|
SENSITIVE_PATH_RE,
|
|
21441
21974
|
SENSITIVE_PATH_REGEXES,
|
|
21975
|
+
SHELL_INTERPRETERS,
|
|
21442
21976
|
SSRF_MAX_HOST,
|
|
21443
21977
|
STARTUP_NAMES,
|
|
21444
21978
|
SYSTEM_AUTH_DIRS,
|
|
@@ -21539,6 +22073,7 @@ export {
|
|
|
21539
22073
|
isPrivateHost,
|
|
21540
22074
|
isProtectedHomePath,
|
|
21541
22075
|
isPublicRegistryHost,
|
|
22076
|
+
isPublicSshMaterial,
|
|
21542
22077
|
isRecordOnly,
|
|
21543
22078
|
isShellShapedTool,
|
|
21544
22079
|
isShieldVerdict,
|