Created
October 5, 2019 12:26
-
-
Save emrekizildas/beaa9f7e31de9dccc1c11c2d1b050e76 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
app.Use((context, next) => | |
{ | |
var rng = new RNGCryptoServiceProvider(); | |
var nonceBytes = new byte[32]; | |
rng.GetBytes(nonceBytes); | |
var nonce = Convert.ToBase64String(nonceBytes); | |
context.Items.Add("ScriptNonce", nonce); | |
context.Response.Headers.Add("Content-Security-Policy", | |
new[] { string.Format("script-src 'self' 'nonce-{0}'", nonce) }); | |
return next(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment