Externalize license footer script to satisfy CSP

This commit is contained in:
Jennie Robinson Faber 2026-05-17 18:59:53 +01:00
parent 05082b6f01
commit acecd619e9
3 changed files with 87 additions and 2 deletions

View file

@ -7,6 +7,7 @@ services:
- outline - outline
volumes: volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro - ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./theme:/usr/share/nginx/html/theme:ro
networks: networks:
- default - default
- dokploy-network - dokploy-network

View file

@ -52,6 +52,14 @@ http {
access_log off; access_log off;
} }
# Same-origin static assets we inject (license footer script, etc.).
# Same-origin URLs satisfy Outline's CSP without needing a nonce.
location /theme/ {
root /usr/share/nginx/html;
expires 1h;
access_log off;
}
# Homepage: inject OG meta tags + license footer script # Homepage: inject OG meta tags + license footer script
location = / { location = / {
proxy_pass http://outline; proxy_pass http://outline;
@ -70,7 +78,7 @@ http {
sub_filter '<head>' '<head><meta property="og:title" content="Ghost Guild Wiki" /><meta property="og:description" content="A living knowledge base for Baby Ghosts &amp; Ghost Guild." /><meta property="og:type" content="website" /><meta property="og:url" content="https://wiki.ghostguild.org" /><meta name="twitter:card" content="summary" /><meta name="twitter:title" content="Ghost Guild Wiki" /><meta name="twitter:description" content="A living knowledge base for Baby Ghosts &amp; Ghost Guild." />'; sub_filter '<head>' '<head><meta property="og:title" content="Ghost Guild Wiki" /><meta property="og:description" content="A living knowledge base for Baby Ghosts &amp; Ghost Guild." /><meta property="og:type" content="website" /><meta property="og:url" content="https://wiki.ghostguild.org" /><meta name="twitter:card" content="summary" /><meta name="twitter:title" content="Ghost Guild Wiki" /><meta name="twitter:description" content="A living knowledge base for Baby Ghosts &amp; Ghost Guild." />';
# CC BY-SA 4.0 license footer (script self-gates to /doc/ pages). # CC BY-SA 4.0 license footer (script self-gates to /doc/ pages).
sub_filter '</head>' '<style>.cc-license-footer{margin:4rem 0 2rem;padding:1.5rem 0 0;border-top:1px solid rgba(128,128,128,0.25);font-size:0.85em;line-height:1.5;opacity:0.75}.cc-license-footer p{margin:0}.cc-license-footer a{color:inherit;text-decoration:underline}</style><script>(function(){var URL_HREF="https://creativecommons.org/licenses/by-sa/4.0/";var PREFIX="Content on this site by Baby Ghosts Studio Development Fund is licensed under CC BY-SA 4.0. To view a copy of this license, visit ";function isDoc(){return location.pathname.indexOf("/doc/")===0}function findTarget(){var pm=document.querySelector(".ProseMirror");if(pm&&pm.parentElement)return pm.parentElement;return document.querySelector("article")||document.querySelector("[role=main]")||document.querySelector("main")}function render(){var ex=document.querySelector(".cc-license-footer");if(!isDoc()){if(ex)ex.remove();return}if(ex)return;var t=findTarget();if(!t)return;var f=document.createElement("footer");f.className="cc-license-footer";var p=document.createElement("p");p.appendChild(document.createTextNode(PREFIX));var a=document.createElement("a");a.href=URL_HREF;a.target="_blank";a.rel="noopener noreferrer";a.textContent=URL_HREF;p.appendChild(a);f.appendChild(p);t.appendChild(f)}var pending=false;function s(){if(pending)return;pending=true;requestAnimationFrame(function(){pending=false;render()})}["pushState","replaceState"].forEach(function(m){var o=history[m];history[m]=function(){o.apply(this,arguments);s()}});window.addEventListener("popstate",s);function go(){new MutationObserver(s).observe(document.body,{childList:true,subtree:true});s()}if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",go)}else{go()}})();</script></head>'; sub_filter '</head>' '<style>.cc-license-footer{margin:4rem 0 2rem;padding:1.5rem 0 0;border-top:1px solid rgba(128,128,128,0.25);font-size:0.85em;line-height:1.5;opacity:0.75}.cc-license-footer p{margin:0}.cc-license-footer a{color:inherit;text-decoration:underline}</style><script src="/theme/license-footer.js" defer></script></head>';
sub_filter_once on; sub_filter_once on;
sub_filter_types text/html; sub_filter_types text/html;
@ -95,7 +103,7 @@ http {
proxy_set_header Connection "upgrade"; proxy_set_header Connection "upgrade";
# CC BY-SA 4.0 license footer (script self-gates to /doc/ pages). # CC BY-SA 4.0 license footer (script self-gates to /doc/ pages).
sub_filter '</head>' '<style>.cc-license-footer{margin:4rem 0 2rem;padding:1.5rem 0 0;border-top:1px solid rgba(128,128,128,0.25);font-size:0.85em;line-height:1.5;opacity:0.75}.cc-license-footer p{margin:0}.cc-license-footer a{color:inherit;text-decoration:underline}</style><script>(function(){var URL_HREF="https://creativecommons.org/licenses/by-sa/4.0/";var PREFIX="Content on this site by Baby Ghosts Studio Development Fund is licensed under CC BY-SA 4.0. To view a copy of this license, visit ";function isDoc(){return location.pathname.indexOf("/doc/")===0}function findTarget(){var pm=document.querySelector(".ProseMirror");if(pm&&pm.parentElement)return pm.parentElement;return document.querySelector("article")||document.querySelector("[role=main]")||document.querySelector("main")}function render(){var ex=document.querySelector(".cc-license-footer");if(!isDoc()){if(ex)ex.remove();return}if(ex)return;var t=findTarget();if(!t)return;var f=document.createElement("footer");f.className="cc-license-footer";var p=document.createElement("p");p.appendChild(document.createTextNode(PREFIX));var a=document.createElement("a");a.href=URL_HREF;a.target="_blank";a.rel="noopener noreferrer";a.textContent=URL_HREF;p.appendChild(a);f.appendChild(p);t.appendChild(f)}var pending=false;function s(){if(pending)return;pending=true;requestAnimationFrame(function(){pending=false;render()})}["pushState","replaceState"].forEach(function(m){var o=history[m];history[m]=function(){o.apply(this,arguments);s()}});window.addEventListener("popstate",s);function go(){new MutationObserver(s).observe(document.body,{childList:true,subtree:true});s()}if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",go)}else{go()}})();</script></head>'; sub_filter '</head>' '<style>.cc-license-footer{margin:4rem 0 2rem;padding:1.5rem 0 0;border-top:1px solid rgba(128,128,128,0.25);font-size:0.85em;line-height:1.5;opacity:0.75}.cc-license-footer p{margin:0}.cc-license-footer a{color:inherit;text-decoration:underline}</style><script src="/theme/license-footer.js" defer></script></head>';
sub_filter_once on; sub_filter_once on;
sub_filter_types text/html; sub_filter_types text/html;

76
theme/license-footer.js Normal file
View file

@ -0,0 +1,76 @@
(function () {
var URL_HREF = "https://creativecommons.org/licenses/by-sa/4.0/";
var PREFIX =
"Content on this site by Baby Ghosts Studio Development Fund is licensed under CC BY-SA 4.0. " +
"To view a copy of this license, visit ";
function isDoc() {
return location.pathname.indexOf("/doc/") === 0;
}
function findTarget() {
var pm = document.querySelector(".ProseMirror");
if (pm && pm.parentElement) return pm.parentElement;
return (
document.querySelector("article") ||
document.querySelector("[role=main]") ||
document.querySelector("main")
);
}
function render() {
var existing = document.querySelector(".cc-license-footer");
if (!isDoc()) {
if (existing) existing.remove();
return;
}
if (existing) return;
var target = findTarget();
if (!target) return;
var footer = document.createElement("footer");
footer.className = "cc-license-footer";
var p = document.createElement("p");
p.appendChild(document.createTextNode(PREFIX));
var a = document.createElement("a");
a.href = URL_HREF;
a.target = "_blank";
a.rel = "noopener noreferrer";
a.textContent = URL_HREF;
p.appendChild(a);
footer.appendChild(p);
target.appendChild(footer);
}
var pending = false;
function schedule() {
if (pending) return;
pending = true;
requestAnimationFrame(function () {
pending = false;
render();
});
}
["pushState", "replaceState"].forEach(function (m) {
var orig = history[m];
history[m] = function () {
orig.apply(this, arguments);
schedule();
};
});
window.addEventListener("popstate", schedule);
function start() {
new MutationObserver(schedule).observe(document.body, {
childList: true,
subtree: true,
});
schedule();
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", start);
} else {
start();
}
})();