agent-sanitizer 2.63.1 → 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.
@@ -1,9 +1,10 @@
1
1
  /**
2
- * GENERATED by scripts/gen-joining-type.mjs from the pinned UCD 17.0.0 — DO NOT EDIT.
2
+ * GENERATED by scripts/gen-joining-type.mjs from the pinned UCD 17.0.0 at install
3
+ * time; git-ignored, never committed — DO NOT EDIT.
3
4
  *
4
5
  * Unicode Joining_Type, Indic virama and Brahmic consonant range tables backing
5
- * the ZWNJ/ZWJ carve-out in invisible.mjs. Regenerate with `pnpm gen:joining-type`;
6
- * test/joining-type.test.mjs fails if this drifts from the pinned UCD.
6
+ * the ZWNJ/ZWJ carve-out in invisible.mjs. Regenerate with `pnpm gen:joining-type`
7
+ * (`pnpm install` does).
7
8
  */
8
9
 
9
10
  export const UNICODE_VERSION = "17.0.0";
@@ -1,20 +1,20 @@
1
1
  /**
2
2
  * GENERATED by scripts/gen-standardized-variants.mjs from UCD
3
- * StandardizedVariants.txt (Unicode 17.0.0) — DO NOT EDIT.
3
+ * StandardizedVariants.txt (Unicode 17.0.0) at install time; git-ignored,
4
+ * never committed — DO NOT EDIT.
4
5
  *
5
6
  * Registered standardized variation sequences: a base code point followed by the
6
7
  * variation selector the UCD registers for it. invisible.mjs preserves such a
7
8
  * selector only when the immediately preceding base appears here; every other
8
9
  * one is stripped as a hidden-payload byte. Regenerate with
9
- * `node scripts/gen-standardized-variants.mjs`;
10
- * test/invisible-charset.test.mjs fails if this drifts from the pinned UCD.
10
+ * `node scripts/gen-standardized-variants.mjs` (`pnpm install` does).
11
11
  */
12
12
 
13
13
  export const UNICODE_VERSION = "17.0.0";
14
14
 
15
15
  // The table below is GENERATED UCD data, not hand-written logic. Its correctness
16
16
  // is pinned by the SSOT round-trip in test/invisible-charset.test.mjs (re-parse
17
- // the vendored file, then assert every pair matches) — a stronger and faster
17
+ // the pinned file, then assert every pair matches) — a stronger and faster
18
18
  // guard than mutating a few hundred numeric literals, so Stryker skips them.
19
19
  // Stryker disable all
20
20
  /** @type {Array<[number, number]>} [base, selector], sorted by base then selector. */
@@ -1,10 +1,11 @@
1
1
  /**
2
- * GENERATED by scripts/gen-unicode-properties.mjs from the pinned UCD 17.0.0 — DO NOT EDIT.
2
+ * GENERATED by scripts/gen-unicode-properties.mjs from the pinned UCD 17.0.0 at
3
+ * install time; git-ignored, never committed — DO NOT EDIT.
3
4
  *
4
5
  * The Unicode properties src/invisible.mjs's carve-out reads, PINNED so the
5
6
  * carve-out answers the same on every Node whatever its ICU's Unicode version.
6
- * Regenerate with `node scripts/gen-unicode-properties.mjs`;
7
- * test/unicode-properties.test.mjs fails if this drifts from the pinned package.
7
+ * Regenerate with `node scripts/gen-unicode-properties.mjs` (`pnpm install`
8
+ * does).
8
9
  */
9
10
 
10
11
  export const UNICODE_VERSION = "17.0.0";
@@ -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
+ );
@@ -1,13 +1,14 @@
1
1
  /**
2
- * GENERATED by scripts/gen-invisible-charset.mjs from the pinned UCD
3
- * (General_Category=Cf, Unicode 17.0.0) — DO NOT EDIT.
2
+ * GENERATED by scripts/gen-cf-charset.mjs from the pinned UCD
3
+ * (General_Category=Cf, Unicode 17.0.0) at install, pack and build
4
+ * time; git-ignored, never committed — DO NOT EDIT.
4
5
  *
5
6
  * The general-category Cf code points, PINNED at generation time. invisible.mjs
6
7
  * strips exactly this set instead of asking the runtime for Cf, and the Python port
7
8
  * reads the SAME set from data/invisible-charset.json's `cf_codepoints`, so both
8
9
  * layers strip an identical Cf set regardless of each runtime's own Unicode
9
- * version. Regenerate with `node scripts/gen-invisible-charset.mjs`;
10
- * test/invisible-charset.test.mjs fails if this drifts from the pinned UCD.
10
+ * version. Regenerate with `node scripts/gen-cf-charset.mjs` (`pnpm install`
11
+ * does).
11
12
  */
12
13
  export const UNICODE_VERSION: "17.0.0";
13
14
  /** @type {readonly number[]} Sorted ascending. */
@@ -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;
@@ -24,11 +24,12 @@ export function isVirama(cp: number): boolean;
24
24
  */
25
25
  export function isBrahmicConsonant(cp: number): boolean;
26
26
  /**
27
- * GENERATED by scripts/gen-joining-type.mjs from the pinned UCD 17.0.0 — DO NOT EDIT.
27
+ * GENERATED by scripts/gen-joining-type.mjs from the pinned UCD 17.0.0 at install
28
+ * time; git-ignored, never committed — DO NOT EDIT.
28
29
  *
29
30
  * Unicode Joining_Type, Indic virama and Brahmic consonant range tables backing
30
- * the ZWNJ/ZWJ carve-out in invisible.mjs. Regenerate with `pnpm gen:joining-type`;
31
- * test/joining-type.test.mjs fails if this drifts from the pinned UCD.
31
+ * the ZWNJ/ZWJ carve-out in invisible.mjs. Regenerate with `pnpm gen:joining-type`
32
+ * (`pnpm install` does).
32
33
  */
33
34
  export const UNICODE_VERSION: "17.0.0";
34
35
  /** @type {ReadonlyArray<readonly [string, number, number]>} */
@@ -1,13 +1,14 @@
1
1
  /**
2
- * GENERATED by scripts/gen-invisible-charset.mjs from the pinned UCD
3
- * (General_Category=Cf, Unicode 17.0.0) — DO NOT EDIT.
2
+ * GENERATED by scripts/gen-cf-charset.mjs from the pinned UCD
3
+ * (General_Category=Cf, Unicode 17.0.0) at install, pack and build
4
+ * time; git-ignored, never committed — DO NOT EDIT.
4
5
  *
5
6
  * The general-category Cf code points, PINNED at generation time. invisible.mjs
6
7
  * strips exactly this set instead of asking the runtime for Cf, and the Python port
7
8
  * reads the SAME set from data/invisible-charset.json's `cf_codepoints`, so both
8
9
  * layers strip an identical Cf set regardless of each runtime's own Unicode
9
- * version. Regenerate with `node scripts/gen-invisible-charset.mjs`;
10
- * test/invisible-charset.test.mjs fails if this drifts from the pinned UCD.
10
+ * version. Regenerate with `node scripts/gen-cf-charset.mjs` (`pnpm install`
11
+ * does).
11
12
  */
12
13
  export const UNICODE_VERSION: "17.0.0";
13
14
  /** @type {readonly number[]} Sorted ascending. */
@@ -24,11 +24,12 @@ export function isVirama(cp: number): boolean;
24
24
  */
25
25
  export function isBrahmicConsonant(cp: number): boolean;
26
26
  /**
27
- * GENERATED by scripts/gen-joining-type.mjs from the pinned UCD 17.0.0 — DO NOT EDIT.
27
+ * GENERATED by scripts/gen-joining-type.mjs from the pinned UCD 17.0.0 at install
28
+ * time; git-ignored, never committed — DO NOT EDIT.
28
29
  *
29
30
  * Unicode Joining_Type, Indic virama and Brahmic consonant range tables backing
30
- * the ZWNJ/ZWJ carve-out in invisible.mjs. Regenerate with `pnpm gen:joining-type`;
31
- * test/joining-type.test.mjs fails if this drifts from the pinned UCD.
31
+ * the ZWNJ/ZWJ carve-out in invisible.mjs. Regenerate with `pnpm gen:joining-type`
32
+ * (`pnpm install` does).
32
33
  */
33
34
  export const UNICODE_VERSION: "17.0.0";
34
35
  /** @type {ReadonlyArray<readonly [string, number, number]>} */
@@ -8,14 +8,14 @@
8
8
  export function isStandardizedVariant(base: number, selector: number): boolean;
