Skip to content

Commit c0ba666

Browse files
committed
Fixed SVG rendering on camo.githubusercontent.com
1 parent 1b0e525 commit c0ba666

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

bootstrap.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ const hashCElements = "'sha256-rWWOwtKo7HU91YBF/nwZe2B2qiwVkRbtgbN0jJqfqXs='";
319319

320320
// Known GitLab instances based on https://gitlab.com/vednoc/dark-gitlab/-/blob/master/gitlab.user.css
321321
const glmask = "^gitlab\\.|^((0xacab|framagit)\\.org|code\\.(briarproject\\.org|foxkit\\.us|videolan\\.org)|dev\\.gajim\\.org|forge\\.tedomum\\.net|foss\\.heptapod\\.net|git\\.(alchemyviewer\\.org|callpipe\\.com|cardiff\\.ac\\.uk|cit\\.bcit\\.ca|coop|drk\\.sc|drupalcode\\.org|empiresmod\\.com|feneas\\.org|fosscommunity\\.in|gnu\\.io|happy-dev\\.fr|immc\\.ucl\\.ac\\.be|jami\\.net|ligo\\.org|linux-kernel\\.at|najer\\.info|nzoss\\.org\\.nz|oeru\\.org|pleroma\\.social|pwmt\\.org|rockylinux\\.org|silence\\.dev|synz\\.io)|gitgud\\.io|gitplac\\.si|invent\\.kde\\.org|lab\\.libreho\\.st|mau\\.dev|mpeg\\.expert|opencode\\.net|repo\\.getmonero\\.org|salsa\\.debian\\.org|skylab\\.vc\\.h-brs\\.de|source\\.(joinmastodon\\.org|puri\\.sm|small-tech\\.org))$";
322-
const githost = new RegExp("^(gist\\.)?github\\.(githubassets\\.)?com$|" + glmask);
322+
const githost = new RegExp("^(gist\\.)?github\\.com$|^camo\\.githubusercontent\\.com$|" + glmask);
323323
const gitlab = new RegExp(glmask);
324324
const gitlabjs = new RegExp("^/assets/webpack/.+\\.chunk\\.js$");
325325

@@ -331,21 +331,27 @@ var httpObserver = {
331331
subject instanceof Ci.nsIHttpChannel && githost.test(subject.URI.host) &&
332332
(subject.responseStatus == 200 || subject.responseStatus == 304)) {
333333
try {
334-
if (subject.responseStatus == 200 &&
334+
if (subject.URI.host === "camo.githubusercontent.com") {
335+
if (subject.getResponseHeader("Content-Type").indexOf("image/svg") != -1) {
336+
let csp = subject.getResponseHeader("Content-Security-Policy");
337+
csp += " 'self'; style-src 'unsafe-inline'";
338+
subject.setResponseHeader("Content-Security-Policy", csp, false);
339+
}
340+
} else if (subject.responseStatus == 200 &&
335341
(subject.loadInfo.externalContentPolicyType == Ci.nsIContentPolicy.TYPE_DOCUMENT ||
336342
subject.loadInfo.externalContentPolicyType == Ci.nsIContentPolicy.TYPE_SUBDOCUMENT) &&
337343
subject.getResponseHeader("Content-Type").indexOf("text/html") != -1) {
338344
try {
339345
let csp = subject.getResponseHeader("Content-Security-Policy");
340346
if (gitlab.test(subject.URI.host)) {
341347
if (subject.URI.host != "0xacab.org") {
342-
csp = csp.replace(/script-src /g, "script-src " + hashCElements + " ");
348+
csp = csp.replace("script-src ", "script-src " + hashCElements + " ");
343349
}
344350
} else {
345-
csp = csp.replace(/script-src /g, "script-src " + hashBase + " " + hashFollowUp + " ");
351+
csp = csp.replace("script-src ", "script-src " + hashBase + " " + hashFollowUp + " ");
346352
if (isSeaMonkey) {
347-
csp = csp.replace(/script-src /g, "script-src github.com gist.github.com " + hashSeaMonkey + " ");
348-
csp = csp.replace(/default-src 'none'/g, "default-src github.com gist.github.com");
353+
csp = csp.replace("script-src ", "script-src github.com gist.github.com " + hashSeaMonkey + " ");
354+
csp = csp.replace("default-src 'none'", "default-src github.com gist.github.com");
349355
}
350356
}
351357
subject.setResponseHeader("Content-Security-Policy", csp, false);
@@ -365,7 +371,7 @@ var httpObserver = {
365371
newListener.originalListener = subject.setNewListener(newListener);
366372
} else if (subject.URI.path.indexOf("/socket-worker-") != -1) {
367373
let csp = subject.getResponseHeader("Content-Security-Policy");
368-
csp = csp.replace(/worker-src /g, "worker-src github.githubassets.com ");
374+
csp = csp.replace("worker-src ", "worker-src github.githubassets.com ");
369375
subject.setResponseHeader("Content-Security-Policy", csp, false);
370376
}
371377
} catch (e) {}
@@ -407,7 +413,6 @@ tracingListener.prototype = {
407413
if (this.site == "github") {
408414
data = data.replace("<head>", "<head><script>" + pfFollowUp + "</script>");
409415
data = data.replace("<head>", "<head><script crossorigin=\"anonymous\" integrity=\"sha512-g4ztuyuFPzjTvIqYBeZdHEDaHz2K6RCz4RszsnL3m5ko4kiWCjB9W6uIScLkNr8l/BtC2dYiIFkOdOLDYBHLqQ==\" type=\"application/javascript\" src=\"https://github.githubassets.com/assets/compat-838cedbb.js\"></script>");
410-
data = data.replace(/<script.+chunk-index2-[a-z0-9]+\.js"><\/script>/, "<script crossorigin=\"anonymous\" defer=\"defer\" integrity=\"sha512-o/3J98IT190CWjNtrpkWpVUdnrkKSwQ1jDFOagsCc8ZvvyaqewKygiqxbxF/Z/BzHnrUvLkTe43sQ/D4PAyGRA==\" type=\"application/javascript\" data-module-id=\"./chunk-index2.js\" data-src=\"https://github.githubassets.com/assets/chunk-index2-a3fdc9f7.js\"></script>");
411416
data = data.replace("<head>", "<head><script>" + pfBase + "</script>");
412417
if (isSeaMonkey) {
413418
data = data.replace("<head>", "<head><script>" + pfSeaMonkey + "</script>");

0 commit comments

Comments
 (0)