agent-sanitizer 2.47.8 → 2.47.10

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/html.mjs +25 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-sanitizer",
3
- "version": "2.47.8",
3
+ "version": "2.47.10",
4
4
  "description": "Defend an agent against hidden-content injection: strip payload-capable invisible Unicode and ANSI, splice out human-invisible HTML, and flag data-exfil URLs in untrusted text before any model sees it.",
5
5
  "type": "module",
6
6
  "repository": {
package/src/html.mjs CHANGED
@@ -29,9 +29,23 @@
29
29
  * entry `await import()`s this module only when its cheap regex gates match.
30
30
  */
31
31
  import { createHash } from "node:crypto";
32
+ // Subpath specifiers, never the `css-tree` root: the root builds the default
33
+ // syntax at module scope, that construction reaches the lexer's `lib/data.js`,
34
+ // and `lib/data.js` pulls the whole `mdn-data` CSS table set in through
35
+ // `createRequire`. esbuild cannot tree-shake a side-effectful module-level
36
+ // construction, so the root put ~18k lines of at-rule/property/syntax tables
37
+ // into every shipped bundle for four functions that never consult them. Each
38
+ // subpath's closure stops at `syntax/config/*`, and the functions are the same
39
+ // ones the root re-exports, built by the same factories from the same config.
32
40
  // @ts-ignore -- css-tree ships no bundled types and @types/css-tree lags the 3.x
33
41
  // API (e.g. `ident.decode`); the value AST is walked with local `any` types.
34
- import * as csstree from "css-tree";
42
+ import cssParse from "css-tree/parser";
43
+ // @ts-ignore -- see above. Aliased: `walk` is this module's own unist walker.
44
+ import cssWalk from "css-tree/walker";
45
+ // @ts-ignore -- see above.
46
+ import cssGenerate from "css-tree/generator";
47
+ // @ts-ignore -- see above.
48
+ import { ident as cssIdent } from "css-tree/utils";
35
49
  import { unified } from "unified";
36
50
  import remarkParse from "remark-parse";
37
51
  import remarkGfm from "remark-gfm";
@@ -752,7 +766,7 @@ function canonicalizeColor(raw) {
752
766
  function paintsImageLayer(node) {
753
767
  if (!node) return false;
754
768
  let found = false;
755
- csstree.walk(node, {
769
+ cssWalk(node, {
756
770
  enter(/** @type {any} */ child) {
757
771
  if (child.type === "Url" || child.type === "Raw") found = true;
758
772
  // Names are canonicalized at the parse boundary, so a suffix test covers
@@ -1111,7 +1125,7 @@ const CSS_PROPERTY_IDENT_RE = /^-{0,2}[A-Za-z_][A-Za-z0-9_-]*$/;
1111
1125
  * @returns {string}
1112
1126
  */
1113
1127
  function tokenText(token) {
1114
- return token.type === "Identifier" ? token.name : csstree.generate(token);
1128
+ return token.type === "Identifier" ? token.name : cssGenerate(token);
1115
1129
  }
1116
1130
 
1117
1131
  /**
@@ -1151,14 +1165,14 @@ function declText(valueNode) {
1151
1165
  * @returns {void}
1152
1166
  */
1153
1167
  function canonicalizeValue(valueNode) {
1154
- csstree.walk(valueNode, {
1168
+ cssWalk(valueNode, {
1155
1169
  enter(/** @type {any} */ node) {
1156
- // ident.decode is pure string iteration and cannot throw on a token the
1170
+ // cssIdent.decode is pure string iteration and cannot throw on a token the
1157
1171
  // tokenizer already produced.
1158
1172
  if (node.type === "Identifier" || node.type === "Function")
1159
- node.name = csstree.ident.decode(node.name).toLowerCase();
1173
+ node.name = cssIdent.decode(node.name).toLowerCase();
1160
1174
  else if (node.type === "Dimension")
1161
- node.unit = csstree.ident.decode(node.unit).toLowerCase();
1175
+ node.unit = cssIdent.decode(node.unit).toLowerCase();
1162
1176
  },
1163
1177
  });
1164
1178
  }
@@ -1182,7 +1196,7 @@ function parseDeclarations(styleStr) {
1182
1196
  const decls = new Map();
1183
1197
  let ast;
1184
1198
  try {
1185
- ast = csstree.parse(styleStr, {
1199
+ ast = cssParse(styleStr, {
1186
1200
  context: "declarationList",
1187
1201
  parseValue: true,
1188
1202
  parseCustomProperty: false,
@@ -1195,12 +1209,12 @@ function parseDeclarations(styleStr) {
1195
1209
  return decls;
1196
1210
  }
1197
1211
  /* c8 ignore stop */
1198
- csstree.walk(ast, {
1212
+ cssWalk(ast, {
1199
1213
  visit: "Declaration",
1200
1214
  enter(/** @type {any} */ node) {
1201
- // ident.decode is pure string iteration and cannot throw on a real ident
1215
+ // cssIdent.decode is pure string iteration and cannot throw on a real ident
1202
1216
  // token; property is escape-decoded then gated to a clean CSS ident.
1203
- const property = csstree.ident.decode(node.property).trim().toLowerCase();
1217
+ const property = cssIdent.decode(node.property).trim().toLowerCase();
1204
1218
  if (!CSS_PROPERTY_IDENT_RE.test(property)) return;
1205
1219
  canonicalizeValue(node.value);
1206
1220
  decls.set(property, node.value);