@skrr-ai/cli 0.1.163 → 0.1.165
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/README.md +13 -0
- package/dist/base-command.d.ts +14 -1
- package/dist/base-command.js +190 -58
- package/dist/commands/agent/message/send.d.ts +1 -0
- package/dist/commands/agent/message/send.js +3 -0
- package/dist/commands/agents/mini-computer/app/set.js +1 -1
- package/dist/commands/agents/mini-computer/show.js +7 -1
- package/dist/commands/agents/mini-computer/tasks-view.js +1 -1
- package/dist/commands/agents/supervision.d.ts +25 -0
- package/dist/commands/agents/supervision.js +129 -0
- package/dist/commands/apps/check.js +3 -8
- package/dist/commands/apps/data/batch.d.ts +1 -0
- package/dist/commands/apps/data/batch.js +19 -2
- package/dist/commands/apps/data/delete.d.ts +1 -0
- package/dist/commands/apps/data/delete.js +14 -2
- package/dist/commands/apps/data/patch.d.ts +1 -0
- package/dist/commands/apps/data/patch.js +11 -2
- package/dist/commands/apps/data/put.d.ts +1 -0
- package/dist/commands/apps/data/put.js +17 -3
- package/dist/commands/apps/install.js +7 -2
- package/dist/commands/apps/installations/compatibility.d.ts +13 -0
- package/dist/commands/apps/installations/compatibility.js +60 -0
- package/dist/commands/apps/installations/show.js +9 -3
- package/dist/commands/apps/installations/snapshot.js +5 -2
- package/dist/commands/apps/operations/check.d.ts +16 -0
- package/dist/commands/apps/operations/check.js +127 -0
- package/dist/commands/apps/publish/propose.js +33 -4
- package/dist/commands/apps/reconsent.js +7 -1
- package/dist/commands/apps/reference.d.ts +4 -2
- package/dist/commands/apps/reference.js +7 -4
- package/dist/commands/apps/rollback.d.ts +9 -0
- package/dist/commands/apps/rollback.js +81 -2
- package/dist/commands/apps/upgrade.d.ts +8 -0
- package/dist/commands/apps/upgrade.js +67 -2
- package/dist/commands/apps/version/cat.d.ts +22 -0
- package/dist/commands/apps/version/cat.js +220 -0
- package/dist/commands/apps/version/show.js +3 -1
- package/dist/commands/commerce/incidents/release.d.ts +24 -0
- package/dist/commands/commerce/incidents/release.js +46 -0
- package/dist/commands/duties/action-proposal.js +19 -11
- package/dist/commands/duties/cadence-decisions.js +7 -0
- package/dist/commands/duties/cases.js +12 -1
- package/dist/commands/duties/hypotheses.js +10 -3
- package/dist/commands/duties/observations.d.ts +4 -0
- package/dist/commands/duties/observations.js +14 -3
- package/dist/commands/duties/trigger-status.js +2 -2
- package/dist/commands/duties/wake-capabilities.js +12 -6
- package/dist/commands/outbox/list.d.ts +11 -4
- package/dist/commands/outbox/list.js +56 -9
- package/dist/commands/outbox/retry.d.ts +8 -2
- package/dist/commands/outbox/retry.js +76 -16
- package/dist/commands/outbox/show.d.ts +20 -0
- package/dist/commands/outbox/show.js +83 -0
- package/dist/commands/proposals/list.js +13 -9
- package/dist/commands/requests/show.d.ts +12 -0
- package/dist/commands/requests/show.js +42 -23
- package/dist/commands/spaces/deletion/cancel.d.ts +21 -0
- package/dist/commands/spaces/deletion/cancel.js +70 -0
- package/dist/commands/spaces/workflows/run.js +12 -0
- package/dist/commands/widgets/check.d.ts +9 -0
- package/dist/commands/widgets/check.js +16 -3
- package/dist/generated/agent-guides.json +17 -17
- package/dist/lib/api-fetch.d.ts +5 -0
- package/dist/lib/api-fetch.js +53 -21
- package/dist/lib/appCompatibility.d.ts +31 -0
- package/dist/lib/appCompatibility.js +66 -0
- package/dist/lib/appData.d.ts +46 -4
- package/dist/lib/appData.js +156 -31
- package/dist/lib/appInstallations.d.ts +32 -5
- package/dist/lib/appInstallations.js +218 -34
- package/dist/lib/appVersionFile.d.ts +82 -0
- package/dist/lib/appVersionFile.js +195 -0
- package/dist/lib/apps-command.d.ts +14 -3
- package/dist/lib/apps-command.js +68 -60
- package/dist/lib/appsCheck.js +31 -6
- package/dist/lib/chat-supervision.d.ts +21 -0
- package/dist/lib/chat-supervision.js +37 -0
- package/dist/lib/commerce.d.ts +6 -0
- package/dist/lib/commerce.js +9 -0
- package/dist/lib/duties.d.ts +19 -1
- package/dist/lib/duties.js +21 -3
- package/dist/lib/json-output.d.ts +2 -0
- package/dist/lib/json-output.js +8 -4
- package/dist/lib/miniComputer.d.ts +1 -0
- package/dist/lib/miniComputer.js +7 -2
- package/dist/lib/miniComputerCommand.js +4 -1
- package/dist/lib/node-adapter.d.ts +2 -0
- package/dist/lib/node-adapter.js +35 -8
- package/dist/lib/outbox.d.ts +110 -1
- package/dist/lib/outbox.js +261 -35
- package/dist/lib/roles.d.ts +1 -1
- package/dist/lib/space-deletion-cancel.d.ts +47 -0
- package/dist/lib/space-deletion-cancel.js +141 -0
- package/dist/lib/widgetCheck.js +30 -4
- package/dist/lib/widgetStaticScan.d.ts +24 -9
- package/dist/lib/widgetStaticScan.js +207 -192
- package/dist/lib/write-outcome.d.ts +74 -0
- package/dist/lib/write-outcome.js +176 -0
- package/dist/node_modules/@skrr-ai/data-provider/APP_HTML_PARSER_LICENSES.txt +36 -0
- package/dist/node_modules/@skrr-ai/data-provider/index.js +20204 -15169
- package/oclif.manifest.json +2143 -25
- package/package.json +10 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkModuleSyntax = checkModuleSyntax;
|
|
3
4
|
exports.lexJs = lexJs;
|
|
4
5
|
exports.maskJsComments = maskJsComments;
|
|
5
6
|
exports.maskCssComments = maskCssComments;
|
|
6
|
-
exports.maskHtmlComments = maskHtmlComments;
|
|
7
7
|
exports.classifyUrl = classifyUrl;
|
|
8
8
|
exports.scanWidgetSource = scanWidgetSource;
|
|
9
9
|
/**
|
|
@@ -29,8 +29,10 @@ exports.scanWidgetSource = scanWidgetSource;
|
|
|
29
29
|
* calls and names run over the code view only, so `"eval( is blocked"` in a label and
|
|
30
30
|
* a comment that says "do not call fetch()" are not findings, and the rules about
|
|
31
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
|
|
33
|
-
*
|
|
32
|
+
* regular expression here can backtrack on the size the widget limits allow. HTML is
|
|
33
|
+
* not tokenized here at all: the elements come from the shared parser pass
|
|
34
|
+
* (`analyzeAppHtml`), the one a browser would make, so that this scan and the parser
|
|
35
|
+
* cannot disagree about where a comment ends or what a `<noscript>` holds.
|
|
34
36
|
*
|
|
35
37
|
* The eval's static checks (`api/.../eval/generativeUi/staticChecks.js`) ask most
|
|
36
38
|
* of the same questions with a lexer of their own (`sourceLexers.js`), because this
|
|
@@ -38,8 +40,21 @@ exports.scanWidgetSource = scanWidgetSource;
|
|
|
38
40
|
* both over one corpus and fails when they disagree about what the frame refuses.
|
|
39
41
|
*/
|
|
40
42
|
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
41
|
-
const entities_1 = require("entities");
|
|
42
43
|
const decode_1 = require("entities/decode");
|
|
44
|
+
const acorn_1 = require("acorn");
|
|
45
|
+
/** Parse as an actual ECMAScript module without executing author code. */
|
|
46
|
+
function checkModuleSyntax(source) {
|
|
47
|
+
try {
|
|
48
|
+
(0, acorn_1.parse)(source, { ecmaVersion: 'latest', sourceType: 'module' });
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (!(error instanceof SyntaxError))
|
|
53
|
+
throw error;
|
|
54
|
+
const location = error.loc;
|
|
55
|
+
return { message: error.message, ...(location?.line ? { line: location.line } : {}) };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
43
58
|
const IS_IDENT_CHAR_RE = /[A-Za-z0-9_$]/;
|
|
44
59
|
const LEX_JS_RE = /[a-z]/i;
|
|
45
60
|
const LEX_JS_RE_2 = /[A-Za-z_$]/;
|
|
@@ -51,8 +66,13 @@ const SCAN_CSS_INTO_RE_2 = /^['"]|['"]$/g;
|
|
|
51
66
|
const CALLS_RE = /\b(?:window\s*\.\s*)?skrr\s*\.\s*app\s*\.\s*(?:http|service)\s*\.\s*fetch\s*\(/g;
|
|
52
67
|
const BROKER_FETCH_OFFSETS_RE = /\s/;
|
|
53
68
|
const SCAN_JS_INTO_RE = /\bopenLink\b/;
|
|
54
|
-
const SCAN_JS_INTO_RE_2 = /<\/script/i;
|
|
69
|
+
const SCAN_JS_INTO_RE_2 = /<\/script(?=[\t\n\f\r />])/i;
|
|
55
70
|
const SRCSET_SPACE_RE = /[\t\n\f\r ]/;
|
|
71
|
+
/** What a finding in markup the page does not show at first load says about when it would matter. */
|
|
72
|
+
const DORMANT_CONDITION = {
|
|
73
|
+
template: 'If this template content is inserted into the page: ',
|
|
74
|
+
noscript: 'If this <noscript> fallback is shown (scripting off): ',
|
|
75
|
+
};
|
|
56
76
|
const OPEN_LINK = 'window.skrr.openLink(url)';
|
|
57
77
|
// ── small text helpers ──────────────────────────────────────────────────────
|
|
58
78
|
/** ASCII-only lowercase: the same length as the input, so offsets stay valid. */
|
|
@@ -99,9 +119,6 @@ function lineAt(starts, index) {
|
|
|
99
119
|
function isSpace(c) {
|
|
100
120
|
return c === 32 || c === 9 || c === 10 || c === 13 || c === 12;
|
|
101
121
|
}
|
|
102
|
-
function isAsciiLetter(c) {
|
|
103
|
-
return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
|
|
104
|
-
}
|
|
105
122
|
// ── comment masking ─────────────────────────────────────────────────────────
|
|
106
123
|
/** Replace `from..to` with spaces, keeping line breaks so line numbers stay valid. */
|
|
107
124
|
function blank(chars, from, to, javascript = false) {
|
|
@@ -322,18 +339,6 @@ function maskCssComments(src) {
|
|
|
322
339
|
}
|
|
323
340
|
return chars.join('');
|
|
324
341
|
}
|
|
325
|
-
/** Blank `<!-- … -->` comments of HTML. */
|
|
326
|
-
function maskHtmlComments(src) {
|
|
327
|
-
const chars = src.split('');
|
|
328
|
-
let i = src.indexOf('<!--');
|
|
329
|
-
while (i !== -1) {
|
|
330
|
-
const end = src.indexOf('-->', i + 4);
|
|
331
|
-
const to = end === -1 ? src.length : end + 3;
|
|
332
|
-
blank(chars, i, to);
|
|
333
|
-
i = src.indexOf('<!--', to);
|
|
334
|
-
}
|
|
335
|
-
return chars.join('');
|
|
336
|
-
}
|
|
337
342
|
/** A URL the frame cannot fetch from, a self-contained one, or one with no base to resolve against. */
|
|
338
343
|
function classifyUrl(raw) {
|
|
339
344
|
const value = raw.trim();
|
|
@@ -366,14 +371,16 @@ class Collector {
|
|
|
366
371
|
constructor(section) {
|
|
367
372
|
this.section = section;
|
|
368
373
|
}
|
|
369
|
-
add(severity, code, line, message, fix) {
|
|
374
|
+
add(severity, code, line, message, fix, conditional = false, provenance) {
|
|
370
375
|
this.findings.push({
|
|
371
376
|
severity,
|
|
372
377
|
code,
|
|
373
378
|
section: this.section,
|
|
374
|
-
line,
|
|
379
|
+
...(line === undefined ? {} : { line }),
|
|
375
380
|
message,
|
|
376
381
|
...(fix ? { fix } : {}),
|
|
382
|
+
...(conditional ? { conditional: true } : {}),
|
|
383
|
+
...(provenance === undefined ? {} : { provenance }),
|
|
377
384
|
});
|
|
378
385
|
}
|
|
379
386
|
}
|
|
@@ -383,8 +390,9 @@ class Collector {
|
|
|
383
390
|
*/
|
|
384
391
|
function isAppLocalReference(value, enabled) {
|
|
385
392
|
const trimmed = value.trim();
|
|
386
|
-
return enabled &&
|
|
387
|
-
|
|
393
|
+
return (enabled &&
|
|
394
|
+
trimmed.startsWith(data_provider_1.APP_FILE_REF_SCHEME) &&
|
|
395
|
+
(0, data_provider_1.isSafeAppPath)(trimmed.slice(data_provider_1.APP_FILE_REF_SCHEME.length)));
|
|
388
396
|
}
|
|
389
397
|
// ── CSS ─────────────────────────────────────────────────────────────────────
|
|
390
398
|
function scanCssInto(source, baseLine, out, allowAppLocalReferences) {
|
|
@@ -398,7 +406,10 @@ function scanCssInto(source, baseLine, out, allowAppLocalReferences) {
|
|
|
398
406
|
const statement = masked.slice(i, end === -1 ? undefined : end);
|
|
399
407
|
const target = SCAN_CSS_INTO_RE.exec(statement);
|
|
400
408
|
const kind = target && isAppLocalReference(target[1], allowAppLocalReferences)
|
|
401
|
-
? 'inline'
|
|
409
|
+
? 'inline'
|
|
410
|
+
: target
|
|
411
|
+
? classifyUrl(target[1])
|
|
412
|
+
: 'relative';
|
|
402
413
|
if (kind === 'external') {
|
|
403
414
|
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.');
|
|
404
415
|
}
|
|
@@ -412,7 +423,9 @@ function scanCssInto(source, baseLine, out, allowAppLocalReferences) {
|
|
|
412
423
|
const close = masked.indexOf(')', u + 4);
|
|
413
424
|
const inner = masked.slice(u + 4, close === -1 ? undefined : close).trim();
|
|
414
425
|
const value = inner.replace(SCAN_CSS_INTO_RE_2, '');
|
|
415
|
-
const kind = isAppLocalReference(value, allowAppLocalReferences)
|
|
426
|
+
const kind = isAppLocalReference(value, allowAppLocalReferences)
|
|
427
|
+
? 'inline'
|
|
428
|
+
: classifyUrl(value);
|
|
416
429
|
if (kind === 'external') {
|
|
417
430
|
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.');
|
|
418
431
|
}
|
|
@@ -586,14 +599,22 @@ function brokerFetchOffsets(code) {
|
|
|
586
599
|
}
|
|
587
600
|
return offsets;
|
|
588
601
|
}
|
|
589
|
-
function scanJsInto(source, baseLine, out) {
|
|
602
|
+
function scanJsInto(source, baseLine, out, parsedFromHtml = false, sourceLines, sourceId) {
|
|
590
603
|
// HTML parsing and JavaScript both treat CR and CRLF as line breaks; use one
|
|
591
604
|
// form consistently in the lexer, comments, and its source-line lookups.
|
|
592
605
|
source = source.replace(/\r\n?/g, '\n');
|
|
593
606
|
const { code, commentless, literals } = lexJs(source);
|
|
594
607
|
const brokerFetches = brokerFetchOffsets(code);
|
|
595
608
|
const starts = (0, data_provider_1.jsLineStarts)(source);
|
|
596
|
-
const lineOf = (index) =>
|
|
609
|
+
const lineOf = (index) => {
|
|
610
|
+
const line = lineAt(starts, index);
|
|
611
|
+
return sourceLines === undefined ? baseLine + line - 1 : sourceLines?.[line - 1];
|
|
612
|
+
};
|
|
613
|
+
const addAt = (severity, code, index, message, fix) => {
|
|
614
|
+
const line = lineOf(index);
|
|
615
|
+
const provenance = sourceLines !== undefined ? `${sourceId ?? 'unknown'}:${lineAt(starts, index)}` : undefined;
|
|
616
|
+
out.add(severity, code, line, message, fix, false, provenance);
|
|
617
|
+
};
|
|
597
618
|
const codeLines = code.split(/\r\n?|[\n\u2028\u2029]/);
|
|
598
619
|
const textual = literals.filter((literal) => literal.kind !== 'regex');
|
|
599
620
|
const byOpen = new Map(textual.map((literal) => [literal.open, literal]));
|
|
@@ -603,7 +624,7 @@ function scanJsInto(source, baseLine, out) {
|
|
|
603
624
|
for (const match of code.matchAll(rule.pattern)) {
|
|
604
625
|
if (rule.code === 'network-api' && brokerFetches.has(match.index ?? 0))
|
|
605
626
|
continue;
|
|
606
|
-
|
|
627
|
+
addAt(rule.severity, rule.code, match.index ?? 0, rule.message, rule.fix);
|
|
607
628
|
}
|
|
608
629
|
}
|
|
609
630
|
// A call or assignment whose argument is a literal that names a URL.
|
|
@@ -612,7 +633,7 @@ function scanJsInto(source, baseLine, out) {
|
|
|
612
633
|
const open = (match.index ?? 0) + match[0].length - 1;
|
|
613
634
|
const literal = byOpen.get(open);
|
|
614
635
|
if (literal && URL_START.test(literal.value)) {
|
|
615
|
-
|
|
636
|
+
addAt('error', 'external-resource', match.index ?? 0, rule.message, rule.fix);
|
|
616
637
|
}
|
|
617
638
|
}
|
|
618
639
|
}
|
|
@@ -620,7 +641,7 @@ function scanJsInto(source, baseLine, out) {
|
|
|
620
641
|
for (const literal of textual) {
|
|
621
642
|
for (const rule of STRING_RULES) {
|
|
622
643
|
for (const match of literal.value.matchAll(rule.pattern)) {
|
|
623
|
-
|
|
644
|
+
addAt('error', 'external-resource', literal.start + (match.index ?? 0), rule.message, rule.fix);
|
|
624
645
|
}
|
|
625
646
|
}
|
|
626
647
|
for (const match of literal.value.matchAll(URL_IN_STRING)) {
|
|
@@ -630,112 +651,29 @@ function scanJsInto(source, baseLine, out) {
|
|
|
630
651
|
if (isNamespaceUrl(url) || SCAN_JS_INTO_RE.test(text)) {
|
|
631
652
|
continue;
|
|
632
653
|
}
|
|
633
|
-
|
|
654
|
+
addAt('warn', 'external-url', index, `A URL string (${url.length > 60 ? `${url.slice(0, 57)}...` : url}): the frame can load nothing from a URL.`, `If it is a link, pass it to ${OPEN_LINK}; if it is data or an image, inline it.`);
|
|
634
655
|
}
|
|
635
656
|
}
|
|
636
657
|
// The one rule that reads the text as the HTML parser would, and so reads strings too.
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
658
|
+
const closingScript = SCAN_JS_INTO_RE_2.exec(commentless);
|
|
659
|
+
if (closingScript && !parsedFromHtml) {
|
|
660
|
+
const at = closingScript.index;
|
|
661
|
+
addAt('warn', 'element-close', at, 'The text contains a closing script tag, which can end the script early depending on how the frame embeds it.', 'Write it as <\\/script> inside a string.');
|
|
640
662
|
}
|
|
641
663
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
664
|
+
// ── HTML ────────────────────────────────────────────────────────────────────
|
|
665
|
+
/** The attribute of that name, as the parser read it. A name that repeats keeps its first, as the browser does. */
|
|
666
|
+
function attr(element, name) {
|
|
667
|
+
for (const a of element.attributes) {
|
|
645
668
|
if (a.name === name) {
|
|
646
|
-
return a
|
|
669
|
+
return a;
|
|
647
670
|
}
|
|
648
671
|
}
|
|
649
672
|
return undefined;
|
|
650
673
|
}
|
|
651
|
-
/**
|
|
652
|
-
function
|
|
653
|
-
|
|
654
|
-
const tags = [];
|
|
655
|
-
const raws = [];
|
|
656
|
-
const n = html.length;
|
|
657
|
-
let i = 0;
|
|
658
|
-
while (i < n) {
|
|
659
|
-
const lt = html.indexOf('<', i);
|
|
660
|
-
if (lt === -1) {
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
663
|
-
const next = html.charCodeAt(lt + 1);
|
|
664
|
-
if (html.startsWith('<!--', lt)) {
|
|
665
|
-
const end = html.indexOf('-->', lt + 4);
|
|
666
|
-
i = end === -1 ? n : end + 3;
|
|
667
|
-
continue;
|
|
668
|
-
}
|
|
669
|
-
if (next === 33 || next === 63 || next === 47) {
|
|
670
|
-
const end = html.indexOf('>', lt + 2);
|
|
671
|
-
i = end === -1 ? n : end + 1;
|
|
672
|
-
continue;
|
|
673
|
-
}
|
|
674
|
-
if (!isAsciiLetter(next)) {
|
|
675
|
-
i = lt + 1;
|
|
676
|
-
continue;
|
|
677
|
-
}
|
|
678
|
-
let p = lt + 1;
|
|
679
|
-
while (p < n && !isSpace(html.charCodeAt(p)) && html[p] !== '>' && html[p] !== '/') {
|
|
680
|
-
p += 1;
|
|
681
|
-
}
|
|
682
|
-
const tag = { name: lower.slice(lt + 1, p), index: lt, attrs: [] };
|
|
683
|
-
while (p < n) {
|
|
684
|
-
while (p < n && (isSpace(html.charCodeAt(p)) || html[p] === '/')) {
|
|
685
|
-
p += 1;
|
|
686
|
-
}
|
|
687
|
-
if (p >= n) {
|
|
688
|
-
break;
|
|
689
|
-
}
|
|
690
|
-
if (html[p] === '>') {
|
|
691
|
-
p += 1;
|
|
692
|
-
break;
|
|
693
|
-
}
|
|
694
|
-
const nameStart = p;
|
|
695
|
-
while (p < n && !isSpace(html.charCodeAt(p)) && !'=>/'.includes(html.charAt(p))) {
|
|
696
|
-
p += 1;
|
|
697
|
-
}
|
|
698
|
-
const name = lower.slice(nameStart, p);
|
|
699
|
-
while (p < n && isSpace(html.charCodeAt(p))) {
|
|
700
|
-
p += 1;
|
|
701
|
-
}
|
|
702
|
-
let value = '';
|
|
703
|
-
if (html[p] === '=') {
|
|
704
|
-
p += 1;
|
|
705
|
-
while (p < n && isSpace(html.charCodeAt(p))) {
|
|
706
|
-
p += 1;
|
|
707
|
-
}
|
|
708
|
-
const quote = html.charAt(p);
|
|
709
|
-
if (quote === '"' || quote === "'") {
|
|
710
|
-
const end = html.indexOf(quote, p + 1);
|
|
711
|
-
value = html.slice(p + 1, end === -1 ? n : end);
|
|
712
|
-
p = end === -1 ? n : end + 1;
|
|
713
|
-
}
|
|
714
|
-
else {
|
|
715
|
-
const valueStart = p;
|
|
716
|
-
while (p < n && !isSpace(html.charCodeAt(p)) && html[p] !== '>') {
|
|
717
|
-
p += 1;
|
|
718
|
-
}
|
|
719
|
-
value = html.slice(valueStart, p);
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
if (name) {
|
|
723
|
-
tag.attrs.push({ name, value });
|
|
724
|
-
}
|
|
725
|
-
else if (p === nameStart) {
|
|
726
|
-
p += 1;
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
tags.push(tag);
|
|
730
|
-
i = p;
|
|
731
|
-
if (RAW_TEXT_ELEMENTS.has(tag.name)) {
|
|
732
|
-
const close = lower.indexOf(`</${tag.name}`, p);
|
|
733
|
-
const end = close === -1 ? n : close;
|
|
734
|
-
raws.push({ tag, content: html.slice(p, end), contentIndex: p });
|
|
735
|
-
i = end;
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return { tags, raws };
|
|
674
|
+
/** What the browser holds for an attribute: the parser has already decoded its character references. */
|
|
675
|
+
function attrValue(element, name) {
|
|
676
|
+
return attr(element, name)?.value;
|
|
739
677
|
}
|
|
740
678
|
const RESOURCE_ATTRIBUTES = ['src', 'srcset', 'poster', 'data', 'background', 'xlink:href', 'href'];
|
|
741
679
|
/** Decode once in HTML attribute mode and retain the raw source of every UTF-16 unit. */
|
|
@@ -751,7 +689,9 @@ function decodedAttribute(value) {
|
|
|
751
689
|
}
|
|
752
690
|
};
|
|
753
691
|
let output = '';
|
|
754
|
-
const decoder = new decode_1.EntityDecoder(decode_1.htmlDecodeTree, (cp) => {
|
|
692
|
+
const decoder = new decode_1.EntityDecoder(decode_1.htmlDecodeTree, (cp) => {
|
|
693
|
+
output += String.fromCodePoint(cp);
|
|
694
|
+
});
|
|
755
695
|
let position = 0;
|
|
756
696
|
while (position < value.length) {
|
|
757
697
|
const amp = value.indexOf('&', position);
|
|
@@ -815,21 +755,21 @@ function srcsetUrls(value) {
|
|
|
815
755
|
return urls;
|
|
816
756
|
}
|
|
817
757
|
const STYLESHEET_LIKE_REL = /\b(?:stylesheet|preload|modulepreload|prefetch|icon|manifest)\b/i;
|
|
818
|
-
function scanTag(
|
|
819
|
-
const name =
|
|
758
|
+
function scanTag(element, line, out, allowAppLocalReferences) {
|
|
759
|
+
const name = element.tagName;
|
|
820
760
|
if (name === 'base') {
|
|
821
761
|
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.');
|
|
822
762
|
return;
|
|
823
763
|
}
|
|
824
764
|
if (name === 'meta') {
|
|
825
|
-
const equiv = asciiLower((
|
|
765
|
+
const equiv = asciiLower(attrValue(element, 'http-equiv') ?? '').trim();
|
|
826
766
|
if (equiv === 'refresh') {
|
|
827
767
|
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.');
|
|
828
768
|
}
|
|
829
769
|
return;
|
|
830
770
|
}
|
|
831
771
|
if (name === 'form') {
|
|
832
|
-
const action =
|
|
772
|
+
const action = attrValue(element, 'action');
|
|
833
773
|
if (action !== undefined && action.trim() !== '') {
|
|
834
774
|
out.add('error', 'form-action', line, 'A form with an action: form-action is none in the frame, so submitting is blocked.', 'Drop the action and handle the input and change events in script.');
|
|
835
775
|
}
|
|
@@ -839,33 +779,32 @@ function scanTag(tag, line, out, allowAppLocalReferences) {
|
|
|
839
779
|
return;
|
|
840
780
|
}
|
|
841
781
|
if (name === 'iframe' || name === 'frame') {
|
|
842
|
-
const src = (
|
|
782
|
+
const src = attrValue(element, 'src') ?? '';
|
|
843
783
|
const external = classifyUrl(src) === 'external';
|
|
844
784
|
out.add(external ? 'error' : 'warn', 'nested-frame', line, external
|
|
845
785
|
? `<${name}> of a URL: frame-src is none in the frame, so it is blocked.`
|
|
846
786
|
: `<${name}>: frame-src is none in the frame; nested frames are not supported.`, 'Render the content directly in this widget.');
|
|
847
787
|
return;
|
|
848
788
|
}
|
|
849
|
-
const formaction =
|
|
789
|
+
const formaction = attrValue(element, 'formaction');
|
|
850
790
|
if (formaction !== undefined && formaction.trim() !== '') {
|
|
851
791
|
out.add('error', 'form-action', line, 'formaction: form-action is none in the frame, so submitting is blocked.', 'Handle the click in script.');
|
|
852
792
|
}
|
|
853
793
|
if (name === 'a' || name === 'area') {
|
|
854
|
-
const
|
|
855
|
-
const href = rawHref === undefined ? undefined : (0, entities_1.decodeHTMLAttribute)(rawHref);
|
|
794
|
+
const href = attrValue(element, 'href');
|
|
856
795
|
if (href !== undefined && classifyUrl(href) === 'external') {
|
|
857
796
|
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}.`);
|
|
858
797
|
}
|
|
859
|
-
const target = asciiLower((
|
|
798
|
+
const target = asciiLower(attrValue(element, 'target') ?? '').trim();
|
|
860
799
|
if (target === '_blank' || target === '_top' || target === '_parent') {
|
|
861
800
|
out.add('warn', 'popup', line, `target="${target}": the sandbox has no allow-popups or top navigation, so nothing opens.`, `Use ${OPEN_LINK}.`);
|
|
862
801
|
}
|
|
863
802
|
return;
|
|
864
803
|
}
|
|
865
|
-
const rel = (
|
|
804
|
+
const rel = attrValue(element, 'rel') ?? '';
|
|
866
805
|
for (const attribute of RESOURCE_ATTRIBUTES) {
|
|
867
|
-
const
|
|
868
|
-
if (
|
|
806
|
+
const found = attr(element, attribute);
|
|
807
|
+
if (found === undefined) {
|
|
869
808
|
continue;
|
|
870
809
|
}
|
|
871
810
|
if (attribute === 'href' && name === 'link' && !STYLESHEET_LIKE_REL.test(rel)) {
|
|
@@ -874,18 +813,24 @@ function scanTag(tag, line, out, allowAppLocalReferences) {
|
|
|
874
813
|
if (attribute === 'data' && name !== 'object') {
|
|
875
814
|
continue;
|
|
876
815
|
}
|
|
877
|
-
// HTML decodes character references before interpreting resource URLs.
|
|
878
|
-
// exempt literal app references: the package resolver reads the raw source
|
|
879
|
-
// and cannot promise to replace a reference written using entities.
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
const
|
|
816
|
+
// HTML decodes character references before interpreting resource URLs, and the parser has: `found.value` is the
|
|
817
|
+
// address the browser resolves. Only exempt literal app references: the package resolver reads the raw source
|
|
818
|
+
// and cannot promise to replace a reference written using entities. `decodedAttribute` maps the decoded text back
|
|
819
|
+
// to the source for that and is trusted for nothing else: when it does not give back the parser's text, no
|
|
820
|
+
// exemption applies.
|
|
821
|
+
const decoded = decodedAttribute(found.raw);
|
|
822
|
+
const literal = decoded.text === found.value;
|
|
823
|
+
const text = found.value;
|
|
824
|
+
const trimmed = text.trim();
|
|
825
|
+
const leading = text.length - text.trimStart().length;
|
|
883
826
|
const candidates = attribute === 'srcset'
|
|
884
|
-
? srcsetUrls(
|
|
827
|
+
? srcsetUrls(text)
|
|
828
|
+
: [{ url: trimmed, start: leading, end: leading + trimmed.length }];
|
|
885
829
|
for (const { url, start, end } of candidates) {
|
|
886
|
-
const raw = end > start ?
|
|
830
|
+
const raw = literal && end > start ? found.raw.slice(decoded.starts[start], decoded.ends[end - 1]) : '';
|
|
887
831
|
const kind = isAppLocalReference(url, allowAppLocalReferences && raw === url)
|
|
888
|
-
? 'inline'
|
|
832
|
+
? 'inline'
|
|
833
|
+
: classifyUrl(url);
|
|
889
834
|
if (kind === 'external' && !isNamespaceUrl(url)) {
|
|
890
835
|
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.');
|
|
891
836
|
}
|
|
@@ -895,44 +840,99 @@ function scanTag(tag, line, out, allowAppLocalReferences) {
|
|
|
895
840
|
}
|
|
896
841
|
}
|
|
897
842
|
}
|
|
898
|
-
function isClassicScript(tag) {
|
|
899
|
-
const type = asciiLower((0, entities_1.decodeHTMLAttribute)(attr(tag, 'type') ?? ''))
|
|
900
|
-
.trim()
|
|
901
|
-
.split(';')[0];
|
|
902
|
-
return (type === '' ||
|
|
903
|
-
type === 'text/javascript' ||
|
|
904
|
-
type === 'application/javascript' ||
|
|
905
|
-
type === 'text/ecmascript' ||
|
|
906
|
-
type === 'application/ecmascript');
|
|
907
|
-
}
|
|
908
|
-
function isScannableScript(tag) {
|
|
909
|
-
return isClassicScript(tag) || asciiLower((0, entities_1.decodeHTMLAttribute)(attr(tag, 'type') ?? '')).trim() === 'module';
|
|
910
|
-
}
|
|
911
843
|
function scanHtmlInto(html, out, allowAppLocalReferences) {
|
|
912
|
-
const masked = maskHtmlComments(html);
|
|
913
844
|
const starts = lineStarts(html);
|
|
914
|
-
|
|
845
|
+
// Every element, script, style and handler below comes from this one parse, which reads comments, raw text and
|
|
846
|
+
// attribute values the way a browser does. There is no second tokenizer here to disagree with it, and a parse that
|
|
847
|
+
// cannot finish throws: the caller reports an incomplete scan, never a clean one.
|
|
848
|
+
const parsed = (0, data_provider_1.analyzeAppHtml)(html);
|
|
849
|
+
const parsedScripts = parsed.scripts;
|
|
915
850
|
const inlineScripts = [];
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
851
|
+
const inlineModules = [];
|
|
852
|
+
const inlineHandlers = [];
|
|
853
|
+
let inlineCoverageComplete = true;
|
|
854
|
+
// Defer dormant findings so an active finding on the same line and with the
|
|
855
|
+
// same code wins deduplication even when both have warning severity.
|
|
856
|
+
const conditionalFindings = [];
|
|
857
|
+
const scanMarkupPart = (dormant, scan) => {
|
|
858
|
+
if (dormant === null) {
|
|
859
|
+
scan(out);
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
const conditional = new Collector('html');
|
|
863
|
+
scan(conditional);
|
|
864
|
+
for (const finding of conditional.findings) {
|
|
865
|
+
conditionalFindings.push({
|
|
866
|
+
...finding,
|
|
867
|
+
severity: 'warn',
|
|
868
|
+
message: `${DORMANT_CONDITION[dormant]}${finding.message}`,
|
|
869
|
+
});
|
|
933
870
|
}
|
|
871
|
+
};
|
|
872
|
+
for (const element of parsed.elements) {
|
|
873
|
+
scanMarkupPart(element.dormant, (collector) => {
|
|
874
|
+
const line = lineAt(starts, element.start);
|
|
875
|
+
scanTag(element, line, collector, allowAppLocalReferences);
|
|
876
|
+
const style = attrValue(element, 'style');
|
|
877
|
+
if (style)
|
|
878
|
+
scanCssInto(style, line, collector, allowAppLocalReferences);
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
for (const element of parsed.elements) {
|
|
882
|
+
const text = element.text;
|
|
883
|
+
if (text === undefined)
|
|
884
|
+
continue;
|
|
885
|
+
scanMarkupPart(element.dormant, (collector) => scanCssInto(text.content, lineAt(starts, text.offset), collector, allowAppLocalReferences));
|
|
886
|
+
}
|
|
887
|
+
// Script content comes from the same parse: a literal </script> can occur in script-data's double-escaped state.
|
|
888
|
+
for (const script of parsedScripts) {
|
|
889
|
+
// A foreign attribute such as xlink:type is not the DOM's "type" attribute.
|
|
890
|
+
const get = (name) => script.attributes.find((a) => a.name === name && !a.prefix && !a.namespace)?.value;
|
|
891
|
+
if (get('src') !== undefined || !script.content.trim())
|
|
892
|
+
continue;
|
|
893
|
+
const originalType = get('type') ?? '';
|
|
894
|
+
let type = asciiLower(originalType).trim();
|
|
895
|
+
// The frame also activates its inert marker if it was present in the input.
|
|
896
|
+
if (originalType === 'text/x-skrr-inert')
|
|
897
|
+
type = asciiLower(get('data-skrr-type') ?? '').trim();
|
|
898
|
+
const module = type === 'module';
|
|
899
|
+
const classicType = type.split(';')[0].trim();
|
|
900
|
+
const classic = classicType === '' ||
|
|
901
|
+
classicType === 'text/javascript' ||
|
|
902
|
+
classicType === 'application/javascript' ||
|
|
903
|
+
classicType === 'text/ecmascript' ||
|
|
904
|
+
classicType === 'application/ecmascript';
|
|
905
|
+
if (!classic && !module)
|
|
906
|
+
continue;
|
|
907
|
+
if (!script.active) {
|
|
908
|
+
inlineCoverageComplete = false;
|
|
909
|
+
continue;
|
|
910
|
+
}
|
|
911
|
+
const line = lineAt(starts, script.offset);
|
|
912
|
+
scanJsInto(script.content, line, out, true, script.sourceLines, script.start);
|
|
913
|
+
if (script.sourceLines === null)
|
|
914
|
+
out.add('warn', 'source-line-unavailable', undefined, 'Exact HTML source lines are unavailable for this script because parsing changed its text.');
|
|
915
|
+
(module ? inlineModules : inlineScripts).push({
|
|
916
|
+
content: script.content,
|
|
917
|
+
line,
|
|
918
|
+
sourceLines: script.sourceLines,
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
// Inline event attributes and javascript: addresses come from the same parse as the scripts, so the two agree on what
|
|
922
|
+
// is markup. The frame's policy allows inline script, and these are inline script.
|
|
923
|
+
for (const handler of parsed.handlers) {
|
|
924
|
+
if (!handler.active) {
|
|
925
|
+
inlineCoverageComplete = false;
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
const line = handler.sourceLines[0];
|
|
929
|
+
scanJsInto(handler.content, line, out, true, handler.sourceLines, handler.offset);
|
|
930
|
+
inlineHandlers.push({ content: handler.content, line, sourceLines: handler.sourceLines });
|
|
931
|
+
}
|
|
932
|
+
for (const finding of conditionalFindings) {
|
|
933
|
+
out.add(finding.severity, finding.code, finding.line, finding.message, finding.fix, true);
|
|
934
934
|
}
|
|
935
|
-
return inlineScripts;
|
|
935
|
+
return { inlineScripts, inlineModules, inlineHandlers, inlineCoverageComplete };
|
|
936
936
|
}
|
|
937
937
|
// ── entry point ─────────────────────────────────────────────────────────────
|
|
938
938
|
/** Findings per (section, code) before the rest collapse into one line. */
|
|
@@ -943,7 +943,7 @@ function tidy(findings) {
|
|
|
943
943
|
// recognise the same call must not report it twice.
|
|
944
944
|
const best = new Map();
|
|
945
945
|
for (const f of findings) {
|
|
946
|
-
const key = `${f.section}:${f.line}:${f.code}`;
|
|
946
|
+
const key = `${f.section}:${f.provenance ?? f.line ?? 'unknown'}:${f.code}`;
|
|
947
947
|
const held = best.get(key);
|
|
948
948
|
if (!held || SEVERITY_RANK[f.severity] > SEVERITY_RANK[held.severity]) {
|
|
949
949
|
best.set(key, f);
|
|
@@ -951,10 +951,16 @@ function tidy(findings) {
|
|
|
951
951
|
}
|
|
952
952
|
// A generic URL warning on a line that already has the specific error is noise.
|
|
953
953
|
const resourceLines = new Set([...best.values()]
|
|
954
|
-
.filter((f) => f.code === 'external-resource')
|
|
955
|
-
.map((f) => `${f.section}:${f.line}`));
|
|
956
|
-
const kept = [...best.values()].filter((f) => !(f.code === 'external-url' &&
|
|
957
|
-
|
|
954
|
+
.filter((f) => f.code === 'external-resource' && !f.conditional)
|
|
955
|
+
.map((f) => `${f.section}:${f.provenance ?? f.line ?? 'unknown'}`));
|
|
956
|
+
const kept = [...best.values()].filter((f) => !(f.code === 'external-url' &&
|
|
957
|
+
resourceLines.has(`${f.section}:${f.provenance ?? f.line ?? 'unknown'}`)));
|
|
958
|
+
// Keep the most serious occurrences before applying the per-code cap. A
|
|
959
|
+
// conditional warning must not displace a later active error from the list.
|
|
960
|
+
kept.sort((a, b) => SEVERITY_RANK[b.severity] - SEVERITY_RANK[a.severity] ||
|
|
961
|
+
Number(Boolean(a.conditional)) - Number(Boolean(b.conditional)) ||
|
|
962
|
+
a.section.localeCompare(b.section) ||
|
|
963
|
+
(a.line ?? 0) - (b.line ?? 0));
|
|
958
964
|
const seen = new Map();
|
|
959
965
|
const out = [];
|
|
960
966
|
const dropped = new Map();
|
|
@@ -982,12 +988,18 @@ function tidy(findings) {
|
|
|
982
988
|
const { count, ...rest } = entry;
|
|
983
989
|
out.push({ ...rest, message: `...and ${count} more of the same kind in ${rest.section}.` });
|
|
984
990
|
}
|
|
985
|
-
return out
|
|
991
|
+
return out
|
|
992
|
+
.sort((a, b) => a.section.localeCompare(b.section) || (a.line ?? 0) - (b.line ?? 0))
|
|
993
|
+
.map((finding) => {
|
|
994
|
+
const publicFinding = { ...finding };
|
|
995
|
+
delete publicFinding.conditional;
|
|
996
|
+
delete publicFinding.provenance;
|
|
997
|
+
return publicFinding;
|
|
998
|
+
});
|
|
986
999
|
}
|
|
987
1000
|
/**
|
|
988
|
-
* Scan one widget's three sections
|
|
989
|
-
*
|
|
990
|
-
* caller has already bounded by the widget limits.
|
|
1001
|
+
* Scan one widget's three sections without executing author code. The caller
|
|
1002
|
+
* must bound inputs and treat parser failures as an incomplete scan.
|
|
991
1003
|
*/
|
|
992
1004
|
function scanWidgetSource(source, options = {}) {
|
|
993
1005
|
const css = new Collector('css');
|
|
@@ -995,10 +1007,13 @@ function scanWidgetSource(source, options = {}) {
|
|
|
995
1007
|
const js = new Collector('js');
|
|
996
1008
|
const allowAppLocalReferences = options.allowAppLocalReferences === true;
|
|
997
1009
|
scanCssInto(source.css, 1, css, allowAppLocalReferences);
|
|
998
|
-
const inlineScripts = scanHtmlInto(source.html, html, allowAppLocalReferences);
|
|
1010
|
+
const { inlineScripts, inlineModules, inlineHandlers, inlineCoverageComplete } = scanHtmlInto(source.html, html, allowAppLocalReferences);
|
|
999
1011
|
scanJsInto(source.js, 1, js);
|
|
1000
1012
|
return {
|
|
1001
1013
|
findings: tidy([...css.findings, ...html.findings, ...js.findings]),
|
|
1002
1014
|
inlineScripts,
|
|
1015
|
+
inlineModules,
|
|
1016
|
+
inlineHandlers,
|
|
1017
|
+
inlineCoverageComplete,
|
|
1003
1018
|
};
|
|
1004
1019
|
}
|