diff --git a/server.js b/server.js
index e8baeb6..0880bac 100644
--- a/server.js
+++ b/server.js
@@ -67,7 +67,7 @@ function generateCSP() {
"default-src 'self'",
`script-src ${scriptSrc}`,
`style-src ${styleSrc}`,
- "img-src 'self' https:",
+ "img-src 'self' https: data:",
"font-src 'self'",
"connect-src 'self'",
"media-src 'self'",
@@ -78,11 +78,9 @@ function generateCSP() {
"form-action 'self'",
"base-uri 'self'",
"manifest-src 'self'",
+ "upgrade-insecure-requests",
].join("; ");
- const hashCount = scriptSources.length + styleSources.length;
- console.log(`Generated CSP with ${hashCount} inline content hashes:`);
- console.log(`${csp}\n`);
return csp;
}
@@ -421,26 +419,6 @@ function preCompress(buf) {
});
}
-function injectSRIHashes(html) {
- const cssEntry = files.get("/style.css");
- if (cssEntry && cssEntry.sri) {
- html = html.replace(
- /]*href=["']style\.css["'][^>]*)>/gi,
- ``
- );
- }
-
- const jsEntry = files.get("/script.js");
- if (jsEntry && jsEntry.sri) {
- html = html.replace(
- /`
+ );
+ }
+
+ extractInlineContent(processedContent);
}
- const body = minify ? Buffer.from(minify(originalContent), "utf8") : src;
+ const body = minify
+ ? Buffer.from(minify(processedContent), "utf8")
+ : Buffer.from(processedContent, "utf8");
let sriHash = null;
if (relPath === "style.css" || relPath === "script.js") {
@@ -530,6 +534,11 @@ async function build() {
}
const cspPolicy = generateCSP();
files.set("__csp__", cspPolicy);
+
+ console.log("CSS and JavaScript have been inlined into HTML automatically");
+ console.log(
+ "CSP policy generated with secure hashes for all inline content"
+ );
}
function setSecurityHeaders(res) {