@acepaste/ingress 0.0.0-stage → 0.8.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/LICENSE +105 -0
- package/README.md +15 -2
- package/dist/src/acepaste-alphabet.d.ts +26 -0
- package/dist/src/acepaste-alphabet.js +47 -0
- package/dist/src/acquire.d.ts +42 -0
- package/dist/src/acquire.js +271 -0
- package/dist/src/adapters.d.ts +30 -0
- package/dist/src/adapters.js +160 -0
- package/dist/src/character.d.ts +22 -0
- package/dist/src/character.js +291 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +75 -0
- package/dist/src/color.d.ts +26 -0
- package/dist/src/color.js +111 -0
- package/dist/src/engine.d.ts +131 -0
- package/dist/src/engine.js +715 -0
- package/dist/src/evidence.d.ts +21 -0
- package/dist/src/evidence.js +77 -0
- package/dist/src/index.d.ts +28 -0
- package/dist/src/index.js +20 -0
- package/dist/src/meaning.d.ts +28 -0
- package/dist/src/meaning.js +227 -0
- package/dist/src/netpolicy.d.ts +34 -0
- package/dist/src/netpolicy.js +122 -0
- package/dist/src/normalize.d.ts +34 -0
- package/dist/src/normalize.js +204 -0
- package/dist/src/policyfile.d.ts +2 -0
- package/dist/src/policyfile.js +50 -0
- package/dist/src/sandbox.d.ts +45 -0
- package/dist/src/sandbox.js +231 -0
- package/dist/src/script.d.ts +23 -0
- package/dist/src/script.js +220 -0
- package/dist/src/secrets.d.ts +24 -0
- package/dist/src/secrets.js +192 -0
- package/dist/src/summary.d.ts +40 -0
- package/dist/src/summary.js +62 -0
- package/dist/src/supplychain.d.ts +24 -0
- package/dist/src/supplychain.js +182 -0
- package/dist/src/taint.d.ts +37 -0
- package/dist/src/taint.js +39 -0
- package/dist/src/types.d.ts +202 -0
- package/dist/src/types.js +33 -0
- package/dist/src/visibility.d.ts +41 -0
- package/dist/src/visibility.js +424 -0
- package/package.json +64 -4
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script pass (underlight lineage).
|
|
3
|
+
*
|
|
4
|
+
* Static, millisecond-budget analysis of every script on the page. It does
|
|
5
|
+
* not execute anything. A high score marks the page for sandbox escalation
|
|
6
|
+
* (sandbox not yet implemented; the hook is in engine.ts).
|
|
7
|
+
*
|
|
8
|
+
* Surfaces, from the underlight list: obfuscation and minification signatures,
|
|
9
|
+
* runtime code generation, typed-array / binary-buffer decoding, automation
|
|
10
|
+
* detection (agent-targeted cloaking), post-load text injection, and outbound
|
|
11
|
+
* beacons that could carry exfiltrated context.
|
|
12
|
+
*/
|
|
13
|
+
import * as acorn from "acorn";
|
|
14
|
+
import * as walk from "acorn-walk";
|
|
15
|
+
const AUTOMATION_PROBES = [
|
|
16
|
+
"webdriver", "__webdriver", "_phantom", "callPhantom", "__nightmare", "__selenium", "domAutomation",
|
|
17
|
+
"HeadlessChrome", "puppeteer", "playwright", "__playwright", "chrome.runtime", "navigator.plugins.length",
|
|
18
|
+
"navigator.languages.length", "outerWidth", "connection.rtt", "permissions.query", "notifications",
|
|
19
|
+
"GPTBot", "ClaudeBot", "Claude-Web", "anthropic-ai", "PerplexityBot", "ChatGPT-User", "OAI-SearchBot", "Google-Extended", "cohere-ai", "Bytespider",
|
|
20
|
+
];
|
|
21
|
+
const EXFIL_SINKS = ["sendBeacon", "XMLHttpRequest", "fetch", "WebSocket", "EventSource"];
|
|
22
|
+
const TEXT_SINKS = ["innerHTML", "outerHTML", "textContent", "innerText", "insertAdjacentHTML", "write", "writeln", "appendChild", "replaceChildren", "createTextNode"];
|
|
23
|
+
const CODEGEN = ["eval", "Function", "setTimeout", "setInterval", "execScript", "importScripts"];
|
|
24
|
+
const BINARY_DECODE = ["TextDecoder", "Uint8Array", "Uint16Array", "Int8Array", "DataView", "ArrayBuffer", "atob", "fromCharCode", "fromCodePoint", "decodeURIComponent", "unescape", "charCodeAt"];
|
|
25
|
+
function shannon(s) {
|
|
26
|
+
if (!s)
|
|
27
|
+
return 0;
|
|
28
|
+
const freq = new Map();
|
|
29
|
+
for (const c of s)
|
|
30
|
+
freq.set(c, (freq.get(c) ?? 0) + 1);
|
|
31
|
+
let h = 0;
|
|
32
|
+
for (const n of freq.values()) {
|
|
33
|
+
const p = n / s.length;
|
|
34
|
+
h -= p * Math.log2(p);
|
|
35
|
+
}
|
|
36
|
+
return h;
|
|
37
|
+
}
|
|
38
|
+
function memberChain(node) {
|
|
39
|
+
if (!node)
|
|
40
|
+
return "";
|
|
41
|
+
if (node.type === "Identifier")
|
|
42
|
+
return node.name;
|
|
43
|
+
if (node.type === "ThisExpression")
|
|
44
|
+
return "this";
|
|
45
|
+
if (node.type === "MemberExpression") {
|
|
46
|
+
const prop = node.computed ? (node.property.type === "Literal" ? String(node.property.value) : "[]") : node.property.name;
|
|
47
|
+
return `${memberChain(node.object)}.${prop}`;
|
|
48
|
+
}
|
|
49
|
+
if (node.type === "CallExpression")
|
|
50
|
+
return memberChain(node.callee) + "()";
|
|
51
|
+
return node.type;
|
|
52
|
+
}
|
|
53
|
+
export function analyzeScript(unit) {
|
|
54
|
+
const findings = [];
|
|
55
|
+
const src = unit.source;
|
|
56
|
+
const loc = unit.inline ? `inline script #${unit.index}` : `script #${unit.index} src=${unit.src}`;
|
|
57
|
+
if (!src.trim())
|
|
58
|
+
return { findings, suspicion: 0 };
|
|
59
|
+
// --- lexical signals, computed before parsing (obfuscated code may not parse)
|
|
60
|
+
const hexIdents = (src.match(/\b_0x[0-9a-f]{2,}\b/g) ?? []).length;
|
|
61
|
+
const escapes = (src.match(/\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}/g) ?? []).length;
|
|
62
|
+
const longStrings = (src.match(/["'`][^"'`\n]{200,}["'`]/g) ?? []);
|
|
63
|
+
const longStringEntropy = longStrings.length ? Math.max(...longStrings.map(shannon)) : 0;
|
|
64
|
+
const bracketAccess = (src.match(/\[\s*["'][A-Za-z_$][\w$]*["']\s*\]/g) ?? []).length;
|
|
65
|
+
const jsfuck = /(\[\]|!\[\]|\+\[\]|\(!\[\]\+\[\]\))\s*[\[\+]/.test(src) && (src.match(/\[\]/g) ?? []).length > 40;
|
|
66
|
+
const nonAscii = ([...src].filter((c) => c.charCodeAt(0) > 127).length) / Math.max(1, src.length);
|
|
67
|
+
let obf = 0;
|
|
68
|
+
// hex identifiers are the javascript-obfuscator.io signature; even a few are diagnostic
|
|
69
|
+
obf += hexIdents >= 3 ? Math.min(0.4, 0.2 + hexIdents / 40) : 0;
|
|
70
|
+
obf += Math.min(0.25, escapes / 80);
|
|
71
|
+
obf += longStringEntropy > 5.2 ? 0.2 : 0;
|
|
72
|
+
obf += Math.min(0.15, bracketAccess / 60);
|
|
73
|
+
obf += jsfuck ? 0.5 : 0;
|
|
74
|
+
obf += nonAscii > 0.05 ? 0.1 : 0;
|
|
75
|
+
// minified-but-legitimate bundles have short identifiers but no hex idents or escapes; keep obf low for them
|
|
76
|
+
if (obf >= 0.3) {
|
|
77
|
+
findings.push({
|
|
78
|
+
pass: "script", kind: "script.obfuscation", confidence: Math.min(0.9, obf), severity: 0.5,
|
|
79
|
+
message: `obfuscation signatures: ${hexIdents} hex identifiers, ${escapes} escapes, string entropy ${longStringEntropy.toFixed(2)}${jsfuck ? ", symbol-only encoding" : ""}`,
|
|
80
|
+
location: loc, action: "none",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// --- structural signals via AST
|
|
84
|
+
let ast;
|
|
85
|
+
try {
|
|
86
|
+
ast = acorn.parse(src, { ecmaVersion: "latest", sourceType: "script", allowHashBang: true, allowReturnOutsideFunction: true });
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
try {
|
|
90
|
+
ast = acorn.parse(src, { ecmaVersion: "latest", sourceType: "module" });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
ast = null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let codegen = 0, automation = 0, textInject = 0, exfil = 0, binary = 0;
|
|
97
|
+
const automationHits = new Set();
|
|
98
|
+
const exfilHits = new Set();
|
|
99
|
+
const urlLiterals = new Set();
|
|
100
|
+
if (ast) {
|
|
101
|
+
walk.simple(ast, {
|
|
102
|
+
CallExpression(node) {
|
|
103
|
+
const chain = memberChain(node.callee);
|
|
104
|
+
const tail = chain.split(".").pop() ?? "";
|
|
105
|
+
if (tail === "eval" || tail === "Function" || tail === "execScript")
|
|
106
|
+
codegen += 1;
|
|
107
|
+
if ((tail === "setTimeout" || tail === "setInterval") && node.arguments[0]?.type !== "FunctionExpression" && node.arguments[0]?.type !== "ArrowFunctionExpression" && node.arguments[0]?.type !== "Identifier")
|
|
108
|
+
codegen += 0.6;
|
|
109
|
+
if (EXFIL_SINKS.includes(tail) || chain.endsWith("navigator.sendBeacon") || chain === "new Image") {
|
|
110
|
+
exfil += 1;
|
|
111
|
+
exfilHits.add(tail);
|
|
112
|
+
}
|
|
113
|
+
if (TEXT_SINKS.includes(tail))
|
|
114
|
+
textInject += 0.5;
|
|
115
|
+
if (BINARY_DECODE.includes(tail))
|
|
116
|
+
binary += 0.5;
|
|
117
|
+
if (tail === "fromCharCode" && node.arguments.length > 8)
|
|
118
|
+
binary += 1.5;
|
|
119
|
+
},
|
|
120
|
+
NewExpression(node) {
|
|
121
|
+
const name = memberChain(node.callee);
|
|
122
|
+
if (name === "Function")
|
|
123
|
+
codegen += 1;
|
|
124
|
+
if (BINARY_DECODE.includes(name))
|
|
125
|
+
binary += 0.5;
|
|
126
|
+
if (name === "Image" || name === "WebSocket" || name === "XMLHttpRequest") {
|
|
127
|
+
exfil += 0.5;
|
|
128
|
+
exfilHits.add(name);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
MemberExpression(node) {
|
|
132
|
+
const chain = memberChain(node);
|
|
133
|
+
for (const probe of AUTOMATION_PROBES)
|
|
134
|
+
if (chain.includes(probe)) {
|
|
135
|
+
automation += 1;
|
|
136
|
+
automationHits.add(probe);
|
|
137
|
+
}
|
|
138
|
+
if (/\.(innerHTML|outerHTML|textContent|innerText)$/.test(chain))
|
|
139
|
+
textInject += 0.5;
|
|
140
|
+
if (chain.endsWith(".src") || chain.endsWith(".href"))
|
|
141
|
+
exfil += 0.1;
|
|
142
|
+
},
|
|
143
|
+
Literal(node) {
|
|
144
|
+
if (node.regex) {
|
|
145
|
+
for (const probe of AUTOMATION_PROBES)
|
|
146
|
+
if (node.regex.pattern.includes(probe)) {
|
|
147
|
+
automation += 0.8;
|
|
148
|
+
automationHits.add(probe);
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (typeof node.value !== "string")
|
|
153
|
+
return;
|
|
154
|
+
for (const probe of AUTOMATION_PROBES)
|
|
155
|
+
if (node.value.includes(probe)) {
|
|
156
|
+
automation += 0.8;
|
|
157
|
+
automationHits.add(probe);
|
|
158
|
+
}
|
|
159
|
+
if (/^(https?:)?\/\/[^/]+\/(collect|beacon|track|pixel|log|t\.gif|p\.gif|hook|webhook)/i.test(node.value)) {
|
|
160
|
+
exfil += 0.8;
|
|
161
|
+
exfilHits.add(node.value.slice(0, 60));
|
|
162
|
+
}
|
|
163
|
+
if (/^https?:\/\/[^\s"']+$/.test(node.value))
|
|
164
|
+
urlLiterals.add(node.value.slice(0, 120));
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// unparseable: treat lexical hits as structural
|
|
170
|
+
for (const p of AUTOMATION_PROBES)
|
|
171
|
+
if (src.includes(p)) {
|
|
172
|
+
automation += 1;
|
|
173
|
+
automationHits.add(p);
|
|
174
|
+
}
|
|
175
|
+
if (/\beval\s*\(|new\s+Function\s*\(/.test(src))
|
|
176
|
+
codegen += 1;
|
|
177
|
+
obf += 0.2;
|
|
178
|
+
}
|
|
179
|
+
if (codegen >= 1)
|
|
180
|
+
findings.push({
|
|
181
|
+
pass: "script", kind: "script.runtime_codegen", confidence: Math.min(0.85, 0.4 + codegen * 0.15), severity: 0.6,
|
|
182
|
+
message: `runtime code generation (${Math.round(codegen)} sites: eval / new Function / string timers)`, location: loc, action: "none",
|
|
183
|
+
});
|
|
184
|
+
if (automation >= 1)
|
|
185
|
+
findings.push({
|
|
186
|
+
pass: "script", kind: "script.automation_detection", confidence: Math.min(0.95, 0.45 + automation * 0.12), severity: 0.85,
|
|
187
|
+
message: `probes for automation or AI crawlers: ${[...automationHits].slice(0, 6).join(", ")}`, excerpt: [...urlLiterals].slice(0, 5).join(" "), location: loc, action: "none",
|
|
188
|
+
});
|
|
189
|
+
if (textInject >= 2 && (codegen >= 1 || binary >= 2 || obf >= 0.3))
|
|
190
|
+
findings.push({
|
|
191
|
+
pass: "script", kind: "script.post_load_text_injection", confidence: 0.6, severity: 0.7,
|
|
192
|
+
message: `writes text into the document after load, combined with decoding or code generation`, location: loc, action: "none",
|
|
193
|
+
});
|
|
194
|
+
if (exfil >= 1.5 && (textInject >= 1 || binary >= 1 || automation >= 1))
|
|
195
|
+
findings.push({
|
|
196
|
+
pass: "script", kind: "script.exfil_beacon", confidence: Math.min(0.8, 0.3 + exfil * 0.1), severity: 0.6,
|
|
197
|
+
message: `outbound channels present: ${[...exfilHits].slice(0, 4).join(", ")}`, excerpt: [...urlLiterals].slice(0, 5).join(" "), location: loc, action: "none",
|
|
198
|
+
});
|
|
199
|
+
if (binary >= 3)
|
|
200
|
+
findings.push({
|
|
201
|
+
pass: "script", kind: "script.binary_decoding", confidence: Math.min(0.8, 0.3 + binary * 0.08), severity: 0.5,
|
|
202
|
+
message: `typed-array / char-code decoding of embedded data (${Math.round(binary)} sites)`, location: loc, action: "none",
|
|
203
|
+
});
|
|
204
|
+
// suspicion for sandbox escalation: automation detection and codegen+textinject are the strongest tells
|
|
205
|
+
const suspicion = Math.min(1, obf * 0.6 +
|
|
206
|
+
(automation >= 1 ? 0.5 : 0) +
|
|
207
|
+
(codegen >= 1 && textInject >= 1 ? 0.35 : 0) +
|
|
208
|
+
(binary >= 3 ? 0.15 : 0));
|
|
209
|
+
return { findings, suspicion };
|
|
210
|
+
}
|
|
211
|
+
export function analyzeScripts(units) {
|
|
212
|
+
const findings = [];
|
|
213
|
+
let maxSuspicion = 0;
|
|
214
|
+
for (const u of units) {
|
|
215
|
+
const r = analyzeScript(u);
|
|
216
|
+
findings.push(...r.findings);
|
|
217
|
+
maxSuspicion = Math.max(maxSuspicion, r.suspicion);
|
|
218
|
+
}
|
|
219
|
+
return { findings, maxSuspicion };
|
|
220
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secrets pass (Kith & Revere lineage, ported 2026-10-31).
|
|
3
|
+
*
|
|
4
|
+
* Kith & Revere's rule for credentials: name the kind of secret and where it
|
|
5
|
+
* is, never print the secret itself. The gate applies the same rule at the
|
|
6
|
+
* ingestion boundary. A credential in fetched content is either a leak (it
|
|
7
|
+
* should not land in a model's context, logs or training data) or bait (a
|
|
8
|
+
* planted key with instructions to use it). Either way the gate redacts it
|
|
9
|
+
* from everything it emits: delivered text, finding excerpts, the attack log
|
|
10
|
+
* and the public feed. Detection alone does not refuse a page; a credential
|
|
11
|
+
* in hidden text does count against it.
|
|
12
|
+
*/
|
|
13
|
+
import type { Finding, TextSegment } from "./types.js";
|
|
14
|
+
/** The literal credential values present in these texts, for scrubbing excerpts that were cut or altered before redaction. */
|
|
15
|
+
export declare function collectSecrets(texts: ReadonlyArray<string>): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Make an excerpt safe to log or publish. Redacts detected credentials, then removes any fragment of a known
|
|
18
|
+
* credential (an excerpt cut mid-token, or with an invisible character swapped for a marker, can no longer match
|
|
19
|
+
* a pattern on its own). Works on a copy with invisible characters and replacement markers removed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function scrubExcerpt(text: string, known: ReadonlyArray<string>): string;
|
|
22
|
+
/** Replace every detected credential with a label naming its kind. Never reversible. */
|
|
23
|
+
export declare function redactSecrets(text: string): string;
|
|
24
|
+
export declare function scanSecrets(segments: ReadonlyArray<TextSegment>, decodedPayloads: ReadonlyArray<string>): Finding[];
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secrets pass (Kith & Revere lineage, ported 2026-10-31).
|
|
3
|
+
*
|
|
4
|
+
* Kith & Revere's rule for credentials: name the kind of secret and where it
|
|
5
|
+
* is, never print the secret itself. The gate applies the same rule at the
|
|
6
|
+
* ingestion boundary. A credential in fetched content is either a leak (it
|
|
7
|
+
* should not land in a model's context, logs or training data) or bait (a
|
|
8
|
+
* planted key with instructions to use it). Either way the gate redacts it
|
|
9
|
+
* from everything it emits: delivered text, finding excerpts, the attack log
|
|
10
|
+
* and the public feed. Detection alone does not refuse a page; a credential
|
|
11
|
+
* in hidden text does count against it.
|
|
12
|
+
*/
|
|
13
|
+
// Every quantifier is bounded and every pattern has a cheap literal pre-filter: this pass runs on attacker-supplied
|
|
14
|
+
// text, so no pattern may be able to scan quadratically ("a.a.a.…", "sk-sk-sk-…", an unterminated key block).
|
|
15
|
+
// A token ends at the first character that cannot continue it, not at a word boundary ("ghp_…_backup" still matches).
|
|
16
|
+
const END = String.raw `(?![A-Za-z0-9])`;
|
|
17
|
+
const PATTERNS = [
|
|
18
|
+
{ name: "AWS access key id", pre: /A[KSBC][IC]A/, re: new RegExp(String.raw `(?<![A-Za-z0-9])(AKIA|ASIA|ABIA|ACCA)[0-9A-Z]{16}` + END, "g") },
|
|
19
|
+
{ name: "AWS secret access key", pre: /secret_?access_?key/i, re: /(aws_secret_access_key\s{0,3}[=:]\s{0,3}["']?|"SecretAccessKey"\s{0,3}:\s{0,3}")[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=])/gi },
|
|
20
|
+
{ name: "GitHub token", pre: /gh[pousr]_|github_pat_/, re: new RegExp(String.raw `(?<![A-Za-z0-9])((ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,80}|github_pat_[A-Za-z0-9_]{60,120})` + END, "g") },
|
|
21
|
+
{ name: "GitLab token", pre: /glpat-/, re: new RegExp(String.raw `glpat-[A-Za-z0-9_-]{20,64}` + END, "g") },
|
|
22
|
+
{ name: "Slack token", pre: /xox[abposr]-/, re: new RegExp(String.raw `xox[abposr]-[A-Za-z0-9-]{10,120}` + END, "g") },
|
|
23
|
+
{ name: "Stripe secret key", pre: /[sr]k_live_/, re: new RegExp(String.raw `(sk|rk)_live_[A-Za-z0-9]{20,120}` + END, "g") },
|
|
24
|
+
{ name: "npm token", pre: /npm_|_authToken/, re: /(?<![A-Za-z0-9])npm_[A-Za-z0-9]{36}(?![A-Za-z0-9])|_authToken\s{0,3}=\s{0,3}[^\s"']{20,200}/g },
|
|
25
|
+
{ name: "Anthropic API key", pre: /sk-ant-/, re: new RegExp(String.raw `sk-ant-[A-Za-z0-9_-]{30,200}` + END, "g") },
|
|
26
|
+
{ name: "OpenAI API key", pre: /sk-/, re: new RegExp(String.raw `(?<![A-Za-z0-9-])sk-(proj-|svcacct-)?[A-Za-z0-9_-]{40,200}` + END, "g") },
|
|
27
|
+
{ name: "Hugging Face token", pre: /hf_/, re: new RegExp(String.raw `(?<![A-Za-z0-9])hf_[A-Za-z0-9]{34,40}` + END, "g") },
|
|
28
|
+
{ name: "SendGrid key", pre: /SG\./, re: /(?<![A-Za-z0-9])SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])/g },
|
|
29
|
+
{ name: "Google API key", pre: /AIza/, re: new RegExp(String.raw `AIza[0-9A-Za-z_-]{35}` + END, "g") },
|
|
30
|
+
{ name: "private key block", pre: /PRIVATE KEY/, re: /-----BEGIN (RSA |EC |OPENSSH |DSA |PGP |ENCRYPTED )?PRIVATE KEY( BLOCK)?-----[\s\S]{20,16000}?-----END (RSA |EC |OPENSSH |DSA |PGP |ENCRYPTED )?PRIVATE KEY( BLOCK)?-----/g },
|
|
31
|
+
{ name: "credential in URL", pre: /:\/\/[^\s/@]{0,200}:[^\s/@]{0,200}@/, re: /(?<![A-Za-z0-9+.-])[a-z][a-z0-9+.-]{0,20}:\/\/([^\s:/@]{2,64}):([^\s:/@]{6,128})@([^\s/:]{1,253})/gi },
|
|
32
|
+
{ name: "Kubernetes credential", pre: /client-(key|certificate)-data/, re: /(client-key-data|client-certificate-data):\s{0,3}[A-Za-z0-9+/=]{40,20000}/g },
|
|
33
|
+
];
|
|
34
|
+
/** documentation placeholders are not secrets */
|
|
35
|
+
const PLACEHOLDER = /EXAMPLE|example|xxxx|XXXX|your[_-]?(key|token)|placeholder|dummy|redacted|\*{4,}|<[^>]+>|\.\.\.|0{12,}|1234567890/;
|
|
36
|
+
/** well-known development defaults are not credentials worth redacting */
|
|
37
|
+
const DEFAULT_PASSWORDS = /^(password|passwd|postgres|secret|changeme|root|admin|example|test|guest|pass|mysql|redis)$/i;
|
|
38
|
+
const LOCAL_HOST = /^(localhost|127\.\d+\.\d+\.\d+|0\.0\.0\.0|\[::1\]|db|postgres|mysql|redis|.*\.(local|localhost|internal|test|example))$/i;
|
|
39
|
+
function entropy(s) {
|
|
40
|
+
const f = new Map();
|
|
41
|
+
for (const c of s)
|
|
42
|
+
f.set(c, (f.get(c) ?? 0) + 1);
|
|
43
|
+
let h = 0;
|
|
44
|
+
for (const n of f.values()) {
|
|
45
|
+
const p = n / s.length;
|
|
46
|
+
h -= p * Math.log2(p);
|
|
47
|
+
}
|
|
48
|
+
return h;
|
|
49
|
+
}
|
|
50
|
+
function plausible(p, m) {
|
|
51
|
+
const v = m[0];
|
|
52
|
+
if (PLACEHOLDER.test(v))
|
|
53
|
+
return false;
|
|
54
|
+
if (p.name === "private key block" || p.name === "Kubernetes credential")
|
|
55
|
+
return true;
|
|
56
|
+
if (p.name === "credential in URL") {
|
|
57
|
+
const [, user, pass, host] = m;
|
|
58
|
+
if (LOCAL_HOST.test(host) || DEFAULT_PASSWORDS.test(pass) || user === pass)
|
|
59
|
+
return false;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
const body = v.replace(/^[a-z_]+[-_]/i, "");
|
|
63
|
+
if (entropy(body) < 3.0)
|
|
64
|
+
return false;
|
|
65
|
+
if (p.name === "OpenAI API key") {
|
|
66
|
+
// a key mixes case and digits and has at most a few hyphens; a URL slug like "sk-hynix-posts-record-…" does not
|
|
67
|
+
const b = v.replace(/^sk-(proj-|svcacct-)?/, "");
|
|
68
|
+
if (!(/[a-z]/.test(b) && /[A-Z]/.test(b) && /\d/.test(b)) || (b.match(/-/g) ?? []).length > 4)
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
function findSecrets(text) {
|
|
74
|
+
const hits = [];
|
|
75
|
+
if (!text || text.length < 16)
|
|
76
|
+
return hits;
|
|
77
|
+
// private key blocks: a linear scan (each BEGIN is paired with the next END by index, never by backtracking)
|
|
78
|
+
if (text.includes("PRIVATE KEY-----")) {
|
|
79
|
+
const begin = /-----BEGIN (?:RSA |EC |OPENSSH |DSA |PGP |ENCRYPTED )?PRIVATE KEY(?: BLOCK)?-----/g;
|
|
80
|
+
let m;
|
|
81
|
+
let after = 0, cachedEnd = -2;
|
|
82
|
+
while ((m = begin.exec(text)) && hits.length < 500) {
|
|
83
|
+
if (m.index < after)
|
|
84
|
+
continue;
|
|
85
|
+
if (cachedEnd < m.index + m[0].length && cachedEnd !== -1)
|
|
86
|
+
cachedEnd = text.indexOf("-----END ", m.index + m[0].length);
|
|
87
|
+
const endAt = cachedEnd;
|
|
88
|
+
if (endAt < 0)
|
|
89
|
+
break;
|
|
90
|
+
const close = text.indexOf("-----", endAt + 9);
|
|
91
|
+
if (close < 0)
|
|
92
|
+
break;
|
|
93
|
+
const stop = close + 5;
|
|
94
|
+
const body = text.slice(m.index + m[0].length, endAt);
|
|
95
|
+
if (body.length >= 20 && body.length <= 16000 && !PLACEHOLDER.test(body) && !/-----BEGIN /.test(body)) {
|
|
96
|
+
hits.push({ name: "private key block", start: m.index, end: stop, value: text.slice(m.index, stop) });
|
|
97
|
+
after = stop;
|
|
98
|
+
}
|
|
99
|
+
begin.lastIndex = Math.max(begin.lastIndex, m.index + m[0].length);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const p of PATTERNS) {
|
|
103
|
+
if (p.name === "private key block")
|
|
104
|
+
continue;
|
|
105
|
+
if (!p.pre.test(text))
|
|
106
|
+
continue;
|
|
107
|
+
p.re.lastIndex = 0;
|
|
108
|
+
for (const m of text.matchAll(p.re)) {
|
|
109
|
+
if (!plausible(p, m))
|
|
110
|
+
continue;
|
|
111
|
+
hits.push({ name: p.name, start: m.index, end: m.index + m[0].length, value: m[0] });
|
|
112
|
+
if (hits.length > 500)
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return hits.sort((a, b) => a.start - b.start).filter((h, i, arr) => i === 0 || h.start >= arr[i - 1].end);
|
|
117
|
+
}
|
|
118
|
+
/** The literal credential values present in these texts, for scrubbing excerpts that were cut or altered before redaction. */
|
|
119
|
+
export function collectSecrets(texts) {
|
|
120
|
+
const out = new Set();
|
|
121
|
+
for (const t of texts)
|
|
122
|
+
for (const h of findSecrets(t))
|
|
123
|
+
out.add(h.value);
|
|
124
|
+
return [...out];
|
|
125
|
+
}
|
|
126
|
+
const INVISIBLE_OR_REPLACEMENT = /[\u200B-\u200F\u2060-\u2064\uFEFF\u00AD\uFFFD\u{E0000}-\u{E007F}]/gu;
|
|
127
|
+
/**
|
|
128
|
+
* Make an excerpt safe to log or publish. Redacts detected credentials, then removes any fragment of a known
|
|
129
|
+
* credential (an excerpt cut mid-token, or with an invisible character swapped for a marker, can no longer match
|
|
130
|
+
* a pattern on its own). Works on a copy with invisible characters and replacement markers removed.
|
|
131
|
+
*/
|
|
132
|
+
export function scrubExcerpt(text, known) {
|
|
133
|
+
if (!text)
|
|
134
|
+
return text;
|
|
135
|
+
let out = redactSecrets(text);
|
|
136
|
+
const flat = out.replace(INVISIBLE_OR_REPLACEMENT, "");
|
|
137
|
+
let scrubbed = redactSecrets(flat);
|
|
138
|
+
for (const k of known) {
|
|
139
|
+
const plain = k.replace(INVISIBLE_OR_REPLACEMENT, "");
|
|
140
|
+
// any run of 10+ characters of the credential, which also covers a truncated head or tail
|
|
141
|
+
for (let len = Math.min(plain.length, 400); len >= 10; len = len > 40 ? len - 20 : len - 1) {
|
|
142
|
+
let changed = false;
|
|
143
|
+
for (let i = 0; i + len <= plain.length; i += Math.max(1, Math.floor(len / 2))) {
|
|
144
|
+
const frag = plain.slice(i, i + len);
|
|
145
|
+
if (scrubbed.includes(frag)) {
|
|
146
|
+
scrubbed = scrubbed.split(frag).join("[redacted]");
|
|
147
|
+
changed = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (changed)
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return scrubbed !== flat ? scrubbed : out;
|
|
155
|
+
}
|
|
156
|
+
/** Replace every detected credential with a label naming its kind. Never reversible. */
|
|
157
|
+
export function redactSecrets(text) {
|
|
158
|
+
if (!text)
|
|
159
|
+
return text;
|
|
160
|
+
const hits = findSecrets(text);
|
|
161
|
+
if (!hits.length)
|
|
162
|
+
return text;
|
|
163
|
+
let out = "", i = 0;
|
|
164
|
+
for (const h of hits) {
|
|
165
|
+
out += text.slice(i, h.start) + `[redacted: ${h.name}]`;
|
|
166
|
+
i = h.end;
|
|
167
|
+
}
|
|
168
|
+
return out + text.slice(i);
|
|
169
|
+
}
|
|
170
|
+
export function scanSecrets(segments, decodedPayloads) {
|
|
171
|
+
const byKind = new Map();
|
|
172
|
+
const visit = (text, hidden, where) => {
|
|
173
|
+
for (const h of findSecrets(text)) {
|
|
174
|
+
const e = byKind.get(h.name) ?? { n: 0, hidden: false, where };
|
|
175
|
+
e.n++;
|
|
176
|
+
e.hidden ||= hidden;
|
|
177
|
+
byKind.set(h.name, e);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
for (const s of segments)
|
|
181
|
+
visit(s.text, s.visibility !== "visible", s.path);
|
|
182
|
+
for (const p of decodedPayloads)
|
|
183
|
+
visit(p, true, "decoded payload");
|
|
184
|
+
return [...byKind.entries()].map(([name, e]) => ({
|
|
185
|
+
pass: "secrets", kind: "secrets.credential_in_content",
|
|
186
|
+
confidence: 0.8,
|
|
187
|
+
// a visible leaked key is not an attack on the model; a hidden one is bait or a planted channel
|
|
188
|
+
severity: e.hidden ? 0.6 : 0.25,
|
|
189
|
+
message: `${e.n} ${name}${e.n === 1 ? "" : "s"} in ${e.hidden ? "hidden " : ""}content; redacted from everything the gate emits (the value is never logged)`,
|
|
190
|
+
excerpt: `[redacted: ${name}]`, location: e.where, action: "neutralized",
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact, machine-readable digest of a result: findings grouped by pass and
|
|
3
|
+
* kind with counts and peak weight, plus the heaviest findings first.
|
|
4
|
+
* Adapted from Briar Greenway's probe script (2026-11-03).
|
|
5
|
+
*/
|
|
6
|
+
import type { Finding, IngressResult } from "./types.js";
|
|
7
|
+
export interface FindingGroup {
|
|
8
|
+
pass: string;
|
|
9
|
+
kind: string;
|
|
10
|
+
count: number;
|
|
11
|
+
maxWeight: number | null;
|
|
12
|
+
}
|
|
13
|
+
export interface TopFinding {
|
|
14
|
+
pass: string;
|
|
15
|
+
kind: string;
|
|
16
|
+
weight: number | null;
|
|
17
|
+
message: string;
|
|
18
|
+
excerpt: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ResultSummary {
|
|
21
|
+
url: string;
|
|
22
|
+
tier: IngressResult["tier"];
|
|
23
|
+
score: number;
|
|
24
|
+
contentKind: IngressResult["contentKind"];
|
|
25
|
+
findingCount: number;
|
|
26
|
+
groups: FindingGroup[];
|
|
27
|
+
top: TopFinding[];
|
|
28
|
+
}
|
|
29
|
+
/** confidence x severity, or null when either is not a finite number */
|
|
30
|
+
export declare function findingWeight(f: Pick<Finding, "confidence" | "severity">): number | null;
|
|
31
|
+
export declare function summarize(result: IngressResult, topN?: number): ResultSummary;
|
|
32
|
+
/**
|
|
33
|
+
* Cloaking-check settings from environment variables, shared by the CLI, the
|
|
34
|
+
* MCP server and the HTTP service:
|
|
35
|
+
* INGRESS_AGENT_UA "honest" to send only the gate's own name, or a "|"-separated list of user agents
|
|
36
|
+
* INGRESS_CLOAKING_JITTER "min,max" milliseconds between the two fetches
|
|
37
|
+
* INGRESS_HUMAN_PROXY HTTP(S) proxy URL for the browser-fingerprint fetch (e.g. a residential proxy)
|
|
38
|
+
* INGRESS_HUMAN_FETCH "browser" to make that fetch in a real headless Chromium
|
|
39
|
+
*/
|
|
40
|
+
export declare function cloakingConfigFromEnv(env: Record<string, string | undefined>, honestUserAgent: string): Partial<import("./types.js").IngressConfig>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact, machine-readable digest of a result: findings grouped by pass and
|
|
3
|
+
* kind with counts and peak weight, plus the heaviest findings first.
|
|
4
|
+
* Adapted from Briar Greenway's probe script (2026-11-03).
|
|
5
|
+
*/
|
|
6
|
+
/** confidence x severity, or null when either is not a finite number */
|
|
7
|
+
export function findingWeight(f) {
|
|
8
|
+
const n = f.confidence * f.severity;
|
|
9
|
+
return Number.isFinite(n) ? n : null;
|
|
10
|
+
}
|
|
11
|
+
const rounded = (n) => (n === null ? null : Number(n.toFixed(2)));
|
|
12
|
+
export function summarize(result, topN = 6) {
|
|
13
|
+
const groups = new Map();
|
|
14
|
+
for (const f of result.findings) {
|
|
15
|
+
// a tuple key cannot collide even if a pass or kind contains a colon
|
|
16
|
+
const key = JSON.stringify([f.pass, f.kind]);
|
|
17
|
+
const g = groups.get(key) ?? { pass: f.pass, kind: f.kind, count: 0, maxWeight: null };
|
|
18
|
+
g.count++;
|
|
19
|
+
const w = findingWeight(f);
|
|
20
|
+
if (w !== null && (g.maxWeight === null || w > g.maxWeight))
|
|
21
|
+
g.maxWeight = w;
|
|
22
|
+
groups.set(key, g);
|
|
23
|
+
}
|
|
24
|
+
const top = result.findings
|
|
25
|
+
.map((f, index) => ({ f, index, w: findingWeight(f) }))
|
|
26
|
+
.sort((a, b) => (b.w ?? -Infinity) - (a.w ?? -Infinity) || a.index - b.index)
|
|
27
|
+
.slice(0, topN)
|
|
28
|
+
.map(({ f, w }) => ({
|
|
29
|
+
pass: f.pass, kind: f.kind, weight: rounded(w),
|
|
30
|
+
message: (f.message || "").slice(0, 140),
|
|
31
|
+
excerpt: (f.excerpt || "").replace(/\s+/g, " ").slice(0, 80),
|
|
32
|
+
}));
|
|
33
|
+
return {
|
|
34
|
+
url: result.receipt.finalUrl || result.receipt.url,
|
|
35
|
+
tier: result.tier, score: result.score, contentKind: result.contentKind,
|
|
36
|
+
findingCount: result.findings.length,
|
|
37
|
+
groups: [...groups.values()].map((g) => ({ ...g, maxWeight: rounded(g.maxWeight) })),
|
|
38
|
+
top,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Cloaking-check settings from environment variables, shared by the CLI, the
|
|
43
|
+
* MCP server and the HTTP service:
|
|
44
|
+
* INGRESS_AGENT_UA "honest" to send only the gate's own name, or a "|"-separated list of user agents
|
|
45
|
+
* INGRESS_CLOAKING_JITTER "min,max" milliseconds between the two fetches
|
|
46
|
+
* INGRESS_HUMAN_PROXY HTTP(S) proxy URL for the browser-fingerprint fetch (e.g. a residential proxy)
|
|
47
|
+
* INGRESS_HUMAN_FETCH "browser" to make that fetch in a real headless Chromium
|
|
48
|
+
*/
|
|
49
|
+
export function cloakingConfigFromEnv(env, honestUserAgent) {
|
|
50
|
+
const cfg = {};
|
|
51
|
+
const ua = env.INGRESS_AGENT_UA?.trim();
|
|
52
|
+
if (ua)
|
|
53
|
+
cfg.agentUserAgents = ua === "honest" ? [honestUserAgent] : ua.split("|").map((s) => s.trim()).filter(Boolean);
|
|
54
|
+
const j = env.INGRESS_CLOAKING_JITTER?.split(",").map((x) => Number(x.trim()));
|
|
55
|
+
if (j && j.length === 2 && j.every((x) => Number.isFinite(x)))
|
|
56
|
+
cfg.cloakingJitterMs = [j[0], j[1]];
|
|
57
|
+
if (env.INGRESS_HUMAN_PROXY)
|
|
58
|
+
cfg.humanProxy = env.INGRESS_HUMAN_PROXY;
|
|
59
|
+
if (env.INGRESS_HUMAN_FETCH === "browser" || env.INGRESS_HUMAN_FETCH === "http")
|
|
60
|
+
cfg.humanFetch = env.INGRESS_HUMAN_FETCH;
|
|
61
|
+
return cfg;
|
|
62
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supply-chain pass (underlight lineage, ported 2026-10-31).
|
|
3
|
+
*
|
|
4
|
+
* underlight inventories JavaScript that can execute on a machine. The part
|
|
5
|
+
* of it that sits on the gate's boundary is the moment an agent reads
|
|
6
|
+
* something that would make it install or run code: a package manifest, a
|
|
7
|
+
* lockfile, or an install command in a README. This pass ports underlight's
|
|
8
|
+
* manifest detectors (lifecycle scripts, URL-valued dependency specifiers,
|
|
9
|
+
* off-registry lockfile resolutions; same patterns as underlight.py 0.2.2)
|
|
10
|
+
* and adds one the gate needs: install commands in text, graded by whether a
|
|
11
|
+
* human reading the page would see them.
|
|
12
|
+
*
|
|
13
|
+
* Visible install commands are documentation (rustup, Homebrew) and score
|
|
14
|
+
* low. The same command in hidden text, a decoded payload, or reaching for
|
|
15
|
+
* credentials is the attack.
|
|
16
|
+
*/
|
|
17
|
+
import type { ContentKind, Finding, TextSegment } from "./types.js";
|
|
18
|
+
export interface SupplyChainInput {
|
|
19
|
+
kind: ContentKind;
|
|
20
|
+
raw: string;
|
|
21
|
+
segments: ReadonlyArray<TextSegment>;
|
|
22
|
+
decodedPayloads: ReadonlyArray<string>;
|
|
23
|
+
}
|
|
24
|
+
export declare function scanSupplyChain(input: SupplyChainInput): Finding[];
|