agent-sanitizer 2.64.0 → 2.64.1

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.
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The attributes a browser resolves as URLs: the one table every Layer-3 URL
3
+ * read (and Layer 2's data: resource count) goes through; its test partitions
4
+ * the HTML Standard's URL attributes between it and an exempt list. `property`
5
+ * is the hast spelling; `elements` null means any element; a "form" or
6
+ * "refresh" `context` is also flagged for leaving the origin; `fetched` is a
7
+ * load nobody decides on, except on `notFetchedOn`. Rows state only where they
8
+ * differ from {@link DEFAULTS}.
9
+ */
10
+
11
+ /**
12
+ * @typedef {{
13
+ * attribute: string,
14
+ * property: string,
15
+ * grammar: "url" | "urls" | "srcset" | "refresh" | "css",
16
+ * elements: readonly string[] | null,
17
+ * context: "resource" | "form" | "refresh",
18
+ * fetched: boolean,
19
+ * notFetchedOn: readonly string[],
20
+ * }} UrlAttribute
21
+ */
22
+
23
+ const DEFAULTS = Object.freeze({
24
+ grammar: "url",
25
+ elements: null,
26
+ context: "resource",
27
+ fetched: true,
28
+ notFetchedOn: [],
29
+ });
30
+
31
+ /** @type {readonly UrlAttribute[]} */
32
+ export const URL_ATTRIBUTES = Object.freeze(
33
+ /** @type {Array<Partial<UrlAttribute> & { attribute: string, property: string }>} */ ([
34
+ { attribute: "src", property: "src" },
35
+ // A link waits for a click; `<base>` only re-bases relative URLs.
36
+ {
37
+ attribute: "href",
38
+ property: "href",
39
+ notFetchedOn: ["a", "area", "base"],
40
+ },
41
+ { attribute: "xlink:href", property: "xLinkHref", notFetchedOn: ["a"] },
42
+ { attribute: "background", property: "background" },
43
+ { attribute: "srcset", property: "srcSet", grammar: "srcset" },
44
+ {
45
+ attribute: "imagesrcset",
46
+ property: "imageSrcSet",
47
+ grammar: "srcset",
48
+ elements: ["link"],
49
+ },
50
+ { attribute: "ping", property: "ping", grammar: "urls" },
51
+ { attribute: "action", property: "action", context: "form" },
52
+ { attribute: "formaction", property: "formAction", context: "form" },
53
+ { attribute: "data", property: "data", elements: ["object"] },
54
+ { attribute: "poster", property: "poster", elements: ["video"] },
55
+ {
56
+ attribute: "cite",
57
+ property: "cite",
58
+ elements: ["blockquote", "del", "ins", "q"],
59
+ fetched: false,
60
+ },
61
+ {
62
+ attribute: "longdesc",
63
+ property: "longDesc",
64
+ elements: ["img", "iframe", "frame"],
65
+ fetched: false,
66
+ },
67
+ {
68
+ attribute: "content",
69
+ property: "content",
70
+ grammar: "refresh",
71
+ elements: ["meta"],
72
+ context: "refresh",
73
+ },
74
+ { attribute: "style", property: "style", grammar: "css" },
75
+ ]).map((row) => Object.freeze({ ...DEFAULTS, ...row })),
76
+ );
@@ -0,0 +1,6 @@
1
+ /** GENERATED by scripts/gen-css-syntax.mjs — DO NOT EDIT (mdn-data, CC0). */
2
+ /** @type {{ types: Record<string, string>, properties: Record<string, string> }} */
3
+ export const CSS_SYNTAX: {
4
+ types: Record<string, string>;
5
+ properties: Record<string, string>;
6
+ };
@@ -21,3 +21,46 @@ export function createTreeAdapter(): {
21
21
  * @returns {any}
22
22
  */
23
23
  export function parseHtmlFragment(html: string): any;
24
+ /**
25
+ * `fromParse5(tree, { file })`, recursing at most `chunkDepth` levels at a time.
26
+ *
27
+ * Every node a multiple of `chunkDepth` levels down is converted on its own,
28
+ * deepest first, and then stands in its parent's `childNodes` as a placeholder
29
+ * text node carrying the converted subtree's position — the one thing about a
30
+ * child its parent's conversion reads (an unclosed element ends where its last
31
+ * child does). One walk then swaps each placeholder for its subtree. The result
32
+ * is the tree a single `fromParse5` call returns, which
33
+ * `html-tree-adapter.test` holds it to.
34
+ *
35
+ * Mutates `tree`: {@link parseHtmlFragment} owns the parse and drops it after.
36
+ * @param {any} tree
37
+ * @param {VFile} file
38
+ * @param {number} [chunkDepth]
39
+ * @returns {any}
40
+ */
41
+ export function fromParse5Bounded(tree: any, file: VFile, chunkDepth?: number): any;
42
+ /**
43
+ * How many levels of the tree one `fromParse5` call converts.
44
+ *
45
+ * WHY IT EXISTS — `hast-util-from-parse5` converts by recursion, three frames
46
+ * (`one` → `all` → `element`) per level, so how deep a tree it survives is
47
+ * whatever stack is left, and that depends on the JIT tier: a cold call's
48
+ * interpreted frames are bigger than an optimized one's. ~2500 nested elements
49
+ * overflowed on the first call in a process and converted fine on a later one,
50
+ * so the same document came back withheld or sanitized depending on what had
51
+ * run before it. 128 levels still convert cold on a 100 KB stack, a tenth of
52
+ * Node's default.
53
+ */
54
+ export const CONVERT_DEPTH: 128;
55
+ /**
56
+ * The deepest a node may sit below the fragment root; a deeper parse throws, so
57
+ * the caller fails closed on it.
58
+ *
59
+ * Conversion no longer limits depth (see {@link CONVERT_DEPTH}), so this is the
60
+ * one place that does, and it answers the same way at every JIT tier. No real
61
+ * document comes near it — Blink's parser flattens anything nested past 512 —
62
+ * and what lies past it is built to cost: parse5's scope checks walk the
63
+ * open-element stack per tag, so parsing is quadratic in depth.
64
+ */
65
+ export const MAX_HTML_DEPTH: 4096;
66
+ import { VFile } from "vfile";
package/types/html.d.mts CHANGED
@@ -1,15 +1,18 @@
1
1
  /**
2
+ * True when an inline style hides its element's text, read as a block box
3
+ * with nothing inherited.
2
4
  * @param {string} styleStr
3
5
  * @returns {boolean}
4
6
  */
5
7
  export function isHiddenStyle(styleStr: string): boolean;
6
8
  /**
7
- * True for an element a rendered page would not show: `hidden` attribute or a
8
- * hiding inline style. Works on both hast nodes and parseHtmlTag results.
9
+ * True for an element a rendered page would not show (`hidden` or a hiding
10
+ * inline style, in element context). Takes hast nodes and parseHtmlTag results.
9
11
  * @param {any} node
12
+ * @param {any} [parent] the element's parent, when known
10
13
  * @returns {boolean}
11
14
  */
12
- export function isHiddenElement(node: any): boolean;
15
+ export function isHiddenElement(node: any, parent?: any): boolean;
13
16
  /**
14
17
  * @param {string} htmlValue
15
18
  * @returns {string | null}
@@ -119,10 +122,9 @@ export function checkExfilUrl(url: string, options?: {
119
122
  */
120
123
  export function urlHost(url: string): string;
121
124
  /**
122
- * Layer 3: report data-exfil-shaped URLs in markdown links/images/definitions
123
- * and HTML attributes (src/href/background/srcset/ping, form action/formaction,
124
- * meta-refresh). Detection only — the text is never modified; the caller
125
- * surfaces the threats as a warning.
125
+ * Layer 3: report data-exfil-shaped URLs among the ones {@link collectUrls}
126
+ * reads. Detection only — the text is never modified; the caller surfaces the
127
+ * threats as a warning.
126
128
  *
127
129
  * `autoFetched` marks a threat that needs no deliberate act to fire — a
128
130
  * rendered image, a stylesheet, a form target, a meta refresh — as opposed to a
@@ -161,6 +163,40 @@ export const REPORTED_TAGS: Set<string>;
161
163
  export const HIDDEN_PLACEHOLDER: "[hidden HTML removed";
162
164
  export const COMMENT_PLACEHOLDER: "[HTML comment removed";
163
165
  export const DATA_URI_LENGTH_THRESHOLD: 4096;
166
+ export type StyleDeclaration = {
167
+ property: string;
168
+ value: any;
169
+ important: boolean;
170
+ index: number;
171
+ };
172
+ /**
173
+ * `winnerOf`: the declaration applied (its own, a shorthand's or `all`'s);
174
+ * `nodeOf`/`textOf`: its value when it is the property's OWN (else null/"");
175
+ * `exhausted`: a lookup ran out of {@link VALIDATION_BUDGET}.
176
+ */
177
+ export type Cascade = {
178
+ winnerOf: (property: string) => StyleDeclaration | null;
179
+ nodeOf: (property: string) => any;
180
+ textOf: (property: string) => string;
181
+ exhausted: boolean;
182
+ };
183
+ export type InheritedHide = "font-size" | "visibility" | "color" | "text-indent";
184
+ /**
185
+ * `color` and a concrete `-webkit-text-fill-color` (`textFill`) inherit
186
+ * SEPARATELY, so a child's `color` does not undo an inherited transparent fill.
187
+ */
188
+ export type ColorState = {
189
+ color: string;
190
+ textFill: string;
191
+ backdrop: string;
192
+ imageLayer: boolean;
193
+ paintedVisible: boolean;
194
+ };
195
+ export type RegionState = {
196
+ kinds: Set<InheritedHide>;
197
+ color: ColorState;
198
+ };
199
+ export type RegionVerdict = "hidden" | "neutral" | "visible" | "mixed";
164
200
  export type CollectedUrl = {
165
201
  url: string;
166
202
  isImage: boolean;
@@ -0,0 +1,11 @@
1
+ /** @type {readonly UrlAttribute[]} */
2
+ export const URL_ATTRIBUTES: readonly UrlAttribute[];
3
+ export type UrlAttribute = {
4
+ attribute: string;
5
+ property: string;
6
+ grammar: "url" | "urls" | "srcset" | "refresh" | "css";
7
+ elements: readonly string[] | null;
8
+ context: "resource" | "form" | "refresh";
9
+ fetched: boolean;
10
+ notFetchedOn: readonly string[];
11
+ };