@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,424 @@
|
|
|
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 { parse, defaultTreeAdapter } from "parse5";
|
|
13
|
+
import { decodeEntities } from "./adapters.js";
|
|
14
|
+
import { colorsFromStyle, contrastRatio, blend, parseColor, INVISIBLE_CONTRAST } from "./color.js";
|
|
15
|
+
/** never rendered and never read by a human; still scanned as hidden text */
|
|
16
|
+
const HIDDEN_CONTAINER_TAGS = new Set(["noscript", "template"]);
|
|
17
|
+
/** not rendered as page copy at all; skipped (scripts are collected separately) */
|
|
18
|
+
const SKIPPED_TAGS = new Set(["script", "style", "head", "meta", "link", "base"]);
|
|
19
|
+
const A11Y_CLASS_HINTS = /\b(sr-only|visually-hidden|screen-reader-only|visuallyhidden|a11y-hidden|screen-reader-text|visually-hidden-focusable)\b/i;
|
|
20
|
+
const HIDDEN_CLASS_HINTS = /\b(hidden|offscreen|clip|is-hidden|d-none|invisible)\b/i;
|
|
21
|
+
/** Classify a style declaration string. Returns the hiding reason or null. */
|
|
22
|
+
export function classifyStyle(style) {
|
|
23
|
+
const s = style.toLowerCase().replace(/\s+/g, "");
|
|
24
|
+
if (/display:none/.test(s) || /visibility:(hidden|collapse)/.test(s))
|
|
25
|
+
return "css_hidden";
|
|
26
|
+
if (/content-visibility:hidden/.test(s))
|
|
27
|
+
return "css_hidden";
|
|
28
|
+
const op = s.match(/opacity:(0?\.\d+|0|1)(?![\d.])/);
|
|
29
|
+
if (op && Number(op[1]) < 0.1)
|
|
30
|
+
return "tiny_or_transparent";
|
|
31
|
+
const fs = s.match(/font-size:(\d*\.?\d+)(px|pt|em|rem|%)?/);
|
|
32
|
+
if (fs && Number(fs[1]) <= (fs[2] === "em" || fs[2] === "rem" ? 0.1 : fs[2] === "%" ? 10 : 1))
|
|
33
|
+
return "tiny_or_transparent";
|
|
34
|
+
if (/color:transparent/.test(s) || /color:rgba\([^)]*,0\)/.test(s) || /color:#[0-9a-f]{6}00\b/.test(s))
|
|
35
|
+
return "tiny_or_transparent";
|
|
36
|
+
if (/transform:[^;]*scale(x|y|3d)?\(0(\.0+)?[,)]/.test(s) || /transform:[^;]*scale(x|y)?\(0\.0\d/.test(s))
|
|
37
|
+
return "tiny_or_transparent";
|
|
38
|
+
if (/filter:[^;]*opacity\(0(\.0\d*)?\)/.test(s))
|
|
39
|
+
return "tiny_or_transparent";
|
|
40
|
+
if (/(^|;)scale:0(\.0\d*)?(\s|;|$)/.test(s))
|
|
41
|
+
return "tiny_or_transparent";
|
|
42
|
+
if (/(^|;)translate:-?\d{3,}(px|em|rem|vw|vh|%)/.test(s))
|
|
43
|
+
return "offscreen";
|
|
44
|
+
if (/(^|;)inset:[^;]*-\d{3,}(px|em|rem|vw|vh|%)/.test(s))
|
|
45
|
+
return "offscreen";
|
|
46
|
+
if (/(^|;)font:[^;]*(^|\s|:)0(px|pt|em|rem|%)?\/|(^|;)font:0(px)?(\s|\/|;|$)/.test(s))
|
|
47
|
+
return "tiny_or_transparent";
|
|
48
|
+
// a custom property driving display/visibility/opacity/transform cannot be resolved statically; treat as hidden (hidden text is never delivered, so the cost of being wrong is low)
|
|
49
|
+
if (/(display|visibility|opacity|transform|clip-path|font-size|scale|translate):var\(/.test(s))
|
|
50
|
+
return "css_hidden";
|
|
51
|
+
if (/transform:[^;]*translate(x|y|3d)?\(-?\d{3,}(px|em|rem|vw|vh)/.test(s))
|
|
52
|
+
return "offscreen";
|
|
53
|
+
// same-colour text is judged by contrast in the cascade (color.ts), not by comparing two strings here
|
|
54
|
+
if (/-webkit-text-fill-color:transparent/.test(s))
|
|
55
|
+
return "tiny_or_transparent";
|
|
56
|
+
if (/(left|top|right|bottom|margin-left|margin-top|text-indent):-\d{3,}(px|em|rem|%|vw|vh)/.test(s))
|
|
57
|
+
return "offscreen";
|
|
58
|
+
if (/text-indent:(1\d\d|[2-9]\d\d|\d{4,})%/.test(s) || /text-indent:\d{4,}px/.test(s))
|
|
59
|
+
return "offscreen";
|
|
60
|
+
if (/position:(absolute|fixed)/.test(s) && /(left|top):\d{4,}(px|vw|vh)/.test(s))
|
|
61
|
+
return "offscreen";
|
|
62
|
+
if (/clip:rect\(0(px)?,0(px)?,0(px)?,0(px)?\)/.test(s) || /clip:rect\(1px,1px,1px,1px\)/.test(s))
|
|
63
|
+
return "offscreen";
|
|
64
|
+
if (/clip-path:(inset\(([4-9]\d|100)%|circle\(0|polygon\(0(px|%)?\s*0)/.test(s))
|
|
65
|
+
return "offscreen";
|
|
66
|
+
if (/(width|height|max-height|max-width):0(px)?;.*overflow:hidden/.test(s) || /overflow:hidden;.*(width|height|max-height|max-width):0(px)?(;|$)/.test(s))
|
|
67
|
+
return "offscreen";
|
|
68
|
+
if (/(width|height):1px;.*overflow:hidden/.test(s) && /position:absolute/.test(s))
|
|
69
|
+
return "offscreen";
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
export function rulesFromCss(cssIn) {
|
|
73
|
+
const rules = [];
|
|
74
|
+
// flatten @media / @supports wrappers: "@media x { a{..} }" -> "a{..}"; drop keyframes and comments
|
|
75
|
+
const css = cssIn
|
|
76
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
77
|
+
.replace(/@keyframes[^{]*\{(?:[^{}]*\{[^{}]*\})*[^{}]*\}/g, "")
|
|
78
|
+
.replace(/@(media|supports|layer|container)[^{]*\{/g, "");
|
|
79
|
+
const re = /([^{}]+)\{([^{}]*)\}/g;
|
|
80
|
+
let m;
|
|
81
|
+
let count = 0;
|
|
82
|
+
while ((m = re.exec(css)) && count++ < 20000) {
|
|
83
|
+
const reason = classifyStyle(m[2]);
|
|
84
|
+
if (!reason)
|
|
85
|
+
continue;
|
|
86
|
+
for (const sel of m[1].split(",")) {
|
|
87
|
+
const t = sel.trim();
|
|
88
|
+
if (/^[.#]?[\w-]+$/.test(t)) {
|
|
89
|
+
rules.push({ selector: t, reason });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
// compound/descendant selectors: key on the last simple class or id; over-matching only raises suspicion
|
|
93
|
+
const last = t.split(/[\s>+~]+/).pop() ?? "";
|
|
94
|
+
const simple = last.match(/[.#][\w-]+/g);
|
|
95
|
+
if (simple)
|
|
96
|
+
rules.push({ selector: simple[simple.length - 1], reason });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return rules;
|
|
100
|
+
}
|
|
101
|
+
/** Remove @media blocks that do not describe the default screen rendering (dark mode, print), brace-matched. */
|
|
102
|
+
function dropAlternateMedia(css) {
|
|
103
|
+
let out = "", i = 0;
|
|
104
|
+
const re = /@media[^{]*(prefers-color-scheme\s*:\s*dark|print|forced-colors|prefers-contrast)[^{]*\{/gi;
|
|
105
|
+
let m;
|
|
106
|
+
while ((m = re.exec(css))) {
|
|
107
|
+
out += css.slice(i, m.index);
|
|
108
|
+
let depth = 1, j = m.index + m[0].length;
|
|
109
|
+
while (j < css.length && depth > 0) {
|
|
110
|
+
if (css[j] === "{")
|
|
111
|
+
depth++;
|
|
112
|
+
else if (css[j] === "}")
|
|
113
|
+
depth--;
|
|
114
|
+
j++;
|
|
115
|
+
}
|
|
116
|
+
i = j;
|
|
117
|
+
re.lastIndex = j;
|
|
118
|
+
}
|
|
119
|
+
return out + css.slice(i);
|
|
120
|
+
}
|
|
121
|
+
export function colorRulesFromCss(cssIn) {
|
|
122
|
+
const rules = [];
|
|
123
|
+
const css = dropAlternateMedia(cssIn.replace(/\/\*[\s\S]*?\*\//g, ""))
|
|
124
|
+
.replace(/@keyframes[^{]*\{(?:[^{}]*\{[^{}]*\})*[^{}]*\}/g, "")
|
|
125
|
+
.replace(/@(media|supports|layer|container)[^{]*\{/g, "");
|
|
126
|
+
const re = /([^{}]+)\{([^{}]*)\}/g;
|
|
127
|
+
let m;
|
|
128
|
+
let count = 0;
|
|
129
|
+
while ((m = re.exec(css)) && count++ < 20000) {
|
|
130
|
+
if (!/color|background/i.test(m[2]))
|
|
131
|
+
continue;
|
|
132
|
+
const c = colorsFromStyle(m[2]);
|
|
133
|
+
if (c.fg === undefined && c.bg === undefined && c.fill === undefined)
|
|
134
|
+
continue;
|
|
135
|
+
for (const sel of m[1].split(",")) {
|
|
136
|
+
const t = sel.trim().toLowerCase();
|
|
137
|
+
if (/^([.#][\w-]+|[a-z][\w-]*|:root)$/.test(t)) {
|
|
138
|
+
rules.push({ selector: t === ":root" ? "html" : t, ...c });
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// a colour set through a compound, attribute or pseudo selector cannot be resolved statically: mark the colour
|
|
142
|
+
// unknown on the element it keys on, so the element is never judged hidden on a guess (over-matching only loses detection)
|
|
143
|
+
const last = t.split(/[\s>+~]+/).pop() ?? "";
|
|
144
|
+
const key = (last.match(/[.#][\w-]+/g) ?? []).pop() ?? (last.match(/^[a-z][\w-]*/) ?? [])[0];
|
|
145
|
+
if (!key)
|
|
146
|
+
continue;
|
|
147
|
+
rules.push({ selector: key, ...(c.fg !== undefined ? { fg: null } : {}), ...(c.fill !== undefined ? { fill: null } : {}), ...(c.bg !== undefined ? { bg: null } : {}) });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return rules;
|
|
151
|
+
}
|
|
152
|
+
function attr(el, name) {
|
|
153
|
+
return el.attrs.find((a) => a.name === name)?.value;
|
|
154
|
+
}
|
|
155
|
+
function matchesRule(el, rule) {
|
|
156
|
+
if (rule.selector.startsWith(".")) {
|
|
157
|
+
const cls = attr(el, "class") ?? "";
|
|
158
|
+
return cls.split(/\s+/).includes(rule.selector.slice(1));
|
|
159
|
+
}
|
|
160
|
+
if (rule.selector.startsWith("#"))
|
|
161
|
+
return attr(el, "id") === rule.selector.slice(1);
|
|
162
|
+
return el.tagName === rule.selector;
|
|
163
|
+
}
|
|
164
|
+
function children(n) {
|
|
165
|
+
return (n.childNodes ?? []);
|
|
166
|
+
}
|
|
167
|
+
/** Collect hrefs of <link rel=stylesheet> so the engine can fetch them (same origin) before the real pass. */
|
|
168
|
+
export function findStylesheetLinks(html) {
|
|
169
|
+
const out = [];
|
|
170
|
+
const stack = [parse(html)];
|
|
171
|
+
while (stack.length) {
|
|
172
|
+
const n = stack.pop();
|
|
173
|
+
if (defaultTreeAdapter.isElementNode(n) && n.tagName === "link") {
|
|
174
|
+
const rel = (attr(n, "rel") ?? "").toLowerCase();
|
|
175
|
+
const href = attr(n, "href");
|
|
176
|
+
if (/\bstylesheet\b/.test(rel) && href)
|
|
177
|
+
out.push(href);
|
|
178
|
+
}
|
|
179
|
+
for (const c of children(n))
|
|
180
|
+
stack.push(c);
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
const BROWSER_FG = { r: 0, g: 0, b: 0, a: 1 };
|
|
185
|
+
const BROWSER_BG = { r: 255, g: 255, b: 255, a: 1 };
|
|
186
|
+
export function analyzeHtml(html, externalRules = [], externalColorRules = []) {
|
|
187
|
+
const doc = parse(html);
|
|
188
|
+
const segments = [];
|
|
189
|
+
const scripts = [];
|
|
190
|
+
const findings = [];
|
|
191
|
+
const stylesheetLinks = [];
|
|
192
|
+
const styleRules = [...externalRules];
|
|
193
|
+
const colorRules = [...externalColorRules];
|
|
194
|
+
/** segments hidden by colour, with the measured contrast */
|
|
195
|
+
const lowContrast = new Map();
|
|
196
|
+
const lowContrastRatio = new Map();
|
|
197
|
+
let maxDepth = 0;
|
|
198
|
+
// pass 1: <style> rules and stylesheet links (iterative)
|
|
199
|
+
{
|
|
200
|
+
const stack = [doc];
|
|
201
|
+
while (stack.length) {
|
|
202
|
+
const n = stack.pop();
|
|
203
|
+
if (defaultTreeAdapter.isElementNode(n)) {
|
|
204
|
+
if (n.tagName === "style") {
|
|
205
|
+
const css = n.childNodes.map((c) => (defaultTreeAdapter.isTextNode(c) ? c.value : "")).join("");
|
|
206
|
+
styleRules.push(...rulesFromCss(css));
|
|
207
|
+
colorRules.push(...colorRulesFromCss(css));
|
|
208
|
+
}
|
|
209
|
+
if (n.tagName === "link" && /\bstylesheet\b/.test((attr(n, "rel") ?? "").toLowerCase()) && attr(n, "href"))
|
|
210
|
+
stylesheetLinks.push(attr(n, "href"));
|
|
211
|
+
}
|
|
212
|
+
for (const c of children(n))
|
|
213
|
+
stack.push(c);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// pass 2: segments and scripts (iterative, document order)
|
|
217
|
+
let scriptIndex = 0;
|
|
218
|
+
const stack = [{ node: doc, vis: "visible", path: "", depth: 0, inA11y: false, fg: BROWSER_FG, bg: BROWSER_BG }];
|
|
219
|
+
// colour cascade, roughly by specificity: tag rules, then class, then id, then presentational attributes, then inline style
|
|
220
|
+
const byTag = colorRules.filter((r) => !/^[.#]/.test(r.selector));
|
|
221
|
+
const byClass = colorRules.filter((r) => r.selector.startsWith("."));
|
|
222
|
+
const byId = colorRules.filter((r) => r.selector.startsWith("#"));
|
|
223
|
+
const a11yShort = new Set();
|
|
224
|
+
while (stack.length) {
|
|
225
|
+
const { node: n, vis: inherited, path, depth, inA11y, fg: inFg, bg: inBg, fill: inFill } = stack.pop();
|
|
226
|
+
if (depth > maxDepth)
|
|
227
|
+
maxDepth = depth;
|
|
228
|
+
if (defaultTreeAdapter.isCommentNode(n)) {
|
|
229
|
+
const text = decodeEntities(n.data).text.trim();
|
|
230
|
+
if (text)
|
|
231
|
+
segments.push({ text, visibility: "comment", path: `${path}#comment` });
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (defaultTreeAdapter.isTextNode(n)) {
|
|
235
|
+
const text = n.value;
|
|
236
|
+
if (text.trim()) {
|
|
237
|
+
// colour is judged where the text is: the colour it inherits against the background it sits on
|
|
238
|
+
let visibility = inherited;
|
|
239
|
+
const textColor = inFill ?? inFg;
|
|
240
|
+
if (visibility === "visible" && textColor && inBg) {
|
|
241
|
+
const ratio = contrastRatio(textColor, inBg);
|
|
242
|
+
if (ratio <= INVISIBLE_CONTRAST) {
|
|
243
|
+
visibility = "tiny_or_transparent";
|
|
244
|
+
lowContrastRatio.set(path + "\u0000" + segments.length, ratio);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const seg = { text, visibility, path };
|
|
248
|
+
const key = path + "\u0000" + segments.length;
|
|
249
|
+
segments.push(seg);
|
|
250
|
+
if (lowContrastRatio.has(key))
|
|
251
|
+
lowContrast.set(seg, lowContrastRatio.get(key));
|
|
252
|
+
if (inA11y)
|
|
253
|
+
a11yShort.add(seg);
|
|
254
|
+
}
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (!defaultTreeAdapter.isElementNode(n)) {
|
|
258
|
+
const kids = children(n);
|
|
259
|
+
for (let i = kids.length - 1; i >= 0; i--)
|
|
260
|
+
stack.push({ node: kids[i], vis: inherited, path, depth, inA11y, fg: inFg, bg: inBg, fill: inFill });
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const el = n;
|
|
264
|
+
const tag = el.tagName;
|
|
265
|
+
// content a reader reveals with one click (a collapsed <details>, a hidden tab panel) is marked so passes that
|
|
266
|
+
// weigh visibility can treat it as documentation rather than concealment
|
|
267
|
+
const revealable = (tag === "details" && attr(el, "open") === undefined) ||
|
|
268
|
+
(attr(el, "hidden") !== undefined && (/^(tabpanel|region)$/i.test(attr(el, "role") ?? "") || /\b(tab|panel|accordion|collapse)/i.test(attr(el, "class") ?? "")));
|
|
269
|
+
const myPath = `${path}/${tag}${revealable ? "~revealable" : ""}`;
|
|
270
|
+
if (tag === "script") {
|
|
271
|
+
const src = attr(el, "src");
|
|
272
|
+
const source = el.childNodes.map((c) => (defaultTreeAdapter.isTextNode(c) ? c.value : "")).join("");
|
|
273
|
+
if (scripts.length < 2000)
|
|
274
|
+
scripts.push({ index: scriptIndex++, source, inline: !src, src });
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (tag === "title") {
|
|
278
|
+
const t = el.childNodes.map((c) => (defaultTreeAdapter.isTextNode(c) ? c.value : "")).join("").trim();
|
|
279
|
+
if (t)
|
|
280
|
+
segments.push({ text: t, visibility: "attribute", path: `${myPath}` });
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (tag === "meta") {
|
|
284
|
+
const name = (attr(el, "name") ?? attr(el, "property") ?? "").toLowerCase();
|
|
285
|
+
const content = attr(el, "content");
|
|
286
|
+
if (content && /description|keywords|og:|twitter:/.test(name) && content.trim())
|
|
287
|
+
segments.push({ text: content, visibility: "attribute", path: `${myPath}@${name}` });
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (tag === "iframe") {
|
|
291
|
+
const srcdoc = attr(el, "srcdoc");
|
|
292
|
+
if (srcdoc && srcdoc.trim())
|
|
293
|
+
segments.push({ text: srcdoc.replace(/<[^>]+>/g, " "), visibility: "css_hidden", path: `${myPath}@srcdoc` });
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (SKIPPED_TAGS.has(tag))
|
|
297
|
+
continue;
|
|
298
|
+
if (tag === "svg" && inherited === "visible") {
|
|
299
|
+
// SVG text renders, but as graphics: scan it as its own channel, do not deliver it as page copy
|
|
300
|
+
const kids = el.childNodes;
|
|
301
|
+
for (let i = kids.length - 1; i >= 0; i--)
|
|
302
|
+
stack.push({ node: kids[i], vis: "attribute", path: `${myPath}@svg`, depth: depth + 1, inA11y, fg: inFg, bg: inBg, fill: inFill });
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
// attribute-only text: alt, title, aria-label, placeholder, value, data-*
|
|
306
|
+
for (const a of el.attrs) {
|
|
307
|
+
if (["alt", "title", "aria-label", "aria-description", "placeholder", "value", "label"].includes(a.name) || a.name.startsWith("data-")) {
|
|
308
|
+
if (a.value.trim().length > 0)
|
|
309
|
+
segments.push({ text: a.value, visibility: "attribute", path: `${myPath}@${a.name}` });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
let vis = inherited;
|
|
313
|
+
let a11y = inA11y;
|
|
314
|
+
// colour: resolve this element's text colour and the background it sits on
|
|
315
|
+
let fg = inFg, bg = inBg, fill = inFill;
|
|
316
|
+
const apply = (c) => {
|
|
317
|
+
if (c.fg !== undefined)
|
|
318
|
+
fg = c.fg;
|
|
319
|
+
if (c.fill !== undefined)
|
|
320
|
+
fill = c.fill;
|
|
321
|
+
if (c.bg !== undefined) {
|
|
322
|
+
if (c.bg === null)
|
|
323
|
+
bg = null; // image or gradient: unknown, never flag
|
|
324
|
+
else if (c.bg.a >= 0.999)
|
|
325
|
+
bg = c.bg;
|
|
326
|
+
else if (c.bg.a > 0 && bg)
|
|
327
|
+
bg = blend(c.bg, bg);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
const clsList = (attr(el, "class") ?? "").toLowerCase().split(/\s+/).filter(Boolean);
|
|
331
|
+
const id = (attr(el, "id") ?? "").toLowerCase();
|
|
332
|
+
for (const r of byTag)
|
|
333
|
+
if (r.selector === tag)
|
|
334
|
+
apply(r);
|
|
335
|
+
for (const r of byClass)
|
|
336
|
+
if (clsList.includes(r.selector.slice(1)))
|
|
337
|
+
apply(r);
|
|
338
|
+
if (id)
|
|
339
|
+
for (const r of byId)
|
|
340
|
+
if (r.selector === "#" + id)
|
|
341
|
+
apply(r);
|
|
342
|
+
const pres = (a) => { const v = attr(el, a); return v ? parseColor(v) : undefined; };
|
|
343
|
+
if (tag === "font" && pres("color"))
|
|
344
|
+
apply({ fg: pres("color") });
|
|
345
|
+
if (tag === "body" && pres("text"))
|
|
346
|
+
apply({ fg: pres("text") });
|
|
347
|
+
if (pres("bgcolor"))
|
|
348
|
+
apply({ bg: pres("bgcolor") });
|
|
349
|
+
const inlineStyle = attr(el, "style");
|
|
350
|
+
if (inlineStyle)
|
|
351
|
+
apply(colorsFromStyle(inlineStyle));
|
|
352
|
+
if (vis === "visible") {
|
|
353
|
+
if (attr(el, "hidden") !== undefined || attr(el, "aria-hidden") === "true" || attr(el, "inert") !== undefined)
|
|
354
|
+
vis = "css_hidden";
|
|
355
|
+
if (HIDDEN_CONTAINER_TAGS.has(tag))
|
|
356
|
+
vis = "css_hidden";
|
|
357
|
+
if (tag === "details" && attr(el, "open") === undefined)
|
|
358
|
+
vis = "css_hidden"; // summary re-opened below
|
|
359
|
+
if (tag === "input" && /^(hidden)$/i.test(attr(el, "type") ?? ""))
|
|
360
|
+
vis = "css_hidden";
|
|
361
|
+
const style = attr(el, "style");
|
|
362
|
+
if (style)
|
|
363
|
+
vis = classifyStyle(style) ?? vis;
|
|
364
|
+
if (vis === "visible")
|
|
365
|
+
for (const r of styleRules)
|
|
366
|
+
if (matchesRule(el, r)) {
|
|
367
|
+
vis = r.reason;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
const cls = attr(el, "class") ?? "";
|
|
371
|
+
if (vis === "visible" && A11Y_CLASS_HINTS.test(cls)) {
|
|
372
|
+
vis = "css_hidden";
|
|
373
|
+
a11y = true;
|
|
374
|
+
}
|
|
375
|
+
if (vis === "visible" && HIDDEN_CLASS_HINTS.test(cls))
|
|
376
|
+
vis = "css_hidden";
|
|
377
|
+
}
|
|
378
|
+
const kids = el.childNodes;
|
|
379
|
+
for (let i = kids.length - 1; i >= 0; i--) {
|
|
380
|
+
const c = kids[i];
|
|
381
|
+
// the <summary> of a collapsed <details> is visible
|
|
382
|
+
const childVis = tag === "details" && defaultTreeAdapter.isElementNode(c) && c.tagName === "summary" && inherited === "visible" ? "visible" : vis;
|
|
383
|
+
stack.push({ node: c, vis: childVis, path: myPath, depth: depth + 1, inA11y: a11y, fg, bg, fill });
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// findings: any non-visible text that is long enough to carry an instruction
|
|
387
|
+
const kindFor = {
|
|
388
|
+
css_hidden: "visibility.css_hidden",
|
|
389
|
+
offscreen: "visibility.offscreen",
|
|
390
|
+
attribute: "visibility.attribute_only",
|
|
391
|
+
comment: "visibility.html_comment",
|
|
392
|
+
tiny_or_transparent: "visibility.tiny_or_transparent",
|
|
393
|
+
};
|
|
394
|
+
for (const s of segments) {
|
|
395
|
+
if (s.visibility === "visible")
|
|
396
|
+
continue;
|
|
397
|
+
const words = s.text.trim().split(/\s+/).length;
|
|
398
|
+
// short hidden text is page furniture; attributes (alt, title) are routinely a sentence long
|
|
399
|
+
if (words < (s.visibility === "attribute" ? 14 : 6))
|
|
400
|
+
continue;
|
|
401
|
+
const isA11y = a11yShort.has(s) && words < 20;
|
|
402
|
+
const base = s.visibility === "attribute" ? 0.15 : isA11y ? 0.3 : 0.55;
|
|
403
|
+
findings.push({
|
|
404
|
+
pass: "visibility",
|
|
405
|
+
kind: kindFor[s.visibility],
|
|
406
|
+
confidence: Math.min(0.95, base + Math.min(words, 60) / 120),
|
|
407
|
+
// hidden text is not delivered, so on its own it is informational; the meaning pass decides whether it is an attack
|
|
408
|
+
severity: 0.35,
|
|
409
|
+
message: lowContrast.has(s)
|
|
410
|
+
? `${words} words in a colour matching their background (contrast ${lowContrast.get(s).toFixed(2)}:1) a human would not see`
|
|
411
|
+
: `${words} words of ${s.visibility.replace(/_/g, " ")} text a human would not see${isA11y ? " (screen-reader label)" : ""}`,
|
|
412
|
+
excerpt: s.text.trim().slice(0, 160),
|
|
413
|
+
location: s.path,
|
|
414
|
+
action: "none",
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
const visibleText = segments
|
|
418
|
+
.filter((s) => s.visibility === "visible")
|
|
419
|
+
.map((s) => s.text)
|
|
420
|
+
.join(" ")
|
|
421
|
+
.replace(/\s+/g, " ")
|
|
422
|
+
.trim();
|
|
423
|
+
return { segments, scripts, findings, visibleText, stylesheetLinks, maxDepth };
|
|
424
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acepaste/ingress",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "AcePaste Ingress engine: acquire, visibility, character, script, supply-chain, sandbox, meaning, verdict, envelope, receipts.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"types": "dist/src/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"ingress": "dist/src/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc -p tsconfig.json",
|
|
13
|
+
"test": "tsc -p tsconfig.json && node --test \"dist/test/**/*.test.js\""
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"acorn": "^8.12.0",
|
|
17
|
+
"acorn-walk": "^8.3.0",
|
|
18
|
+
"parse5": "^7.1.2",
|
|
19
|
+
"undici": "^6.19.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.0.0",
|
|
23
|
+
"typescript": "^5.5.0"
|
|
24
|
+
},
|
|
25
|
+
"license": "FSL-1.1-ALv2",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/src/index.d.ts",
|
|
29
|
+
"import": "./dist/src/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"optionalDependencies": {
|
|
33
|
+
"playwright": "^1.47.0"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/sugarcypher/acepasteINGRESS.git",
|
|
38
|
+
"directory": "packages/core"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/sugarcypher/acepasteINGRESS#readme",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/sugarcypher/acepasteINGRESS/issues"
|
|
43
|
+
},
|
|
44
|
+
"author": "Briar Morgan Greenway (ThinkWell Labs LLC)",
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"prompt-injection",
|
|
53
|
+
"ai-security",
|
|
54
|
+
"llm",
|
|
55
|
+
"mcp",
|
|
56
|
+
"model-context-protocol",
|
|
57
|
+
"unicode",
|
|
58
|
+
"supply-chain",
|
|
59
|
+
"acepaste"
|
|
60
|
+
],
|
|
61
|
+
"files": [
|
|
62
|
+
"dist/src",
|
|
63
|
+
"README.md",
|
|
64
|
+
"LICENSE"
|
|
65
|
+
]
|
|
66
|
+
}
|