Last active
February 28, 2018 18:32
-
-
Save spencermountain/3f62b80f978efc1d126f0de6bf3840b6 to your computer and use it in GitHub Desktop.
test a content-security-policy
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
//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