fix(orchestrator): drop the 3D library's nonce-less injected styles
The vendored 3d-force-graph appends three empty style elements to head while it loads and fills them with its own CSS; the page CSP allows styles by nonce only, so it blocks them and Firefox logs six style-src-elem errors, which failed the W3 artifacts e2e once 594d185 opened the 3D view there. page-graph3d.js now intercepts head.appendChild only while that script runs (document.currentScript is its tag), skips style elements from it and removes the interception on load or error. The CSP and the pinned library stay unchanged; the page already styles the classes those blocks targeted.
🎯 Fix: 95 %
💥 Break: 3 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 92
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e5aac8a37
commit
908bd094e0
1 file changed
+18
-2
@@ -29,14 +29,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function refuseInjectedStyles(tag) {
|
||||||
|
const head = document.head;
|
||||||
|
const append = head.appendChild;
|
||||||
|
head.appendChild = function (node) {
|
||||||
|
return document.currentScript === tag && node instanceof HTMLStyleElement ? node : append.call(this, node);
|
||||||
|
};
|
||||||
|
return () => delete head.appendChild;
|
||||||
|
}
|
||||||
|
|
||||||
function loadScript(src) {
|
function loadScript(src) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const tag = document.createElement("script");
|
const tag = document.createElement("script");
|
||||||
|
const restore = refuseInjectedStyles(tag);
|
||||||
tag.src = src;
|
tag.src = src;
|
||||||
tag.nonce = NONCE;
|
tag.nonce = NONCE;
|
||||||
tag.async = true;
|
tag.async = true;
|
||||||
tag.addEventListener("load", resolve);
|
tag.addEventListener("load", () => {
|
||||||
tag.addEventListener("error", () => reject(new Error(`${src} not loaded`)));
|
restore();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
tag.addEventListener("error", () => {
|
||||||
|
restore();
|
||||||
|
reject(new Error(`${src} not loaded`));
|
||||||
|
});
|
||||||
document.head.append(tag);
|
document.head.append(tag);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user