Skip to content

Instantly share code, notes, and snippets.

@randomdross
randomdross / Send nonce to frontend.js
Created May 13, 2019 22:06
Send nonce to frontend
request.headers.set('x-random-csp-nonce', randomNonce)
CSPNonce: validateCSPNonce(req.Header.Get("x-random-csp-nonce"))
func validateCSPNonce(cspNonce string) string {
if m, _ := regexp.MatchString("^[a-zA-Z0-9]{20}$", cspNonce); !m {
return ""
}
return cspNonce
}
@randomdross
randomdross / Cloudflare CSP Worker.js
Created May 13, 2019 22:03
Cloudflare CSP Worker
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Fetch a request and return the response, with CSP applied
* @param {Request} request
*/
async function handleRequest(request) {
randomNonce = generateNonce(20)
@randomdross
randomdross / Nonce validation.txt
Created April 23, 2019 21:38
Nonce validation
func validateCSPNonce(cspNonce string) string {
if m, _ := regexp.MatchString("^[a-zA-Z0-9]{20}$", cspNonce); !m {
return ""
}
return cspNonce
}
@randomdross
randomdross / Retrieve header.txt
Created April 23, 2019 21:36
Retrieve header
CSPNonce: validateCSPNonce(req.Header.Get("x-random-csp-nonce"))
@randomdross
randomdross / Cloudflare CSP Worker.txt
Created April 23, 2019 21:35
Cloudflare CSP Worker
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Fetch a request and return the response, with CSP applied
* @param {Request} request
*/
async function handleRequest(request) {
randomNonce = generateNonce(20)
@randomdross
randomdross / Send nonce to frontend.txt
Last active April 23, 2019 21:33
Send nonce to frontend
request.headers.set('x-random-csp-nonce', randomNonce)
object-src 'none'; script-src 'nonce-[random nonce]' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:; base-uri 'none';
### Keybase proof
I hereby claim:
* I am randomdross on github.
* I am dross (https://keybase.io/dross) on keybase.
* I have a public key whose fingerprint is 248D 07E5 5F4B ED0B 5C90 6774 9683 9400 595D F27E
To claim this, I am signing this object: