@skrr-ai/cli 0.1.162 → 0.1.163

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 (82) hide show
  1. package/dist/base-command.d.ts +5 -2
  2. package/dist/base-command.js +96 -39
  3. package/dist/commands/activity/list.d.ts +7 -0
  4. package/dist/commands/activity/list.js +17 -0
  5. package/dist/commands/activity/scan-older.d.ts +2 -2
  6. package/dist/commands/activity/scan-older.js +6 -5
  7. package/dist/commands/activity/show.d.ts +0 -2
  8. package/dist/commands/activity/show.js +21 -42
  9. package/dist/commands/agents/always-on/release-run.d.ts +3 -3
  10. package/dist/commands/agents/always-on/release-run.js +5 -6
  11. package/dist/commands/agents/mini-computer/app/reset.d.ts +1 -0
  12. package/dist/commands/agents/mini-computer/app/reset.js +5 -2
  13. package/dist/commands/agents/mini-computer/app/set.js +1 -1
  14. package/dist/commands/agents/mini-computer/show.js +4 -2
  15. package/dist/commands/agents/mini-computer/tasks-view.js +2 -2
  16. package/dist/commands/agents/triggers/replay.js +1 -1
  17. package/dist/commands/agents/triggers/runs.d.ts +2 -3
  18. package/dist/commands/agents/triggers/runs.js +4 -5
  19. package/dist/commands/apps/auto-apply.js +31 -10
  20. package/dist/commands/apps/check.js +8 -0
  21. package/dist/commands/apps/data/batch.js +16 -5
  22. package/dist/commands/apps/data/collections.js +1 -1
  23. package/dist/commands/apps/data/delete.js +12 -4
  24. package/dist/commands/apps/data/patch.js +11 -4
  25. package/dist/commands/apps/data/put.js +13 -6
  26. package/dist/commands/apps/data/query.js +3 -3
  27. package/dist/commands/apps/install.js +24 -7
  28. package/dist/commands/apps/installations/events.d.ts +1 -0
  29. package/dist/commands/apps/installations/events.js +63 -10
  30. package/dist/commands/apps/installations/show.js +26 -5
  31. package/dist/commands/apps/installations/snapshot.js +1 -1
  32. package/dist/commands/apps/installations/versions.js +25 -9
  33. package/dist/commands/apps/logs.js +4 -1
  34. package/dist/commands/apps/push.js +10 -2
  35. package/dist/commands/apps/reconsent.js +7 -1
  36. package/dist/commands/apps/rollback.js +2 -2
  37. package/dist/commands/apps/settings/set.js +81 -4
  38. package/dist/commands/apps/settings/show.js +38 -7
  39. package/dist/commands/duties/status.js +20 -15
  40. package/dist/commands/outbox/drop.js +21 -15
  41. package/dist/commands/outbox/list.d.ts +2 -1
  42. package/dist/commands/outbox/list.js +20 -11
  43. package/dist/commands/outbox/retry.d.ts +8 -11
  44. package/dist/commands/outbox/retry.js +135 -92
  45. package/dist/commands/spaces/create.js +1 -1
  46. package/dist/commands/tasks/comments/add.js +1 -1
  47. package/dist/commands/triggers/audit.js +3 -5
  48. package/dist/commands/triggers/fire-detail.js +7 -1
  49. package/dist/commands/triggers/replay.js +1 -1
  50. package/dist/commands/triggers/runs.d.ts +2 -4
  51. package/dist/commands/triggers/runs.js +3 -5
  52. package/dist/generated/agent-guides.json +19 -19
  53. package/dist/lib/agent-activity.d.ts +21 -1
  54. package/dist/lib/agent-activity.js +98 -29
  55. package/dist/lib/api-fetch.d.ts +2 -0
  56. package/dist/lib/api-fetch.js +5 -5
  57. package/dist/lib/appData.d.ts +43 -5
  58. package/dist/lib/appData.js +117 -25
  59. package/dist/lib/appInstallations.d.ts +5 -5
  60. package/dist/lib/appInstallations.js +211 -74
  61. package/dist/lib/appSettings.d.ts +2 -0
  62. package/dist/lib/appSettings.js +36 -3
  63. package/dist/lib/apps-command.d.ts +9 -0
  64. package/dist/lib/apps-command.js +191 -7
  65. package/dist/lib/appsCheck.js +29 -3
  66. package/dist/lib/appsFs.d.ts +1 -1
  67. package/dist/lib/json-output.d.ts +4 -0
  68. package/dist/lib/json-output.js +38 -0
  69. package/dist/lib/miniComputer.js +9 -2
  70. package/dist/lib/node-adapter.js +35 -2
  71. package/dist/lib/outbox.d.ts +20 -5
  72. package/dist/lib/outbox.js +233 -76
  73. package/dist/lib/rate-limit-retry.d.ts +3 -2
  74. package/dist/lib/rate-limit-retry.js +3 -2
  75. package/dist/lib/roles.d.ts +1 -1
  76. package/dist/lib/triggers.d.ts +3 -0
  77. package/dist/lib/triggers.js +10 -0
  78. package/dist/lib/widgetStaticScan.d.ts +3 -1
  79. package/dist/lib/widgetStaticScan.js +182 -47
  80. package/dist/node_modules/@skrr-ai/data-provider/index.js +10416 -9520
  81. package/oclif.manifest.json +137 -44
  82. package/package.json +4 -3
@@ -6,6 +6,40 @@ exports.maskCssComments = maskCssComments;
6
6
  exports.maskHtmlComments = maskHtmlComments;
7
7
  exports.classifyUrl = classifyUrl;
8
8
  exports.scanWidgetSource = scanWidgetSource;
9
+ /**
10
+ * Generative UI — a cheap, conservative static scan of a widget's CSS, HTML and
11
+ * JavaScript for things that predict a failure INSIDE the sandboxed frame.
12
+ *
13
+ * WHAT THIS IS NOT. It is not the frame. The frame's Content-Security-Policy and
14
+ * `sandbox="allow-scripts"` (packages/data-provider `generativeUi/csp.ts`) decide
15
+ * what actually runs; this module only reads source text and says what the frame
16
+ * would very likely refuse. Every finding is therefore tagged `heuristic` by the
17
+ * caller, and the wording never claims more than the text shows ("looks like a
18
+ * fetch() call"). A finding can be a false positive (a name inside a string that
19
+ * never runs); the ABSENCE of findings proves nothing, because a script can
20
+ * assemble `fetch` at run time. It exists so a harness can notice the likely
21
+ * mistake before it sends the message, when fixing it is free.
22
+ *
23
+ * Severity: `error` means "the frame's CSP or sandbox blocks this if it runs";
24
+ * `warn` means "this probably does not do what the author meant".
25
+ *
26
+ * It is a lexer-light scanner on purpose. JavaScript is read once into a CODE
27
+ * view (comments, string and template text and regular-expression bodies blanked,
28
+ * same length, line breaks kept) and a list of the string literals: the rules about
29
+ * calls and names run over the code view only, so `"eval( is blocked"` in a label and
30
+ * a comment that says "do not call fetch()" are not findings, and the rules about
31
+ * what a string SAYS (a URL, markup that loads one) run over the literals only. No
32
+ * regular expression here can backtrack on the size the widget limits allow, and
33
+ * HTML is walked with `indexOf`, not with a lazy regex.
34
+ *
35
+ * The eval's static checks (`api/.../eval/generativeUi/staticChecks.js`) ask most
36
+ * of the same questions with a lexer of their own (`sourceLexers.js`), because this
37
+ * package may not import from `api/`. `generativeUiScannerAgreement.spec.js` runs
38
+ * both over one corpus and fails when they disagree about what the frame refuses.
39
+ */
40
+ const data_provider_1 = require("@skrr-ai/data-provider");
41
+ const entities_1 = require("entities");
42
+ const decode_1 = require("entities/decode");
9
43
  const IS_IDENT_CHAR_RE = /[A-Za-z0-9_$]/;
10
44
  const LEX_JS_RE = /[a-z]/i;
11
45
  const LEX_JS_RE_2 = /[A-Za-z_$]/;
@@ -18,7 +52,7 @@ const CALLS_RE = /\b(?:window\s*\.\s*)?skrr\s*\.\s*app\s*\.\s*(?:http|service)\s
18
52
  const BROKER_FETCH_OFFSETS_RE = /\s/;
19
53
  const SCAN_JS_INTO_RE = /\bopenLink\b/;
20
54
  const SCAN_JS_INTO_RE_2 = /<\/script/i;
21
- const SRCSET_URLS_RE = /\s+/;
55
+ const SRCSET_SPACE_RE = /[\t\n\f\r ]/;
22
56
  const OPEN_LINK = 'window.skrr.openLink(url)';
23
57
  // ── small text helpers ──────────────────────────────────────────────────────
24
58
  /** ASCII-only lowercase: the same length as the input, so offsets stay valid. */
@@ -36,10 +70,15 @@ function asciiLower(value) {
36
70
  }
37
71
  function lineStarts(text) {
38
72
  const starts = [0];
39
- let i = text.indexOf('\n');
40
- while (i !== -1) {
41
- starts.push(i + 1);
42
- i = text.indexOf('\n', i + 1);
73
+ for (let i = 0; i < text.length; i += 1) {
74
+ if (text[i] === '\r') {
75
+ if (text[i + 1] === '\n')
76
+ i += 1;
77
+ starts.push(i + 1);
78
+ }
79
+ else if (text[i] === '\n') {
80
+ starts.push(i + 1);
81
+ }
43
82
  }
44
83
  return starts;
45
84
  }
@@ -65,9 +104,9 @@ function isAsciiLetter(c) {
65
104
  }
66
105
  // ── comment masking ─────────────────────────────────────────────────────────
67
106
  /** Replace `from..to` with spaces, keeping line breaks so line numbers stay valid. */
68
- function blank(chars, from, to) {
107
+ function blank(chars, from, to, javascript = false) {
69
108
  for (let k = from; k < to; k += 1) {
70
- if (chars[k] !== '\n') {
109
+ if (chars[k] !== '\n' && chars[k] !== '\r' && !(javascript && (0, data_provider_1.isJsLineTerminator)(chars[k]))) {
71
110
  chars[k] = ' ';
72
111
  }
73
112
  }
@@ -88,7 +127,7 @@ const REGEX_PRECEDING_WORDS = new Set([
88
127
  'yield',
89
128
  'await',
90
129
  ]);
91
- const isIdentChar = (c) => IS_IDENT_CHAR_RE.test(c) || c > '\u007f';
130
+ const isIdentChar = (c) => !(0, data_provider_1.isJsLineTerminator)(c) && (IS_IDENT_CHAR_RE.test(c) || c > '\u007f');
92
131
  /**
93
132
  * Read a script once. Total and linear: it never throws, every loop advances, and
94
133
  * a misread costs a missed or an extra finding, never a hang. It is a heuristic
@@ -109,7 +148,7 @@ function lexJs(src) {
109
148
  let i = 0;
110
149
  const keep = (kind, open, start, end) => {
111
150
  literals.push({ kind, open, start, value: src.slice(start, end) });
112
- blank(code, start, end);
151
+ blank(code, start, end, true);
113
152
  };
114
153
  /** Template text from `from` to a closing backtick or a `${`; returns the next offset to read. */
115
154
  const readTemplate = (from, open) => {
@@ -141,18 +180,18 @@ function lexJs(src) {
141
180
  while (i < n) {
142
181
  const c = src.charAt(i);
143
182
  const d = src.charAt(i + 1);
144
- if (c === '/' && d === '/') {
145
- const end = src.indexOf('\n', i);
183
+ if ((i === 0 && c === '#' && d === '!') || (c === '/' && d === '/')) {
184
+ const end = (0, data_provider_1.nextJsLineTerminator)(src, i);
146
185
  const to = end === -1 ? n : end;
147
- blank(code, i, to);
148
- blank(commentless, i, to);
186
+ blank(code, i, to, true);
187
+ blank(commentless, i, to, true);
149
188
  i = to;
150
189
  }
151
190
  else if (c === '/' && d === '*') {
152
191
  const end = src.indexOf('*/', i + 2);
153
192
  const to = end === -1 ? n : end + 2;
154
- blank(code, i, to);
155
- blank(commentless, i, to);
193
+ blank(code, i, to, true);
194
+ blank(commentless, i, to, true);
156
195
  i = to;
157
196
  }
158
197
  else if (c === '"' || c === "'") {
@@ -179,8 +218,10 @@ function lexJs(src) {
179
218
  if (regexAllowed && i > regexBlockedUntil) {
180
219
  let j = i + 1;
181
220
  let inClass = false;
182
- while (j < n && src.charAt(j) !== '\n') {
221
+ while (j < n && !(0, data_provider_1.isJsLineTerminator)(src.charAt(j))) {
183
222
  const e = src.charAt(j);
223
+ if (e === '\\' && (0, data_provider_1.isJsLineTerminator)(src.charAt(j + 1)))
224
+ break;
184
225
  if (e === '\\') {
185
226
  j += 2;
186
227
  continue;
@@ -214,7 +255,7 @@ function lexJs(src) {
214
255
  regexAllowed = true;
215
256
  }
216
257
  }
217
- else if (LEX_JS_RE_2.test(c) || c > '\u007f') {
258
+ else if (!(0, data_provider_1.isJsLineTerminator)(c) && (LEX_JS_RE_2.test(c) || c > '\u007f')) {
218
259
  let j = i + 1;
219
260
  while (j < n && isIdentChar(src.charAt(j))) {
220
261
  j += 1;
@@ -232,7 +273,7 @@ function lexJs(src) {
232
273
  }
233
274
  else {
234
275
  // Whitespace says nothing about whether a `/` divides or starts a regular expression.
235
- if (!isSpace(src.charCodeAt(i))) {
276
+ if (!isSpace(src.charCodeAt(i)) && !(0, data_provider_1.isJsLineTerminator)(c)) {
236
277
  if (c === '{') {
237
278
  depth += 1;
238
279
  }
@@ -336,8 +377,17 @@ class Collector {
336
377
  });
337
378
  }
338
379
  }
380
+ /** Only a complete, safe app entry-file reference gets the app-specific exception.
381
+ * The app resolver still judges whether the file is declared and produces the hard error.
382
+ * This is never enabled for widgets or separately served modules.
383
+ */
384
+ function isAppLocalReference(value, enabled) {
385
+ const trimmed = value.trim();
386
+ return enabled && trimmed.startsWith(data_provider_1.APP_FILE_REF_SCHEME) &&
387
+ (0, data_provider_1.isSafeAppPath)(trimmed.slice(data_provider_1.APP_FILE_REF_SCHEME.length));
388
+ }
339
389
  // ── CSS ─────────────────────────────────────────────────────────────────────
340
- function scanCssInto(source, baseLine, out) {
390
+ function scanCssInto(source, baseLine, out, allowAppLocalReferences) {
341
391
  const masked = maskCssComments(source);
342
392
  const lower = asciiLower(masked);
343
393
  const starts = lineStarts(source);
@@ -347,9 +397,10 @@ function scanCssInto(source, baseLine, out) {
347
397
  const end = lower.indexOf(';', i);
348
398
  const statement = masked.slice(i, end === -1 ? undefined : end);
349
399
  const target = SCAN_CSS_INTO_RE.exec(statement);
350
- const kind = target ? classifyUrl(target[1]) : 'relative';
400
+ const kind = target && isAppLocalReference(target[1], allowAppLocalReferences)
401
+ ? 'inline' : target ? classifyUrl(target[1]) : 'relative';
351
402
  if (kind === 'external') {
352
- out.add('error', 'external-resource', lineOf(i), '@import of a URL: the frame allows no stylesheet from a URL, so the rules never load.', 'Write the rules inline in this section; there are no web fonts or remote stylesheets.');
403
+ out.add('error', 'external-resource', lineOf(i), '@import of a URL: the frame allows no stylesheet from a URL, so the rules never load.', 'Write the rules inline in this section; remote fonts and stylesheets are unavailable.');
353
404
  }
354
405
  else if (kind !== 'inline') {
355
406
  out.add('warn', 'relative-url', lineOf(i), '@import has nothing to resolve against inside the frame, so it loads nothing.', 'Write the rules inline.');
@@ -361,7 +412,7 @@ function scanCssInto(source, baseLine, out) {
361
412
  const close = masked.indexOf(')', u + 4);
362
413
  const inner = masked.slice(u + 4, close === -1 ? undefined : close).trim();
363
414
  const value = inner.replace(SCAN_CSS_INTO_RE_2, '');
364
- const kind = classifyUrl(value);
415
+ const kind = isAppLocalReference(value, allowAppLocalReferences) ? 'inline' : classifyUrl(value);
365
416
  if (kind === 'external') {
366
417
  out.add('error', 'external-resource', lineOf(u), 'url() of an external address: img-src and font-src allow only data: and blob: URLs here, so it is blocked.', 'Use inline SVG, a gradient, or a data: URI.');
367
418
  }
@@ -536,11 +587,14 @@ function brokerFetchOffsets(code) {
536
587
  return offsets;
537
588
  }
538
589
  function scanJsInto(source, baseLine, out) {
590
+ // HTML parsing and JavaScript both treat CR and CRLF as line breaks; use one
591
+ // form consistently in the lexer, comments, and its source-line lookups.
592
+ source = source.replace(/\r\n?/g, '\n');
539
593
  const { code, commentless, literals } = lexJs(source);
540
594
  const brokerFetches = brokerFetchOffsets(code);
541
- const starts = lineStarts(source);
595
+ const starts = (0, data_provider_1.jsLineStarts)(source);
542
596
  const lineOf = (index) => baseLine + lineAt(starts, index) - 1;
543
- const codeLines = code.split('\n');
597
+ const codeLines = code.split(/\r\n?|[\n\u2028\u2029]/);
544
598
  const textual = literals.filter((literal) => literal.kind !== 'regex');
545
599
  const byOpen = new Map(textual.map((literal) => [literal.open, literal]));
546
600
  // What the code does: names and calls, over the code view, where a word inside a
@@ -684,22 +738,91 @@ function walkHtml(html) {
684
738
  return { tags, raws };
685
739
  }
686
740
  const RESOURCE_ATTRIBUTES = ['src', 'srcset', 'poster', 'data', 'background', 'xlink:href', 'href'];
687
- /** The first URL of each `srcset` candidate. */
741
+ /** Decode once in HTML attribute mode and retain the raw source of every UTF-16 unit. */
742
+ function decodedAttribute(value) {
743
+ const parts = [];
744
+ const starts = [];
745
+ const ends = [];
746
+ const plain = (from, to) => {
747
+ parts.push(value.slice(from, to));
748
+ for (let i = from; i < to; i += 1) {
749
+ starts.push(i);
750
+ ends.push(i + 1);
751
+ }
752
+ };
753
+ let output = '';
754
+ const decoder = new decode_1.EntityDecoder(decode_1.htmlDecodeTree, (cp) => { output += String.fromCodePoint(cp); });
755
+ let position = 0;
756
+ while (position < value.length) {
757
+ const amp = value.indexOf('&', position);
758
+ if (amp < 0) {
759
+ plain(position, value.length);
760
+ break;
761
+ }
762
+ plain(position, amp);
763
+ output = '';
764
+ decoder.startEntity(decode_1.DecodingMode.Attribute);
765
+ let consumed = decoder.write(value, amp + 1);
766
+ if (consumed < 0)
767
+ consumed = decoder.end();
768
+ if (consumed === 0) {
769
+ plain(amp, amp + 1);
770
+ position = amp + 1;
771
+ continue;
772
+ }
773
+ parts.push(output);
774
+ for (let i = 0; i < output.length; i += 1) {
775
+ starts.push(amp);
776
+ ends.push(amp + consumed);
777
+ }
778
+ position = amp + consumed;
779
+ }
780
+ return { text: parts.join(''), starts, ends };
781
+ }
782
+ /** Extract candidate URLs and offsets without treating data URL commas as delimiters. */
688
783
  function srcsetUrls(value) {
689
- return value
690
- .split(',')
691
- .map((candidate) => candidate.trim().split(SRCSET_URLS_RE)[0])
692
- .filter(Boolean);
784
+ const urls = [];
785
+ let i = 0;
786
+ while (i < value.length) {
787
+ while (i < value.length && (value[i] === ',' || SRCSET_SPACE_RE.test(value[i])))
788
+ i += 1;
789
+ const start = i;
790
+ while (i < value.length && !SRCSET_SPACE_RE.test(value[i]))
791
+ i += 1;
792
+ const token = value.slice(start, i);
793
+ let end = token.length;
794
+ while (end > 0 && token[end - 1] === ',')
795
+ end -= 1;
796
+ const url = token.slice(0, end);
797
+ if (url)
798
+ urls.push({ url, start, end: start + end });
799
+ if (url.length !== token.length)
800
+ continue;
801
+ // Skip descriptors through the next candidate separator. A comma in a
802
+ // parenthesized descriptor is not a separator; malformed descriptors are
803
+ // still scanned conservatively rather than being treated as trusted URLs.
804
+ let inParens = false;
805
+ while (i < value.length) {
806
+ const char = value[i++];
807
+ if (char === '(')
808
+ inParens = true;
809
+ else if (char === ')')
810
+ inParens = false;
811
+ else if (char === ',' && !inParens)
812
+ break;
813
+ }
814
+ }
815
+ return urls;
693
816
  }
694
817
  const STYLESHEET_LIKE_REL = /\b(?:stylesheet|preload|modulepreload|prefetch|icon|manifest)\b/i;
695
- function scanTag(tag, line, out) {
818
+ function scanTag(tag, line, out, allowAppLocalReferences) {
696
819
  const name = tag.name;
697
820
  if (name === 'base') {
698
821
  out.add('error', 'base-element', line, 'The base element is blocked: base-uri is none in the frame.', 'Remove it; use absolute data: URIs or none at all.');
699
822
  return;
700
823
  }
701
824
  if (name === 'meta') {
702
- const equiv = asciiLower(attr(tag, 'http-equiv') ?? '').trim();
825
+ const equiv = asciiLower((0, entities_1.decodeHTMLAttribute)(attr(tag, 'http-equiv') ?? '')).trim();
703
826
  if (equiv === 'refresh') {
704
827
  out.add('error', 'navigation', line, 'A meta refresh navigates the frame itself: the host allows one load and removes the widget on the second.', 'Remove it; update the page with script instead.');
705
828
  }
@@ -716,7 +839,7 @@ function scanTag(tag, line, out) {
716
839
  return;
717
840
  }
718
841
  if (name === 'iframe' || name === 'frame') {
719
- const src = attr(tag, 'src') ?? '';
842
+ const src = (0, entities_1.decodeHTMLAttribute)(attr(tag, 'src') ?? '');
720
843
  const external = classifyUrl(src) === 'external';
721
844
  out.add(external ? 'error' : 'warn', 'nested-frame', line, external
722
845
  ? `<${name}> of a URL: frame-src is none in the frame, so it is blocked.`
@@ -728,17 +851,18 @@ function scanTag(tag, line, out) {
728
851
  out.add('error', 'form-action', line, 'formaction: form-action is none in the frame, so submitting is blocked.', 'Handle the click in script.');
729
852
  }
730
853
  if (name === 'a' || name === 'area') {
731
- const href = attr(tag, 'href');
854
+ const rawHref = attr(tag, 'href');
855
+ const href = rawHref === undefined ? undefined : (0, entities_1.decodeHTMLAttribute)(rawHref);
732
856
  if (href !== undefined && classifyUrl(href) === 'external') {
733
857
  out.add('warn', 'external-link', line, 'A link to a URL: following it would navigate the frame itself, and the host removes the widget on that second load.', `Use a button that calls ${OPEN_LINK}.`);
734
858
  }
735
- const target = asciiLower(attr(tag, 'target') ?? '').trim();
859
+ const target = asciiLower((0, entities_1.decodeHTMLAttribute)(attr(tag, 'target') ?? '')).trim();
736
860
  if (target === '_blank' || target === '_top' || target === '_parent') {
737
861
  out.add('warn', 'popup', line, `target="${target}": the sandbox has no allow-popups or top navigation, so nothing opens.`, `Use ${OPEN_LINK}.`);
738
862
  }
739
863
  return;
740
864
  }
741
- const rel = attr(tag, 'rel') ?? '';
865
+ const rel = (0, entities_1.decodeHTMLAttribute)(attr(tag, 'rel') ?? '');
742
866
  for (const attribute of RESOURCE_ATTRIBUTES) {
743
867
  const value = attr(tag, attribute);
744
868
  if (value === undefined) {
@@ -750,10 +874,20 @@ function scanTag(tag, line, out) {
750
874
  if (attribute === 'data' && name !== 'object') {
751
875
  continue;
752
876
  }
753
- for (const url of attribute === 'srcset' ? srcsetUrls(value) : [value]) {
754
- const kind = classifyUrl(url);
877
+ // HTML decodes character references before interpreting resource URLs. Only
878
+ // exempt literal app references: the package resolver reads the raw source
879
+ // and cannot promise to replace a reference written using entities.
880
+ const decoded = decodedAttribute(value);
881
+ const trimmed = decoded.text.trim();
882
+ const leading = decoded.text.length - decoded.text.trimStart().length;
883
+ const candidates = attribute === 'srcset'
884
+ ? srcsetUrls(decoded.text) : [{ url: trimmed, start: leading, end: leading + trimmed.length }];
885
+ for (const { url, start, end } of candidates) {
886
+ const raw = end > start ? value.slice(decoded.starts[start], decoded.ends[end - 1]) : '';
887
+ const kind = isAppLocalReference(url, allowAppLocalReferences && raw === url)
888
+ ? 'inline' : classifyUrl(url);
755
889
  if (kind === 'external' && !isNamespaceUrl(url)) {
756
- out.add('error', 'external-resource', line, `<${name} ${attribute}> loads from a URL: the frame allows no script, stylesheet, image or font from a URL.`, 'Inline it: markup, inline SVG, canvas, or a data: URI. Libraries come only by bare name through a dynamic import.');
890
+ out.add('error', 'external-resource', line, `<${name} ${attribute}> loads from a URL: the frame allows no script, stylesheet, image or font from a URL.`, 'Inline it: markup, inline SVG, canvas, or a data: URI. Use approved libraries by bare name.');
757
891
  }
758
892
  else if (kind === 'relative' && name !== 'a' && attribute !== 'href') {
759
893
  out.add('warn', 'relative-url', line, `<${name} ${attribute}> is a relative path, which has nothing to resolve against inside the frame.`, 'Inline it or use a data: URI.');
@@ -762,7 +896,7 @@ function scanTag(tag, line, out) {
762
896
  }
763
897
  }
764
898
  function isClassicScript(tag) {
765
- const type = asciiLower(attr(tag, 'type') ?? '')
899
+ const type = asciiLower((0, entities_1.decodeHTMLAttribute)(attr(tag, 'type') ?? ''))
766
900
  .trim()
767
901
  .split(';')[0];
768
902
  return (type === '' ||
@@ -772,24 +906,24 @@ function isClassicScript(tag) {
772
906
  type === 'application/ecmascript');
773
907
  }
774
908
  function isScannableScript(tag) {
775
- return isClassicScript(tag) || asciiLower(attr(tag, 'type') ?? '').trim() === 'module';
909
+ return isClassicScript(tag) || asciiLower((0, entities_1.decodeHTMLAttribute)(attr(tag, 'type') ?? '')).trim() === 'module';
776
910
  }
777
- function scanHtmlInto(html, out) {
911
+ function scanHtmlInto(html, out, allowAppLocalReferences) {
778
912
  const masked = maskHtmlComments(html);
779
913
  const starts = lineStarts(html);
780
914
  const { tags, raws } = walkHtml(masked);
781
915
  const inlineScripts = [];
782
916
  for (const tag of tags) {
783
- scanTag(tag, lineAt(starts, tag.index), out);
917
+ scanTag(tag, lineAt(starts, tag.index), out, allowAppLocalReferences);
784
918
  const style = attr(tag, 'style');
785
919
  if (style) {
786
- scanCssInto(style, lineAt(starts, tag.index), out);
920
+ scanCssInto(style, lineAt(starts, tag.index), out, allowAppLocalReferences);
787
921
  }
788
922
  }
789
923
  for (const raw of raws) {
790
924
  const line = lineAt(starts, raw.contentIndex);
791
925
  if (raw.tag.name === 'style') {
792
- scanCssInto(raw.content, line, out);
926
+ scanCssInto(raw.content, line, out, allowAppLocalReferences);
793
927
  }
794
928
  else if (raw.tag.name === 'script' && isScannableScript(raw.tag)) {
795
929
  scanJsInto(raw.content, line, out);
@@ -855,12 +989,13 @@ function tidy(findings) {
855
989
  * only the strings it is given; the cost is linear in their length, which the
856
990
  * caller has already bounded by the widget limits.
857
991
  */
858
- function scanWidgetSource(source) {
992
+ function scanWidgetSource(source, options = {}) {
859
993
  const css = new Collector('css');
860
994
  const html = new Collector('html');
861
995
  const js = new Collector('js');
862
- scanCssInto(source.css, 1, css);
863
- const inlineScripts = scanHtmlInto(source.html, html);
996
+ const allowAppLocalReferences = options.allowAppLocalReferences === true;
997
+ scanCssInto(source.css, 1, css, allowAppLocalReferences);
998
+ const inlineScripts = scanHtmlInto(source.html, html, allowAppLocalReferences);
864
999
  scanJsInto(source.js, 1, js);
865
1000
  return {
866
1001
  findings: tidy([...css.findings, ...html.findings, ...js.findings]),