Skip to content

Commit c52891e

Browse files
authored
Merge pull request #4 from mdarrik/support-cloudfront-urls
Support cloudfront urls
2 parents 9c4028b + d123cef commit c52891e

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ const isCssLink = require('hast-util-is-css-link')
1111

1212
let unsafeInlineStyles = process.env.CSP_HEADERS_UNSAFE_STYLES ?? false
1313
let reportUrl = process.env.CSP_HEADERS_REPORT_URL
14+
let allowCloudfrontSource = process.env.CSP_HEADERS_ALLOW_CLOUDFRONT_SOURCE
1415

1516
module.exports= {
1617
onPostBuild: async function({constants, utils, inputs}) {
1718
unsafeInlineStyles = inputs.unsafeStyles ?? unsafeInlineStyles
19+
allowCloudfrontSource = inputs.allowCloudfrontSource ?? allowCloudfrontSource
1820
reportUrl = inputs.reportUrl ?? reportUrl
1921
try {
2022
const htmlFiles = await getHtmlFilesFromDir(constants.PUBLISH_DIR)
@@ -115,7 +117,7 @@ const url = filePath.replace(publishPath, '').replace(/^\/index.html/, '/');
115117
return (
116118
`${url} ${reportToHeader === '' ? '' : `
117119
${reportToHeader}`}
118-
Content-Security-Policy: default-src 'self'; script-src 'self' 'strict-dynamic' 'unsafe-inline' ${hashes['script'].join(" ")}; style-src 'self' 'unsafe-inline' ${unsafeInlineStyles ? '' : hashes['style'].join(' ')}; ${ reportUrl == null ? null : `report-to netlify-csp-endpoint; report-uri ${reportUrl};`}
120+
Content-Security-Policy: default-src 'self' ${allowCloudfrontSource ? `'https://*.cloudfront.net'` : ''}; script-src 'self' 'strict-dynamic' 'unsafe-inline' ${hashes['script'].join(" ")}; style-src 'self' 'unsafe-inline' ${unsafeInlineStyles ? '' : hashes['style'].join(' ')}; ${ reportUrl == null ? null : `report-to netlify-csp-endpoint; report-uri ${reportUrl};`}
119121
`)
120122
}
121123
/**

manifest.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ inputs:
44
description: Value of "true" allows unsafe-inline styles in your site. This leaves the style tag hashes out of your CSP headers. This gets around issues from Netlify transforming urls and other things after the plugin runs. Can instead use CSP_HEADERS_UNSAFE_STYLES environment variable.
55
- name: reportUrl
66
description: url for the CSP-reports. Useful for monitoring/debugging issues with the CSP configuration.
7-
7+
- name: allowCloudfrontSource
8+
description: allows cloudfront sources as part of the "default src" CSP header. This should work to prevent asset optimized content that's not a script or style tag from being blocked by CSP headers. But malicious attackers could potentially use a cloudfront url to allow malicious content.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "netlify-plugin-csp-headers",
3-
"version": "0.0.1-alpha.06",
3+
"version": "0.0.1-alpha.07",
44
"main": "index.js",
55
"repository": "https://github.com/mdarrik/netlify-plugin-csp-hash.git",
66
"author": "Darrik <30670444+mdarrik@users.noreply.github.com>",

0 commit comments

Comments
 (0)