9
9
  /**
10
10
  * GENERATED by scripts/gen-standardized-variants.mjs from UCD
11
- * StandardizedVariants.txt (Unicode 17.0.0) — DO NOT EDIT.
11
+ * StandardizedVariants.txt (Unicode 17.0.0) at install time; git-ignored,
12
+ * never committed — DO NOT EDIT.
12
13
  *
13
14
  * Registered standardized variation sequences: a base code point followed by the
14
15
  * variation selector the UCD registers for it. invisible.mjs preserves such a
15
16
  * selector only when the immediately preceding base appears here; every other
16
17
  * one is stripped as a hidden-payload byte. Regenerate with
17
- * `node scripts/gen-standardized-variants.mjs`;
18
- * test/invisible-charset.test.mjs fails if this drifts from the pinned UCD.
18
+ * `node scripts/gen-standardized-variants.mjs` (`pnpm install` does).
19
19
  */
20
20
  export const UNICODE_VERSION: "17.0.0";
21
21
  /** @type {Array<[number, number]>} [base, selector], sorted by base then selector. */
@@ -7,12 +7,13 @@
7
7
  */
8
8
  export function inSpans(spans: ReadonlyArray<readonly [number, number]>, cp: number): boolean;
9
9
  /**
10
- * GENERATED by scripts/gen-unicode-properties.mjs from the pinned UCD 17.0.0 — DO NOT EDIT.
10
+ * GENERATED by scripts/gen-unicode-properties.mjs from the pinned UCD 17.0.0 at
11
+ * install time; git-ignored, never committed — DO NOT EDIT.
11
12
  *
12
13
  * The Unicode properties src/invisible.mjs's carve-out reads, PINNED so the
13
14
  * carve-out answers the same on every Node whatever its ICU's Unicode version.
14
- * Regenerate with `node scripts/gen-unicode-properties.mjs`;
15
- * test/unicode-properties.test.mjs fails if this drifts from the pinned package.
15
+ * Regenerate with `node scripts/gen-unicode-properties.mjs` (`pnpm install`
16
+ * does).
16
17
  */
17
18
  export const UNICODE_VERSION: "17.0.0";
18
19
  /** @type {ReadonlyArray<readonly [number, number]>} */
@@ -8,14 +8,14 @@
8
8
  export function isStandardizedVariant(base: number, selector: number): boolean;
9
9
  /**
10
10
  * GENERATED by scripts/gen-standardized-variants.mjs from UCD
11
- * StandardizedVariants.txt (Unicode 17.0.0) — DO NOT EDIT.
11
+ * StandardizedVariants.txt (Unicode 17.0.0) at install time; git-ignored,
12
+ * never committed — DO NOT EDIT.
12
13
  *
13
14
  * Registered standardized variation sequences: a base code point followed by the
14
15
  * variation selector the UCD registers for it. invisible.mjs preserves such a
15
16
  * selector only when the immediately preceding base appears here; every other
16
17
  * one is stripped as a hidden-payload byte. Regenerate with
17
- * `node scripts/gen-standardized-variants.mjs`;
18
- * test/invisible-charset.test.mjs fails if this drifts from the pinned UCD.
18
+ * `node scripts/gen-standardized-variants.mjs` (`pnpm install` does).
19
19
  */
20
20
  export const UNICODE_VERSION: "17.0.0";
21
21
  /** @type {Array<[number, number]>} [base, selector], sorted by base then selector. */
@@ -7,12 +7,13 @@
7
7
  */
8
8
  export function inSpans(spans: ReadonlyArray<readonly [number, number]>, cp: number): boolean;
9
9
  /**
10
- * GENERATED by scripts/gen-unicode-properties.mjs from the pinned UCD 17.0.0 — DO NOT EDIT.
10
+ * GENERATED by scripts/gen-unicode-properties.mjs from the pinned UCD 17.0.0 at
11
+ * install time; git-ignored, never committed — DO NOT EDIT.
11
12
  *
12
13
  * The Unicode properties src/invisible.mjs's carve-out reads, PINNED so the
13
14
  * carve-out answers the same on every Node whatever its ICU's Unicode version.
14
- * Regenerate with `node scripts/gen-unicode-properties.mjs`;
15
- * test/unicode-properties.test.mjs fails if this drifts from the pinned package.
15
+ * Regenerate with `node scripts/gen-unicode-properties.mjs` (`pnpm install`
16
+ * does).
16
17
  */
17
18
  export const UNICODE_VERSION: "17.0.0";
18
19
  /** @type {ReadonlyArray<readonly [number, number]>} */
@@ -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
+ };