actionwall 0.1.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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +204 -0
- package/dist/cli/format.d.ts +26 -0
- package/dist/cli/format.js +74 -0
- package/dist/cli/format.js.map +1 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +156 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/audit.d.ts +61 -0
- package/dist/core/audit.js +126 -0
- package/dist/core/audit.js.map +1 -0
- package/dist/core/engine.d.ts +48 -0
- package/dist/core/engine.js +140 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/policy.d.ts +307 -0
- package/dist/core/policy.js +138 -0
- package/dist/core/policy.js.map +1 -0
- package/dist/core/types.d.ts +147 -0
- package/dist/core/types.js +24 -0
- package/dist/core/types.js.map +1 -0
- package/dist/demo/mockAgent.d.ts +33 -0
- package/dist/demo/mockAgent.js +130 -0
- package/dist/demo/mockAgent.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/scanners/commandRisk.d.ts +20 -0
- package/dist/scanners/commandRisk.js +335 -0
- package/dist/scanners/commandRisk.js.map +1 -0
- package/dist/scanners/filePolicy.d.ts +15 -0
- package/dist/scanners/filePolicy.js +165 -0
- package/dist/scanners/filePolicy.js.map +1 -0
- package/dist/scanners/injection.d.ts +15 -0
- package/dist/scanners/injection.js +111 -0
- package/dist/scanners/injection.js.map +1 -0
- package/dist/scanners/secrets.d.ts +12 -0
- package/dist/scanners/secrets.js +102 -0
- package/dist/scanners/secrets.js.map +1 -0
- package/dist/scanners/toolPermissions.d.ts +7 -0
- package/dist/scanners/toolPermissions.js +60 -0
- package/dist/scanners/toolPermissions.js.map +1 -0
- package/dist/scanners/urlPolicy.d.ts +16 -0
- package/dist/scanners/urlPolicy.js +176 -0
- package/dist/scanners/urlPolicy.js.map +1 -0
- package/dist/util/ansi.d.ts +13 -0
- package/dist/util/ansi.js +20 -0
- package/dist/util/ansi.js.map +1 -0
- package/dist/util/entropy.d.ts +6 -0
- package/dist/util/entropy.js +20 -0
- package/dist/util/entropy.js.map +1 -0
- package/dist/util/paths.d.ts +43 -0
- package/dist/util/paths.js +192 -0
- package/dist/util/paths.js.map +1 -0
- package/dist/util/secretPatterns.d.ts +19 -0
- package/dist/util/secretPatterns.js +93 -0
- package/dist/util/secretPatterns.js.map +1 -0
- package/dist/util/shell.d.ts +31 -0
- package/dist/util/shell.js +154 -0
- package/dist/util/shell.js.map +1 -0
- package/docs/ARCHITECTURE.md +115 -0
- package/docs/COMPARISON.md +99 -0
- package/docs/POLICY_REFERENCE.md +126 -0
- package/docs/REQUIREMENTS.md +87 -0
- package/docs/ROADMAP.md +36 -0
- package/docs/THREAT_MODEL.md +88 -0
- package/package.json +67 -0
- package/policies/default.yaml +70 -0
- package/policies/readonly.yaml +58 -0
- package/policies/strict.yaml +75 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt-injection scanner.
|
|
3
|
+
*
|
|
4
|
+
* Inspects text flowing INTO the model — the tool output the agent just
|
|
5
|
+
* received and the user prompt — for instructions trying to hijack the agent:
|
|
6
|
+
* "ignore previous instructions", fake system markers, role-override lines,
|
|
7
|
+
* exfiltration via markdown images, hidden/invisible characters.
|
|
8
|
+
*
|
|
9
|
+
* Honest scope (see docs/THREAT_MODEL.md): pattern heuristics catch the common
|
|
10
|
+
* and lazy injections; paraphrased or multilingual attacks require an
|
|
11
|
+
* LLM-based classifier, which ActionWall accepts as a pluggable scanner
|
|
12
|
+
* rather than pretending regex is a complete defense.
|
|
13
|
+
*/
|
|
14
|
+
import { truncate } from "../util/secretPatterns.js";
|
|
15
|
+
const PATTERNS = [
|
|
16
|
+
{
|
|
17
|
+
id: "IGNORE-PRIOR",
|
|
18
|
+
regex: /\bignore\s+(?:all\s+|any\s+|the\s+|your\s+)?(?:previous|prior|above|earlier|past)\s+(?:instructions?|prompts?|rules?|directions?|context)\b/i,
|
|
19
|
+
label: '"ignore previous instructions" override',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "DISREGARD",
|
|
23
|
+
regex: /\bdisregard\s+(?:all\s+|your\s+|any\s+|the\s+)?(?:instructions?|rules?|guardrails?|guidelines|constraints?|context)\b/i,
|
|
24
|
+
label: '"disregard your rules" override',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "ROLE-OVERRIDE",
|
|
28
|
+
regex: /\byou\s+are\s+now\s+(?:a|an|the)\b/i,
|
|
29
|
+
label: 'role override ("you are now a…")',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "SYSTEM-PROMPT-EXTRACT",
|
|
33
|
+
regex: /\b(?:reveal|repeat|print|show|output|dump|ignore)\s+(?:your\s+|the\s+|its\s+)?system\s+prompt\b/i,
|
|
34
|
+
label: "system prompt extraction request",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "FAKE-SYSTEM-MARKER",
|
|
38
|
+
regex: /<\|im_start\|>|<\|endoftext\|>|\[SYSTEM\]|\{\{SYSTEM\}\}|(?:^|\n)\s*system\s*:\s*/im,
|
|
39
|
+
label: "fake system/message marker",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "NEW-INSTRUCTIONS",
|
|
43
|
+
regex: /\bnew\s+(?:system\s+)?(?:instructions?|directives?|rules?|objective)\s*:/i,
|
|
44
|
+
label: '"new instructions:" injection',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "URGENT-EXEC",
|
|
48
|
+
regex: /\b(?:important|urgent|emergency|critical)[^\n.]{0,60}\b(?:run|execute|delete|send|post|upload|exfiltrate)\b/i,
|
|
49
|
+
label: 'urgent "do X now" directive',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "IMPERSONATION",
|
|
53
|
+
regex: /(?:^|\n)\s*(?:assistant|ai|agent|bot)\s*:\s*/im,
|
|
54
|
+
label: "impersonated assistant turn",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "EXFIL-IMAGE",
|
|
58
|
+
regex: /!\[[^\]]*\]\(\s*(?:https?:)?\/\/[^)]*(?:[?&])(?:data|q|payload|token|d|secret|content)=[^)]*\)/i,
|
|
59
|
+
label: "possible data exfiltration via markdown image URL",
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
const HIDDEN_CHARS_RE = /[\u200B-\u200D\u2060\uFEFF]/;
|
|
63
|
+
export const injectionScanner = {
|
|
64
|
+
name: "injection",
|
|
65
|
+
scan(action, policy) {
|
|
66
|
+
if (!policy.injection.enabled)
|
|
67
|
+
return [];
|
|
68
|
+
const sources = [
|
|
69
|
+
{ label: "tool output", text: action.context?.toolOutput },
|
|
70
|
+
{ label: "user prompt", text: action.context?.userPrompt },
|
|
71
|
+
];
|
|
72
|
+
const findings = [];
|
|
73
|
+
for (const source of sources) {
|
|
74
|
+
const text = source.text;
|
|
75
|
+
if (!text || text.length === 0)
|
|
76
|
+
continue;
|
|
77
|
+
const hits = [];
|
|
78
|
+
for (const pattern of PATTERNS) {
|
|
79
|
+
const m = pattern.regex.exec(text);
|
|
80
|
+
if (m) {
|
|
81
|
+
hits.push({ id: pattern.id, label: pattern.label, snippet: m[0] });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let hidden = false;
|
|
85
|
+
if (HIDDEN_CHARS_RE.test(text)) {
|
|
86
|
+
hidden = true;
|
|
87
|
+
hits.push({ id: "HIDDEN-CHARS", label: "hidden/invisible characters (zero-width or word-joiner)", snippet: "(invisible characters present)" });
|
|
88
|
+
}
|
|
89
|
+
if (hits.length === 0)
|
|
90
|
+
continue;
|
|
91
|
+
const exfil = hits.some((h) => h.id === "EXFIL-IMAGE");
|
|
92
|
+
const distinct = new Set(hits.map((h) => h.id)).size;
|
|
93
|
+
const severity = exfil || distinct >= policy.injection.hits_for_high ? "HIGH" : "MEDIUM";
|
|
94
|
+
const labels = hits.slice(0, 3).map((h) => h.label).join("; ");
|
|
95
|
+
findings.push({
|
|
96
|
+
scanner: this.name,
|
|
97
|
+
ruleId: exfil ? "INJ-EXFIL-IMAGE" : distinct >= policy.injection.hits_for_high ? "INJ-MULTI-PATTERN" : "INJ-SINGLE-PATTERN",
|
|
98
|
+
severity,
|
|
99
|
+
title: exfil ? "Possible data exfiltration via markdown image" : "Possible prompt injection",
|
|
100
|
+
reason: `${severity === "HIGH" ? distinct : 1} injection pattern${distinct === 1 ? "" : "s"} detected in ${source.label}: ${labels}. ` +
|
|
101
|
+
(exfil
|
|
102
|
+
? "A markdown image URL carries data out to a third-party server when the model renders it."
|
|
103
|
+
: "Content inside tool output is untrusted input — an attacker-controlled page or file may be steering the agent."),
|
|
104
|
+
policyRef: "injection.enabled",
|
|
105
|
+
evidence: truncate(truncate(hits[0].snippet, 80)),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return findings;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=injection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection.js","sourceRoot":"","sources":["../../src/scanners/injection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAQrD,MAAM,QAAQ,GAAuB;IACnC;QACE,EAAE,EAAE,cAAc;QAClB,KAAK,EAAE,8IAA8I;QACrJ,KAAK,EAAE,yCAAyC;KACjD;IACD;QACE,EAAE,EAAE,WAAW;QACf,KAAK,EAAE,wHAAwH;QAC/H,KAAK,EAAE,iCAAiC;KACzC;IACD;QACE,EAAE,EAAE,eAAe;QACnB,KAAK,EAAE,qCAAqC;QAC5C,KAAK,EAAE,kCAAkC;KAC1C;IACD;QACE,EAAE,EAAE,uBAAuB;QAC3B,KAAK,EAAE,kGAAkG;QACzG,KAAK,EAAE,kC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AAM,EAAE,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,oBAAoB;gBAC3H,QAAQ;gBACR,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,2BAA2B;gBAC5F,MAAM,EACJ,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,qBAAqB,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,gBAAgB,MAAM,CAAC,KAAK,KAAK,MAAM,IAAI;oBAC9H,CAAC,KAAK;wBACJ,CAAC,CAAC,0FAA0F;wBAC5F,CAAC,CAAC,gHAAgH,CAAC;gBACvH,SAAS,EAAE,mBAAmB;gBAC9B,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;aACnD,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret scanner: catches credentials leaving the agent's context through
|
|
3
|
+
* tool arguments — an Authorization header pointing at a third-party host,
|
|
4
|
+
* `curl` with an API key in the URL, a `db.connect(password=…)` call, etc.
|
|
5
|
+
*
|
|
6
|
+
* Detection: built-in signatures for well-known token formats + a
|
|
7
|
+
* high-entropy-token heuristic for unknown formats + user-supplied regexes.
|
|
8
|
+
* Everything the scanner reports is redacted before it reaches findings,
|
|
9
|
+
* findings-as-strings, or the audit log.
|
|
10
|
+
*/
|
|
11
|
+
import type { Scanner } from "../core/types.js";
|
|
12
|
+
export declare const secretsScanner: Scanner;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret scanner: catches credentials leaving the agent's context through
|
|
3
|
+
* tool arguments — an Authorization header pointing at a third-party host,
|
|
4
|
+
* `curl` with an API key in the URL, a `db.connect(password=…)` call, etc.
|
|
5
|
+
*
|
|
6
|
+
* Detection: built-in signatures for well-known token formats + a
|
|
7
|
+
* high-entropy-token heuristic for unknown formats + user-supplied regexes.
|
|
8
|
+
* Everything the scanner reports is redacted before it reaches findings,
|
|
9
|
+
* findings-as-strings, or the audit log.
|
|
10
|
+
*/
|
|
11
|
+
import { BUILTIN_SECRET_PATTERNS, isPlaceholderValue } from "../util/secretPatterns.js";
|
|
12
|
+
import { shannonEntropy } from "../util/entropy.js";
|
|
13
|
+
import { truncate } from "../util/secretPatterns.js";
|
|
14
|
+
const ENTROPY_TOKEN_RE = /[A-Za-z0-9_-]{32,}/g;
|
|
15
|
+
const ENTROPY_THRESHOLD = 4.0;
|
|
16
|
+
const MAX_FINDINGS = 12;
|
|
17
|
+
function overlaps(spans, start, end) {
|
|
18
|
+
return spans.some((s) => start < s.end && end > s.start);
|
|
19
|
+
}
|
|
20
|
+
export const secretsScanner = {
|
|
21
|
+
name: "secrets",
|
|
22
|
+
scan(action, policy) {
|
|
23
|
+
if (!policy.secrets.enabled)
|
|
24
|
+
return [];
|
|
25
|
+
const text = JSON.stringify(action.params);
|
|
26
|
+
if (text.length === 0 || text === "{}")
|
|
27
|
+
return [];
|
|
28
|
+
const findings = [];
|
|
29
|
+
const spans = [];
|
|
30
|
+
const redactEvidence = (s) => {
|
|
31
|
+
const keep = Math.min(4, Math.floor(s.length / 4));
|
|
32
|
+
return truncate(`${s.slice(0, keep)}*REDACTED*`, 60);
|
|
33
|
+
};
|
|
34
|
+
const add = (ruleId, severity, name, matched, span, extra) => {
|
|
35
|
+
if (findings.length >= MAX_FINDINGS)
|
|
36
|
+
return;
|
|
37
|
+
spans.push(span);
|
|
38
|
+
findings.push({
|
|
39
|
+
scanner: this.name,
|
|
40
|
+
ruleId,
|
|
41
|
+
severity,
|
|
42
|
+
title: `Possible ${name} exposed in tool arguments`,
|
|
43
|
+
reason: `A value matching the ${name} format was found in the action parameters${extra ? ` (${extra})` : ""}. Sending it through a tool call can leak it to third parties; the audit log stores only a redacted form.`,
|
|
44
|
+
policyRef: "secrets.custom_patterns",
|
|
45
|
+
evidence: redactEvidence(matched),
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const patterns = [
|
|
49
|
+
...BUILTIN_SECRET_PATTERNS.map((p) => ({ name: p.name, regex: p.regex, severity: p.severity, builtin: true })),
|
|
50
|
+
...policy.secrets.custom_patterns.map((p) => ({
|
|
51
|
+
name: p.name,
|
|
52
|
+
regex: new RegExp(p.regex, "g"),
|
|
53
|
+
severity: p.severity,
|
|
54
|
+
builtin: false,
|
|
55
|
+
})),
|
|
56
|
+
];
|
|
57
|
+
for (const pattern of patterns) {
|
|
58
|
+
const re = new RegExp(pattern.regex.source, pattern.regex.flags.includes("g") ? pattern.regex.flags : `${pattern.regex.flags}g`);
|
|
59
|
+
let count = 0;
|
|
60
|
+
for (const match of text.matchAll(re)) {
|
|
61
|
+
if (count >= 5)
|
|
62
|
+
break;
|
|
63
|
+
const matched = match[0];
|
|
64
|
+
if (matched === undefined)
|
|
65
|
+
continue;
|
|
66
|
+
count++;
|
|
67
|
+
// The credential-assignment rule captures the value in group 1;
|
|
68
|
+
// skip obvious placeholders like password=changeme or ${DB_PASS}.
|
|
69
|
+
const value = match[1];
|
|
70
|
+
if (pattern.name === "credential-assignment" && value !== undefined && isPlaceholderValue(value)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
add(`SEC-${pattern.name.toUpperCase()}`, pattern.severity, pattern.name, matched, { start: match.index ?? 0, end: (match.index ?? 0) + matched.length });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// High-entropy heuristic for unknown secret formats.
|
|
77
|
+
if (policy.secrets.scan_entropy) {
|
|
78
|
+
let count = 0;
|
|
79
|
+
for (const match of text.matchAll(ENTROPY_TOKEN_RE)) {
|
|
80
|
+
if (count >= 3)
|
|
81
|
+
break;
|
|
82
|
+
const token = match[0];
|
|
83
|
+
const start = match.index ?? 0;
|
|
84
|
+
if (token === undefined || overlaps(spans, start, start + token.length))
|
|
85
|
+
continue;
|
|
86
|
+
if (shannonEntropy(token) >= ENTROPY_THRESHOLD) {
|
|
87
|
+
count++;
|
|
88
|
+
findings.push({
|
|
89
|
+
scanner: this.name,
|
|
90
|
+
ruleId: "SEC-HIGH-ENTROPY",
|
|
91
|
+
severity: "MEDIUM",
|
|
92
|
+
title: "Possible high-entropy credential",
|
|
93
|
+
reason: `A ${token.length}-character high-entropy token was found in the action parameters. If it is not a credential, allow it via a scanner exception; if it is, remove it.`,
|
|
94
|
+
evidence: redactEvidence(token),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return findings;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/scanners/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAC/C,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,YAAY,GAAG,EAAE,CAAC;AAOxB,SAAS,QAAQ,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW;IACzD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAA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CAAkC;wBACzC,MAAM,EAAE,KAAK,KAAK,CAAC,MAAM,qJAAqJ;wBAC9K,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC;qBAChC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-permission scanner: the coarse gate before content-level scanners run.
|
|
3
|
+
* Implements allow/deny lists with wildcards ("file.*", "admin.*"), an
|
|
4
|
+
* optional deny-by-default mode, and per-agent overrides.
|
|
5
|
+
*/
|
|
6
|
+
import type { Scanner } from "../core/types.js";
|
|
7
|
+
export declare const toolPermissionsScanner: Scanner;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-permission scanner: the coarse gate before content-level scanners run.
|
|
3
|
+
* Implements allow/deny lists with wildcards ("file.*", "admin.*"), an
|
|
4
|
+
* optional deny-by-default mode, and per-agent overrides.
|
|
5
|
+
*/
|
|
6
|
+
function wildcardMatch(pattern, tool) {
|
|
7
|
+
if (!pattern.includes("*"))
|
|
8
|
+
return pattern === tool;
|
|
9
|
+
const re = new RegExp(`^${pattern.split("*").map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*")}$`);
|
|
10
|
+
return re.test(tool);
|
|
11
|
+
}
|
|
12
|
+
function listMatches(list, tool) {
|
|
13
|
+
return list.some((p) => wildcardMatch(p, tool));
|
|
14
|
+
}
|
|
15
|
+
export const toolPermissionsScanner = {
|
|
16
|
+
name: "toolPermissions",
|
|
17
|
+
scan(action, policy) {
|
|
18
|
+
// Per-agent config replaces the global lists when present.
|
|
19
|
+
const agentOverride = policy.tools.agents[action.agentId];
|
|
20
|
+
const rules = agentOverride
|
|
21
|
+
? {
|
|
22
|
+
default: agentOverride.default ?? policy.tools.default,
|
|
23
|
+
allow: agentOverride.allow,
|
|
24
|
+
deny: agentOverride.deny,
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
default: policy.tools.default,
|
|
28
|
+
allow: policy.tools.allow,
|
|
29
|
+
deny: policy.tools.deny,
|
|
30
|
+
};
|
|
31
|
+
// Deny always wins over allow — explicit blocks cannot be bypassed by
|
|
32
|
+
// adding the tool to the allowlist.
|
|
33
|
+
if (listMatches(rules.deny, action.tool)) {
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
scanner: this.name,
|
|
37
|
+
ruleId: "TP-TOOL-DENIED",
|
|
38
|
+
severity: "HIGH",
|
|
39
|
+
title: `Tool "${action.tool}" is denied by policy`,
|
|
40
|
+
reason: `The tool "${action.tool}" appears in the deny list for agent "${action.agentId}". Deny rules always take precedence over allow rules.`,
|
|
41
|
+
policyRef: agentOverride ? "tools.agents[].deny" : "tools.deny",
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
if (rules.default === "deny" && !listMatches(rules.allow, action.tool)) {
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
scanner: this.name,
|
|
49
|
+
ruleId: "TP-NOT-ALLOWED",
|
|
50
|
+
severity: "MEDIUM",
|
|
51
|
+
title: `Tool "${action.tool}" is not in the allowlist`,
|
|
52
|
+
reason: `This policy runs deny-by-default and "${action.tool}" is not on the allow list for agent "${action.agentId}". Escalating to a human before first use.`,
|
|
53
|
+
policyRef: agentOverride ? "tools.agents[].default/allow" : "tools.default/allow",
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
return [];
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=toolPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolPermissions.js","sourceRoot":"","sources":["../../src/scanners/toolPermissions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,SAAS,aAAa,CAAC,OAAe,EAAE,IAAY;IAClD,IAAI,CAAC,OAAO,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AE,CAAC;YACzC,OAAO;gBACL;oBACE,OAAO,EAAE,IAAI,CAAC,IAAI;oBAClB,MAAM,EAAE,gBAAgB;oBACxB,QAAQ,EAAE,MAAM;oBAChB,KAAK,EAAE,SAAS,MAAM,CAAC,IAAI,uBAAuB;oBAClD,MAAM,EAAE,aAAa,MAAM,CAAC,IAAI,yCAAyC,MAAM,CAAC,OAAO,wDAAwD;oBAC/I,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,YAAY;iBAChE;aACF,CAAC;QACJ,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACvE,OAAO;gBACL;oBACE,OAAO,EAAE,IAAI,CAAC,IAAI;oBAClB,MAAM,EAAE,gBAAgB;oBACxB,QAAQ,EAAE,QAAQ;oBAClB,KAAK,EAAE,SAAS,MAAM,CAAC,IAAI,2BAA2B;oBACtD,MAAM,EAAE,yCAAyC,MAAM,CAAC,IAAI,yCAAyC,MAAM,CAAC,OAAO,4CAA4C;oBAC/J,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAAC,CAAC,qBAAqB;iBAClF;aACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL / domain policy scanner with SSRF protection.
|
|
3
|
+
*
|
|
4
|
+
* Inspects outbound destinations from the web tool family (http.request,
|
|
5
|
+
* web.fetch, browser.*, web.search) and from shell commands (curl, wget,
|
|
6
|
+
* httpie). Checks, in order of severity:
|
|
7
|
+
* - cloud metadata endpoints (CRITICAL — the classic SSRF prize)
|
|
8
|
+
* - other private/loopback network targets (HIGH)
|
|
9
|
+
* - explicitly denied domains (HIGH)
|
|
10
|
+
* - domain allowlist violations when one is configured (HIGH)
|
|
11
|
+
* - disallowed URL schemes, e.g. file:// or implicit http (HIGH)
|
|
12
|
+
*/
|
|
13
|
+
import type { Scanner } from "../core/types.js";
|
|
14
|
+
/** "api.example.com" vs patterns like "example.com" or "*.example.com". */
|
|
15
|
+
export declare function domainMatches(host: string, pattern: string): boolean;
|
|
16
|
+
export declare const urlPolicyScanner: Scanner;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL / domain policy scanner with SSRF protection.
|
|
3
|
+
*
|
|
4
|
+
* Inspects outbound destinations from the web tool family (http.request,
|
|
5
|
+
* web.fetch, browser.*, web.search) and from shell commands (curl, wget,
|
|
6
|
+
* httpie). Checks, in order of severity:
|
|
7
|
+
* - cloud metadata endpoints (CRITICAL — the classic SSRF prize)
|
|
8
|
+
* - other private/loopback network targets (HIGH)
|
|
9
|
+
* - explicitly denied domains (HIGH)
|
|
10
|
+
* - domain allowlist violations when one is configured (HIGH)
|
|
11
|
+
* - disallowed URL schemes, e.g. file:// or implicit http (HIGH)
|
|
12
|
+
*/
|
|
13
|
+
import { redactText, truncate } from "../util/secretPatterns.js";
|
|
14
|
+
import { splitSegments } from "../util/shell.js";
|
|
15
|
+
const WEB_TOOLS = new Set(["http.request", "http.get", "http.post", "web.fetch", "web.search", "browser.open", "browser.navigate"]);
|
|
16
|
+
const SHELL_FETCHERS = new Set(["curl", "wget", "http", "https", "httpie", "gh", "fetch"]);
|
|
17
|
+
const URL_RE = /\b(?:https?|ftp|file):\/\/[^\s'"<>\\)\]]+/g;
|
|
18
|
+
const METADATA_HOSTS = new Set(["169.254.169.254", "metadata.google.internal", "100.100.100.200"]);
|
|
19
|
+
/** hostname → is it a private/loopback/link-local target? */
|
|
20
|
+
function isPrivateHost(host) {
|
|
21
|
+
const h = host.toLowerCase().replace(/^\[|\]$/g, "");
|
|
22
|
+
if (h === "localhost" || h.endsWith(".localhost") || h.endsWith(".local") || h.endsWith(".internal") || h.endsWith(".home.arpa")) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
// IPv4
|
|
26
|
+
const ipv4 = h.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
27
|
+
if (ipv4) {
|
|
28
|
+
const [a, b] = [Number(ipv4[1]), Number(ipv4[2])];
|
|
29
|
+
if (a === 127 || a === 10 || a === 0)
|
|
30
|
+
return true;
|
|
31
|
+
if (a === 192 && b === 168)
|
|
32
|
+
return true;
|
|
33
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
34
|
+
return true;
|
|
35
|
+
if (a === 169 && b === 254)
|
|
36
|
+
return true;
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
// IPv6 — loopback, link-local (fe80::/10), unique-local (fc00::/7)
|
|
40
|
+
if (h === "::1" || h === "::")
|
|
41
|
+
return true;
|
|
42
|
+
if (h.startsWith("fc") || h.startsWith("fd") || h.startsWith("fe8") || h.startsWith("fe9") || h.startsWith("fea") || h.startsWith("feb")) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
/** "api.example.com" vs patterns like "example.com" or "*.example.com". */
|
|
48
|
+
export function domainMatches(host, pattern) {
|
|
49
|
+
const h = host.toLowerCase();
|
|
50
|
+
const p = pattern.toLowerCase();
|
|
51
|
+
if (p.startsWith("*.")) {
|
|
52
|
+
const base = p.slice(2);
|
|
53
|
+
return h === base || h.endsWith(`.${base}`);
|
|
54
|
+
}
|
|
55
|
+
return h === p;
|
|
56
|
+
}
|
|
57
|
+
/** Extract candidate URLs from an action's params. */
|
|
58
|
+
function extractUrls(action) {
|
|
59
|
+
const urls = [];
|
|
60
|
+
const consider = (candidate) => {
|
|
61
|
+
const raw = candidate.trim();
|
|
62
|
+
if (raw.length === 0)
|
|
63
|
+
return;
|
|
64
|
+
try {
|
|
65
|
+
const u = new URL(raw.includes("://") ? raw : `http://${raw}`);
|
|
66
|
+
urls.push({ raw, scheme: u.protocol.replace(/:$/, "").toLowerCase(), host: u.hostname });
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Not a parseable URL — ignore.
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
if (WEB_TOOLS.has(action.tool)) {
|
|
73
|
+
for (const key of ["url", "uri", "host", "base_url", "baseUrl"]) {
|
|
74
|
+
const v = action.params[key];
|
|
75
|
+
if (typeof v === "string")
|
|
76
|
+
consider(v);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (action.tool === "shell" && typeof action.params.command === "string") {
|
|
80
|
+
for (const match of action.params.command.matchAll(URL_RE)) {
|
|
81
|
+
consider(match[0]);
|
|
82
|
+
}
|
|
83
|
+
const { segments } = splitSegments(action.params.command);
|
|
84
|
+
for (const seg of segments) {
|
|
85
|
+
const words = seg.trim().split(/\s+/);
|
|
86
|
+
if (words.length >= 2 && SHELL_FETCHERS.has(words[0])) {
|
|
87
|
+
const arg = words.find((w, i) => i > 0 && !w.startsWith("-") && !w.includes("://"));
|
|
88
|
+
if (arg)
|
|
89
|
+
consider(arg);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Any tool that carries a url-ish param is checked too.
|
|
94
|
+
if (!WEB_TOOLS.has(action.tool)) {
|
|
95
|
+
const v = action.params.url;
|
|
96
|
+
if (typeof v === "string")
|
|
97
|
+
consider(v);
|
|
98
|
+
}
|
|
99
|
+
return urls;
|
|
100
|
+
}
|
|
101
|
+
export const urlPolicyScanner = {
|
|
102
|
+
name: "urlPolicy",
|
|
103
|
+
scan(action, policy) {
|
|
104
|
+
const urls = extractUrls(action);
|
|
105
|
+
if (urls.length === 0)
|
|
106
|
+
return [];
|
|
107
|
+
const cfg = policy.url_policy;
|
|
108
|
+
const findings = [];
|
|
109
|
+
const seen = new Set();
|
|
110
|
+
const push = (f) => {
|
|
111
|
+
const key = `${f.ruleId}:${f.evidence}`;
|
|
112
|
+
if (!seen.has(key)) {
|
|
113
|
+
seen.add(key);
|
|
114
|
+
findings.push(f);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
for (const { raw, scheme, host } of urls) {
|
|
118
|
+
const evidence = truncate(redactText(raw), 100);
|
|
119
|
+
if (cfg.block_private_networks && METADATA_HOSTS.has(host.toLowerCase())) {
|
|
120
|
+
push({
|
|
121
|
+
scanner: this.name,
|
|
122
|
+
ruleId: "URL-METADATA",
|
|
123
|
+
severity: "CRITICAL",
|
|
124
|
+
title: "Cloud metadata endpoint access (SSRF)",
|
|
125
|
+
reason: `"${host}" is a cloud instance-metadata service. Prompt-injected agents historically steal IAM credentials here. Metadata endpoints are never a legitimate agent destination.`,
|
|
126
|
+
evidence,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (cfg.block_private_networks && isPrivateHost(host)) {
|
|
130
|
+
push({
|
|
131
|
+
scanner: this.name,
|
|
132
|
+
ruleId: "URL-PRIVATE-NETWORK",
|
|
133
|
+
severity: "HIGH",
|
|
134
|
+
title: "Private network access (SSRF)",
|
|
135
|
+
reason: `"${host}" resolves into loopback/link-local/private address space. Outbound requests to private networks are a server-side request forgery vector.`,
|
|
136
|
+
evidence,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (cfg.denied_domains.some((d) => domainMatches(host, d))) {
|
|
140
|
+
push({
|
|
141
|
+
scanner: this.name,
|
|
142
|
+
ruleId: "URL-DENIED-DOMAIN",
|
|
143
|
+
severity: "HIGH",
|
|
144
|
+
title: "Denied domain",
|
|
145
|
+
reason: `"${host}" is on the denied_domains list.`,
|
|
146
|
+
policyRef: "url_policy.denied_domains",
|
|
147
|
+
evidence,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else if (cfg.allowed_domains.length > 0 && !cfg.allowed_domains.some((d) => domainMatches(host, d))) {
|
|
151
|
+
push({
|
|
152
|
+
scanner: this.name,
|
|
153
|
+
ruleId: "URL-DOMAIN-NOT-ALLOWED",
|
|
154
|
+
severity: "HIGH",
|
|
155
|
+
title: "Domain not in allowlist",
|
|
156
|
+
reason: `"${host}" is not on allowed_domains and an allowlist is configured.`,
|
|
157
|
+
policyRef: "url_policy.allowed_domains",
|
|
158
|
+
evidence,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (!cfg.allowed_schemes.includes(scheme)) {
|
|
162
|
+
push({
|
|
163
|
+
scanner: this.name,
|
|
164
|
+
ruleId: "URL-SCHEME",
|
|
165
|
+
severity: "HIGH",
|
|
166
|
+
title: "Disallowed URL scheme",
|
|
167
|
+
reason: `Scheme "${scheme}:" is not in allowed_schemes [${cfg.allowed_schemes.join(", ")}]. Non-HTTPS schemes can carry local files (file://) or unencrypted traffic.`,
|
|
168
|
+
policyRef: "url_policy.allowed_schemes",
|
|
169
|
+
evidence,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return findings;
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=urlPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlPolicy.js","sourceRoot":"","sources":["../../src/scanners/urlPolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACpI,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAC3F,MAAM,MAAM,GAAG,4CAA4C,CAAC;AAE5D,MAAM,cAAc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AG,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtG,IAAI,CAAC;oBACH,OAAO,EAAE,IAAI,CAAC,IAAI;oBAClB,MAAM,EAAE,wBAAwB;oBAChC,QAAQ,EAAE,MAAM;oBAChB,KAAK,EAAE,yBAAyB;oBAChC,MAAM,EAAE,IAAI,IAAI,6DAA6D;oBAC7E,SAAS,EAAE,4BAA4B;oBACvC,QAAQ;iBACT,CAAC,CAAC;YACL,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1C,IAAI,CAAC;oBACH,OAAO,EAAE,IAAI,CAAC,IAAI;oBAClB,MAAM,EAAE,YAAY;oBACpB,QAAQ,EAAE,MAAM;oBAChB,KAAK,EAAE,uBAAuB;oBAC9B,MAAM,EAAE,WAAW,MAAM,iCAAiC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,8EAA8E;oBACtK,SAAS,EAAE,4BAA4B;oBACvC,QAAQ;iBACT,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal ANSI coloring with automatic disabling when stdout is not a TTY
|
|
3
|
+
* or NO_COLOR is set (https://no-color.org). Keeps the dependency tree at zero
|
|
4
|
+
* for something this trivial.
|
|
5
|
+
*/
|
|
6
|
+
export declare const bold: (t: string) => string;
|
|
7
|
+
export declare const dim: (t: string) => string;
|
|
8
|
+
export declare const red: (t: string) => string;
|
|
9
|
+
export declare const green: (t: string) => string;
|
|
10
|
+
export declare const yellow: (t: string) => string;
|
|
11
|
+
export declare const blue: (t: string) => string;
|
|
12
|
+
export declare const magenta: (t: string) => string;
|
|
13
|
+
export declare const cyan: (t: string) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal ANSI coloring with automatic disabling when stdout is not a TTY
|
|
3
|
+
* or NO_COLOR is set (https://no-color.org). Keeps the dependency tree at zero
|
|
4
|
+
* for something this trivial.
|
|
5
|
+
*/
|
|
6
|
+
function enabled() {
|
|
7
|
+
return Boolean(process.stdout.isTTY) && !process.env.NO_COLOR && !process.env.FORCE_COLOR?.startsWith("0");
|
|
8
|
+
}
|
|
9
|
+
function wrap(code, text) {
|
|
10
|
+
return enabled() ? `\x1b[${code}m${text}\x1b[0m` : text;
|
|
11
|
+
}
|
|
12
|
+
export const bold = (t) => wrap("1", t);
|
|
13
|
+
export const dim = (t) => wrap("2", t);
|
|
14
|
+
export const red = (t) => wrap("31", t);
|
|
15
|
+
export const green = (t) => wrap("32", t);
|
|
16
|
+
export const yellow = (t) => wrap("33", t);
|
|
17
|
+
export const blue = (t) => wrap("34", t);
|
|
18
|
+
export const magenta = (t) => wrap("35", t);
|
|
19
|
+
export const cyan = (t) => wrap("36", t);
|
|
20
|
+
//# sourceMappingURL=ansi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ansi.js","sourceRoot":"","sources":["../../src/util/ansi.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,SAAS,OAAO;IACd,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;AAC7G,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,IAAY;IACtC,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACpD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shannon entropy over the character distribution of a string.
|
|
3
|
+
* Used as a secondary signal for "this long random-looking token is probably
|
|
4
|
+
* a credential" — regexes alone only catch well-known secret formats.
|
|
5
|
+
*/
|
|
6
|
+
export declare function shannonEntropy(text: string): number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shannon entropy over the character distribution of a string.
|
|
3
|
+
* Used as a secondary signal for "this long random-looking token is probably
|
|
4
|
+
* a credential" — regexes alone only catch well-known secret formats.
|
|
5
|
+
*/
|
|
6
|
+
export function shannonEntropy(text) {
|
|
7
|
+
if (text.length === 0)
|
|
8
|
+
return 0;
|
|
9
|
+
const counts = new Map();
|
|
10
|
+
for (const ch of text) {
|
|
11
|
+
counts.set(ch, (counts.get(ch) ?? 0) + 1);
|
|
12
|
+
}
|
|
13
|
+
let entropy = 0;
|
|
14
|
+
for (const count of counts.values()) {
|
|
15
|
+
const p = count / text.length;
|
|
16
|
+
entropy -= p * Math.log2(p);
|
|
17
|
+
}
|
|
18
|
+
return entropy;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=entropy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.js","sourceRoot":"","sources":["../../src/util/entropy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QACtB,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path helpers: home expansion, POSIX normalization, glob matching and a
|
|
3
|
+
* bounded filesystem counter used by the bulk-delete rule.
|
|
4
|
+
*
|
|
5
|
+
* All matching is done on POSIX-style absolute paths with any Windows drive
|
|
6
|
+
* prefix ("C:") stripped, so policies written as "/etc/**" or ".env" match
|
|
7
|
+
* identically on Linux, macOS and Windows.
|
|
8
|
+
*/
|
|
9
|
+
/** Hard caps so a pathological glob can never make the scanner hang. */
|
|
10
|
+
export declare const WALK_MAX_ENTRIES = 5000;
|
|
11
|
+
export declare const WALK_MAX_DEPTH = 12;
|
|
12
|
+
export declare function expandHome(p: string): string;
|
|
13
|
+
/** Absolute, normalized, POSIX-flavored path (drive prefix stripped on Windows). */
|
|
14
|
+
export declare function normalizePath(p: string, cwd?: string): string;
|
|
15
|
+
/** Remove a leading "C:" style drive prefix, leaving "/foo/bar". */
|
|
16
|
+
export declare function stripDrive(p: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Glob → RegExp. Semantics kept intentionally small:
|
|
19
|
+
* `**` matches any number of path segments (including none, and `/`)
|
|
20
|
+
* `*` matches any characters except `/`
|
|
21
|
+
* `?` matches a single character except `/`
|
|
22
|
+
* Everything else is literal.
|
|
23
|
+
*/
|
|
24
|
+
export declare function globToRegExp(pattern: string): RegExp;
|
|
25
|
+
/** True when `p` (already normalized) matches a policy glob pattern. */
|
|
26
|
+
export declare function pathMatches(pattern: string, p: string): boolean;
|
|
27
|
+
export declare function hasGlobChars(p: string): boolean;
|
|
28
|
+
export interface CountResult {
|
|
29
|
+
/** Number of files that would be removed (directories count their contents). */
|
|
30
|
+
files: number;
|
|
31
|
+
/** True when the walk hit its safety cap and the number is a lower bound. */
|
|
32
|
+
capped: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Count the real files a delete of `targets` would touch, expanding globs and
|
|
36
|
+
* recursing into directories. Read-only and strictly bounded.
|
|
37
|
+
*/
|
|
38
|
+
export declare function countDeletableFiles(targets: string[], cwd?: string): CountResult;
|
|
39
|
+
/**
|
|
40
|
+
* True for delete targets that mean "the whole machine / home / current tree":
|
|
41
|
+
* "/", "/*", "~", "~/*", "$HOME", ".", "..", "*", a bare drive root, etc.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isRootishTarget(target: string): boolean;
|