@skrr-ai/cli 0.1.163 → 0.1.164
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/dist/base-command.js +24 -12
- package/dist/commands/agents/mini-computer/show.js +7 -1
- package/dist/commands/agents/supervision.d.ts +25 -0
- package/dist/commands/agents/supervision.js +129 -0
- package/dist/commands/duties/action-proposal.js +19 -11
- package/dist/commands/duties/cadence-decisions.js +7 -0
- package/dist/commands/duties/trigger-status.js +2 -2
- package/dist/commands/duties/wake-capabilities.js +12 -6
- package/dist/lib/appInstallations.js +21 -0
- package/dist/lib/appsCheck.js +15 -4
- package/dist/lib/chat-supervision.d.ts +21 -0
- package/dist/lib/chat-supervision.js +37 -0
- package/dist/lib/duties.d.ts +4 -0
- 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/roles.d.ts +1 -1
- package/dist/lib/widgetCheck.js +30 -4
- package/dist/lib/widgetStaticScan.d.ts +14 -5
- package/dist/lib/widgetStaticScan.js +167 -60
- 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 +14243 -9729
- package/oclif.manifest.json +198 -4
- package/package.json +3 -2
package/dist/lib/widgetCheck.js
CHANGED
|
@@ -198,7 +198,7 @@ function errorMessage(err) {
|
|
|
198
198
|
const message = err?.message;
|
|
199
199
|
return typeof message === 'string' ? message : String(err);
|
|
200
200
|
}
|
|
201
|
-
function syntaxIssue(script, section, firstLine) {
|
|
201
|
+
function syntaxIssue(script, section, firstLine, sourceLines) {
|
|
202
202
|
try {
|
|
203
203
|
// Compile only. `vm.Script` parses and reports early errors; it never runs the code.
|
|
204
204
|
new vm.Script(script, { filename: 'widget.js' });
|
|
@@ -215,7 +215,9 @@ function syntaxIssue(script, section, firstLine) {
|
|
|
215
215
|
source: 'syntax',
|
|
216
216
|
code: 'syntax/js',
|
|
217
217
|
section,
|
|
218
|
-
line:
|
|
218
|
+
line: sourceLines === undefined
|
|
219
|
+
? firstLine + (at ? Number(at[1]) - 1 : 0)
|
|
220
|
+
: sourceLines?.[(at ? Number(at[1]) : 1) - 1],
|
|
219
221
|
message: `JavaScript syntax error: ${message}. The script would stop before running.`,
|
|
220
222
|
...(fix ? { fix } : {}),
|
|
221
223
|
};
|
|
@@ -242,9 +244,33 @@ function contentIssues(parts) {
|
|
|
242
244
|
issues.push(syntax);
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
|
-
|
|
247
|
+
let scan;
|
|
248
|
+
try {
|
|
249
|
+
scan = (0, widgetStaticScan_1.scanWidgetSource)(parts);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
issues.push({
|
|
253
|
+
severity: 'error',
|
|
254
|
+
source: 'static',
|
|
255
|
+
code: 'static/scanner-unavailable',
|
|
256
|
+
message: 'The static scan could not finish; static findings and inline script syntax checks may be incomplete.',
|
|
257
|
+
fix: 'Simplify the widget markup or try the check again.',
|
|
258
|
+
heuristic: true,
|
|
259
|
+
});
|
|
260
|
+
return issues;
|
|
261
|
+
}
|
|
262
|
+
if (scan.inlineCoverageComplete === false) {
|
|
263
|
+
issues.push({
|
|
264
|
+
severity: 'warn',
|
|
265
|
+
source: 'static',
|
|
266
|
+
code: 'static/template-script-unchecked',
|
|
267
|
+
section: 'html',
|
|
268
|
+
message: 'Scripts in templates do not run at initial load; if widget code activates them later, their syntax and static findings have not been checked.',
|
|
269
|
+
heuristic: true,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
246
272
|
for (const script of scan.inlineScripts) {
|
|
247
|
-
const syntax = syntaxIssue(script.content, 'html', script.line);
|
|
273
|
+
const syntax = syntaxIssue(script.content, 'html', script.line, script.sourceLines);
|
|
248
274
|
if (syntax) {
|
|
249
275
|
issues.push(syntax);
|
|
250
276
|
}
|
|
@@ -30,15 +30,20 @@
|
|
|
30
30
|
* both over one corpus and fails when they disagree about what the frame refuses.
|
|
31
31
|
*/
|
|
32
32
|
import { UI_WIDGET_FENCE } from '@skrr-ai/data-provider';
|
|
33
|
+
/** Parse as an actual ECMAScript module without executing author code. */
|
|
34
|
+
export declare function checkModuleSyntax(source: string): {
|
|
35
|
+
message: string;
|
|
36
|
+
line?: number;
|
|
37
|
+
} | null;
|
|
33
38
|
export type ScanSection = Exclude<(typeof UI_WIDGET_FENCE.sections)[number], 'fallback'>;
|
|
34
39
|
export type StaticSeverity = 'error' | 'warn';
|
|
35
|
-
export type StaticCode = 'external-resource' | 'external-url' | 'external-link' | 'relative-url' | 'network-api' | 'worker' | 'dynamic-code' | 'storage' | 'host-access' | 'popup' | 'navigation' | 'form-action' | 'base-element' | 'nested-frame' | 'plugin-element' | 'element-close' | 'webrtc';
|
|
40
|
+
export type StaticCode = 'external-resource' | 'external-url' | 'external-link' | 'relative-url' | 'network-api' | 'worker' | 'dynamic-code' | 'storage' | 'host-access' | 'popup' | 'navigation' | 'form-action' | 'base-element' | 'nested-frame' | 'plugin-element' | 'element-close' | 'webrtc' | 'source-line-unavailable';
|
|
36
41
|
export interface StaticFinding {
|
|
37
42
|
severity: StaticSeverity;
|
|
38
43
|
code: StaticCode;
|
|
39
44
|
section: ScanSection;
|
|
40
45
|
/** 1-based line within the section's own text. */
|
|
41
|
-
line
|
|
46
|
+
line?: number;
|
|
42
47
|
message: string;
|
|
43
48
|
fix?: string;
|
|
44
49
|
}
|
|
@@ -47,11 +52,16 @@ export interface InlineScript {
|
|
|
47
52
|
content: string;
|
|
48
53
|
/** 1-based line within the html section where the script's text starts. */
|
|
49
54
|
line: number;
|
|
55
|
+
sourceLines: number[] | null;
|
|
50
56
|
}
|
|
51
57
|
export interface StaticScanResult {
|
|
52
58
|
findings: StaticFinding[];
|
|
53
59
|
/** Classic inline scripts of the html section, for a syntax check by the caller. */
|
|
54
60
|
inlineScripts: InlineScript[];
|
|
61
|
+
/** Inline module bodies, separately so classic-only widget syntax checks remain unchanged. */
|
|
62
|
+
inlineModules: InlineScript[];
|
|
63
|
+
/** False when template-contained script could be activated later by app code. */
|
|
64
|
+
inlineCoverageComplete: boolean;
|
|
55
65
|
}
|
|
56
66
|
export interface WidgetSource {
|
|
57
67
|
css: string;
|
|
@@ -103,9 +113,8 @@ type UrlKind = 'external' | 'inline' | 'relative' | 'empty';
|
|
|
103
113
|
/** A URL the frame cannot fetch from, a self-contained one, or one with no base to resolve against. */
|
|
104
114
|
export declare function classifyUrl(raw: string): UrlKind;
|
|
105
115
|
/**
|
|
106
|
-
* Scan one widget's three sections
|
|
107
|
-
*
|
|
108
|
-
* caller has already bounded by the widget limits.
|
|
116
|
+
* Scan one widget's three sections without executing author code. The caller
|
|
117
|
+
* must bound inputs and treat parser failures as an incomplete scan.
|
|
109
118
|
*/
|
|
110
119
|
export declare function scanWidgetSource(source: WidgetSource, options?: {
|
|
111
120
|
allowAppLocalReferences?: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
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;
|
|
@@ -40,6 +41,20 @@ exports.scanWidgetSource = scanWidgetSource;
|
|
|
40
41
|
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
41
42
|
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,9 @@ 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
|
+
const TEMPLATE_CONDITION = 'If this template content is inserted into the page: ';
|
|
56
72
|
const OPEN_LINK = 'window.skrr.openLink(url)';
|
|
57
73
|
// ── small text helpers ──────────────────────────────────────────────────────
|
|
58
74
|
/** ASCII-only lowercase: the same length as the input, so offsets stay valid. */
|
|
@@ -366,14 +382,16 @@ class Collector {
|
|
|
366
382
|
constructor(section) {
|
|
367
383
|
this.section = section;
|
|
368
384
|
}
|
|
369
|
-
add(severity, code, line, message, fix) {
|
|
385
|
+
add(severity, code, line, message, fix, conditional = false, provenance) {
|
|
370
386
|
this.findings.push({
|
|
371
387
|
severity,
|
|
372
388
|
code,
|
|
373
389
|
section: this.section,
|
|
374
|
-
line,
|
|
390
|
+
...(line === undefined ? {} : { line }),
|
|
375
391
|
message,
|
|
376
392
|
...(fix ? { fix } : {}),
|
|
393
|
+
...(conditional ? { conditional: true } : {}),
|
|
394
|
+
...(provenance === undefined ? {} : { provenance }),
|
|
377
395
|
});
|
|
378
396
|
}
|
|
379
397
|
}
|
|
@@ -383,8 +401,9 @@ class Collector {
|
|
|
383
401
|
*/
|
|
384
402
|
function isAppLocalReference(value, enabled) {
|
|
385
403
|
const trimmed = value.trim();
|
|
386
|
-
return enabled &&
|
|
387
|
-
|
|
404
|
+
return (enabled &&
|
|
405
|
+
trimmed.startsWith(data_provider_1.APP_FILE_REF_SCHEME) &&
|
|
406
|
+
(0, data_provider_1.isSafeAppPath)(trimmed.slice(data_provider_1.APP_FILE_REF_SCHEME.length)));
|
|
388
407
|
}
|
|
389
408
|
// ── CSS ─────────────────────────────────────────────────────────────────────
|
|
390
409
|
function scanCssInto(source, baseLine, out, allowAppLocalReferences) {
|
|
@@ -398,7 +417,10 @@ function scanCssInto(source, baseLine, out, allowAppLocalReferences) {
|
|
|
398
417
|
const statement = masked.slice(i, end === -1 ? undefined : end);
|
|
399
418
|
const target = SCAN_CSS_INTO_RE.exec(statement);
|
|
400
419
|
const kind = target && isAppLocalReference(target[1], allowAppLocalReferences)
|
|
401
|
-
? 'inline'
|
|
420
|
+
? 'inline'
|
|
421
|
+
: target
|
|
422
|
+
? classifyUrl(target[1])
|
|
423
|
+
: 'relative';
|
|
402
424
|
if (kind === 'external') {
|
|
403
425
|
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
426
|
}
|
|
@@ -412,7 +434,9 @@ function scanCssInto(source, baseLine, out, allowAppLocalReferences) {
|
|
|
412
434
|
const close = masked.indexOf(')', u + 4);
|
|
413
435
|
const inner = masked.slice(u + 4, close === -1 ? undefined : close).trim();
|
|
414
436
|
const value = inner.replace(SCAN_CSS_INTO_RE_2, '');
|
|
415
|
-
const kind = isAppLocalReference(value, allowAppLocalReferences)
|
|
437
|
+
const kind = isAppLocalReference(value, allowAppLocalReferences)
|
|
438
|
+
? 'inline'
|
|
439
|
+
: classifyUrl(value);
|
|
416
440
|
if (kind === 'external') {
|
|
417
441
|
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
442
|
}
|
|
@@ -586,14 +610,22 @@ function brokerFetchOffsets(code) {
|
|
|
586
610
|
}
|
|
587
611
|
return offsets;
|
|
588
612
|
}
|
|
589
|
-
function scanJsInto(source, baseLine, out) {
|
|
613
|
+
function scanJsInto(source, baseLine, out, parsedFromHtml = false, sourceLines, sourceId) {
|
|
590
614
|
// HTML parsing and JavaScript both treat CR and CRLF as line breaks; use one
|
|
591
615
|
// form consistently in the lexer, comments, and its source-line lookups.
|
|
592
616
|
source = source.replace(/\r\n?/g, '\n');
|
|
593
617
|
const { code, commentless, literals } = lexJs(source);
|
|
594
618
|
const brokerFetches = brokerFetchOffsets(code);
|
|
595
619
|
const starts = (0, data_provider_1.jsLineStarts)(source);
|
|
596
|
-
const lineOf = (index) =>
|
|
620
|
+
const lineOf = (index) => {
|
|
621
|
+
const line = lineAt(starts, index);
|
|
622
|
+
return sourceLines === undefined ? baseLine + line - 1 : sourceLines?.[line - 1];
|
|
623
|
+
};
|
|
624
|
+
const addAt = (severity, code, index, message, fix) => {
|
|
625
|
+
const line = lineOf(index);
|
|
626
|
+
const provenance = sourceLines !== undefined ? `${sourceId ?? 'unknown'}:${lineAt(starts, index)}` : undefined;
|
|
627
|
+
out.add(severity, code, line, message, fix, false, provenance);
|
|
628
|
+
};
|
|
597
629
|
const codeLines = code.split(/\r\n?|[\n\u2028\u2029]/);
|
|
598
630
|
const textual = literals.filter((literal) => literal.kind !== 'regex');
|
|
599
631
|
const byOpen = new Map(textual.map((literal) => [literal.open, literal]));
|
|
@@ -603,7 +635,7 @@ function scanJsInto(source, baseLine, out) {
|
|
|
603
635
|
for (const match of code.matchAll(rule.pattern)) {
|
|
604
636
|
if (rule.code === 'network-api' && brokerFetches.has(match.index ?? 0))
|
|
605
637
|
continue;
|
|
606
|
-
|
|
638
|
+
addAt(rule.severity, rule.code, match.index ?? 0, rule.message, rule.fix);
|
|
607
639
|
}
|
|
608
640
|
}
|
|
609
641
|
// A call or assignment whose argument is a literal that names a URL.
|
|
@@ -612,7 +644,7 @@ function scanJsInto(source, baseLine, out) {
|
|
|
612
644
|
const open = (match.index ?? 0) + match[0].length - 1;
|
|
613
645
|
const literal = byOpen.get(open);
|
|
614
646
|
if (literal && URL_START.test(literal.value)) {
|
|
615
|
-
|
|
647
|
+
addAt('error', 'external-resource', match.index ?? 0, rule.message, rule.fix);
|
|
616
648
|
}
|
|
617
649
|
}
|
|
618
650
|
}
|
|
@@ -620,7 +652,7 @@ function scanJsInto(source, baseLine, out) {
|
|
|
620
652
|
for (const literal of textual) {
|
|
621
653
|
for (const rule of STRING_RULES) {
|
|
622
654
|
for (const match of literal.value.matchAll(rule.pattern)) {
|
|
623
|
-
|
|
655
|
+
addAt('error', 'external-resource', literal.start + (match.index ?? 0), rule.message, rule.fix);
|
|
624
656
|
}
|
|
625
657
|
}
|
|
626
658
|
for (const match of literal.value.matchAll(URL_IN_STRING)) {
|
|
@@ -630,13 +662,14 @@ function scanJsInto(source, baseLine, out) {
|
|
|
630
662
|
if (isNamespaceUrl(url) || SCAN_JS_INTO_RE.test(text)) {
|
|
631
663
|
continue;
|
|
632
664
|
}
|
|
633
|
-
|
|
665
|
+
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
666
|
}
|
|
635
667
|
}
|
|
636
668
|
// The one rule that reads the text as the HTML parser would, and so reads strings too.
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
669
|
+
const closingScript = SCAN_JS_INTO_RE_2.exec(commentless);
|
|
670
|
+
if (closingScript && !parsedFromHtml) {
|
|
671
|
+
const at = closingScript.index;
|
|
672
|
+
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
673
|
}
|
|
641
674
|
}
|
|
642
675
|
const RAW_TEXT_ELEMENTS = new Set(['script', 'style', 'textarea', 'title']);
|
|
@@ -648,8 +681,8 @@ function attr(tag, name) {
|
|
|
648
681
|
}
|
|
649
682
|
return undefined;
|
|
650
683
|
}
|
|
651
|
-
/** Walk
|
|
652
|
-
function walkHtml(html) {
|
|
684
|
+
/** Walk markup for best-effort resource and style heuristics. */
|
|
685
|
+
function walkHtml(html, scriptEnds) {
|
|
653
686
|
const lower = asciiLower(html);
|
|
654
687
|
const tags = [];
|
|
655
688
|
const raws = [];
|
|
@@ -729,8 +762,20 @@ function walkHtml(html) {
|
|
|
729
762
|
tags.push(tag);
|
|
730
763
|
i = p;
|
|
731
764
|
if (RAW_TEXT_ELEMENTS.has(tag.name)) {
|
|
732
|
-
const
|
|
733
|
-
|
|
765
|
+
const endTag = `</${tag.name}`;
|
|
766
|
+
let close = lower.indexOf(endTag, p);
|
|
767
|
+
while (close !== -1) {
|
|
768
|
+
const boundary = lower.charAt(close + endTag.length);
|
|
769
|
+
if (boundary === '>' || boundary === '/' || isSpace(boundary.charCodeAt(0)))
|
|
770
|
+
break;
|
|
771
|
+
close = lower.indexOf(endTag, close + endTag.length);
|
|
772
|
+
}
|
|
773
|
+
// The browser's script-data tokenizer, unlike a substring search, keeps
|
|
774
|
+
// </script> inside double-escaped content. Avoid inventing tags there.
|
|
775
|
+
const parsedEnd = tag.name === 'script' ? scriptEnds.get(tag.index) : undefined;
|
|
776
|
+
// An offset from the parser is only an end if it is not before the text it ends: `end < p` would put `i` before this
|
|
777
|
+
// tag again and the walk would revisit it forever (one unclosed `<script>` used to exhaust the heap that way).
|
|
778
|
+
const end = parsedEnd !== undefined && parsedEnd >= p ? parsedEnd : close === -1 ? n : close;
|
|
734
779
|
raws.push({ tag, content: html.slice(p, end), contentIndex: p });
|
|
735
780
|
i = end;
|
|
736
781
|
}
|
|
@@ -751,7 +796,9 @@ function decodedAttribute(value) {
|
|
|
751
796
|
}
|
|
752
797
|
};
|
|
753
798
|
let output = '';
|
|
754
|
-
const decoder = new decode_1.EntityDecoder(decode_1.htmlDecodeTree, (cp) => {
|
|
799
|
+
const decoder = new decode_1.EntityDecoder(decode_1.htmlDecodeTree, (cp) => {
|
|
800
|
+
output += String.fromCodePoint(cp);
|
|
801
|
+
});
|
|
755
802
|
let position = 0;
|
|
756
803
|
while (position < value.length) {
|
|
757
804
|
const amp = value.indexOf('&', position);
|
|
@@ -881,11 +928,13 @@ function scanTag(tag, line, out, allowAppLocalReferences) {
|
|
|
881
928
|
const trimmed = decoded.text.trim();
|
|
882
929
|
const leading = decoded.text.length - decoded.text.trimStart().length;
|
|
883
930
|
const candidates = attribute === 'srcset'
|
|
884
|
-
? srcsetUrls(decoded.text)
|
|
931
|
+
? srcsetUrls(decoded.text)
|
|
932
|
+
: [{ url: trimmed, start: leading, end: leading + trimmed.length }];
|
|
885
933
|
for (const { url, start, end } of candidates) {
|
|
886
934
|
const raw = end > start ? value.slice(decoded.starts[start], decoded.ends[end - 1]) : '';
|
|
887
935
|
const kind = isAppLocalReference(url, allowAppLocalReferences && raw === url)
|
|
888
|
-
? 'inline'
|
|
936
|
+
? 'inline'
|
|
937
|
+
: classifyUrl(url);
|
|
889
938
|
if (kind === 'external' && !isNamespaceUrl(url)) {
|
|
890
939
|
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
940
|
}
|
|
@@ -895,44 +944,88 @@ function scanTag(tag, line, out, allowAppLocalReferences) {
|
|
|
895
944
|
}
|
|
896
945
|
}
|
|
897
946
|
}
|
|
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
947
|
function scanHtmlInto(html, out, allowAppLocalReferences) {
|
|
912
|
-
const masked = maskHtmlComments(html);
|
|
913
948
|
const starts = lineStarts(html);
|
|
914
|
-
|
|
949
|
+
// walkHtml skips real markup comments while preserving script/style raw text;
|
|
950
|
+
// globally masking comments would erase `<!--` inside JavaScript strings.
|
|
951
|
+
const parsed = (0, data_provider_1.analyzeAppHtml)(html);
|
|
952
|
+
const parsedScripts = parsed.scripts;
|
|
953
|
+
const activeElements = new Map(parsed.elements.map((element) => [element.start, element.active]));
|
|
954
|
+
const { tags, raws } = walkHtml(html, new Map(parsedScripts.map((script) => [script.start, script.end])));
|
|
915
955
|
const inlineScripts = [];
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
956
|
+
const inlineModules = [];
|
|
957
|
+
let inlineCoverageComplete = true;
|
|
958
|
+
// Defer dormant findings so an active finding on the same line and with the
|
|
959
|
+
// same code wins deduplication even when both have warning severity.
|
|
960
|
+
const conditionalFindings = [];
|
|
961
|
+
const scanMarkupPart = (active, scan) => {
|
|
962
|
+
if (active) {
|
|
963
|
+
scan(out);
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
const conditional = new Collector('html');
|
|
967
|
+
scan(conditional);
|
|
968
|
+
for (const finding of conditional.findings) {
|
|
969
|
+
conditionalFindings.push({
|
|
970
|
+
...finding,
|
|
971
|
+
severity: 'warn',
|
|
972
|
+
message: `${TEMPLATE_CONDITION}${finding.message}`,
|
|
973
|
+
});
|
|
921
974
|
}
|
|
975
|
+
};
|
|
976
|
+
for (const tag of tags) {
|
|
977
|
+
scanMarkupPart(activeElements.get(tag.index) !== false, (collector) => {
|
|
978
|
+
scanTag(tag, lineAt(starts, tag.index), collector, allowAppLocalReferences);
|
|
979
|
+
const style = attr(tag, 'style');
|
|
980
|
+
if (style)
|
|
981
|
+
scanCssInto(style, lineAt(starts, tag.index), collector, allowAppLocalReferences);
|
|
982
|
+
});
|
|
922
983
|
}
|
|
923
984
|
for (const raw of raws) {
|
|
924
985
|
const line = lineAt(starts, raw.contentIndex);
|
|
925
986
|
if (raw.tag.name === 'style') {
|
|
926
|
-
scanCssInto(raw.content, line,
|
|
987
|
+
scanMarkupPart(activeElements.get(raw.tag.index) !== false, (collector) => scanCssInto(raw.content, line, collector, allowAppLocalReferences));
|
|
927
988
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
989
|
+
}
|
|
990
|
+
// Script content must come from the HTML tokenizer, not the heuristic walker:
|
|
991
|
+
// a literal </script> can occur in script-data's double-escaped state.
|
|
992
|
+
for (const script of parsedScripts) {
|
|
993
|
+
// A foreign attribute such as xlink:type is not the DOM's "type" attribute.
|
|
994
|
+
const get = (name) => script.attributes.find((a) => a.name === name && !a.prefix && !a.namespace)?.value;
|
|
995
|
+
if (get('src') !== undefined || !script.content.trim())
|
|
996
|
+
continue;
|
|
997
|
+
const originalType = get('type') ?? '';
|
|
998
|
+
let type = asciiLower(originalType).trim();
|
|
999
|
+
// The frame also activates its inert marker if it was present in the input.
|
|
1000
|
+
if (originalType === 'text/x-skrr-inert')
|
|
1001
|
+
type = asciiLower(get('data-skrr-type') ?? '').trim();
|
|
1002
|
+
const module = type === 'module';
|
|
1003
|
+
const classicType = type.split(';')[0].trim();
|
|
1004
|
+
const classic = classicType === '' ||
|
|
1005
|
+
classicType === 'text/javascript' ||
|
|
1006
|
+
classicType === 'application/javascript' ||
|
|
1007
|
+
classicType === 'text/ecmascript' ||
|
|
1008
|
+
classicType === 'application/ecmascript';
|
|
1009
|
+
if (!classic && !module)
|
|
1010
|
+
continue;
|
|
1011
|
+
if (!script.active) {
|
|
1012
|
+
inlineCoverageComplete = false;
|
|
1013
|
+
continue;
|
|
933
1014
|
}
|
|
1015
|
+
const line = lineAt(starts, script.offset);
|
|
1016
|
+
scanJsInto(script.content, line, out, true, script.sourceLines, script.start);
|
|
1017
|
+
if (script.sourceLines === null)
|
|
1018
|
+
out.add('warn', 'source-line-unavailable', undefined, 'Exact HTML source lines are unavailable for this script because parsing changed its text.');
|
|
1019
|
+
(module ? inlineModules : inlineScripts).push({
|
|
1020
|
+
content: script.content,
|
|
1021
|
+
line,
|
|
1022
|
+
sourceLines: script.sourceLines,
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
for (const finding of conditionalFindings) {
|
|
1026
|
+
out.add(finding.severity, finding.code, finding.line, finding.message, finding.fix, true);
|
|
934
1027
|
}
|
|
935
|
-
return inlineScripts;
|
|
1028
|
+
return { inlineScripts, inlineModules, inlineCoverageComplete };
|
|
936
1029
|
}
|
|
937
1030
|
// ── entry point ─────────────────────────────────────────────────────────────
|
|
938
1031
|
/** Findings per (section, code) before the rest collapse into one line. */
|
|
@@ -943,7 +1036,7 @@ function tidy(findings) {
|
|
|
943
1036
|
// recognise the same call must not report it twice.
|
|
944
1037
|
const best = new Map();
|
|
945
1038
|
for (const f of findings) {
|
|
946
|
-
const key = `${f.section}:${f.line}:${f.code}`;
|
|
1039
|
+
const key = `${f.section}:${f.provenance ?? f.line ?? 'unknown'}:${f.code}`;
|
|
947
1040
|
const held = best.get(key);
|
|
948
1041
|
if (!held || SEVERITY_RANK[f.severity] > SEVERITY_RANK[held.severity]) {
|
|
949
1042
|
best.set(key, f);
|
|
@@ -951,10 +1044,16 @@ function tidy(findings) {
|
|
|
951
1044
|
}
|
|
952
1045
|
// A generic URL warning on a line that already has the specific error is noise.
|
|
953
1046
|
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
|
-
|
|
1047
|
+
.filter((f) => f.code === 'external-resource' && !f.conditional)
|
|
1048
|
+
.map((f) => `${f.section}:${f.provenance ?? f.line ?? 'unknown'}`));
|
|
1049
|
+
const kept = [...best.values()].filter((f) => !(f.code === 'external-url' &&
|
|
1050
|
+
resourceLines.has(`${f.section}:${f.provenance ?? f.line ?? 'unknown'}`)));
|
|
1051
|
+
// Keep the most serious occurrences before applying the per-code cap. A
|
|
1052
|
+
// conditional warning must not displace a later active error from the list.
|
|
1053
|
+
kept.sort((a, b) => SEVERITY_RANK[b.severity] - SEVERITY_RANK[a.severity] ||
|
|
1054
|
+
Number(Boolean(a.conditional)) - Number(Boolean(b.conditional)) ||
|
|
1055
|
+
a.section.localeCompare(b.section) ||
|
|
1056
|
+
(a.line ?? 0) - (b.line ?? 0));
|
|
958
1057
|
const seen = new Map();
|
|
959
1058
|
const out = [];
|
|
960
1059
|
const dropped = new Map();
|
|
@@ -982,12 +1081,18 @@ function tidy(findings) {
|
|
|
982
1081
|
const { count, ...rest } = entry;
|
|
983
1082
|
out.push({ ...rest, message: `...and ${count} more of the same kind in ${rest.section}.` });
|
|
984
1083
|
}
|
|
985
|
-
return out
|
|
1084
|
+
return out
|
|
1085
|
+
.sort((a, b) => a.section.localeCompare(b.section) || (a.line ?? 0) - (b.line ?? 0))
|
|
1086
|
+
.map((finding) => {
|
|
1087
|
+
const publicFinding = { ...finding };
|
|
1088
|
+
delete publicFinding.conditional;
|
|
1089
|
+
delete publicFinding.provenance;
|
|
1090
|
+
return publicFinding;
|
|
1091
|
+
});
|
|
986
1092
|
}
|
|
987
1093
|
/**
|
|
988
|
-
* Scan one widget's three sections
|
|
989
|
-
*
|
|
990
|
-
* caller has already bounded by the widget limits.
|
|
1094
|
+
* Scan one widget's three sections without executing author code. The caller
|
|
1095
|
+
* must bound inputs and treat parser failures as an incomplete scan.
|
|
991
1096
|
*/
|
|
992
1097
|
function scanWidgetSource(source, options = {}) {
|
|
993
1098
|
const css = new Collector('css');
|
|
@@ -995,10 +1100,12 @@ function scanWidgetSource(source, options = {}) {
|
|
|
995
1100
|
const js = new Collector('js');
|
|
996
1101
|
const allowAppLocalReferences = options.allowAppLocalReferences === true;
|
|
997
1102
|
scanCssInto(source.css, 1, css, allowAppLocalReferences);
|
|
998
|
-
const inlineScripts = scanHtmlInto(source.html, html, allowAppLocalReferences);
|
|
1103
|
+
const { inlineScripts, inlineModules, inlineCoverageComplete } = scanHtmlInto(source.html, html, allowAppLocalReferences);
|
|
999
1104
|
scanJsInto(source.js, 1, js);
|
|
1000
1105
|
return {
|
|
1001
1106
|
findings: tidy([...css.findings, ...html.findings, ...js.findings]),
|
|
1002
1107
|
inlineScripts,
|
|
1108
|
+
inlineModules,
|
|
1109
|
+
inlineCoverageComplete,
|
|
1003
1110
|
};
|
|
1004
1111
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
parse5 8.1.1 (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-2019 Ivan Nikulin (ifaaan@gmail.com, https://github.com/inikulin)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
entities 9.0.0 (BSD-2-Clause)
|
|
25
|
+
|
|
26
|
+
Copyright (c) Felix Böhm
|
|
27
|
+
All rights reserved.
|
|
28
|
+
|
|
29
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
30
|
+
|
|
31
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
32
|
+
|
|
33
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
34
|
+
|
|
35
|
+
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
|
|
36
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|