@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,182 @@
|
|
|
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
|
+
/** scripts that run when a package is installed as a dependency (underlight CONSUMER_LIFECYCLE) */
|
|
18
|
+
const CONSUMER_LIFECYCLE = ["preinstall", "install", "postinstall", "prepare"];
|
|
19
|
+
/**
|
|
20
|
+
* underlight SUSPICIOUS_SCRIPT_RE, split three ways after adversarial review (2026-11-01):
|
|
21
|
+
* strong — fetches, opens a socket, or runs decoded or generated code: flags on its own
|
|
22
|
+
* weak — inline interpreters, shells and URLs: common in harmless scripts ("node -e" feature checks,
|
|
23
|
+
* husky recipes, an echoed docs link), so they flag only in combination
|
|
24
|
+
* cred — reaches for credentials
|
|
25
|
+
*/
|
|
26
|
+
const STRONG_RE = /(\bcurl\b|\bwget\b|\/dev\/(tcp|udp)\/|\bnc(at)?\s|\bsocat\b|\bnslookup\b|\bdig\s|\bfetch\(|child_process|\bexec(Sync)?\(|\bspawn(Sync)?\(|powershell|Invoke-WebRequest|\biwr\b|certutil|\beval\(|\bFunction\(|\batob\(|base64\s+(-d|--decode|-D)\b|\b(perl|ruby)\s+-e\b|\bphp\s+-r\b|\\x[0-9a-fA-F]{2}|require\(\s*["'](https?|net|dgram|dns|tls)["']\s*\))/i;
|
|
27
|
+
/** unambiguous on install: a socket back to a host, a decoded or downloaded payload handed straight to a shell */
|
|
28
|
+
const CRITICAL_RE = /(\/dev\/(tcp|udp)\/|\bnc(at)?\s[^\n]{0,120}\s-(e|c)\s|\bsocat\b[^\n]{0,120}exec|\b(curl|wget)\b[^\n|]{0,300}\|\s*(sudo\s+)?(ba|z)?sh\b|base64\s+(-d|--decode|-D)\b[^\n]{0,80}\|\s*(ba|z)?sh\b|\\x[0-9a-fA-F]{2}[^\n]{0,200}\|\s*(ba|z)?sh\b)/i;
|
|
29
|
+
const WEAK_RE = /(\bnode\s+-e\b|\b(ba|z)?sh\s+-c\b|\bpython[23]?\s+-c\b|https?:\/\/|\$\()/gi;
|
|
30
|
+
const CRED_RE = /(\$\{?HOME\b|~\/\.ssh|\.ssh\/id_|\.npmrc|\.aws\/|\.config\/gh|\.git-credentials|\bAWS_[A-Z_]+|GITHUB_TOKEN|NPM_TOKEN|\bprintenv\b|\benv\s*\|)/i;
|
|
31
|
+
function execSignal(script) {
|
|
32
|
+
if (STRONG_RE.test(script))
|
|
33
|
+
return true;
|
|
34
|
+
const weak = new Set((script.match(WEAK_RE) ?? []).map((w) => w.toLowerCase().replace(/\s+/g, " ").replace(/^(ba|z)sh/, "sh")));
|
|
35
|
+
// a URL inside an echo or a comment is a message to the installer, not an action
|
|
36
|
+
if (weak.size === 1 && [...weak][0].startsWith("http") && /\becho\b|^\s*#/.test(script))
|
|
37
|
+
return false;
|
|
38
|
+
return weak.size >= 2;
|
|
39
|
+
}
|
|
40
|
+
/** underlight URL_SPEC_RE */
|
|
41
|
+
const URL_SPEC_RE = /^(https?:\/\/|git\+|git:\/\/|ssh:\/\/|github:|gitlab:|bitbucket:|gist:|[\w.-]+\/[\w.-]+(#.*)?$|.*\.tgz$|.*\.tar\.gz$)/i;
|
|
42
|
+
const REGISTRY_HOSTS = new Set(["registry.npmjs.org", "registry.yarnpkg.com", "registry.npmjs.com", "registry.npmmirror.com"]);
|
|
43
|
+
/** install / execute commands an agent might be talked into running */
|
|
44
|
+
const SUDO = String.raw `(sudo(\s+-[A-Za-z]+)*\s+)?`;
|
|
45
|
+
const INSTALL_PATTERNS = [
|
|
46
|
+
{ re: new RegExp(String.raw `\b(curl|wget|fetch)\b[^\n|;]{0,300}\|\s*` + SUDO + String.raw `(ba|z|da|k|fi)?sh\b`, "i"), what: "download piped to a shell" },
|
|
47
|
+
{ re: new RegExp(String.raw `\b(curl|wget)\b[^\n|;]{0,300}\|\s*` + SUDO + String.raw `(python[23]?|node|perl|ruby|php|deno|bun)\b`, "i"), what: "download piped to an interpreter" },
|
|
48
|
+
{ re: /\b(ba|z)?sh\s{1,4}<\(\s{0,4}(curl|wget)\b/i, what: "download run through process substitution" },
|
|
49
|
+
{ re: /\b(ba|z)?sh\s{1,4}-c\s{1,4}["']?\$\(\s{0,4}(curl|wget)\b/i, what: "download run through command substitution" },
|
|
50
|
+
{ re: /\b(curl|wget)\b[^\n;&|]{0,200}\s(-o|-O|--output)\s{0,3}\S{1,200}[^\n]{0,60}(&&|;)\s{0,4}(sudo\s+)?((ba|z)?sh|chmod\s+\+x|\.\/)/i, what: "download saved and then run" },
|
|
51
|
+
{ re: /\b(iwr|irm|Invoke-WebRequest|Invoke-RestMethod)\b[^\n|]{0,300}\|\s*(iex|Invoke-Expression)\b/i, what: "PowerShell download piped to Invoke-Expression" },
|
|
52
|
+
{ re: /\b(iex|Invoke-Expression)\s{0,4}\(\s{0,4}(iwr|irm|Invoke-WebRequest|Invoke-RestMethod|\(?\s{0,4}New-Object\s+Net\.WebClient)/i, what: "PowerShell expression evaluating a download" },
|
|
53
|
+
{ re: /\.DownloadString\s{0,3}\(/i, what: "PowerShell DownloadString" },
|
|
54
|
+
{ re: /\bbase64\s+(-d|--decode|-D)\b[^\n]{0,80}\|\s*(ba|z)?sh\b/i, what: "base64-decoded payload piped to a shell" },
|
|
55
|
+
{ re: /\b(npm|pnpm|yarn|bun)\s+(i|install|add)\s+[^\n]{0,80}(https?:\/\/|git\+|github:|gist:|\.tgz\b)/i, what: "package install from a URL instead of a registry" },
|
|
56
|
+
{ re: /\bnpx\s+(-y\s+|--yes\s+)?(https?:\/\/|github:|gist:)/i, what: "npx executing code from a URL" },
|
|
57
|
+
{ re: /\bdeno\s+run\s+(-A|--allow-all)\b[^\n]{0,60}https?:\/\//i, what: "deno running remote code with all permissions" },
|
|
58
|
+
{ re: /\b(uvx|pipx\s+run)\s+(--from|--spec)\s+(git\+|https?:\/\/)/i, what: "Python tool run from a URL" },
|
|
59
|
+
{ re: /\bpip3?\s+install\s+[^\n]{0,80}(git\+|https?:\/\/)/i, what: "pip install from a URL" },
|
|
60
|
+
{ re: /\b(env|printenv|set)\s*\|\s*(curl|wget|nc|ncat)\b/i, what: "environment variables piped to the network" },
|
|
61
|
+
{ re: /\b(cat|tar|zip)\b[^\n|]{0,120}(\.ssh|\.npmrc|\.aws|\.git-credentials|\.config\/gh|id_rsa|id_ed25519)[^\n|]{0,80}\|\s*(curl|wget|nc|ncat)\b/i, what: "credential files piped to the network" },
|
|
62
|
+
{ re: /\b(curl|wget)\b[^\n]{0,200}\s(-d|--data(-binary|-raw|-urlencode)?|-F|--form|-T|--upload-file|--post-file)[=\s]{1,3}["']?@?[^\s"']{0,200}(\.ssh|\.npmrc|\.aws|\.git-credentials|id_rsa|id_ed25519|\.env\b|@-)/i, what: "upload of local secrets or stdin to a remote host" },
|
|
63
|
+
{ re: /\/dev\/(tcp|udp)\/[\w.-]{1,253}\/\d{1,5}/i, what: "shell socket to a remote host (reverse shell)" },
|
|
64
|
+
{ re: /\bpython3?\s+-c\s+["'][^\n]{0,200}(urllib|requests|socket|exec\()/i, what: "inline Python that fetches or executes" },
|
|
65
|
+
{ re: /\bnode\s+-e\s+["'][^\n]{0,200}(child_process|https?\.get|fetch\(|eval\()/i, what: "inline Node that fetches or executes" },
|
|
66
|
+
];
|
|
67
|
+
const clip = (s, n = 200) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
68
|
+
function hostOf(u) {
|
|
69
|
+
const m = /^[a-z][a-z0-9+.-]*:\/\/([^/@]+@)?([^/:]+)/i.exec(u);
|
|
70
|
+
return m ? m[2].toLowerCase() : null;
|
|
71
|
+
}
|
|
72
|
+
function isManifest(doc) {
|
|
73
|
+
return !!doc && typeof doc === "object" && !Array.isArray(doc) && typeof doc.name === "string" &&
|
|
74
|
+
(typeof doc.version === "string" || typeof doc.scripts === "object" || typeof doc.dependencies === "object");
|
|
75
|
+
}
|
|
76
|
+
function manifestFindings(doc) {
|
|
77
|
+
const out = [];
|
|
78
|
+
const scripts = doc.scripts && typeof doc.scripts === "object" ? doc.scripts : {};
|
|
79
|
+
for (const k of CONSUMER_LIFECYCLE) {
|
|
80
|
+
const v = scripts[k];
|
|
81
|
+
if (typeof v !== "string" || !v.trim())
|
|
82
|
+
continue;
|
|
83
|
+
const cred = CRED_RE.test(v), critical = CRITICAL_RE.test(v), exec = critical || execSignal(v);
|
|
84
|
+
if (!cred && !exec)
|
|
85
|
+
continue;
|
|
86
|
+
out.push({
|
|
87
|
+
pass: "supplychain", kind: "supplychain.lifecycle_script",
|
|
88
|
+
confidence: cred && exec ? 0.95 : cred || critical ? 0.9 : 0.65,
|
|
89
|
+
severity: cred || critical ? 0.95 : 0.6,
|
|
90
|
+
message: `${k} script runs on install and ${cred ? "reaches for credentials" : critical ? "opens a shell to a remote host or pipes a payload into a shell" : "fetches or executes code"}`,
|
|
91
|
+
excerpt: clip(v), location: `$.scripts.${k}`, action: "none",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const url = [];
|
|
95
|
+
for (const field of ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"]) {
|
|
96
|
+
const deps = doc[field];
|
|
97
|
+
if (!deps || typeof deps !== "object")
|
|
98
|
+
continue;
|
|
99
|
+
for (const [name, spec] of Object.entries(deps))
|
|
100
|
+
if (typeof spec === "string" && URL_SPEC_RE.test(spec.trim()))
|
|
101
|
+
url.push(`${name}@${spec}`);
|
|
102
|
+
}
|
|
103
|
+
if (url.length)
|
|
104
|
+
out.push({
|
|
105
|
+
pass: "supplychain", kind: "supplychain.url_dependency", confidence: 0.45, severity: 0.5,
|
|
106
|
+
message: `${url.length} dependenc${url.length === 1 ? "y resolves" : "ies resolve"} to a network location instead of a registry; registry scanners see none of them`,
|
|
107
|
+
excerpt: clip(url.slice(0, 5).join(", ")), location: "$.dependencies", action: "none",
|
|
108
|
+
});
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
function lockfileFindings(raw, doc) {
|
|
112
|
+
const hosts = new Map();
|
|
113
|
+
const note = (u) => { const h = hostOf(u); if (h && !REGISTRY_HOSTS.has(h))
|
|
114
|
+
hosts.set(h, (hosts.get(h) ?? 0) + 1); };
|
|
115
|
+
if (doc && typeof doc === "object" && ("lockfileVersion" in doc)) {
|
|
116
|
+
for (const group of [doc.packages, doc.dependencies])
|
|
117
|
+
if (group && typeof group === "object")
|
|
118
|
+
for (const v of Object.values(group))
|
|
119
|
+
if (v && typeof v.resolved === "string")
|
|
120
|
+
note(v.resolved);
|
|
121
|
+
}
|
|
122
|
+
else if (/^# (yarn lockfile|THIS IS AN AUTOGENERATED FILE)/m.test(raw) || /^lockfileVersion:/m.test(raw)) {
|
|
123
|
+
for (const m of raw.matchAll(/(?:resolved|tarball)[:\s]+["']?(https?:\/\/[^\s"'}]+)/g))
|
|
124
|
+
note(m[1]);
|
|
125
|
+
}
|
|
126
|
+
else
|
|
127
|
+
return [];
|
|
128
|
+
if (!hosts.size)
|
|
129
|
+
return [];
|
|
130
|
+
const list = [...hosts.entries()].sort((a, b) => b[1] - a[1]);
|
|
131
|
+
return [{
|
|
132
|
+
pass: "supplychain", kind: "supplychain.offregistry_resolution", confidence: 0.4, severity: 0.5,
|
|
133
|
+
message: `lockfile resolves packages from ${list.length} host${list.length === 1 ? "" : "s"} outside the public registries (a private registry is legitimate; an unknown one is not)`,
|
|
134
|
+
excerpt: clip(list.slice(0, 5).map(([h, n]) => `${h} (${n})`).join(", ")), action: "none",
|
|
135
|
+
}];
|
|
136
|
+
}
|
|
137
|
+
function installFindings(text, hidden, where) {
|
|
138
|
+
const out = [];
|
|
139
|
+
for (const p of INSTALL_PATTERNS) {
|
|
140
|
+
const m = p.re.exec(text);
|
|
141
|
+
if (!m)
|
|
142
|
+
continue;
|
|
143
|
+
const start = Math.max(0, m.index - 40);
|
|
144
|
+
const ctx = text.slice(start, m.index + m[0].length + 80);
|
|
145
|
+
const cred = CRED_RE.test(ctx);
|
|
146
|
+
out.push({
|
|
147
|
+
pass: "supplychain", kind: "supplychain.install_instruction",
|
|
148
|
+
// a visible curl|sh is ordinary documentation; hidden, decoded, or credential-reaching is not
|
|
149
|
+
confidence: hidden ? 0.92 : cred ? 0.75 : 0.3,
|
|
150
|
+
severity: hidden ? 0.9 : cred ? 0.8 : 0.4,
|
|
151
|
+
message: `${hidden ? "hidden " : ""}${p.what}${cred ? ", reaching for credentials" : ""}${hidden ? " (a human reading the page would not see this command)" : ""}`,
|
|
152
|
+
excerpt: clip(m[0]), location: where, action: "none",
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
export function scanSupplyChain(input) {
|
|
158
|
+
const findings = [];
|
|
159
|
+
let doc;
|
|
160
|
+
if (input.kind === "json") {
|
|
161
|
+
try {
|
|
162
|
+
doc = JSON.parse(input.raw);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
doc = undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (doc !== undefined && isManifest(doc))
|
|
169
|
+
findings.push(...manifestFindings(doc));
|
|
170
|
+
if (input.kind === "json" || input.kind === "text")
|
|
171
|
+
findings.push(...lockfileFindings(input.raw, doc));
|
|
172
|
+
// manifests carry their scripts as JSON strings; those were judged above, so skip segment scanning of $.scripts
|
|
173
|
+
for (const s of input.segments) {
|
|
174
|
+
if (s.path.startsWith("$.scripts."))
|
|
175
|
+
continue;
|
|
176
|
+
// collapsed <details> and hidden tab panels are revealed by one click: install docs live there, so weigh them as visible
|
|
177
|
+
findings.push(...installFindings(s.text, s.visibility !== "visible" && !s.path.includes("~revealable"), s.path));
|
|
178
|
+
}
|
|
179
|
+
for (const p of input.decodedPayloads)
|
|
180
|
+
findings.push(...installFindings(p, true, "decoded payload"));
|
|
181
|
+
return findings;
|
|
182
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Taint guard: opt-in capability control (CaMeL-style separation of
|
|
3
|
+
* untrusted data from side-effecting actions).
|
|
4
|
+
*
|
|
5
|
+
* Once a session has ingested content at or above the configured tier,
|
|
6
|
+
* tools named in `sideEffectTools` are held until `confirm()` is called by
|
|
7
|
+
* the user-facing layer. Nothing here is mandatory; it is middleware the
|
|
8
|
+
* integrator wraps around tool dispatch.
|
|
9
|
+
*/
|
|
10
|
+
import type { IngressResult, Tier } from "./types.js";
|
|
11
|
+
export interface TaintPolicy {
|
|
12
|
+
/** tier at which the session becomes tainted; default "suspect" */
|
|
13
|
+
taintAt: Tier;
|
|
14
|
+
/** tool names that must pause while tainted */
|
|
15
|
+
sideEffectTools: string[];
|
|
16
|
+
/** how long a confirmation stays valid, milliseconds */
|
|
17
|
+
confirmationTtlMs: number;
|
|
18
|
+
}
|
|
19
|
+
export interface TaintGuard {
|
|
20
|
+
/** record a gate result; returns the session's taint state */
|
|
21
|
+
ingest(result: IngressResult): {
|
|
22
|
+
tainted: boolean;
|
|
23
|
+
sources: string[];
|
|
24
|
+
};
|
|
25
|
+
/** true if this tool call may proceed now */
|
|
26
|
+
allow(toolName: string): boolean;
|
|
27
|
+
/** user confirmed a side-effect; unlocks sideEffectTools for the TTL */
|
|
28
|
+
confirm(): void;
|
|
29
|
+
/** forget taint (new task, new context) */
|
|
30
|
+
reset(): void;
|
|
31
|
+
readonly state: {
|
|
32
|
+
tainted: boolean;
|
|
33
|
+
sources: string[];
|
|
34
|
+
confirmedUntil: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare function createTaintGuard(policy?: Partial<TaintPolicy>): TaintGuard;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Taint guard: opt-in capability control (CaMeL-style separation of
|
|
3
|
+
* untrusted data from side-effecting actions).
|
|
4
|
+
*
|
|
5
|
+
* Once a session has ingested content at or above the configured tier,
|
|
6
|
+
* tools named in `sideEffectTools` are held until `confirm()` is called by
|
|
7
|
+
* the user-facing layer. Nothing here is mandatory; it is middleware the
|
|
8
|
+
* integrator wraps around tool dispatch.
|
|
9
|
+
*/
|
|
10
|
+
const TIER_RANK = { clean: 0, unreachable: 0, suspect: 1, hostile: 2 };
|
|
11
|
+
export function createTaintGuard(policy = {}) {
|
|
12
|
+
const p = {
|
|
13
|
+
taintAt: policy.taintAt ?? "suspect",
|
|
14
|
+
sideEffectTools: policy.sideEffectTools ?? ["send", "email", "post", "write", "delete", "pay", "transfer", "execute", "shell", "deploy"],
|
|
15
|
+
confirmationTtlMs: policy.confirmationTtlMs ?? 60_000,
|
|
16
|
+
};
|
|
17
|
+
const state = { tainted: false, sources: [], confirmedUntil: 0 };
|
|
18
|
+
return {
|
|
19
|
+
state,
|
|
20
|
+
ingest(result) {
|
|
21
|
+
if (TIER_RANK[result.tier] >= TIER_RANK[p.taintAt]) {
|
|
22
|
+
state.tainted = true;
|
|
23
|
+
if (!state.sources.includes(result.receipt.finalUrl))
|
|
24
|
+
state.sources.push(result.receipt.finalUrl);
|
|
25
|
+
}
|
|
26
|
+
return { tainted: state.tainted, sources: [...state.sources] };
|
|
27
|
+
},
|
|
28
|
+
allow(toolName) {
|
|
29
|
+
if (!state.tainted)
|
|
30
|
+
return true;
|
|
31
|
+
const isSideEffect = p.sideEffectTools.some((s) => toolName.toLowerCase().includes(s));
|
|
32
|
+
if (!isSideEffect)
|
|
33
|
+
return true;
|
|
34
|
+
return Date.now() < state.confirmedUntil;
|
|
35
|
+
},
|
|
36
|
+
confirm() { state.confirmedUntil = Date.now() + p.confirmationTtlMs; },
|
|
37
|
+
reset() { state.tainted = false; state.sources.length = 0; state.confirmedUntil = 0; },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AcePaste Ingress — shared types.
|
|
3
|
+
*
|
|
4
|
+
* Governing principle: anything the model would receive that a human looking
|
|
5
|
+
* at the same source would not see is suspect by default.
|
|
6
|
+
*/
|
|
7
|
+
import type { NetPolicy } from "./netpolicy.js";
|
|
8
|
+
export declare const ENGINE_VERSION = "0.8.0";
|
|
9
|
+
/** bump whenever a detector's behavior changes; receipts carry it so verdicts are reproducible */
|
|
10
|
+
export declare const RULESET_VERSION = "2026.11.03-1";
|
|
11
|
+
/**
|
|
12
|
+
* clean: delivered. suspect: refused, overridable. hostile: refused, not overridable.
|
|
13
|
+
* unreachable: nothing could be fetched or read (network error, timeout, redirect loop,
|
|
14
|
+
* binary or oversized body). Not an attack verdict, and never written to the attack log.
|
|
15
|
+
*/
|
|
16
|
+
export type Tier = "clean" | "suspect" | "hostile" | "unreachable";
|
|
17
|
+
export type ContentKind = "html" | "markdown" | "json" | "text" | "javascript";
|
|
18
|
+
export type PassName = "acquire" | "policy" | "visibility" | "character" | "script" | "supplychain" | "secrets" | "meaning" | "cloaking" | "sandbox" | "plugin";
|
|
19
|
+
export type FindingKind = "policy.denied_source" | "policy.redirect_chain" | "acquire.unreachable" | "acquire.cloaking_check_incomplete" | "acquire.ai_agent_refused" | "unicode.tag_characters" | "unicode.zero_width" | "unicode.bidi_control" | "unicode.variation_selector_smuggling" | "unicode.mixed_script_confusable" | "unicode.fullwidth_or_math_lookalike" | "unicode.combining_flood" | "unicode.encoded_payload" | "unicode.entity_smuggling" | "unicode.whitespace_channel" | "visibility.css_hidden" | "visibility.offscreen" | "visibility.attribute_only" | "visibility.html_comment" | "visibility.tiny_or_transparent" | "visibility.markdown_hidden" | "script.obfuscation" | "script.runtime_codegen" | "script.automation_detection" | "script.post_load_text_injection" | "script.exfil_beacon" | "script.binary_decoding" | "supplychain.lifecycle_script" | "supplychain.url_dependency" | "supplychain.offregistry_resolution" | "supplychain.install_instruction" | "secrets.credential_in_content" | "sandbox.text_injected_after_load" | "sandbox.webdriver_keyed_divergence" | "sandbox.computed_hidden_text" | "sandbox.blocked_egress_attempt" | "meaning.instruction_shaped" | "meaning.role_token" | "meaning.system_prompt_imitation" | "meaning.tool_call_shaped" | "meaning.exfil_markdown_image" | "meaning.exfil_link" | "cloaking.agent_targeted_divergence" | `plugin.${string}`;
|
|
20
|
+
export interface Finding {
|
|
21
|
+
pass: PassName;
|
|
22
|
+
kind: FindingKind;
|
|
23
|
+
/** 0..1 confidence that this is an attack rather than benign structure */
|
|
24
|
+
confidence: number;
|
|
25
|
+
/** 0..1 severity if it is an attack */
|
|
26
|
+
severity: number;
|
|
27
|
+
/** short human-readable explanation */
|
|
28
|
+
message: string;
|
|
29
|
+
/** excerpt of the offending material, already made safe to print */
|
|
30
|
+
excerpt?: string;
|
|
31
|
+
/** location hint: character offset, selector path, or script index */
|
|
32
|
+
location?: string;
|
|
33
|
+
/** meaning pass: the match was in text a human would not see */
|
|
34
|
+
inHidden?: boolean;
|
|
35
|
+
/** what the engine did about it */
|
|
36
|
+
action: "none" | "neutralized" | "quarantined";
|
|
37
|
+
/** Kith & Revere evidence model, attached by the engine: a finding is a conclusion, never a Fact */
|
|
38
|
+
evidenceClass?: "inference" | "hypothesis";
|
|
39
|
+
/** confidence band: high >= 0.8, medium >= 0.5, low below */
|
|
40
|
+
band?: "high" | "medium" | "low";
|
|
41
|
+
/** sha256 of the artifact the finding cites: its excerpt, or the whole acquired body */
|
|
42
|
+
artifactDigest?: string;
|
|
43
|
+
/** the benign explanation a reviewer should rule out before acting */
|
|
44
|
+
altExplanation?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface AcquireResult {
|
|
47
|
+
url: string;
|
|
48
|
+
finalUrl: string;
|
|
49
|
+
redirectChain: string[];
|
|
50
|
+
status: number;
|
|
51
|
+
headers: Record<string, string>;
|
|
52
|
+
contentType: string;
|
|
53
|
+
/** raw body as text (binary bodies are refused upstream) */
|
|
54
|
+
body: string;
|
|
55
|
+
/** which fingerprint this acquisition used */
|
|
56
|
+
fingerprint: "human" | "agent";
|
|
57
|
+
/** the user-agent string actually sent */
|
|
58
|
+
userAgent: string;
|
|
59
|
+
/** how it was fetched: plain HTTP client, or a real browser (human fingerprint only) */
|
|
60
|
+
via: "http" | "browser";
|
|
61
|
+
fetchedAt: string;
|
|
62
|
+
}
|
|
63
|
+
export interface TextSegment {
|
|
64
|
+
text: string;
|
|
65
|
+
/** visible: a sighted human reading the rendered page sees this */
|
|
66
|
+
visibility: "visible" | "css_hidden" | "offscreen" | "attribute" | "comment" | "tiny_or_transparent";
|
|
67
|
+
/** selector-ish path for the location field */
|
|
68
|
+
path: string;
|
|
69
|
+
}
|
|
70
|
+
export interface ScriptUnit {
|
|
71
|
+
index: number;
|
|
72
|
+
source: string;
|
|
73
|
+
inline: boolean;
|
|
74
|
+
src?: string;
|
|
75
|
+
}
|
|
76
|
+
/** What a custom detector sees. Everything is read-only. */
|
|
77
|
+
export interface DetectorContext {
|
|
78
|
+
url: string;
|
|
79
|
+
contentKind: ContentKind;
|
|
80
|
+
raw: string;
|
|
81
|
+
segments: ReadonlyArray<TextSegment>;
|
|
82
|
+
scripts: ReadonlyArray<ScriptUnit>;
|
|
83
|
+
decodedPayloads: ReadonlyArray<string>;
|
|
84
|
+
}
|
|
85
|
+
/** Plugin interface. Findings are returned with kind `plugin.<name>`. */
|
|
86
|
+
export interface Detector {
|
|
87
|
+
name: string;
|
|
88
|
+
version: string;
|
|
89
|
+
run(ctx: DetectorContext): Finding[] | Promise<Finding[]>;
|
|
90
|
+
}
|
|
91
|
+
export interface DomainRule {
|
|
92
|
+
/** exact host or `.suffix` */
|
|
93
|
+
match: string;
|
|
94
|
+
/** refuse outright regardless of content */
|
|
95
|
+
deny?: boolean;
|
|
96
|
+
suspectThreshold?: number;
|
|
97
|
+
hostileThreshold?: number;
|
|
98
|
+
/** skip the second fetch for this host */
|
|
99
|
+
cloakingCheck?: boolean;
|
|
100
|
+
}
|
|
101
|
+
export interface IngressPolicy {
|
|
102
|
+
domains: DomainRule[];
|
|
103
|
+
}
|
|
104
|
+
export interface TaintReceipt {
|
|
105
|
+
version: "3";
|
|
106
|
+
engineVersion: string;
|
|
107
|
+
rulesetVersion: string;
|
|
108
|
+
issuedAt: string;
|
|
109
|
+
url: string;
|
|
110
|
+
finalUrl: string;
|
|
111
|
+
redirectChain: string[];
|
|
112
|
+
contentKind: ContentKind;
|
|
113
|
+
/** count of hostile invisible characters per the shared AcePaste alphabet (cross-tool parity) */
|
|
114
|
+
acepasteInvisibleCount: number;
|
|
115
|
+
/** sha256 of the raw acquired body */
|
|
116
|
+
rawDigest: string;
|
|
117
|
+
/** sha256 of the delivered text (empty string when refused) */
|
|
118
|
+
deliveredDigest: string;
|
|
119
|
+
tier: Tier;
|
|
120
|
+
score: number;
|
|
121
|
+
/** suspect content was delivered because a human explicitly asked for it */
|
|
122
|
+
overridden: boolean;
|
|
123
|
+
/** which passes actually ran (sandbox may not have) */
|
|
124
|
+
passesRun: PassName[];
|
|
125
|
+
findings: Array<Pick<Finding, "pass" | "kind" | "confidence" | "severity" | "action" | "evidenceClass" | "band" | "artifactDigest">>;
|
|
126
|
+
/** how `signature` was made: a shared-secret HMAC (only the key holder can verify) or ECDSA P-256 (anyone with the public key can verify, nobody without the private key can forge) */
|
|
127
|
+
signatureAlg?: "hmac-sha256" | "ecdsa-p256-sha256";
|
|
128
|
+
/** first 16 hex characters of sha256 over the signer's public key (ECDSA only) */
|
|
129
|
+
keyId?: string;
|
|
130
|
+
/** sha256 of the previous receipt in this session, for audit chains */
|
|
131
|
+
previous?: string;
|
|
132
|
+
/** sha256 of this receipt's canonical body (without signature) */
|
|
133
|
+
digest: string;
|
|
134
|
+
/** HMAC-SHA256 over the canonical receipt body, when a signing key was configured */
|
|
135
|
+
signature?: string;
|
|
136
|
+
}
|
|
137
|
+
export interface IngressResult {
|
|
138
|
+
tier: Tier;
|
|
139
|
+
/** aggregate attack score, 0..1 */
|
|
140
|
+
score: number;
|
|
141
|
+
contentKind: ContentKind;
|
|
142
|
+
/** text delivered to the model; empty unless tier is clean or a suspect verdict was overridden */
|
|
143
|
+
delivered: string;
|
|
144
|
+
/** true when suspect text was delivered under human override */
|
|
145
|
+
overridden: boolean;
|
|
146
|
+
/** spotlighting-style envelope the caller should hand to the model verbatim */
|
|
147
|
+
envelope: string;
|
|
148
|
+
findings: Finding[];
|
|
149
|
+
receipt: TaintReceipt;
|
|
150
|
+
/** timing in milliseconds per pass, for the speed budget */
|
|
151
|
+
timings: Partial<Record<PassName | "total", number>>;
|
|
152
|
+
}
|
|
153
|
+
export interface IngressConfig {
|
|
154
|
+
/** score at or above which the page is refused and cannot be overridden */
|
|
155
|
+
hostileThreshold: number;
|
|
156
|
+
/** score at or above which the page is refused but may be overridden */
|
|
157
|
+
suspectThreshold: number;
|
|
158
|
+
/** run the second, human-fingerprinted fetch and compare */
|
|
159
|
+
cloakingCheck: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* user agents for the agent fetch, one picked at random per fetch. Defaults to the
|
|
162
|
+
* user-triggered fetchers of the major AI assistants, because those are what
|
|
163
|
+
* agent-targeted cloaking keys on. Set to one honest string to stop impersonating.
|
|
164
|
+
*/
|
|
165
|
+
agentUserAgents: string[];
|
|
166
|
+
/** random gap between the two fetches, [min, max] milliseconds; the order is random too */
|
|
167
|
+
cloakingJitterMs: [number, number];
|
|
168
|
+
/**
|
|
169
|
+
* optional HTTP(S) proxy for the human fetch only, e.g. a residential proxy, so the two
|
|
170
|
+
* fetches leave from different networks. Credentials go in the URL. Never logged.
|
|
171
|
+
*/
|
|
172
|
+
humanProxy?: string;
|
|
173
|
+
/** "http": the human fetch is a plain request with browser headers. "browser": a real headless Chromium loads the page. */
|
|
174
|
+
humanFetch: "http" | "browser";
|
|
175
|
+
/** maximum body size accepted, bytes */
|
|
176
|
+
maxBodyBytes: number;
|
|
177
|
+
/** fetch timeout, milliseconds */
|
|
178
|
+
fetchTimeoutMs: number;
|
|
179
|
+
/** optional HMAC key for signing receipts (shared secret: verifiers can also forge) */
|
|
180
|
+
signingKey?: string;
|
|
181
|
+
/** optional ECDSA P-256 private key, PEM (PKCS#8). Preferred over signingKey: receipts become publicly verifiable and unforgeable */
|
|
182
|
+
signingPrivateKey?: string;
|
|
183
|
+
/** cache verdicts by url for this many seconds; 0 disables */
|
|
184
|
+
cacheTtlSeconds: number;
|
|
185
|
+
/** "off": static only. "escalate": run when the static script pass is suspicious. "always": every HTML page. */
|
|
186
|
+
sandbox: "off" | "escalate" | "always";
|
|
187
|
+
/** sandbox per-page budget, milliseconds */
|
|
188
|
+
sandboxTimeoutMs: number;
|
|
189
|
+
/** static suspicion at or above which sandbox escalates (when sandbox = "escalate") */
|
|
190
|
+
sandboxEscalateAt: number;
|
|
191
|
+
/** fetch and parse linked stylesheets for the static visibility pass (same origin only) */
|
|
192
|
+
fetchStylesheets: boolean;
|
|
193
|
+
/** network policy: what the gate itself may connect to */
|
|
194
|
+
net: NetPolicy;
|
|
195
|
+
/** per-domain rules */
|
|
196
|
+
policy: IngressPolicy;
|
|
197
|
+
/** custom detectors */
|
|
198
|
+
detectors: Detector[];
|
|
199
|
+
/** chain receipts: each receipt carries the digest of the previous one */
|
|
200
|
+
chainReceipts: boolean;
|
|
201
|
+
}
|
|
202
|
+
export declare const DEFAULT_CONFIG: IngressConfig;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AcePaste Ingress — shared types.
|
|
3
|
+
*
|
|
4
|
+
* Governing principle: anything the model would receive that a human looking
|
|
5
|
+
* at the same source would not see is suspect by default.
|
|
6
|
+
*/
|
|
7
|
+
export const ENGINE_VERSION = "0.8.0";
|
|
8
|
+
/** bump whenever a detector's behavior changes; receipts carry it so verdicts are reproducible */
|
|
9
|
+
export const RULESET_VERSION = "2026.11.03-1";
|
|
10
|
+
export const DEFAULT_CONFIG = {
|
|
11
|
+
hostileThreshold: 0.7,
|
|
12
|
+
suspectThreshold: 0.25,
|
|
13
|
+
cloakingCheck: true,
|
|
14
|
+
agentUserAgents: [
|
|
15
|
+
// sources: OpenAI bot docs; Cloudflare Radar bot directory; Perplexity agent docs (checked 2026-11-03)
|
|
16
|
+
"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; ChatGPT-User/1.0; +https://openai.com/bot",
|
|
17
|
+
"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Claude-User/1.0; +Claude-User@anthropic.com)",
|
|
18
|
+
"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Perplexity-User/1.0; +https://www.perplexity.ai)",
|
|
19
|
+
],
|
|
20
|
+
cloakingJitterMs: [250, 1500],
|
|
21
|
+
humanFetch: "http",
|
|
22
|
+
maxBodyBytes: 5 * 1024 * 1024,
|
|
23
|
+
fetchTimeoutMs: 15000,
|
|
24
|
+
cacheTtlSeconds: 86400,
|
|
25
|
+
sandbox: "escalate",
|
|
26
|
+
sandboxTimeoutMs: 8000,
|
|
27
|
+
sandboxEscalateAt: 0.5,
|
|
28
|
+
fetchStylesheets: true,
|
|
29
|
+
net: { denyHosts: [], allowHosts: [], extraPorts: [], allowPrivate: false },
|
|
30
|
+
policy: { domains: [] },
|
|
31
|
+
detectors: [],
|
|
32
|
+
chainReceipts: true,
|
|
33
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visibility pass.
|
|
3
|
+
*
|
|
4
|
+
* Labels every piece of text by whether a sighted human reading the rendered
|
|
5
|
+
* page would see it. Static only: inline styles, hidden attributes, the
|
|
6
|
+
* page's own <style> blocks and any same-origin stylesheets the engine
|
|
7
|
+
* fetched are consulted. Script-applied styles belong to the sandbox.
|
|
8
|
+
*
|
|
9
|
+
* Also extracts every <script> for the script pass. Traversal is iterative:
|
|
10
|
+
* attacker-controlled nesting depth must not be able to crash the gate.
|
|
11
|
+
*/
|
|
12
|
+
import type { Finding, ScriptUnit, TextSegment } from "./types.js";
|
|
13
|
+
import { type RGBA } from "./color.js";
|
|
14
|
+
export interface HiddenRule {
|
|
15
|
+
selector: string;
|
|
16
|
+
reason: TextSegment["visibility"];
|
|
17
|
+
}
|
|
18
|
+
/** Classify a style declaration string. Returns the hiding reason or null. */
|
|
19
|
+
export declare function classifyStyle(style: string): TextSegment["visibility"] | null;
|
|
20
|
+
export declare function rulesFromCss(cssIn: string): HiddenRule[];
|
|
21
|
+
export interface ColorRule {
|
|
22
|
+
selector: string;
|
|
23
|
+
fg?: RGBA | null;
|
|
24
|
+
bg?: RGBA | null;
|
|
25
|
+
fill?: RGBA | null;
|
|
26
|
+
}
|
|
27
|
+
export declare function colorRulesFromCss(cssIn: string): ColorRule[];
|
|
28
|
+
export interface VisibilityResult {
|
|
29
|
+
segments: TextSegment[];
|
|
30
|
+
scripts: ScriptUnit[];
|
|
31
|
+
findings: Finding[];
|
|
32
|
+
/** concatenated visible text, whitespace-normalized */
|
|
33
|
+
visibleText: string;
|
|
34
|
+
/** hrefs of linked stylesheets, resolved by the caller */
|
|
35
|
+
stylesheetLinks: string[];
|
|
36
|
+
/** maximum element nesting depth seen */
|
|
37
|
+
maxDepth: number;
|
|
38
|
+
}
|
|
39
|
+
/** Collect hrefs of <link rel=stylesheet> so the engine can fetch them (same origin) before the real pass. */
|
|
40
|
+
export declare function findStylesheetLinks(html: string): string[];
|
|
41
|
+
export declare function analyzeHtml(html: string, externalRules?: HiddenRule[], externalColorRules?: ColorRule[]): VisibilityResult;
|