@mouryaamit/nx-polystack 1.2.2 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/src/cli/commands/csp.d.ts +8 -0
  2. package/dist/src/cli/commands/csp.js +74 -3
  3. package/dist/src/cli/commands/csp.js.map +1 -1
  4. package/dist/src/cli/help.js +3 -0
  5. package/dist/src/cli/help.js.map +1 -1
  6. package/dist/src/cli/launcher.js +1 -1
  7. package/dist/src/cli/launcher.js.map +1 -1
  8. package/dist/src/executors/build/executor.js +36 -5
  9. package/dist/src/executors/build/executor.js.map +1 -1
  10. package/dist/src/executors/build/schema.d.ts +7 -0
  11. package/dist/src/executors/build/schema.json +41 -1
  12. package/dist/src/executors/flutter-build/executor.js +21 -0
  13. package/dist/src/executors/flutter-build/executor.js.map +1 -1
  14. package/dist/src/executors/flutter-build/schema.d.ts +2 -0
  15. package/dist/src/executors/flutter-build/schema.json +5 -0
  16. package/dist/src/generators/app/files/angular/server/README.md__template__ +3 -1
  17. package/dist/src/lib/csp/allowlist.d.ts +17 -0
  18. package/dist/src/lib/csp/allowlist.js +117 -3
  19. package/dist/src/lib/csp/allowlist.js.map +1 -1
  20. package/dist/src/lib/csp/import.js +21 -3
  21. package/dist/src/lib/csp/import.js.map +1 -1
  22. package/dist/src/lib/csp/render.d.ts +10 -5
  23. package/dist/src/lib/csp/render.js +72 -22
  24. package/dist/src/lib/csp/render.js.map +1 -1
  25. package/dist/src/lib/hardening/strip.d.ts +1 -0
  26. package/dist/src/lib/hardening/strip.js +3 -3
  27. package/dist/src/lib/hardening/strip.js.map +1 -1
  28. package/dist/src/lib/helpers/inject-nonce.d.ts +36 -5
  29. package/dist/src/lib/helpers/inject-nonce.js +155 -41
  30. package/dist/src/lib/helpers/inject-nonce.js.map +1 -1
  31. package/dist/src/lib/helpers/inject-sri.d.ts +8 -0
  32. package/dist/src/lib/helpers/inject-sri.js +72 -56
  33. package/dist/src/lib/helpers/inject-sri.js.map +1 -1
  34. package/dist/src/lib/helpers/strip-exif.d.ts +20 -2
  35. package/dist/src/lib/helpers/strip-exif.js +25 -5
  36. package/dist/src/lib/helpers/strip-exif.js.map +1 -1
  37. package/dist/src/lib/html/tags.d.ts +42 -0
  38. package/dist/src/lib/html/tags.js +173 -0
  39. package/dist/src/lib/html/tags.js.map +1 -0
  40. package/package.json +1 -1
@@ -1,59 +1,173 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.injectCspNonce = exports.NONCE_SSI_PLACEHOLDER = void 0;
3
+ exports.injectCspNonce = exports.injectNonceIntoHtml = exports.resolveNonceSettings = exports.DEFAULT_NONCE_FILES = exports.NONCE_SSI_PLACEHOLDER = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs"));
6
6
  const path = tslib_1.__importStar(require("path"));
7
+ const files_1 = require("../hardening/files");
8
+ const strip_1 = require("../hardening/strip");
9
+ const tags_1 = require("../html/tags");
7
10
  /** Filled per request by the server config `pstack csp` writes (Apache SSI, Nginx sub_filter). */
8
11
  exports.NONCE_SSI_PLACEHOLDER = '<!--#echo var="CSP_NONCE" -->';
12
+ exports.DEFAULT_NONCE_FILES = ['index.html'];
9
13
  /** Nonce values left in a page by hand that stand for "fill me in" (as runtime/csp-nonce reads them). */
10
14
  const PLACEHOLDER_NONCE = /((?<![\w-])nonce\s*=\s*)(["'])(random-csp-nonce|nonce|csp-nonce|\{\{[^"']*\}\}|\$\{[^"']*\}|%[^"']*%)\2/gi;
15
+ /**
16
+ * Checks the nonce settings of a release target; throws naming the option. Returns them with the
17
+ * defaults filled in.
18
+ */
19
+ function resolveNonceSettings(raw) {
20
+ const s = raw ?? {};
21
+ if (typeof s !== 'object' || Array.isArray(s))
22
+ throw new Error('nonce must be an object');
23
+ const placeholder = s.placeholder ?? exports.NONCE_SSI_PLACEHOLDER;
24
+ if (typeof placeholder !== 'string' || !placeholder.trim() || /[\r\n]/.test(placeholder)) {
25
+ throw new Error('nonce.placeholder must be one non-empty line');
26
+ }
27
+ const tags = s.tags ?? 'all';
28
+ if (tags !== 'all' && tags !== 'legacy')
29
+ throw new Error('nonce.tags must be "all" or "legacy"');
30
+ const position = s.position ?? 'end';
31
+ if (position !== 'end' && position !== 'after-tag-name') {
32
+ throw new Error('nonce.position must be "end" or "after-tag-name"');
33
+ }
34
+ const replaceTokens = s.replaceTokens ?? [];
35
+ if (!Array.isArray(replaceTokens) ||
36
+ !replaceTokens.every((t) => typeof t === 'string' && /^[A-Za-z0-9_-]{4,}$/.test(t))) {
37
+ throw new Error('nonce.replaceTokens must be a list of tokens (letters, digits, _ and -, at least 4)');
38
+ }
39
+ const files = s.files ?? exports.DEFAULT_NONCE_FILES;
40
+ if (!Array.isArray(files) || files.length === 0) {
41
+ throw new Error('nonce.files must be a non-empty list of .html files');
42
+ }
43
+ for (const f of files) {
44
+ const norm = typeof f === 'string' ? path.posix.normalize(f.replace(/\\/g, '/')) : '';
45
+ if (!norm.endsWith('.html') ||
46
+ norm.startsWith('/') ||
47
+ norm.startsWith('..') ||
48
+ norm === 'assets' ||
49
+ norm.startsWith('assets/')) {
50
+ throw new Error(`nonce.files: "${f}" must be an .html file under the served root, not under assets/`);
51
+ }
52
+ }
53
+ return {
54
+ placeholder,
55
+ tags,
56
+ position,
57
+ replaceTokens,
58
+ addMeta: s.addMeta ?? true,
59
+ files,
60
+ stripComments: s.stripComments ?? false,
61
+ };
62
+ }
63
+ exports.resolveNonceSettings = resolveNonceSettings;
64
+ function wantsNonce(tag, mode) {
65
+ if (tag.name === 'style')
66
+ return true;
67
+ if (tag.name === 'script')
68
+ return mode === 'all' || !(0, tags_1.attr)(tag, 'src');
69
+ if (tag.name === 'link') {
70
+ if (mode === 'legacy')
71
+ return true;
72
+ return /(^|\s)stylesheet(\s|$)/i.test((0, tags_1.attr)(tag, 'rel')?.value ?? '');
73
+ }
74
+ return false;
75
+ }
76
+ /** The quote character of the string the text at `at` sits in on its line, if any. */
77
+ function enclosingQuote(text, at, length) {
78
+ const lineStart = text.lastIndexOf('\n', at - 1) + 1;
79
+ let lineEnd = text.indexOf('\n', at + length);
80
+ if (lineEnd < 0)
81
+ lineEnd = text.length;
82
+ const before = text.slice(lineStart, at);
83
+ const after = text.slice(at + length, lineEnd);
84
+ // The nearest quote before the token is open when it appears an odd number of times before it
85
+ // and closes after it on the same line.
86
+ let best;
87
+ for (const q of ['"', "'", '`']) {
88
+ const pos = before.lastIndexOf(q);
89
+ if (pos < 0 || before.split(q).length % 2 !== 0 || !after.includes(q))
90
+ continue;
91
+ if (!best || pos > best.pos)
92
+ best = { q, pos };
93
+ }
94
+ return best?.q;
95
+ }
96
+ /**
97
+ * Replaces every whole token by the placeholder in one pass (a token is not matched inside a
98
+ * longer word or inside text an earlier replacement inserted); refuses a token inside quotes that
99
+ * the placeholder also uses, as the replaced text would end that string.
100
+ */
101
+ function replaceTokens(html, tokens, placeholder, file) {
102
+ if (tokens.length === 0)
103
+ return html;
104
+ const alternation = [...tokens]
105
+ .sort((a, b) => b.length - a.length)
106
+ .map((t) => t.replace(/[-]/g, '\\-'))
107
+ .join('|');
108
+ const re = new RegExp(`(?<![A-Za-z0-9_-])(?:${alternation})(?![A-Za-z0-9_-])`, 'g');
109
+ return html.replace(re, (token, at) => {
110
+ const q = enclosingQuote(html, at, token.length);
111
+ if (q && placeholder.includes(q)) {
112
+ const line = html.slice(0, at).split('\n').length;
113
+ throw new Error(`${file}:${line}: "${token}" is inside ${q}…${q}, and the nonce placeholder ` +
114
+ `${placeholder} holds ${q}: the replaced text would end that string. Change the ` +
115
+ 'quotes in the page or nonce.placeholder.');
116
+ }
117
+ return placeholder;
118
+ });
119
+ }
120
+ /** The page with the nonce placeholder where the settings say. */
121
+ function injectNonceIntoHtml(input, settings, file = 'index.html') {
122
+ let html = settings.stripComments ? (0, strip_1.stripHtmlComments)(input) : input;
123
+ // Placeholder nonces already in the page get the server-filled one (double-quoted) first, so a
124
+ // nonce='random-csp-nonce' attribute is never seen as a token in single quotes.
125
+ html = html.replace(PLACEHOLDER_NONCE, (_m, a) => `${a}"${settings.placeholder}"`);
126
+ html = replaceTokens(html, settings.replaceTokens, settings.placeholder, file);
127
+ const insertions = [];
128
+ const nonceAttr = `nonce="${settings.placeholder}"`;
129
+ for (const tag of (0, tags_1.scanTags)(html)) {
130
+ if (!wantsNonce(tag, settings.tags) || (0, tags_1.attr)(tag, 'nonce'))
131
+ continue;
132
+ insertions.push(settings.position === 'after-tag-name'
133
+ ? { at: tag.nameEnd, text: ` ${nonceAttr}` }
134
+ : { at: tag.attrsEnd, text: ` ${nonceAttr}` });
135
+ }
136
+ html = (0, tags_1.applyInsertions)(html, insertions);
137
+ if (settings.addMeta && !/property="csp-nonce"/.test(html)) {
138
+ const head = (0, tags_1.scanTags)(html).find((t) => t.name === 'head');
139
+ if (head) {
140
+ const meta = `<meta property="csp-nonce" content="${settings.placeholder}">`;
141
+ html = (0, tags_1.applyInsertions)(html, [{ at: head.end, text: `\n ${meta}` }]);
142
+ }
143
+ }
144
+ return html;
145
+ }
146
+ exports.injectNonceIntoHtml = injectNonceIntoHtml;
147
+ /**
148
+ * Writes the nonce placeholder into the served pages (index.html by default) under distDir's
149
+ * served root. Nothing else is touched: third-party pages under assets/ are never served through
150
+ * SSI, so a placeholder there would stay raw.
151
+ */
11
152
  function injectCspNonce(opts) {
12
153
  if (!fs.existsSync(opts.distDir)) {
13
154
  throw new Error(`injectCspNonce: distDir not found: ${opts.distDir}`);
14
155
  }
15
- for (const htmlFile of walkHtml(opts.distDir)) {
16
- let html = fs.readFileSync(htmlFile, 'utf8');
17
- // Placeholder nonces already in the page get the server-filled one too.
18
- html = html.replace(PLACEHOLDER_NONCE, (_m, attr) => `${attr}"${exports.NONCE_SSI_PLACEHOLDER}"`);
19
- // Add nonce to <script> tags (with or without src)
20
- html = html.replace(/<script\b((?:[^>]*?)?)>/g, (full, attrs) => {
21
- if (/(?<![\w-])nonce\s*=/.test(attrs))
22
- return full;
23
- const trimmed = attrs.trimEnd();
24
- return `<script${trimmed ? trimmed : ''} nonce="${exports.NONCE_SSI_PLACEHOLDER}">`;
25
- });
26
- // Add nonce to <style> tags
27
- html = html.replace(/<style\b((?:[^>]*?)?)>/g, (full, attrs) => {
28
- if (/(?<![\w-])nonce\s*=/.test(attrs))
29
- return full;
30
- const trimmed = attrs.trimEnd();
31
- return `<style${trimmed ? trimmed : ''} nonce="${exports.NONCE_SSI_PLACEHOLDER}">`;
32
- });
33
- // Add nonce to <link rel="stylesheet"> tags
34
- html = html.replace(/<link\b((?:[^>]*?)\brel\s*=\s*["']stylesheet["'](?:[^>]*?))>/g, (full, attrs) => {
35
- if (/(?<![\w-])nonce\s*=/.test(attrs))
36
- return full;
37
- return `<link${attrs} nonce="${exports.NONCE_SSI_PLACEHOLDER}">`;
38
- });
39
- // Add <meta property="csp-nonce"> inside <head>
40
- if (!/property="csp-nonce"/.test(html)) {
41
- const metaTag = `<meta property="csp-nonce" content="${exports.NONCE_SSI_PLACEHOLDER}">`;
42
- if (/<head[^>]*>/i.test(html)) {
43
- html = html.replace(/<head([^>]*)>/i, `<head$1>\n ${metaTag}`);
44
- }
156
+ const settings = resolveNonceSettings(opts);
157
+ const root = (0, files_1.servedRoot)(opts.distDir);
158
+ const written = [];
159
+ for (const rel of settings.files) {
160
+ const file = path.join(root, rel);
161
+ if (!fs.existsSync(file))
162
+ continue;
163
+ const html = fs.readFileSync(file, 'utf8');
164
+ const out = injectNonceIntoHtml(html, settings, rel);
165
+ if (out !== html) {
166
+ fs.writeFileSync(file, out, 'utf8');
167
+ written.push(rel);
45
168
  }
46
- fs.writeFileSync(htmlFile, html, 'utf8');
47
169
  }
170
+ return written;
48
171
  }
49
172
  exports.injectCspNonce = injectCspNonce;
50
- function* walkHtml(dir) {
51
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
52
- const full = path.join(dir, entry.name);
53
- if (entry.isDirectory())
54
- yield* walkHtml(full);
55
- else if (entry.isFile() && full.endsWith('.html'))
56
- yield full;
57
- }
58
- }
59
173
  //# sourceMappingURL=inject-nonce.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inject-nonce.js","sourceRoot":"","sources":["../../../../src/lib/helpers/inject-nonce.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAO7B,kGAAkG;AACrF,QAAA,qBAAqB,GAAG,+BAA+B,CAAC;AAErE,yGAAyG;AACzG,MAAM,iBAAiB,GACrB,2GAA2G,CAAC;AAE9G,SAAgB,cAAc,CAAC,IAAwB;IACrD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,sCAAsC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;KACvE;IACD,KAAK,MAAM,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QAC7C,IAAI,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE7C,wEAAwE;QACxE,IAAI,GAAG,IAAI,CAAC,OAAO,CACjB,iBAAiB,EACjB,CAAC,EAAE,EAAE,IAAY,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,6BAAqB,GAAG,CAC1D,CAAC;QAEF,mDAAmD;QACnD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC9D,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;YACnD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;YAChC,OAAO,UAAU,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,6BAAqB,IAAI,CAAC;QAC9E,CAAC,CAAC,CAAC;QAEH,4BAA4B;QAC5B,IAAI,GAAG,IAAI,CAAC,O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C,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAS;QACnC,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3C,MAAM,GAAG,GAAG,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QACrD,IAAI,GAAG,KAAK,IAAI,EAAE;YAChB,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;YACpC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACnB;KACF;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAlBD,wCAkBC"}
@@ -7,5 +7,13 @@ export interface InjectSriOptions {
7
7
  * were stripped or obfuscated). Default false: tags that have one are left alone.
8
8
  */
9
9
  refresh?: boolean;
10
+ /** Pages to rewrite, relative to the served root (default ["index.html"]); assets/ never. */
11
+ files?: string[];
10
12
  }
13
+ /**
14
+ * Adds integrity/crossorigin to the scripts and stylesheets of the served pages (index.html by
15
+ * default) under distDir's served root, and with refresh recomputes integrity Angular wrote. Tags
16
+ * are parsed (quotes and SSI directives respected) and edited in place: nothing else in a tag
17
+ * moves.
18
+ */
11
19
  export declare function injectSri(opts: InjectSriOptions): void;
@@ -5,69 +5,94 @@ const tslib_1 = require("tslib");
5
5
  const crypto = tslib_1.__importStar(require("crypto"));
6
6
  const fs = tslib_1.__importStar(require("fs"));
7
7
  const path = tslib_1.__importStar(require("path"));
8
+ const files_1 = require("../hardening/files");
9
+ const tags_1 = require("../html/tags");
10
+ const inject_nonce_1 = require("./inject-nonce");
11
+ const isRemote = (url) => /^(?:[a-z]+:)?\/\//i.test(url) || /^[a-z]+:/i.test(url);
12
+ /**
13
+ * Adds integrity/crossorigin to the scripts and stylesheets of the served pages (index.html by
14
+ * default) under distDir's served root, and with refresh recomputes integrity Angular wrote. Tags
15
+ * are parsed (quotes and SSI directives respected) and edited in place: nothing else in a tag
16
+ * moves.
17
+ */
8
18
  function injectSri(opts) {
9
19
  if (!fs.existsSync(opts.distDir)) {
10
20
  throw new Error(`injectSri: distDir not found: ${opts.distDir}`);
11
21
  }
12
22
  const allowlist = new Set(opts.cdnAllowlist);
13
- for (const htmlFile of walkHtml(opts.distDir)) {
14
- let html = fs.readFileSync(htmlFile, 'utf8');
15
- if (opts.refresh) {
16
- html = refreshIntegrity(html, htmlFile, opts.distDir);
17
- }
18
- // <script src="...">
19
- html = html.replace(/<script\b([^>]*?)\bsrc\s*=\s*["']([^"']+)["']([^>]*)>/g, (full, before, src, after) => {
20
- if (/\bintegrity\s*=/.test(full))
21
- return full;
22
- const hash = resolveHash(src, htmlFile, opts.distDir, allowlist);
23
- if (!hash)
24
- return full;
25
- return `<script${before} src="${src}" integrity="${hash}" crossorigin="anonymous"${after}>`;
26
- });
27
- // <link rel="stylesheet" href="...">
28
- html = html.replace(/<link\b([^>]*?\brel\s*=\s*["']stylesheet["'][^>]*?\bhref\s*=\s*["']([^"']+)["'][^>]*)>/g, (full, allAttrs, href) => {
29
- if (/\bintegrity\s*=/.test(full))
30
- return full;
31
- const hash = resolveHash(href, htmlFile, opts.distDir, allowlist);
32
- if (!hash)
33
- return full;
34
- return `<link${allAttrs.replace(href, href)} integrity="${hash}" crossorigin="anonymous">`;
35
- });
36
- fs.writeFileSync(htmlFile, html, 'utf8');
23
+ const root = (0, files_1.servedRoot)(opts.distDir);
24
+ let files;
25
+ try {
26
+ files = (0, inject_nonce_1.resolveNonceSettings)({ files: opts.files ?? inject_nonce_1.DEFAULT_NONCE_FILES }).files;
27
+ }
28
+ catch (err) {
29
+ throw new Error(`injectSri: ${err.message.replace('nonce.files', 'files')}`);
30
+ }
31
+ for (const rel of files) {
32
+ const htmlFile = path.join(root, rel);
33
+ if (!fs.existsSync(htmlFile))
34
+ continue;
35
+ const html = fs.readFileSync(htmlFile, 'utf8');
36
+ const out = sriHtml(html, htmlFile, opts.distDir, allowlist, opts.refresh ?? false);
37
+ if (out !== html)
38
+ fs.writeFileSync(htmlFile, out, 'utf8');
37
39
  }
38
40
  }
39
41
  exports.injectSri = injectSri;
40
- /** Recomputes integrity="…" on script/link tags whose src/href is a local file. */
41
- function refreshIntegrity(html, htmlFile, distDir) {
42
- return html.replace(/<(script|link)\b[^>]*>/gi, (tag) => {
43
- if (!/\bintegrity\s*=/i.test(tag))
44
- return tag;
45
- const url = /\b(?:src|href)\s*=\s*["']([^"']+)["']/i.exec(tag)?.[1];
46
- if (!url || /^(?:[a-z]+:)?\/\//i.test(url) || /^[a-z]+:/i.test(url))
47
- return tag;
48
- const hash = resolveHash(url, htmlFile, distDir, new Set());
49
- // A stale hash makes the browser refuse the file: fail instead of shipping it.
50
- if (!hash) {
51
- throw new Error(`injectSri: ${path.basename(htmlFile)} has an integrity for ${url}, which is not a file ` +
52
- 'under the output; its hash cannot be refreshed (a deployUrl is not supported with sri)');
42
+ function sriHtml(html, htmlFile, distDir, allowlist, refresh) {
43
+ const edits = [];
44
+ for (const tag of (0, tags_1.scanTags)(html)) {
45
+ if (tag.name !== 'script' && tag.name !== 'link')
46
+ continue;
47
+ const urlAttr = (0, tags_1.attr)(tag, tag.name === 'script' ? 'src' : 'href');
48
+ const url = urlAttr?.value;
49
+ if (!urlAttr || !url)
50
+ continue;
51
+ const integrity = (0, tags_1.attr)(tag, 'integrity');
52
+ const crossorigin = (0, tags_1.attr)(tag, 'crossorigin');
53
+ if (integrity) {
54
+ if (!refresh || isRemote(url))
55
+ continue;
56
+ const hash = resolveHash(url, htmlFile, distDir, new Set());
57
+ // A stale hash makes the browser refuse the file: fail instead of shipping it.
58
+ if (!hash) {
59
+ throw new Error(`injectSri: ${path.basename(htmlFile)} has an integrity for ${url}, which is not a file ` +
60
+ 'under the output; its hash cannot be refreshed (a deployUrl is not supported with sri)');
61
+ }
62
+ edits.push({ start: integrity.start, end: integrity.end, text: `integrity="${hash}"` });
63
+ if (!crossorigin) {
64
+ edits.push({ start: tag.attrsEnd, end: tag.attrsEnd, text: ' crossorigin="anonymous"' });
65
+ }
66
+ continue;
53
67
  }
54
- const updated = tag.replace(/\bintegrity\s*=\s*["'][^"']*["']/i, `integrity="${hash}"`);
55
- return /\bcrossorigin\b/i.test(updated)
56
- ? updated
57
- : updated.replace(/\s*\/?>$/, (end) => ` crossorigin="anonymous"${end}`);
58
- });
68
+ if (tag.name === 'link' && !/(^|\s)stylesheet(\s|$)/i.test((0, tags_1.attr)(tag, 'rel')?.value ?? '')) {
69
+ continue;
70
+ }
71
+ const hash = resolveHash(url, htmlFile, distDir, allowlist);
72
+ if (!hash)
73
+ continue;
74
+ const added = ` integrity="${hash}"${crossorigin ? '' : ' crossorigin="anonymous"'}`;
75
+ // Scripts: right after src (as before); links: after the last attribute.
76
+ const at = tag.name === 'script' ? urlAttr.end : tag.attrsEnd;
77
+ edits.push({ start: at, end: at, text: added });
78
+ }
79
+ let out = html;
80
+ for (const e of edits.sort((a, b) => b.start - a.start || b.end - a.end)) {
81
+ out = out.slice(0, e.start) + e.text + out.slice(e.end);
82
+ }
83
+ return out;
59
84
  }
60
85
  function resolveHash(src, htmlFile, distDir, allowlist) {
61
86
  const isExternal = /^https?:\/\//.test(src);
62
87
  if (isExternal) {
63
88
  if (!allowlist.has(src))
64
89
  return null;
65
- // Try to find a local mirror next to index.html
90
+ // A local mirror next to the page (the served root), else at the top of the output.
66
91
  const basename = src.split('/').pop() ?? '';
67
- const local = path.join(distDir, basename);
68
- if (!fs.existsSync(local))
69
- return null;
70
- return sha384(local);
92
+ const local = [path.dirname(htmlFile), distDir]
93
+ .map((d) => path.join(d, basename))
94
+ .find((f) => basename && fs.existsSync(f));
95
+ return local ? sha384(local) : null;
71
96
  }
72
97
  const local = path.resolve(path.dirname(htmlFile), src);
73
98
  const resolved = path.resolve(distDir);
@@ -80,13 +105,4 @@ function sha384(file) {
80
105
  const digest = crypto.createHash('sha384').update(buf).digest('base64');
81
106
  return `sha384-${digest}`;
82
107
  }
83
- function* walkHtml(dir) {
84
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
85
- const full = path.join(dir, entry.name);
86
- if (entry.isDirectory())
87
- yield* walkHtml(full);
88
- else if (entry.isFile() && full.endsWith('.html'))
89
- yield full;
90
- }
91
- }
92
108
  //# sourceMappingURL=inject-sri.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inject-sri.js","sourceRoot":"","sources":["../../../../src/lib/helpers/inject-sri.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,+CAAyB;AACzB,mDAA6B;AAa7B,SAAgB,SAAS,CAAC,IAAsB;IAC9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;KAClE;IACD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAE7C,KAAK,MAAM,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QAC7C,IAAI,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE7C,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,GAAG,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;SACvD;QAED,qBAAqB;QACrB,IAAI,GAAG,IAAI,CAAC,OAAO,CACjB,wDAAwD,EACxD,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;YAC3B,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC9C,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;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AE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxE,OAAO,UAAU,MAAM,EAAE,CAAC;AAC5B,CAAC"}
@@ -1,9 +1,27 @@
1
1
  export interface StripExifOptions {
2
2
  /** Recursive root directory to scan for image files. */
3
3
  rootDir: string;
4
- /** JPEG output quality. Default 90. */
4
+ /** JPEG and WebP output quality for images that are re-encoded. Default 90. */
5
5
  jpegQuality?: number;
6
6
  /** Optional logger; defaults to no-op. */
7
7
  log?: (msg: string) => void;
8
8
  }
9
- export declare function stripExif(opts: StripExifOptions): Promise<void>;
9
+ export interface StripExifResult {
10
+ /** Image files looked at (.jpg, .jpeg, .png, .webp). */
11
+ scanned: number;
12
+ /** Files that had EXIF and were re-encoded without it. */
13
+ stripped: number;
14
+ /** Files without EXIF, left byte-identical. */
15
+ unchanged: number;
16
+ /** Files sharp could not read or write (logged, left as they were). */
17
+ skipped: number;
18
+ }
19
+ /**
20
+ * Removes EXIF from the images under `rootDir`. Only images that carry EXIF are re-encoded (sharp
21
+ * drops metadata unless `withMetadata()` is used); every other image is not written, so its bytes
22
+ * and mtime stay as they were. A stripped image is rotated to its EXIF orientation first, so it
23
+ * still displays the same way once the orientation tag is gone.
24
+ */
25
+ export declare function stripExif(opts: StripExifOptions): Promise<StripExifResult>;
26
+ /** One line for the build log: `strip-exif: 1113 scanned, 222 stripped, 891 unchanged, 0 skipped`. */
27
+ export declare function stripExifSummary(r: StripExifResult): string;
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stripExif = void 0;
3
+ exports.stripExifSummary = exports.stripExif = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs"));
6
6
  const path = tslib_1.__importStar(require("path"));
7
7
  // eslint-disable-next-line @typescript-eslint/no-var-requires
8
8
  const sharp = require('sharp');
9
9
  const SUPPORTED_EXTS = new Set(['.jpg', '.jpeg', '.png', '.webp']);
10
+ /**
11
+ * Removes EXIF from the images under `rootDir`. Only images that carry EXIF are re-encoded (sharp
12
+ * drops metadata unless `withMetadata()` is used); every other image is not written, so its bytes
13
+ * and mtime stay as they were. A stripped image is rotated to its EXIF orientation first, so it
14
+ * still displays the same way once the orientation tag is gone.
15
+ */
10
16
  async function stripExif(opts) {
11
17
  if (!fs.existsSync(opts.rootDir)) {
12
18
  throw new Error(`stripExif: rootDir not found: ${opts.rootDir}`);
@@ -16,30 +22,44 @@ async function stripExif(opts) {
16
22
  /* no-op */
17
23
  });
18
24
  const quality = opts.jpegQuality ?? 90;
25
+ const result = { scanned: 0, stripped: 0, unchanged: 0, skipped: 0 };
19
26
  for (const file of walk(opts.rootDir)) {
20
27
  const ext = path.extname(file).toLowerCase();
21
28
  if (!SUPPORTED_EXTS.has(ext))
22
29
  continue;
30
+ result.scanned++;
23
31
  try {
24
32
  const buf = fs.readFileSync(file);
33
+ const meta = await sharp(buf, { failOn: 'none' }).metadata();
34
+ if (!meta.exif || meta.exif.length === 0) {
35
+ result.unchanged++;
36
+ continue;
37
+ }
25
38
  let pipeline = sharp(buf, { failOn: 'none' }).rotate();
26
- if (ext === '.jpg' || ext === '.jpeg')
27
- pipeline = pipeline.jpeg({ quality });
28
- else if (ext === '.png')
39
+ if (ext === '.png')
29
40
  pipeline = pipeline.png();
30
41
  else if (ext === '.webp')
31
42
  pipeline = pipeline.webp({ quality });
32
- // sharp drops EXIF/IPTC/XMP by default when re-encoding; no withMetadata() needed
43
+ else
44
+ pipeline = pipeline.jpeg({ quality });
33
45
  const out = await pipeline.toBuffer();
34
46
  fs.writeFileSync(file, out);
47
+ result.stripped++;
35
48
  log(`stripped: ${file}`);
36
49
  }
37
50
  catch (e) {
51
+ result.skipped++;
38
52
  log(`skipped (error): ${file} — ${e.message}`);
39
53
  }
40
54
  }
55
+ return result;
41
56
  }
42
57
  exports.stripExif = stripExif;
58
+ /** One line for the build log: `strip-exif: 1113 scanned, 222 stripped, 891 unchanged, 0 skipped`. */
59
+ function stripExifSummary(r) {
60
+ return `strip-exif: ${r.scanned} scanned, ${r.stripped} stripped, ${r.unchanged} unchanged, ${r.skipped} skipped`;
61
+ }
62
+ exports.stripExifSummary = stripExifSummary;
43
63
  function* walk(dir) {
44
64
  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
45
65
  const full = path.join(dir, entry.name);
@@ -1 +1 @@
1
- {"version":3,"file":"strip-exif.js","sourceRoot":"","sources":["../../../../src/lib/helpers/strip-exif.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAa7B,8DAA8D;AAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAkE,CAAC;AAWhG,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE5D,KAAK,UAAU,SAAS,CAAC,IAAsB;IACpD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;KAClE;IACD,MAAM,GAAG,GACP,IAAI,CAAC,GAAG;QACR,CAAC,GAAG,EAAE;YACJ,WAAW;QACb,CAAC,CAAC,CAAC;IACL,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;IAEvC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QACvC,IAAI;Y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C,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE;QAChE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,KAAK,CAAC,WAAW,EAAE;YAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACtC,IAAI,KAAK,CAAC,MAAM,EAAE;YAAE,MAAM,IAAI,CAAC;KACrC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A small HTML start-tag scanner for the build's index.html rewrites (nonce, SRI).
3
+ *
4
+ * - A quoted attribute value ends at its own closing quote; an SSI directive (`<!--#…-->`) inside
5
+ * it is skipped whole, so `nonce="<!--#echo var="X" -->"` is one value.
6
+ * - Comments are skipped; the content of <script>/<style> (raw text) is not scanned for tags.
7
+ * - Offsets let callers insert text without rebuilding (and so without reformatting) a tag.
8
+ */
9
+ export interface HtmlAttribute {
10
+ /** Lower-case name. */
11
+ name: string;
12
+ /** Value without quotes (raw, entities not decoded); undefined for a bare attribute. */
13
+ value?: string;
14
+ /** Offset of the attribute name. */
15
+ start: number;
16
+ /** Offset just after the attribute (after the closing quote of its value). */
17
+ end: number;
18
+ }
19
+ export interface HtmlTag {
20
+ /** Lower-case tag name. */
21
+ name: string;
22
+ /** Offset of `<`. */
23
+ start: number;
24
+ /** Offset just after `>`. */
25
+ end: number;
26
+ /** Offset just after the tag name. */
27
+ nameEnd: number;
28
+ /** Offset after the last attribute (or the name), before any whitespace, `/` and `>`. */
29
+ attrsEnd: number;
30
+ attrs: HtmlAttribute[];
31
+ }
32
+ /** Plain comments outside tags and raw text; SSI (`<!--#`) and IE conditionals stay. */
33
+ export declare function stripHtmlCommentsSafe(html: string): string;
34
+ /** Every start tag in document order. */
35
+ export declare function scanTags(html: string): HtmlTag[];
36
+ export declare const attr: (tag: HtmlTag, name: string) => HtmlAttribute | undefined;
37
+ export interface Insertion {
38
+ at: number;
39
+ text: string;
40
+ }
41
+ /** html with every insertion applied (offsets refer to the original text). */
42
+ export declare function applyInsertions(html: string, insertions: Insertion[]): string;