Skip to content

Instantly share code, notes, and snippets.

@lone-star
Created April 19, 2013 17:33
Show Gist options
  • Save lone-star/5421871 to your computer and use it in GitHub Desktop.
Save lone-star/5421871 to your computer and use it in GitHub Desktop.
// Listens when new request
chrome.webRequest.onHeadersReceived.addListener(function(details) {
for (i = 0; i < details.responseHeaders.length; i++) {
if (isCSPHeader(details.responseHeaders[i].name.toUpperCase())) {
var csp = details.responseHeaders[i].value;
// append "https://mysite.com" to the authorized sites
csp = csp.replace('script-src', 'script-src https://mysite.com');
csp = csp.replace('style-src', 'style-src https://mysite.com');
details.responseHeaders[i].value = csp;
}
}
return { // Return the new HTTP header
responseHeaders: details.responseHeaders
};
}, {
urls: ["https://github.com/*"],
types: ["main_frame"]
}, ["blocking", "responseHeaders"]);
function isCSPHeader(headerName) {
return (headerName == 'CONTENT-SECURITY-POLICY') || (headerName == 'X-WEBKIT-CSP');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment