Skip to content

Instantly share code, notes, and snippets.

@spencermountain
Last active February 28, 2018 18:32
Show Gist options
  • Save spencermountain/3f62b80f978efc1d126f0de6bf3840b6 to your computer and use it in GitHub Desktop.
Save spencermountain/3f62b80f978efc1d126f0de6bf3840b6 to your computer and use it in GitHub Desktop.
test a content-security-policy
//add a new content-security-policy to the page
function addTag(content){
var meta = document.createElement('meta');
meta.httpEquiv = "Content-Security-Policy";
meta.content = content
document.getElementsByTagName('head')[0].appendChild(meta);
}
//try to add a <script> tag
function addScript(src) {
var s = document.createElement( 'script' );
s.setAttribute( 'src', src );
s.onload=()=>{console.log(nlp)}
document.body.appendChild( s );
}
//try a remote origin first...
addScript("https://unpkg.com/compromise")
//ok it should have worked..
setTimeout(()=>{
//add a origin security policy
addTag("default-src 'self' https://*.mydomain.com")
//try it again
addScript("https://unpkg.com/compromise")
},2000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment