@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,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colour parsing and contrast, for same-colour hiding (white on white, black
|
|
3
|
+
* on black, #fefefe on #fff, "snow" on "white"). Contrast is the WCAG 2
|
|
4
|
+
* ratio: 1 means identical, 21 is black on white. Text at or below the
|
|
5
|
+
* threshold is unreadable to a sighted human and is labeled hidden.
|
|
6
|
+
*/
|
|
7
|
+
/** at or below this ratio text is treated as invisible against its background (WCAG body-text minimum is 4.5) */
|
|
8
|
+
export const INVISIBLE_CONTRAST = 1.25;
|
|
9
|
+
const NAMED = {
|
|
10
|
+
aliceblue: "f0f8ff", antiquewhite: "faebd7", aqua: "00ffff", aquamarine: "7fffd4", azure: "f0ffff", beige: "f5f5dc", bisque: "ffe4c4", black: "000000", blanchedalmond: "ffebcd", blue: "0000ff", blueviolet: "8a2be2", brown: "a52a2a", burlywood: "deb887", cadetblue: "5f9ea0", chartreuse: "7fff00", chocolate: "d2691e", coral: "ff7f50", cornflowerblue: "6495ed", cornsilk: "fff8dc", crimson: "dc143c", cyan: "00ffff", darkblue: "00008b", darkcyan: "008b8b", darkgoldenrod: "b8860b", darkgray: "a9a9a9", darkgreen: "006400", darkgrey: "a9a9a9", darkkhaki: "bdb76b", darkmagenta: "8b008b", darkolivegreen: "556b2f", darkorange: "ff8c00", darkorchid: "9932cc", darkred: "8b0000", darksalmon: "e9967a", darkseagreen: "8fbc8f", darkslateblue: "483d8b", darkslategray: "2f4f4f", darkslategrey: "2f4f4f", darkturquoise: "00ced1", darkviolet: "9400d3", deeppink: "ff1493", deepskyblue: "00bfff", dimgray: "696969", dimgrey: "696969", dodgerblue: "1e90ff", firebrick: "b22222", floralwhite: "fffaf0", forestgreen: "228b22", fuchsia: "ff00ff", gainsboro: "dcdcdc", ghostwhite: "f8f8ff", gold: "ffd700", goldenrod: "daa520", gray: "808080", green: "008000", greenyellow: "adff2f", grey: "808080", honeydew: "f0fff0", hotpink: "ff69b4", indianred: "cd5c5c", indigo: "4b0082", ivory: "fffff0", khaki: "f0e68c", lavender: "e6e6fa", lavenderblush: "fff0f5", lawngreen: "7cfc00", lemonchiffon: "fffacd", lightblue: "add8e6", lightcoral: "f08080", lightcyan: "e0ffff", lightgoldenrodyellow: "fafad2", lightgray: "d3d3d3", lightgreen: "90ee90", lightgrey: "d3d3d3", lightpink: "ffb6c1", lightsalmon: "ffa07a", lightseagreen: "20b2aa", lightskyblue: "87cefa", lightslategray: "778899", lightslategrey: "778899", lightsteelblue: "b0c4de", lightyellow: "ffffe0", lime: "00ff00", limegreen: "32cd32", linen: "faf0e6", magenta: "ff00ff", maroon: "800000", mediumaquamarine: "66cdaa", mediumblue: "0000cd", mediumorchid: "ba55d3", mediumpurple: "9370db", mediumseagreen: "3cb371", mediumslateblue: "7b68ee", mediumspringgreen: "00fa9a", mediumturquoise: "48d1cc", mediumvioletred: "c71585", midnightblue: "191970", mintcream: "f5fffa", mistyrose: "ffe4e1", moccasin: "ffe4b5", navajowhite: "ffdead", navy: "000080", oldlace: "fdf5e6", olive: "808000", olivedrab: "6b8e23", orange: "ffa500", orangered: "ff4500", orchid: "da70d6", palegoldenrod: "eee8aa", palegreen: "98fb98", paleturquoise: "afeeee", palevioletred: "db7093", papayawhip: "ffefd5", peachpuff: "ffdab9", peru: "cd853f", pink: "ffc0cb", plum: "dda0dd", powderblue: "b0e0e6", purple: "800080", rebeccapurple: "663399", red: "ff0000", rosybrown: "bc8f8f", royalblue: "4169e1", saddlebrown: "8b4513", salmon: "fa8072", sandybrown: "f4a460", seagreen: "2e8b57", seashell: "fff5ee", sienna: "a0522d", silver: "c0c0c0", skyblue: "87ceeb", slateblue: "6a5acd", slategray: "708090", slategrey: "708090", snow: "fffafa", springgreen: "00ff7f", steelblue: "4682b4", tan: "d2b48c", teal: "008080", thistle: "d8bfd8", tomato: "ff6347", turquoise: "40e0d0", violet: "ee82ee", wheat: "f5deb3", white: "ffffff", whitesmoke: "f5f5f5", yellow: "ffff00", yellowgreen: "9acd32",
|
|
11
|
+
};
|
|
12
|
+
function hex(h) {
|
|
13
|
+
if (!/^[0-9a-f]+$/i.test(h))
|
|
14
|
+
return null;
|
|
15
|
+
if (h.length === 3 || h.length === 4)
|
|
16
|
+
h = [...h].map((c) => c + c).join("");
|
|
17
|
+
if (h.length !== 6 && h.length !== 8)
|
|
18
|
+
return null;
|
|
19
|
+
const n = (i) => parseInt(h.slice(i, i + 2), 16);
|
|
20
|
+
return { r: n(0), g: n(2), b: n(4), a: h.length === 8 ? n(6) / 255 : 1 };
|
|
21
|
+
}
|
|
22
|
+
function num(v, max) {
|
|
23
|
+
v = v.trim();
|
|
24
|
+
return v.endsWith("%") ? (parseFloat(v) / 100) * max : parseFloat(v);
|
|
25
|
+
}
|
|
26
|
+
function hslToRgb(h, s, l) {
|
|
27
|
+
h = ((h % 360) + 360) % 360;
|
|
28
|
+
s /= 100;
|
|
29
|
+
l /= 100;
|
|
30
|
+
const k = (n) => (n + h / 30) % 12;
|
|
31
|
+
const a = s * Math.min(l, 1 - l);
|
|
32
|
+
const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
|
33
|
+
return [f(0) * 255, f(8) * 255, f(4) * 255];
|
|
34
|
+
}
|
|
35
|
+
/** Parse a CSS colour value. Returns null for values that cannot be resolved statically (var(), currentcolor, gradients). */
|
|
36
|
+
export function parseColor(input) {
|
|
37
|
+
const v = input.trim().toLowerCase().replace(/\s*!important$/, "");
|
|
38
|
+
if (!v)
|
|
39
|
+
return null;
|
|
40
|
+
if (v === "transparent")
|
|
41
|
+
return { r: 0, g: 0, b: 0, a: 0 };
|
|
42
|
+
if (v.startsWith("#"))
|
|
43
|
+
return hex(v.slice(1));
|
|
44
|
+
if (NAMED[v])
|
|
45
|
+
return hex(NAMED[v]);
|
|
46
|
+
const fn = /^(rgba?|hsla?)\(([^)]*)\)$/.exec(v);
|
|
47
|
+
if (!fn)
|
|
48
|
+
return null;
|
|
49
|
+
const parts = fn[2].replace(/\//g, " ").split(/[\s,]+/).filter(Boolean);
|
|
50
|
+
if (parts.length < 3 || parts.some((p) => p.includes("var(")))
|
|
51
|
+
return null;
|
|
52
|
+
const alpha = parts[3] !== undefined ? num(parts[3], 1) : 1;
|
|
53
|
+
if (fn[1].startsWith("rgb")) {
|
|
54
|
+
const [r, g, b] = parts.slice(0, 3).map((p) => num(p, 255));
|
|
55
|
+
return [r, g, b, alpha].some(Number.isNaN) ? null : { r, g, b, a: alpha };
|
|
56
|
+
}
|
|
57
|
+
const [r, g, b] = hslToRgb(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]));
|
|
58
|
+
return [r, g, b, alpha].some(Number.isNaN) ? null : { r, g, b, a: alpha };
|
|
59
|
+
}
|
|
60
|
+
/** Composite `top` over an opaque `bottom`. */
|
|
61
|
+
export function blend(top, bottom) {
|
|
62
|
+
const a = Math.max(0, Math.min(1, top.a));
|
|
63
|
+
return { r: top.r * a + bottom.r * (1 - a), g: top.g * a + bottom.g * (1 - a), b: top.b * a + bottom.b * (1 - a), a: 1 };
|
|
64
|
+
}
|
|
65
|
+
function luminance(c) {
|
|
66
|
+
const ch = (x) => { const s = Math.max(0, Math.min(255, x)) / 255; return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4; };
|
|
67
|
+
return 0.2126 * ch(c.r) + 0.7152 * ch(c.g) + 0.0722 * ch(c.b);
|
|
68
|
+
}
|
|
69
|
+
/** WCAG contrast ratio of text colour `fg` (alpha composited) over opaque `bg`. */
|
|
70
|
+
export function contrastRatio(fg, bg) {
|
|
71
|
+
const f = blend(fg, bg);
|
|
72
|
+
const [hi, lo] = [luminance(f), luminance(bg)].sort((x, y) => y - x);
|
|
73
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
74
|
+
}
|
|
75
|
+
/** Pull colour declarations out of a style string. `bg` is null when the background is an image or gradient (unknown). */
|
|
76
|
+
export function colorsFromStyle(style) {
|
|
77
|
+
const out = {};
|
|
78
|
+
for (const decl of style.split(";")) {
|
|
79
|
+
const i = decl.indexOf(":");
|
|
80
|
+
if (i < 0)
|
|
81
|
+
continue;
|
|
82
|
+
const prop = decl.slice(0, i).trim().toLowerCase();
|
|
83
|
+
const val = decl.slice(i + 1).trim();
|
|
84
|
+
if (prop === "color")
|
|
85
|
+
out.fg = parseColor(val);
|
|
86
|
+
else if (prop === "-webkit-text-fill-color")
|
|
87
|
+
out.fill = parseColor(val);
|
|
88
|
+
else if (prop === "background-color")
|
|
89
|
+
out.bg = parseColor(val);
|
|
90
|
+
else if (prop === "background") {
|
|
91
|
+
if (/url\(|gradient\(|var\(|image-set\(/i.test(val)) {
|
|
92
|
+
out.bg = null;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// the shorthand's colour is any token that parses as one
|
|
96
|
+
let found;
|
|
97
|
+
for (const tok of val.match(/#[0-9a-f]{3,8}\b|(?:rgba?|hsla?)\([^)]*\)|[a-z]+/gi) ?? []) {
|
|
98
|
+
const c = parseColor(tok);
|
|
99
|
+
if (c) {
|
|
100
|
+
found = c;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (found)
|
|
105
|
+
out.bg = found;
|
|
106
|
+
}
|
|
107
|
+
else if (prop === "background-image" && !/^none$/i.test(val))
|
|
108
|
+
out.bg = null;
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine: runs the passes, scores, decides a tier, builds the envelope and
|
|
3
|
+
* the taint receipt.
|
|
4
|
+
*
|
|
5
|
+
* Verdict policy (ratified 2026-10-01, amended same day: suspect does not
|
|
6
|
+
* pass text):
|
|
7
|
+
* clean -> pass with receipt
|
|
8
|
+
* suspect -> refuse. The model receives the classification, the source and
|
|
9
|
+
* the receipt, and is told the human may override. With
|
|
10
|
+
* { override: true } the neutralized text is delivered instead.
|
|
11
|
+
* hostile -> refuse. Not overridable at runtime. Logged.
|
|
12
|
+
*/
|
|
13
|
+
import { type KeyObject } from "node:crypto";
|
|
14
|
+
import { acquireWithBrowser, type FetchLike } from "./acquire.js";
|
|
15
|
+
import { runSandbox } from "./sandbox.js";
|
|
16
|
+
import { type Finding, type IngressConfig, type IngressResult, type TaintReceipt, type Tier } from "./types.js";
|
|
17
|
+
export interface IngressOptions {
|
|
18
|
+
/** human explicitly asked for a suspect page anyway; delivers neutralized text. Never applies to hostile. */
|
|
19
|
+
override?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface EngineDeps {
|
|
22
|
+
fetchImpl?: FetchLike;
|
|
23
|
+
/** DNS resolver override (tests, or DNS-over-HTTPS in production) */
|
|
24
|
+
resolver?: (host: string) => Promise<string[]>;
|
|
25
|
+
now?: () => Date;
|
|
26
|
+
/** attack log sink; default is stderr JSON lines */
|
|
27
|
+
log?: (entry: Record<string, unknown>) => void;
|
|
28
|
+
/** sandbox runner override (tests) */
|
|
29
|
+
sandboxImpl?: typeof runSandbox;
|
|
30
|
+
/** browser fetch override for humanFetch: "browser" (tests) */
|
|
31
|
+
browserAcquireImpl?: typeof acquireWithBrowser;
|
|
32
|
+
/** randomness for user-agent choice, fetch order and jitter (tests pin it) */
|
|
33
|
+
random?: () => number;
|
|
34
|
+
/** delay between the two fetches (tests skip it) */
|
|
35
|
+
sleep?: (ms: number) => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export declare class IngressEngine {
|
|
38
|
+
readonly config: IngressConfig;
|
|
39
|
+
private cache;
|
|
40
|
+
private deps;
|
|
41
|
+
private lastReceiptDigest;
|
|
42
|
+
constructor(config?: Partial<IngressConfig>, deps?: EngineDeps);
|
|
43
|
+
/** Gate a URL: policy check, acquire (twice when cloaking check is on), analyze, decide. */
|
|
44
|
+
fetch(url: string, opts?: IngressOptions): Promise<IngressResult>;
|
|
45
|
+
/** Gate text or HTML already in hand (paste, tool result, file). */
|
|
46
|
+
scan(content: string, opts?: IngressOptions & {
|
|
47
|
+
url?: string;
|
|
48
|
+
isHtml?: boolean;
|
|
49
|
+
contentType?: string;
|
|
50
|
+
}): Promise<IngressResult>;
|
|
51
|
+
/** Any analysis failure is a refusal, never a pass: the gate fails closed. */
|
|
52
|
+
private guarded;
|
|
53
|
+
/** Cheap structural pre-check: pathological nesting makes the HTML parser super-linear. Refuse before parsing. */
|
|
54
|
+
private structuralAbuse;
|
|
55
|
+
private analyze;
|
|
56
|
+
private fetchStylesheets;
|
|
57
|
+
private domainRule;
|
|
58
|
+
private refuse;
|
|
59
|
+
private refuseOnAcquire;
|
|
60
|
+
private pickAgentUserAgent;
|
|
61
|
+
private receipt;
|
|
62
|
+
private signerCache?;
|
|
63
|
+
private signer;
|
|
64
|
+
/** The PEM public key that verifies this engine's receipts (ECDSA only). Publish it; it cannot sign. */
|
|
65
|
+
publicKey(): {
|
|
66
|
+
alg: "ecdsa-p256-sha256";
|
|
67
|
+
keyId: string;
|
|
68
|
+
publicKeyPem: string;
|
|
69
|
+
} | null;
|
|
70
|
+
static keyIdOf(pub: KeyObject): string;
|
|
71
|
+
/** Generate an ECDSA P-256 key pair for receipt signing. Keep the private key secret; publish the public key. */
|
|
72
|
+
static generateSigningKeys(): {
|
|
73
|
+
privateKeyPem: string;
|
|
74
|
+
publicKeyPem: string;
|
|
75
|
+
keyId: string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Verify a receipt's digest and, when a key is given, its signature.
|
|
79
|
+
* Pass a PEM public key for ECDSA receipts, or the shared secret for HMAC receipts.
|
|
80
|
+
*/
|
|
81
|
+
static verifyReceipt(receipt: TaintReceipt, key?: string): {
|
|
82
|
+
digestOk: boolean;
|
|
83
|
+
signatureOk: boolean | null;
|
|
84
|
+
signatureAlg?: string;
|
|
85
|
+
keyId?: string;
|
|
86
|
+
};
|
|
87
|
+
private cacheKey;
|
|
88
|
+
private cacheGet;
|
|
89
|
+
private cacheSet;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Score aggregation.
|
|
93
|
+
* - findings are grouped by kind; repeats of one kind add a logarithmic
|
|
94
|
+
* bonus rather than compounding (twelve screen-reader labels are one
|
|
95
|
+
* fact, not twelve attacks)
|
|
96
|
+
* - noisy-OR across kinds
|
|
97
|
+
* - hidden text that carries no instruction shape is informational: it is
|
|
98
|
+
* never delivered, so visibility-only evidence is capped below the
|
|
99
|
+
* suspect line. The page passes clean, the hidden text is stripped, and
|
|
100
|
+
* the findings stay on the receipt (ratified 2026-11-03: hidden menus,
|
|
101
|
+
* collapsed sections and screen-reader labels must not refuse a page)
|
|
102
|
+
* - co-occurrence of hidden-text and meaning findings, cloaking, and
|
|
103
|
+
* webdriver-keyed divergence each add a bonus
|
|
104
|
+
*/
|
|
105
|
+
/** below the default suspect threshold (0.25), so hidden text alone never refuses */
|
|
106
|
+
export declare const VISIBILITY_ONLY_CAP = 0.2;
|
|
107
|
+
export declare function aggregate(findings: Finding[], ctx?: {
|
|
108
|
+
cloakingCompared?: boolean;
|
|
109
|
+
}): number;
|
|
110
|
+
/** words of served text with markup, link targets and bare URLs removed, so Markdown and HTML of the same page compare equal */
|
|
111
|
+
export declare function servedWords(text: string): string[];
|
|
112
|
+
/** how much of what the agent received is absent from what the browser received (word occurrences, not distinct words) */
|
|
113
|
+
export declare function compareServed(agentText: string, humanText: string): {
|
|
114
|
+
agentWords: number;
|
|
115
|
+
agentOnlyWords: number;
|
|
116
|
+
agentOnlyShare: number;
|
|
117
|
+
longestAgentOnlyRun: number;
|
|
118
|
+
sample: string;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Spotlighting-style envelope. Random boundary so content cannot forge the
|
|
122
|
+
* closing marker. The model is told, in one line, how to treat the content.
|
|
123
|
+
*/
|
|
124
|
+
export declare function buildEnvelope(source: string, tier: Tier, delivered: string, findings: Finding[], receipt: TaintReceipt, overridden?: boolean): string;
|
|
125
|
+
/**
|
|
126
|
+
* Attack log entry: the most useful material for the public feed and for
|
|
127
|
+
* incident review. Carries the decoded payloads and excerpts (what the
|
|
128
|
+
* attacker wrote), the hosts the content tried to reach, and the attacking
|
|
129
|
+
* source host. Never carries the customer's own fetch context beyond the URL.
|
|
130
|
+
*/
|
|
131
|
+
export declare function buildLogEntry(url: string, tier: Tier, score: number, findings: Finding[], decodedPayloads: readonly string[], receipt: TaintReceipt, overridden: boolean): Record<string, unknown>;
|