decklight 0.2.0 → 0.4.0
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 +69 -31
- package/SPEC.md +881 -80
- package/cli/agents.mjs +116 -10
- package/cli/associate.mjs +286 -0
- package/cli/audit.mjs +424 -0
- package/cli/bundle.mjs +174 -46
- package/cli/deckfile.mjs +233 -0
- package/cli/decklight.mjs +201 -8
- package/cli/dev.mjs +244 -55
- package/cli/edit.mjs +577 -107
- package/cli/extension.mjs +108 -0
- package/cli/git.mjs +141 -0
- package/cli/import.mjs +398 -0
- package/cli/init.mjs +421 -116
- package/cli/loader.mjs +263 -0
- package/cli/marketplace.mjs +911 -0
- package/cli/pdf.mjs +156 -0
- package/cli/pkg.mjs +69 -0
- package/cli/plugin.mjs +654 -0
- package/cli/port-conflict.mjs +94 -0
- package/cli/present.mjs +564 -0
- package/cli/publish.mjs +342 -0
- package/cli/qr.mjs +334 -0
- package/cli/rec.mjs +5 -8
- package/cli/remote.mjs +149 -0
- package/cli/report-bug.mjs +97 -0
- package/cli/restore.mjs +174 -0
- package/cli/serve.mjs +247 -0
- package/cli/sign.mjs +216 -0
- package/cli/skill-content.mjs +222 -0
- package/cli/skills.mjs +338 -0
- package/cli/supervise.mjs +57 -0
- package/cli/theme.mjs +219 -0
- package/cli/units.mjs +500 -0
- package/cli/upgrade.mjs +250 -0
- package/cli/util.mjs +90 -0
- package/cli/wizard.mjs +432 -0
- package/cli/zip.mjs +121 -0
- package/dist/decklight.css +716 -29
- package/dist/decklight.js +198 -125
- package/dist/decklight.js.map +4 -4
- package/docs/architecture.svg +1 -1
- package/package.json +7 -5
- package/themes/README.md +6 -4
- package/themes/aurora.css +1 -1
- package/themes/berry.css +1 -1
- package/themes/carbon.css +1 -1
- package/themes/citrus.css +1 -1
- package/themes/coastal.css +1 -1
- package/themes/cosmos.css +1 -1
- package/themes/dune.css +1 -1
- package/themes/eclipse.css +1 -1
- package/themes/ember.css +1 -1
- package/themes/fjord.css +1 -1
- package/themes/gallery.html +3 -11
- package/themes/glacier.css +1 -1
- package/themes/graphite.css +1 -1
- package/themes/harvest.css +1 -1
- package/themes/ibm-modern.css +1 -1
- package/themes/ink.css +1 -1
- package/themes/latte.css +1 -1
- package/themes/linen.css +1 -1
- package/themes/meadow.css +1 -1
- package/themes/metropolis.css +1 -1
- package/themes/midnight.css +1 -1
- package/themes/mint.css +1 -1
- package/themes/moss.css +1 -1
- package/themes/obsidian.css +1 -1
- package/themes/orchid.css +1 -1
- package/themes/packs.json +2 -30
- package/themes/paper.css +1 -1
- package/themes/peony.css +1 -1
- package/themes/porcelain.css +1 -1
- package/themes/reveal-beige.css +1 -1
- package/themes/reveal-black.css +1 -1
- package/themes/reveal-blood.css +1 -1
- package/themes/reveal-dracula.css +1 -1
- package/themes/reveal-league.css +1 -1
- package/themes/reveal-moon.css +1 -1
- package/themes/reveal-night.css +1 -1
- package/themes/reveal-serif.css +1 -1
- package/themes/reveal-simple.css +1 -1
- package/themes/reveal-sky.css +1 -1
- package/themes/reveal-solarized.css +1 -1
- package/themes/reveal-white.css +1 -1
- package/themes/sepia.css +1 -1
- package/themes/seriph.css +1 -1
- package/themes/slate.css +1 -1
- package/themes/storm.css +1 -1
- package/themes/synthwave.css +1 -1
- package/themes/velvet.css +1 -1
- package/themes/yamabuki.css +1 -1
- package/tools/args.mjs +32 -0
- package/tools/bridge.mjs +30 -0
- package/tools/chrome.mjs +46 -11
- package/tools/color.mjs +110 -0
- package/tools/deck-html.mjs +138 -0
- package/tools/elevenlabs-tts.mjs +248 -0
- package/tools/escape.mjs +40 -0
- package/tools/extension-check-runner.mjs +41 -0
- package/tools/extension-check.mjs +266 -0
- package/tools/gemini-tts.mjs +25 -3
- package/tools/lipsync-engines.mjs +81 -0
- package/tools/lipsync-server.mjs +78 -37
- package/tools/lipsync.mjs +36 -21
- package/tools/local-voice.mjs +209 -0
- package/tools/ooxml.mjs +151 -0
- package/tools/pptx.mjs +320 -0
- package/tools/publish-site-voices.mjs +2 -1
- package/tools/publish-targets.mjs +143 -0
- package/tools/publish-voices.mjs +230 -0
- package/tools/shot.mjs +91 -47
- package/tools/theme-check.mjs +144 -0
- package/tools/tts-engines.mjs +270 -41
- package/tools/tts-setup.mjs +257 -0
- package/tools/veo.mjs +204 -0
- package/tools/video.mjs +440 -0
- package/tools/voiceover-server.mjs +163 -54
- package/tools/voiceover.mjs +24 -7
- package/tools/zip.mjs +143 -0
- package/docs/demo.svg +0 -124
- package/themes/aliens.css +0 -87
- package/themes/apple2.css +0 -129
- package/themes/blade-runner.css +0 -86
- package/themes/c64.css +0 -88
- package/themes/friends.css +0 -85
- package/themes/gameboy.css +0 -121
- package/themes/genesis.css +0 -87
- package/themes/godfather.css +0 -85
- package/themes/ibm-oldschool.css +0 -87
- package/themes/miami-vice.css +0 -87
- package/themes/pulp-fiction.css +0 -87
- package/themes/severance.css +0 -85
- package/themes/snes.css +0 -85
- package/themes/star-wars.css +0 -88
- package/themes/stranger-things.css +0 -87
- package/themes/terminator.css +0 -87
package/cli/audit.mjs
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The ingredients label — what a deck will execute, itemised.
|
|
6
|
+
*
|
|
7
|
+
* MARKETPLACE.md INTEGRITY calls this the canonical-shape audit, and its value
|
|
8
|
+
* comes from what a decklight deck *is*: content is HTML, themes are CSS,
|
|
9
|
+
* charts are JSON read by the runtime, casts are JSON read by the player. A
|
|
10
|
+
* well-formed deck therefore contains a very short list of executable things,
|
|
11
|
+
* and everything else that executes is worth naming.
|
|
12
|
+
*
|
|
13
|
+
* **An inventory, never a verdict** (PRESENT). There is no "safe", no green
|
|
14
|
+
* check, no score. The scan is a set of heuristics over a file an attacker may
|
|
15
|
+
* have edited; a verdict would manufacture confidence the mechanism cannot
|
|
16
|
+
* back, and the first person to trust it would be the one it fails. A list of
|
|
17
|
+
* what will run makes no such promise and is still the thing you needed.
|
|
18
|
+
*
|
|
19
|
+
* What it does catch is the realistic attack this whole wave exists for:
|
|
20
|
+
* someone appends a `<script>` to a bundled deck before forwarding it. That
|
|
21
|
+
* block matches nothing in the canonical shape, so it gets named, with its
|
|
22
|
+
* line and its opening bytes, before the first slide renders. The same holds
|
|
23
|
+
* for the vector that never needs a block at all: an inline `onerror=` handler
|
|
24
|
+
* or a `javascript:` href, which the CSP's unavoidable `'unsafe-inline'`
|
|
25
|
+
* would happily run — `executableAttributes` names those.
|
|
26
|
+
*
|
|
27
|
+
* The crypto path — a Sigstore signature over the whole file — is
|
|
28
|
+
* INTEGRITY#SIGNING and is separate on purpose: this audit needs no signature,
|
|
29
|
+
* no network, and no cooperation from whoever produced the file.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
33
|
+
import { createHash } from 'node:crypto';
|
|
34
|
+
import path from 'node:path';
|
|
35
|
+
import { scripts, headStyles } from './upgrade.mjs';
|
|
36
|
+
import { PKG_ROOT, inlineRuntime } from './pkg.mjs';
|
|
37
|
+
|
|
38
|
+
const sha256 = (s) => createHash('sha256').update(s).digest('hex');
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The deck's own claim about which runtime it carries.
|
|
42
|
+
*
|
|
43
|
+
* Read from the build banner, because minification renames the exported
|
|
44
|
+
* `version` const and the banner is the one place a tool can read it back out
|
|
45
|
+
* of an inlined bundle (build.mjs says so where it writes it). This is the
|
|
46
|
+
* deck's claim, not a verified fact — the hash below is what makes it checkable.
|
|
47
|
+
*/
|
|
48
|
+
export function runtimeVersion(html) {
|
|
49
|
+
return /\/\*!\s*Decklight v(\d+\.\d+\.\d+[^\s*]*)/.exec(html)?.[1] ?? null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The byte-exact inlined runtime the installed package would produce.
|
|
54
|
+
*
|
|
55
|
+
* `bundle`, `init`, `import` and `upgrade` all inline `dist/decklight.js`
|
|
56
|
+
* through `inlineRuntime` — the same function called here, rather than a
|
|
57
|
+
* reproduction of it, because a reproduction is what drifted: `import` once
|
|
58
|
+
* escaped it slightly differently and every imported deck audited as DIFFERS.
|
|
59
|
+
* They vary only in the whitespace around the payload, which is why the
|
|
60
|
+
* comparison trims.
|
|
61
|
+
*/
|
|
62
|
+
export function installedRuntime(root = PKG_ROOT) {
|
|
63
|
+
const file = path.join(root, 'dist/decklight.js');
|
|
64
|
+
if (!existsSync(file)) return null;
|
|
65
|
+
const js = inlineRuntime(readFileSync(file, 'utf8'));
|
|
66
|
+
return { text: js, hash: sha256(js.trim()), version: runtimeVersion(js) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 1-based line of a byte offset — the coordinate a person can act on. */
|
|
70
|
+
const lineAt = (html, index) => html.slice(0, index).split('\n').length;
|
|
71
|
+
|
|
72
|
+
/** First non-blank line of a block, clipped — enough to recognise it by. */
|
|
73
|
+
function snippet(inner, max = 88) {
|
|
74
|
+
const line = inner.split('\n').map((l) => l.trim()).find(Boolean) ?? '';
|
|
75
|
+
return line.length > max ? line.slice(0, max - 1) + '…' : line;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A `<script>` whose entire body is one `Decklight.init(…)` call — the boot
|
|
80
|
+
* line every deck has, written by `init` and preserved by `bundle`.
|
|
81
|
+
*
|
|
82
|
+
* Matched by SHAPE, not by "mentions Decklight.init": `Decklight.init();
|
|
83
|
+
* fetch('//evil')` mentions it too. Comments and an optional assignment are
|
|
84
|
+
* allowed because that is what the scaffolder writes (`const deck =
|
|
85
|
+
* Decklight.init({…})`); anything after the call's closing paren is not.
|
|
86
|
+
*/
|
|
87
|
+
export function isBootCall(inner) {
|
|
88
|
+
const bare = inner
|
|
89
|
+
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
|
90
|
+
.replace(/(^|[^:])\/\/[^\n]*/g, '$1 ')
|
|
91
|
+
.trim();
|
|
92
|
+
const m = /^(?:(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*)?Decklight\s*\.\s*init\s*\(/.exec(bare);
|
|
93
|
+
if (!m) return false;
|
|
94
|
+
// Walk to the matching paren; whatever follows may be at most a semicolon.
|
|
95
|
+
// A greedy regex to the LAST ")" cannot do this job — `Decklight.init();
|
|
96
|
+
// fetch("//evil")` starts and ends exactly right — and a walker that does
|
|
97
|
+
// not know about strings flags `{ alt: "Acme (Inc)" }`, which is a false
|
|
98
|
+
// positive on a deck that did nothing wrong. So: strings are skipped.
|
|
99
|
+
let depth = 0;
|
|
100
|
+
for (let i = m[0].length - 1; i < bare.length; i++) {
|
|
101
|
+
const c = bare[i];
|
|
102
|
+
if (c === '"' || c === "'" || c === '`') {
|
|
103
|
+
for (i++; i < bare.length && bare[i] !== c; i++) if (bare[i] === '\\') i++;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (c === '(') depth++;
|
|
107
|
+
else if (c === ')' && --depth === 0) return /^\s*;?\s*$/.test(bare.slice(i + 1));
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Does this block define the runtime? (upgrade's fallback locator, verbatim.) */
|
|
113
|
+
const definesRuntime = (s) => /(?:\bvar\s+|\bwindow\.)Decklight\s*=/.test(s.inner);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Sort every `<script>` in `html` into what it is.
|
|
117
|
+
*
|
|
118
|
+
* kinds: `runtime` (inlined engine) · `runtime-src` (the engine by reference,
|
|
119
|
+
* a source deck) · `data` (`type="application/json"` — casts, viseme sidecars,
|
|
120
|
+
* voice manifests) · `template` (`type="text/template"` — never executed by any
|
|
121
|
+
* browser) · `boot` (the `Decklight.init` call) · `external` (someone else's
|
|
122
|
+
* `src=`) · `unaccounted` (executes, matches nothing above).
|
|
123
|
+
*/
|
|
124
|
+
export function classifyScripts(html) {
|
|
125
|
+
const all = scripts(html);
|
|
126
|
+
const marked = all.find((s) => /\bdata-decklight-runtime\b/i.test(s.attrs));
|
|
127
|
+
// Unmarked decks (bundle writes a bare <script>): the runtime is the block
|
|
128
|
+
// defining Decklight before the init call — upgrade's fallback, so the two
|
|
129
|
+
// commands always agree on which block is the engine.
|
|
130
|
+
let fallback = null;
|
|
131
|
+
if (!marked) {
|
|
132
|
+
const initAt = all.findIndex((s) =>
|
|
133
|
+
!/\bsrc\s*=/i.test(s.attrs) && /Decklight\.init\s*\(/.test(s.inner) && !definesRuntime(s));
|
|
134
|
+
for (let i = initAt - 1; i >= 0; i--) {
|
|
135
|
+
if (!/\bsrc\s*=/i.test(all[i].attrs) && definesRuntime(all[i])) { fallback = all[i]; break; }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const runtimeBlock = marked ?? fallback;
|
|
139
|
+
|
|
140
|
+
return all.map((s) => {
|
|
141
|
+
const type = /\btype\s*=\s*["']([^"']+)["']/i.exec(s.attrs)?.[1]?.toLowerCase() ?? '';
|
|
142
|
+
const src = /\bsrc\s*=\s*["']([^"']+)["']/i.exec(s.attrs)?.[1] ?? null;
|
|
143
|
+
// start/end are the block's byte range in `html` — carried so a caller can
|
|
144
|
+
// act on a block, not merely name it (PRESENT#STRICT splices on them).
|
|
145
|
+
const at = { line: lineAt(html, s.start), bytes: s.inner.length, start: s.start, end: s.end };
|
|
146
|
+
if (s === runtimeBlock) return { kind: 'runtime', ...at, inner: s.inner };
|
|
147
|
+
if (src) {
|
|
148
|
+
// a source deck loads dist/decklight.js by reference; anything else with
|
|
149
|
+
// a src is a third party and is named as one
|
|
150
|
+
return /(^|\/)decklight(\.min)?\.js(\?|#|$)/i.test(src)
|
|
151
|
+
? { kind: 'runtime-src', ...at, src }
|
|
152
|
+
: { kind: 'external', ...at, src, snippet: src };
|
|
153
|
+
}
|
|
154
|
+
// Data, not findings. A JSON block is inert until the runtime reads it —
|
|
155
|
+
// no browser executes it — so casts, visemes and voice manifests are
|
|
156
|
+
// inventory lines, never suspects.
|
|
157
|
+
if (type === 'application/json') return { kind: 'data', ...at, subtype: dataSubtype(s.attrs) };
|
|
158
|
+
if (type === 'text/template') return { kind: 'template', ...at };
|
|
159
|
+
// A type the browser does not recognise as JS is not executed either, but
|
|
160
|
+
// it is unusual enough in a deck to be worth naming rather than filing.
|
|
161
|
+
if (type && !/^(text\/javascript|application\/javascript|module)$/.test(type)) {
|
|
162
|
+
return { kind: 'unaccounted', ...at, snippet: `type="${type}" — ${snippet(s.inner)}` };
|
|
163
|
+
}
|
|
164
|
+
if (isBootCall(s.inner)) return { kind: 'boot', ...at };
|
|
165
|
+
return { kind: 'unaccounted', ...at, snippet: snippet(s.inner) };
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function dataSubtype(attrs) {
|
|
170
|
+
if (/\bdata-decklight-visemes\b/i.test(attrs)) return 'visemes';
|
|
171
|
+
if (/\bdata-decklight-voices\b/i.test(attrs)) return 'voice manifest';
|
|
172
|
+
return 'cast';
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Attributes whose value a browser treats as a URL to follow or load. */
|
|
176
|
+
const URL_ATTRS = /^(href|src|action|formaction|xlink:href|data)$/i;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The value the way a browser would read it before deciding what it is:
|
|
180
|
+
* character references decoded, then the whitespace and control characters
|
|
181
|
+
* browsers ignore inside a scheme dropped. `javascript:` and
|
|
182
|
+
* `java\tscript:` both resolve to `javascript:` in a browser, so they resolve
|
|
183
|
+
* to it here too — matching on spelling would be a scanner an attacker chooses
|
|
184
|
+
* the spelling for.
|
|
185
|
+
*/
|
|
186
|
+
function resolvedValue(value) {
|
|
187
|
+
const cp = (n) => (n >= 0 && n <= 0x10ffff ? String.fromCodePoint(n) : '');
|
|
188
|
+
const named = { lt: '<', gt: '>', quot: '"', apos: "'", amp: '&', colon: ':', semi: ';', tab: '\t', newline: '\n' };
|
|
189
|
+
return value
|
|
190
|
+
.replace(/&#x([0-9a-f]+);?/gi, (_, h) => cp(parseInt(h, 16)))
|
|
191
|
+
.replace(/&#(\d+);?/g, (_, d) => cp(Number(d)))
|
|
192
|
+
.replace(/&([a-z]+);/gi, (_, n) => named[n.toLowerCase()] ?? `&${n};`)
|
|
193
|
+
.replace(/[\u0000-\u0020]/g, '')
|
|
194
|
+
.toLowerCase();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Blank a block's inner text, length- and line-preserving, like maskComments. */
|
|
198
|
+
const blankInner = (html, re) =>
|
|
199
|
+
html.replace(re, (_, open, inner, close) => open + inner.replace(/[^\n]/g, ' ') + close);
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Executable ATTRIBUTES — what no `<script>` scan can see.
|
|
203
|
+
*
|
|
204
|
+
* `script-src 'unsafe-inline'` (which a bundled deck forces, cli/present.mjs)
|
|
205
|
+
* does not only permit script blocks: it is exactly what lets an inline
|
|
206
|
+
* `onerror=` handler or a `javascript:` href run too. A deck's canonical shape
|
|
207
|
+
* contains neither — content is markup, behaviour lives in the runtime — so
|
|
208
|
+
* every one found is named, the same way an unaccounted block is.
|
|
209
|
+
*
|
|
210
|
+
* Named, in the one scan the label and the stripper share (PRESENT#STRICT):
|
|
211
|
+
* - `on*` handler attributes carrying a value (`onerror=`, `onclick=`, …)
|
|
212
|
+
* - URL attributes (href, src, action, formaction, xlink:href, data) whose
|
|
213
|
+
* value resolves to `javascript:` or `data:text/html`
|
|
214
|
+
* - `srcdoc` — an inline document that inherits the deck's CSP, so script
|
|
215
|
+
* inside it runs under the same `'unsafe-inline'` that lets the deck boot
|
|
216
|
+
*
|
|
217
|
+
* Deliberately NOT named: a handler *mentioned* in prose, an HTML comment, an
|
|
218
|
+
* escaped code sample (`<img onerror=…>` never forms a tag), or the
|
|
219
|
+
* runtime's own strings. Everything that is not an attribute on a real tag is
|
|
220
|
+
* masked before the scan — a label that cried wolf on a slide ABOUT XSS would
|
|
221
|
+
* be turned off within a day. Still a heuristic over markup, like everything
|
|
222
|
+
* here: an inventory, never a verdict.
|
|
223
|
+
*/
|
|
224
|
+
export function executableAttributes(html) {
|
|
225
|
+
// Comments first (the same mask scripts() applies), then script and style
|
|
226
|
+
// text, so the tag walk below only ever reads markup. Every mask preserves
|
|
227
|
+
// length and line breaks, so offsets found here index the original file.
|
|
228
|
+
let masked = html.replace(/<!--[\s\S]*?-->/g, (m) => m.replace(/[^\n]/g, ' '));
|
|
229
|
+
masked = blankInner(masked, /(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi);
|
|
230
|
+
masked = blankInner(masked, /(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi);
|
|
231
|
+
|
|
232
|
+
const found = [];
|
|
233
|
+
const open = /<([a-zA-Z][^\s/>]*)/g;
|
|
234
|
+
let m;
|
|
235
|
+
while ((m = open.exec(masked))) {
|
|
236
|
+
// Walk to the tag's own `>` — quote-aware, because an attribute value may
|
|
237
|
+
// legitimately contain one (`data-chart` JSON does).
|
|
238
|
+
let i = m.index + m[0].length;
|
|
239
|
+
while (i < masked.length && masked[i] !== '>') {
|
|
240
|
+
const c = masked[i];
|
|
241
|
+
if (c === '"' || c === "'") {
|
|
242
|
+
i = masked.indexOf(c, i + 1);
|
|
243
|
+
if (i === -1) { i = masked.length; break; }
|
|
244
|
+
}
|
|
245
|
+
i++;
|
|
246
|
+
}
|
|
247
|
+
const attrsStart = m.index + m[0].length;
|
|
248
|
+
// Sequential, so a value is consumed by its own attribute's match and its
|
|
249
|
+
// contents are never re-read as attribute names — `alt="use onclick= here"`
|
|
250
|
+
// is one attribute, not two.
|
|
251
|
+
const attrRe = /([^\s"'<>/=]+)(\s*=\s*("([^"]*)"|'([^']*)'|[^\s>]*))?/g;
|
|
252
|
+
const attrsText = masked.slice(attrsStart, Math.min(i, masked.length));
|
|
253
|
+
let a;
|
|
254
|
+
while ((a = attrRe.exec(attrsText))) {
|
|
255
|
+
const name = a[1];
|
|
256
|
+
const value = a[4] ?? a[5] ?? a[3] ?? '';
|
|
257
|
+
const what =
|
|
258
|
+
/^on[a-z]+$/i.test(name) && a[2] !== undefined ? 'handler'
|
|
259
|
+
: URL_ATTRS.test(name) && /^(javascript:|data:text\/html)/.test(resolvedValue(value)) ? 'executable URL'
|
|
260
|
+
: /^srcdoc$/i.test(name) && value.trim() ? 'inline document'
|
|
261
|
+
: null;
|
|
262
|
+
if (!what) continue;
|
|
263
|
+
const start = attrsStart + a.index;
|
|
264
|
+
const end = start + a[0].length;
|
|
265
|
+
found.push({
|
|
266
|
+
kind: what, tag: m[1].toLowerCase(), attr: name.toLowerCase(),
|
|
267
|
+
line: lineAt(html, start), start, end, snippet: snippet(html.slice(start, end)),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
open.lastIndex = i + 1;
|
|
271
|
+
}
|
|
272
|
+
return found;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The whole label, as data. `present` prints it; `--check` exits on it.
|
|
277
|
+
*
|
|
278
|
+
* `runtime.state` is deliberately three-valued. A version this install does not
|
|
279
|
+
* have cannot be hash-checked here at all, and saying so is the honest answer —
|
|
280
|
+
* see the note on hashes in the PR: this package can only vouch for the build it
|
|
281
|
+
* ships, and inventing hashes for versions it has never seen would be the exact
|
|
282
|
+
* manufactured confidence the inventory refuses elsewhere.
|
|
283
|
+
*/
|
|
284
|
+
export function auditDeck(html, { installed = installedRuntime() } = {}) {
|
|
285
|
+
const blocks = classifyScripts(html);
|
|
286
|
+
const handlers = executableAttributes(html);
|
|
287
|
+
const rt = blocks.find((b) => b.kind === 'runtime');
|
|
288
|
+
const rtSrc = blocks.find((b) => b.kind === 'runtime-src');
|
|
289
|
+
const version = runtimeVersion(html);
|
|
290
|
+
|
|
291
|
+
let runtime;
|
|
292
|
+
if (rt) {
|
|
293
|
+
const hash = sha256(rt.inner.trim());
|
|
294
|
+
const state = !installed ? 'uncheckable'
|
|
295
|
+
: hash === installed.hash ? 'matches'
|
|
296
|
+
: version && installed.version && version !== installed.version ? 'other-version'
|
|
297
|
+
: 'differs';
|
|
298
|
+
runtime = { kind: 'inline', version, hash, state, installedVersion: installed?.version ?? null };
|
|
299
|
+
} else if (rtSrc) {
|
|
300
|
+
// A source deck's engine is a separate file this audit never sees. Naming
|
|
301
|
+
// that limit beats hashing the empty <script> tag and reporting a match.
|
|
302
|
+
runtime = { kind: 'external', version, src: rtSrc.src, state: 'not-inlined' };
|
|
303
|
+
} else {
|
|
304
|
+
runtime = { kind: 'missing', version, state: 'not-found' };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const count = (k) => blocks.filter((b) => b.kind === k).length;
|
|
308
|
+
return {
|
|
309
|
+
runtime,
|
|
310
|
+
themes: headStyles(html).filter((s) => /\bdata-theme\b/i.test(s.attrs)).length,
|
|
311
|
+
counts: {
|
|
312
|
+
runtime: count('runtime') + count('runtime-src'),
|
|
313
|
+
data: count('data'),
|
|
314
|
+
template: count('template'),
|
|
315
|
+
boot: count('boot'),
|
|
316
|
+
unaccounted: count('unaccounted') + count('external'),
|
|
317
|
+
handlers: handlers.length,
|
|
318
|
+
},
|
|
319
|
+
unaccounted: blocks.filter((b) => b.kind === 'unaccounted' || b.kind === 'external'),
|
|
320
|
+
handlers,
|
|
321
|
+
blocks,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The same inventory, with the unaccounted blocks taken out (PRESENT#STRICT).
|
|
327
|
+
*
|
|
328
|
+
* Pure: it takes HTML and returns HTML. Nothing here touches the filesystem,
|
|
329
|
+
* which is the whole design — `present` strips on the way OUT, so the deck you
|
|
330
|
+
* were sent is still the deck you were sent, byte for byte, and you can hand
|
|
331
|
+
* the same file to someone else or diff it against the original.
|
|
332
|
+
*
|
|
333
|
+
* What survives is exactly what the label calls accounted for: the runtime
|
|
334
|
+
* (inlined or by `src`), the `Decklight.init` boot call, JSON data blocks and
|
|
335
|
+
* templates. That set is not a convenience — it is what a deck needs to render
|
|
336
|
+
* itself. Builds, layouts, themes and `data-chart` JSON are markup and CSS and
|
|
337
|
+
* attributes, so they are never in the blast radius to begin with.
|
|
338
|
+
*
|
|
339
|
+
* What it removes is what `unaccounted` and `external` mean: a block that
|
|
340
|
+
* executes and matches nothing in the canonical shape. Each becomes a fixed
|
|
341
|
+
* comment of the same shape — fixed on purpose, since interpolating any of the
|
|
342
|
+
* removed bytes into the page is how a stripper hands the payload a second way
|
|
343
|
+
* in, and the terminal is where the details belong anyway (never the
|
|
344
|
+
* audience-facing page).
|
|
345
|
+
*
|
|
346
|
+
* Executable ATTRIBUTES go in the same pass, because the label names them
|
|
347
|
+
* (`executableAttributes` is the one scanner both share): an inline `onerror=`
|
|
348
|
+
* handler, a `javascript:` href, an inline `srcdoc` document. An attribute is
|
|
349
|
+
* spliced OUT of its tag with nothing in its place — a comment cannot live
|
|
350
|
+
* inside a tag, and the fixed-text rule holds either way: none of the removed
|
|
351
|
+
* bytes enter the page. Widening the label without this stripper (or the
|
|
352
|
+
* reverse) would let the printed inventory and the served bytes disagree,
|
|
353
|
+
* which is worse than a limit you can read — so they move together.
|
|
354
|
+
*
|
|
355
|
+
* The honest limit that remains: both are heuristics over markup. A parser
|
|
356
|
+
* trick this scan does not see is a parser trick strict serves, which is why
|
|
357
|
+
* the label is an inventory and never a verdict.
|
|
358
|
+
*/
|
|
359
|
+
export function stripUnaccounted(html) {
|
|
360
|
+
const blocks = classifyScripts(html);
|
|
361
|
+
const strippedBlocks = blocks.filter((b) => b.kind === 'unaccounted' || b.kind === 'external');
|
|
362
|
+
// An attribute inside a block that is going away rides out with the block's
|
|
363
|
+
// own splice — splicing its range a second time would corrupt what survives.
|
|
364
|
+
const attrs = executableAttributes(html)
|
|
365
|
+
.filter((a) => !strippedBlocks.some((b) => a.start >= b.start && a.end <= b.end));
|
|
366
|
+
const splices = [
|
|
367
|
+
...strippedBlocks.map((b) => ({
|
|
368
|
+
at: b, start: b.start, end: b.end,
|
|
369
|
+
insert: `<!-- decklight strict mode: script block removed (${b.bytes} B) -->`,
|
|
370
|
+
})),
|
|
371
|
+
...attrs.map((a) => ({ at: a, start: a.start, end: a.end, insert: '' })),
|
|
372
|
+
];
|
|
373
|
+
let out = html;
|
|
374
|
+
// Back to front: every splice changes the offsets after it, none before it.
|
|
375
|
+
for (const s of [...splices].sort((a, b) => b.start - a.start)) {
|
|
376
|
+
out = `${out.slice(0, s.start)}${s.insert}${out.slice(s.end)}`;
|
|
377
|
+
}
|
|
378
|
+
return { html: out, stripped: splices.sort((a, b) => a.start - b.start).map((s) => s.at) };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const RUNTIME_LINE = {
|
|
382
|
+
matches: (r) => `runtime ${r.version ?? '(unversioned)'} — sha256 ${r.hash.slice(0, 12)}, identical to this install`,
|
|
383
|
+
differs: (r) => `runtime ${r.version ?? '(unversioned)'} — sha256 ${r.hash.slice(0, 12)}, DIFFERS from this install's build of ${r.installedVersion}`,
|
|
384
|
+
'other-version': (r) => `runtime ${r.version} — sha256 ${r.hash.slice(0, 12)}, not comparable here (this install ships ${r.installedVersion})`,
|
|
385
|
+
uncheckable: (r) => `runtime ${r.version ?? '(unversioned)'} — sha256 ${r.hash.slice(0, 12)}, no installed build to compare against`,
|
|
386
|
+
'not-inlined': (r) => `runtime ${r.version ?? '(unknown version)'} — loaded from ${r.src}, not inlined, so not hashed here`,
|
|
387
|
+
'not-found': () => 'no decklight runtime found in this file',
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/** The printed label: plain lines, no verdict, caller decides where they go. */
|
|
391
|
+
export function formatLabel(report, { indent = ' ' } = {}) {
|
|
392
|
+
const { counts, unaccounted, handlers } = report;
|
|
393
|
+
const lines = [`${indent}ingredients — what this file will execute`];
|
|
394
|
+
lines.push(`${indent} ${RUNTIME_LINE[report.runtime.state](report.runtime)}`);
|
|
395
|
+
|
|
396
|
+
const inert = [];
|
|
397
|
+
if (counts.data) inert.push(`${counts.data} data block${counts.data === 1 ? '' : 's'}`);
|
|
398
|
+
if (report.themes) inert.push(`${report.themes} theme style${report.themes === 1 ? '' : 's'}`);
|
|
399
|
+
if (counts.template) inert.push(`${counts.template} template${counts.template === 1 ? '' : 's'}`);
|
|
400
|
+
if (counts.boot) inert.push(`${counts.boot} Decklight.init call`);
|
|
401
|
+
if (inert.length) lines.push(`${indent} ${inert.join(' · ')} — read by the runtime, not executed as script`);
|
|
402
|
+
|
|
403
|
+
if (!counts.unaccounted) {
|
|
404
|
+
lines.push(`${indent} 0 unaccounted script blocks`);
|
|
405
|
+
} else {
|
|
406
|
+
lines.push(`${indent} ${counts.unaccounted} unaccounted script block${counts.unaccounted === 1 ? '' : 's'} — this file runs code that is not the runtime:`);
|
|
407
|
+
for (const b of unaccounted) {
|
|
408
|
+
const size = b.src ? `src=${b.src}` : `${b.bytes} B`;
|
|
409
|
+
lines.push(`${indent} line ${String(b.line).padStart(5)} ${size.padEnd(10)} ${b.snippet}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// Attributes are the other executable surface `script-src 'unsafe-inline'`
|
|
413
|
+
// lets through, and the zero line is as load-bearing as the findings: it is
|
|
414
|
+
// what says this class of content was examined at all.
|
|
415
|
+
if (!counts.handlers) {
|
|
416
|
+
lines.push(`${indent} 0 inline handlers or executable URLs in attributes`);
|
|
417
|
+
} else {
|
|
418
|
+
lines.push(`${indent} ${counts.handlers} executable attribute${counts.handlers === 1 ? '' : 's'} — this file runs code outside any script block:`);
|
|
419
|
+
for (const h of handlers) {
|
|
420
|
+
lines.push(`${indent} line ${String(h.line).padStart(5)} ${`<${h.tag}>`.padEnd(10)} ${h.snippet}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return lines;
|
|
424
|
+
}
|