inlineScriptHashes
función Since 1.3.0
Calcula el hash SHA-256 (base64) de cada <script> en línea de un documento HTML que el
navegador comprueba con script-src: los de JavaScript, module, importmap y
speculationrules. Los bloques de datos (application/json, application/ld+json, el payload
de Meeko) y los scripts con src no cuentan. El texto se lee como lo hace el navegador, así que
el hash coincide con el que comprueba.
import { inlineScriptHashes } from "@meekojs/meeko/build";Source code src/framework/script-hashes.ts:57
Firma #
function inlineScriptHashes(html: string): InlineScriptReportParameters #
-
htmlstring Documento HTML completo.
Returns #
-
InlineScriptReport Los hashes como fuentes CSP y el JavaScript que un hash no puede permitir.
Example #
import { readFile } from "node:fs/promises";
import { inlineScriptHashes } from "@meekojs/meeko/build";
import { contentSecurityPolicy } from "@meekojs/meeko/server";
const { hashes, unhashable } = inlineScriptHashes(await readFile("dist/index.html", "utf8"));
if (unhashable.length) throw new Error(`JavaScript en línea sin hash: ${unhashable.join(", ")}`);
const header = contentSecurityPolicy({ "default-src": ["'self'"] }, hashes);See also #
- CSP with hashes Framework full-stack