Skip to content

Instantly share code, notes, and snippets.

@junderw
Created July 6, 2018 06:27
Show Gist options
  • Save junderw/fe0c43783f43f72d246ea4ea24dae60c to your computer and use it in GitHub Desktop.
Save junderw/fe0c43783f43f72d246ea4ea24dae60c to your computer and use it in GitHub Desktop.
An efficient way of writing CSP directives in NodeJS using template literals. (You can copy and paste URLs, domains, whatever from excel sheet columns and vice versa)
const CSP_DIRECTIVES = `
default-src
'self'
;
object-src
'none'
;
report-uri
someURL
`.trim().replace(/\n/g, " ").replace(/ ;/g, ";")
// turns into
// "default-src 'self'; object-src 'none'; report-uri someURL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment