inlineStyleHashes
función Desde 1.4.0
Calcula el hash SHA-256 (base64) de cada <style> en línea de un documento HTML, como fuentes
CSP 'sha256-…' para style-src: el estilo que añade theme para <MeekoThemeToggle> y los
<style> de los componentes. Los atributos style="…" no cuentan, porque un hash no los
permite. El texto se lee como lo hace el navegador, así que el hash coincide con el que éste
comprueba.
ts
import { inlineStyleHashes } from "@meekojs/meeko/build";Código fuente src/framework/script-hashes.ts:83
Firma #
ts
function inlineStyleHashes(html: string): readonly string[]Parámetros #
-
htmlstring Documento HTML completo.
Devuelve #
-
readonly string[] Los hashes como fuentes CSP, ordenados y sin repetir.
Ejemplo #
ts
import { readFile } from "node:fs/promises";
import { inlineScriptHashes, inlineStyleHashes } from "@meekojs/meeko/build";
import { contentSecurityPolicy } from "@meekojs/meeko/server";
const html = await readFile("dist/index.html", "utf8");
const header = contentSecurityPolicy({ "default-src": ["'self'"] }, inlineScriptHashes(html).hashes, inlineStyleHashes(html));Véase también #
- CSP con hashes Framework full-stack