Created
April 19, 2013 17:33
-
-
Save lone-star/5421871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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