Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
239 commits
Select commit Hold shift + click to select a range
069ecd8
Migrate `onFinish` callback
snuggs Jan 18, 2018
8f0438d
Fix grammatical error
snuggs Jan 18, 2018
e406127
Convert to using object deconstruction
snuggs Jan 18, 2018
869d0ee
Add middleware/policy to loader
snuggs Jan 18, 2018
5d02e10
Add middleware/policy to test loader
snuggs Jan 18, 2018
9e8f456
Add middleware/policy implementaion
snuggs Jan 18, 2018
cdbdbcc
Add middleware/policy.test suite to cover Content Security Policy
snuggs Jan 18, 2018
f785aff
Update test helper functionality
snuggs Jan 18, 2018
288b4fd
Remove only test from middleware
snuggs Jan 18, 2018
f8247c9
Add Node Security Platform link
snuggs Jan 19, 2018
a53d327
Add CORS section to middleware/README.md
snuggs Jan 19, 2018
8a2bab2
Add security and policy information to middlware/README.md
snuggs Jan 19, 2018
e1b62e9
Add middleware/policies.es implementation
snuggs Jan 19, 2018
0a72662
Test Content-Security-Policy: default-src 'none'
snuggs Jan 19, 2018
cda76fe
Test Stub Content-Security-Policy
snuggs Jan 19, 2018
3a4ee5d
Add whitespace formatting
snuggs Jan 19, 2018
119c7d9
Add policy middleware to default Server stack
snuggs Jan 19, 2018
9dd1967
Add default stubs for Content-Security-Policy
snuggs Jan 19, 2018
59c4bd1
Add report-uri for Content-Security-Policy
snuggs Jan 19, 2018
cd0bbb6
Add default stubs for Content-Security-Policy
snuggs Jan 19, 2018
73bbde2
Add test for style-src none
snuggs Jan 19, 2018
356dbbe
Use include for header comparison
snuggs Jan 19, 2018
63756f5
Remove console.logs
snuggs Jan 19, 2018
6492df1
Remove semicolons from test definition
snuggs Jan 19, 2018
1f0e130
Refactor selectors to use includes
snuggs Jan 19, 2018
549bda5
Refactor selectors to use includes
snuggs Jan 19, 2018
4cfc6ac
Refactor policies
snuggs Jan 19, 2018
90dbef2
Remove unnecessary semi-colon
snuggs Jan 19, 2018
d60fa95
Add spec for Content-Security-Policy: frame-src
snuggs Jan 19, 2018
5d2cd0a
Add spec for Content-Security-Policy: connect-src
snuggs Jan 19, 2018
6e59c34
Add spec for Content-Security-Policy: img-src
snuggs Jan 19, 2018
28ad745
Add spec for Content-Security-Policy: script-src
snuggs Jan 19, 2018
bf2fbc2
Remove bug from lowercased variable name
snuggs Jan 19, 2018
fb6951d
Remove only test
snuggs Jan 19, 2018
fa67d6d
Fix scripts policy comment
snuggs Jan 19, 2018
36ff06a
Add spec for Content-Security-Policy: report-uri
snuggs Jan 19, 2018
6084bf2
Convert from self to none in Content-Security-Policy test descriptions
snuggs Jan 19, 2018
1cd371b
Fix comments for Content-Security-Policy middleware implementation
snuggs Jan 19, 2018
1e7b8e5
Add test for script nonce
snuggs Jan 19, 2018
5be3f74
Add link for script nonce
snuggs Jan 19, 2018
fd9e817
Use defaults for Content-Security-Policy: default-src
snuggs Jan 19, 2018
a01ff20
Reformat TSU for Content-Security-Policy middleware
snuggs Jan 19, 2018
8ed6088
Only join policies without trailing semi-colon
snuggs Jan 19, 2018
9f8b35c
Update comment for report-uri
snuggs Jan 19, 2018
5ce352f
Update comment for report-uri
snuggs Jan 19, 2018
01102dc
Use defaults for Content-Security-Policy: font-src
snuggs Jan 19, 2018
fb128dd
Fix font-src comment
snuggs Jan 19, 2018
3caa818
Add spec for Content-Security-Policy: object-uri
snuggs Jan 19, 2018
8a960de
Add spec for Content-Security-Policy: media-uri
snuggs Jan 19, 2018
06bc717
Add note about report-uri analytics
snuggs Jan 19, 2018
d368c56
Add comment for default-src in Content-Security-Policy
snuggs Jan 19, 2018
0e13003
Add comment for report-uri.com pricing
snuggs Jan 19, 2018
f66318d
Add report-uri.com url for reporting
snuggs Jan 19, 2018
e9ba86a
Add spec for Content-Security-Policy-Report-Only
snuggs Jan 19, 2018
fdf382d
Add test to ensure Content-Security-Policy is not sent with ?report
snuggs Jan 19, 2018
68f44f9
Add comment about security breach of ?report
snuggs Jan 19, 2018
24403b6
Add comment about XSS attacks using unsafe-inline
snuggs Jan 19, 2018
65609ad
Add W3C specification link to README.md
snuggs Jan 19, 2018
7ccf2e2
Add W3C NONCE reference to middleware/policy.es
snuggs Jan 19, 2018
9a2c606
Add W3C NONCE uniqueness comment
snuggs Jan 19, 2018
649a6df
Add comment about nonces for Safari Lack of support:-(
snuggs Jan 19, 2018
4ac5895
Add link to MDN documentaiton for CSP
snuggs Jan 19, 2018
7fff289
Add link to MDN documentaiton for HTTP Header Content-Security-Policy
snuggs Jan 19, 2018
47fe530
Add documentation about CSP to middleware/README.md
snuggs Jan 19, 2018
9094a13
Add dummy logic for remaining CSP directives
snuggs Jan 19, 2018
6b58fd0
Add link to Moz://a Security Guidelines
snuggs Jan 19, 2018
e7dca4a
Add link to GOOGLE CSP
snuggs Jan 20, 2018
3c6b946
Add link to security headers.io
snuggs Jan 20, 2018
99a7218
Add wikipedia link for CSP
snuggs Jan 20, 2018
4457047
Add Github link for CSP
snuggs Jan 20, 2018
4ab49bf
Add Github link for post-CSP journey
snuggs Jan 20, 2018
08d6347
Add services and links section to middleware
snuggs Jan 20, 2018
b8c832d
Add link to W3C Web App Security
snuggs Jan 20, 2018
bf3544f
Remove quotes from test description
snuggs Jan 20, 2018
64626fb
Add links for report-uri
snuggs Jan 20, 2018
6c61387
Add Collection of CSP Bypasses
snuggs Jan 20, 2018
4847e82
Format whitespace in middleware/policy.test
snuggs Jan 21, 2018
92cdff3
Add spec for Content-Security-Policy: worker-src specification
snuggs Jan 21, 2018
4dd7f10
Remove only test
snuggs Jan 21, 2018
0bc06c6
Fix formatting of middleware/policy.es
snuggs Jan 21, 2018
842b690
Remove default 'self' value from policy comments
snuggs Jan 21, 2018
7ce2ecd
Content-Security-Policy fallback worker-src to script-src
snuggs Jan 21, 2018
a9e398d
Content-Security-Policy fallback frame-src to default-src
snuggs Jan 21, 2018
680f423
Content-Security-Policy fallback script-src to default-src
snuggs Jan 21, 2018
7921d9f
Content-Security-Policy Deprecate report-uri for report-to
snuggs Jan 21, 2018
59cd8d1
Content-Security-Policy: Rename policies collection to directives
snuggs Jan 21, 2018
2c1e847
Content-Security-Policy: fix broken link
snuggs Jan 21, 2018
5bbf3eb
Add comment for default-src
snuggs Jan 21, 2018
a27293f
Fix bug in Content-Security-Policy creating prefixing semi-colon
snuggs Jan 21, 2018
1a9bce6
Remove only test
snuggs Jan 21, 2018
214d610
Content-Security-Policy: Fallback to using defaults for each directive
snuggs Jan 21, 2018
e5317fb
Add schemes comment
snuggs Jan 21, 2018
a0ed1bf
Fix comment for scripts directives
snuggs Jan 21, 2018
cdae1d7
Remove comment about Content-Security-Policy in favor of README.md
snuggs Jan 21, 2018
8a8e4d0
Remove google strict-csp document in favor of README.md
snuggs Jan 21, 2018
329f209
Set INSECURE true for request upgrade
snuggs Jan 21, 2018
02882b1
fix whitespace
snuggs Jan 21, 2018
98353df
Remove greenfield comment
snuggs Jan 21, 2018
9c4b24c
Content-Security-Policy: block-all-mixed-content specification
snuggs Jan 21, 2018
6d8b987
Content-Security-Policy: update-insecure-requests specification
snuggs Jan 21, 2018
de3b6cb
Adjust const(ant) whitespace
snuggs Jan 21, 2018
afa40fe
Content-Security-Policy: Rearrange and reformat directives
snuggs Jan 21, 2018
85e8c61
Content-Security-Policy: base-uri
snuggs Jan 21, 2018
b030599
Content-Security-Policy: sandbox specification
snuggs Jan 21, 2018
76a4592
Content-Security-Policy: plugin-types specification
snuggs Jan 21, 2018
7f9cba8
Content-Security-Policy: form-action specification
snuggs Jan 21, 2018
e5c4c66
Content-Security-Policy: frame-ancestors specification
snuggs Jan 21, 2018
0040441
Fix whitespace
snuggs Jan 21, 2018
ba0020c
Refactor const(ant) variables
snuggs Jan 21, 2018
39267da
Content-Security-Policy: Refactor report url into variable
snuggs Jan 21, 2018
de7c1c5
Content-Security-Policy: Refactor async/await fetch into expression t…
snuggs Jan 21, 2018
569c4b6
Convert to use single quotes instead of double quotes
snuggs Jan 21, 2018
a4117cb
Convert to use vanity report-uri endpoint
snuggs Jan 21, 2018
5435dc2
Remove merge conflict
snuggs Jun 15, 2018
1c8f2c1
Fix snuggsi error
snuggs Jun 15, 2018
c3e5acc
Comment compressor test for future PR
snuggs Jun 15, 2018
068bf85
Comment negotiator test for future PR
snuggs Jun 15, 2018
11f62e0
Comment librarian test for future PR
snuggs Jun 15, 2018
0ca1969
Add server.close
snuggs Jun 16, 2018
f3c7f12
use serve test helper method. /cc @brandondees @tmornini
snuggs Jun 16, 2018
4c6db97
Update CSP default frames
snuggs Jun 30, 2018
db91f51
Update CSP default connects
snuggs Jun 30, 2018
5870284
Update CSP default images
snuggs Jun 30, 2018
5f2183a
Update CSP default fonts
snuggs Jun 30, 2018
e414bfd
Update CSP default objects
snuggs Jun 30, 2018
e132a36
Update CSP default medias
snuggs Jun 30, 2018
4935fb9
Update CSP default styles
snuggs Jun 30, 2018
d6a1ecf
Update CSP default scripts
snuggs Jun 30, 2018
094e29f
Update CSP default workers
snuggs Jun 30, 2018
9ebf938
Update CSP default bases
snuggs Jun 30, 2018
5586696
Update CSP default forms
snuggs Jun 30, 2018
ed9dd97
Update CSP default ancestors
snuggs Jun 30, 2018
b4884e1
Convert default-src to use self
snuggs Jul 1, 2018
36ec8e1
Migrate to use serve routine
snuggs Jul 1, 2018
6afebd8
Update to use serve in plugin-types
snuggs Jul 1, 2018
5b99692
Update object-src to none
snuggs Jul 1, 2018
1feb440
update plugin types to mime type defaults
snuggs Jul 1, 2018
f6b0176
Update object-src policy to 'none'
snuggs Jul 1, 2018
6712d6b
Update plugins for plugin-src CSP
snuggs Jul 1, 2018
b5b6e58
Update plugins for plugin-src CSP
snuggs Jul 1, 2018
c0b355b
Migrate plugin-types to near object-src since they are dependent
snuggs Jul 1, 2018
135a031
Update object-src test to none
snuggs Jul 1, 2018
96395bb
Update spec description for object-src and plugin-types
snuggs Jul 1, 2018
021560e
Add comment for when object-sr is NOT 'none'
snuggs Jul 1, 2018
67f4674
Add not ok test for plugin-types
snuggs Jul 1, 2018
78176e0
Migrate plugin-types juxtaposed to object-src
snuggs Jul 1, 2018
d4fca68
Remove CSP plugin-types when objects default to 'none'
snuggs Jul 1, 2018
2cd64bb
Fix whitespace with context set derectives
snuggs Jul 1, 2018
40a701c
Refactor secure
snuggs Jul 2, 2018
af66681
Migrate await next within policy middleware
snuggs Jul 2, 2018
3d57255
Add middleware/policy.json
snuggs Jul 2, 2018
52203c5
Add image-src to policy.json
snuggs Jul 2, 2018
482d278
Add script-src to policy.json
snuggs Jul 2, 2018
5399fee
Convert image-src to img-src
snuggs Jul 2, 2018
c5cecc5
Use google analytics in img-src
snuggs Jul 2, 2018
1302079
Add style-src to policy.json
snuggs Jul 2, 2018
f9c00b8
Add report-uri to policy.json
snuggs Jul 2, 2018
2026506
Fix whitespace
snuggs Jul 2, 2018
a1f9967
Remove google analytics
snuggs Jul 2, 2018
d655de1
Fix whitespace for report-uri
snuggs Jul 2, 2018
03d4cd1
Fix header level for resource/README.md
snuggs Jul 2, 2018
9b8d28f
Add comment for updated require
snuggs Jul 2, 2018
348823a
Reorganize external links for request methods
snuggs Jul 2, 2018
5e325f7
Add types to definition in resource/README.md
snuggs Jul 2, 2018
6a0927b
Reorganize definition in resource/README.md
snuggs Jul 2, 2018
c4f46d0
Fix whitespace
snuggs Jul 2, 2018
588a661
Reorganize mime sniffing section
snuggs Jul 2, 2018
2a78475
Fix comment bug LOLZ
snuggs Jul 2, 2018
bf4a839
Update default-src fallback comments
snuggs Jul 2, 2018
0ce788a
Refactor policy variables
snuggs Jul 2, 2018
4e45f0b
Refactor policy variables
snuggs Jul 2, 2018
c2b1412
Convert backticks to double quotes
snuggs Jul 2, 2018
4064b94
Convert backticks to double quotes
snuggs Jul 2, 2018
969adc5
Fix whitespace and comments
snuggs Jul 2, 2018
c2117a6
Update bases uri
snuggs Jul 2, 2018
8bb7e55
Update plugin types for security policy
snuggs Jul 2, 2018
3996f96
Update forms action for security policy
snuggs Jul 2, 2018
f60cdbc
Update frame-ancestors directive for Content Security Policy
snuggs Jul 2, 2018
d48cad1
Update worker-src for Content security policy
snuggs Jul 2, 2018
af3c327
REorganize variables for Security policy
snuggs Jul 2, 2018
0444664
Fix formatting of Content Security Policy constant variables
snuggs Jul 2, 2018
a3c49b3
Update sandbox directives for content security policy
snuggs Jul 2, 2018
49258cf
Fix context.set variable
snuggs Jul 2, 2018
e5716b1
Migrate header variable
snuggs Jul 2, 2018
45c0040
Remove header variable from method signature
snuggs Jul 2, 2018
47ef6ee
Refactor policy to be a middleware signature
snuggs Jul 2, 2018
39db536
Send context to next in policy.es
snuggs Jul 2, 2018
9e72ad4
Updte security breach comment
snuggs Jul 2, 2018
57b7e3c
Convert to backticks for report
snuggs Jul 2, 2018
62fc4dc
Update report variable for policy.es
snuggs Jul 2, 2018
18792eb
Update frames position in variable stack
snuggs Jul 2, 2018
3e64d98
Update img-src variable name for Content Security Policy
snuggs Jul 2, 2018
2d84f83
Update style variable
snuggs Jul 2, 2018
7b3b338
Reorganize directives for content security policy
snuggs Jul 2, 2018
132f4cb
Update sandbox directive for content security policy
snuggs Jul 2, 2018
c97ac17
Update worker-src for CSP
snuggs Jul 2, 2018
d543700
Update script-src
snuggs Jul 2, 2018
7b76686
Update frame-src for CSP
snuggs Jul 2, 2018
17ccd1a
Update font-src for content security policy
snuggs Jul 2, 2018
e1d630f
Update media-src directive for Content Security Policy
snuggs Jul 2, 2018
8849626
Convert Policy variable from connects to connect for CSP directive
snuggs Jul 2, 2018
46dc470
Convert Policy variable from bases to base for CSP directive
snuggs Jul 2, 2018
b87ceff
Update Navigation Directives for Content Security Policy
snuggs Jul 2, 2018
2df3ee1
Reorder variables for CSP
snuggs Jul 2, 2018
272ea62
Update plugin-types variable for CSP
snuggs Jul 2, 2018
3f7d803
Fix bug in objects variable
snuggs Jul 2, 2018
2a933b1
Fix bug in sandbox variable
snuggs Jul 2, 2018
28618d8
Fix indentation level of sandbox defaults
snuggs Jul 2, 2018
ddb4061
Fix bug in sandbox variable
snuggs Jul 2, 2018
3989fe2
Fix indentation level of SECURE, header, and scheme variables for CSP
snuggs Jul 2, 2018
6ef46d9
Add whitespace to CSP directive variable declarations
snuggs Jul 2, 2018
9f3f2b8
Add comments for Document directives
snuggs Jul 2, 2018
96079bb
Update comments for directive section
snuggs Jul 2, 2018
2e6a867
Add secure variable to policy.json
snuggs Jul 2, 2018
ef09038
Reorganizee keys within policy.json
snuggs Jul 2, 2018
b9793b6
Update SECURE for update insecure requests and blocking mixed content
snuggs Jul 2, 2018
0749ab6
Remove using backticks
snuggs Jul 2, 2018
8741b0c
Fix bug related to Content-Security-Policy-Report-Only
snuggs Jul 2, 2018
6c090aa
Refactor Content-Security-Policy-Report-Only test
snuggs Jul 2, 2018
7712bee
Reorder test constants
snuggs Jul 2, 2018
ca20bdf
Rename public/browser-sync.es -> public/browser-sync.js
snuggs Jul 2, 2018
c82fb49
Rename public/browser-sync.es -> public/browser-sync.js
snuggs Jul 2, 2018
bb00739
Refactor test for Content-Security-Policy-Report-Only
snuggs Jul 3, 2018
6c5d1c1
Assert Content-Security-Policy-Report-Only does not exist without que…
snuggs Jul 3, 2018
d29db84
Refactor policy.es
snuggs Jul 3, 2018
6428879
Refactor Content-Security-Policy-Report-Only test
snuggs Jul 3, 2018
5415743
Add report/README.md
snuggs Jul 4, 2018
53fddfb
Add MDN link
snuggs Jul 4, 2018
3199f37
Add report/index.json
snuggs Jul 4, 2018
033e380
Add sample csp report for report resource
snuggs Jul 4, 2018
a33c3b5
Add Report resource to server
snuggs Jul 4, 2018
c4a3610
Fix bug with routing system
snuggs Jul 4, 2018
ed9da82
Migrate color palette and style comments to prevent CSP error
snuggs Jul 6, 2018
fbfff44
Remove legacy style tag
snuggs Jul 6, 2018
e1b761b
Create specification for child-src as per Changes in CSP3
snuggs Jul 6, 2018
33e1ffe
Create specification for manifest-src as per Changes in CSP3
snuggs Jul 6, 2018
327f404
Refactor Content-Security-Policy-Report-Only
snuggs Jul 14, 2018
9a1e9b5
Refactor Content-Security-Policy-Report-Only and Content-Security-Pol…
snuggs Jul 14, 2018
2c78d02
Remove only test
snuggs Jul 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/serve.es
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const
= require ('../middleware')

middleware = [
route (`/hello/`, Resource `/resource/fixtures/`)
route (`/report/`, Resource `/report/`)
, route (`/hello/`, Resource `/resource/fixtures/`)
, route (`/examples/`, Resource `/examples/`)
]

Expand Down
6 changes: 5 additions & 1 deletion index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
// enough inline styles to paint to fold
// Japanese colors - https://en.wikipedia.org/wiki/Traditional_colors_of_Japan#Red.2FViolet_series
*/

:root {
--margin: 0 0;
}
Expand Down Expand Up @@ -271,4 +276,3 @@ body > main, body > aside { flex: 1 }
}

@media (min-width:1300px) { }

9 changes: 2 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
href=/index.css
rel='preload stylesheet'
>

<!--
<link
as=fetch
Expand All @@ -31,12 +32,6 @@
href=/examples/header-group>
-->


<style>
// enough inline styles to paint to fold
// Japanese colors - https://en.wikipedia.org/wiki/Traditional_colors_of_Japan#Red.2FViolet_series
</style>

<!-- https://www.speedshop.co/2015/10/21/hacking-head-tags-for-speed-and-profit.html -->

<!-- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base -->
Expand Down Expand Up @@ -937,5 +932,5 @@ <h3>Further Learning</h3>
<em>Copyright &copy; 2018 A <strong>devPunks</strong> project</em>
</footer>

<script src=/browser-sync.es></script>
<script src=/browser-sync.js></script>

33 changes: 33 additions & 0 deletions middleware/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
# middleware


## snuggsi.cors

Cross Origin Resource Sharing


## snuggsi.auth

Middleware used for Authentication.


## snuggsi.security

Browser security for frames and XSS attacks


## snuggsi.policy

Middleware used for CSP (Content Security Policy).

- W3C Web App Security - https://github.com/w3c/webappsec
- W3C CSP3 Specification - https://w3c.github.io/webappsec-csp
- W3C Mixed Content (CR) - https://w3c.github.io/webappsec-mixed-content
- W3C Upgrade Insecure Requests (CR) - https://w3c.github.io/webappsec/specs/upgrade/
- Wikipedia Documentation - https://en.wikipedia.org/wiki/Content_Security_Policy
- MDN Documentation - https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP


### Services

- Report-Uri - https://report-uri.com
- Reporting for security headers https://securityheaders.io
- Collection of CSP Bypasses - http://sebastian-lekies.de/csp/bypasses.php


### Links

- Helmet - https://helmetjs.github.io
- GOOGLE CSP - https://csp.withgoogle.com/docs/strict-csp.html
- Mozilla Security Guidelines - https://wiki.mozilla.org/Security/Guidelines/Web_Security#Content_Security_Policy
- https://medium.com/square-corner-blog/content-security-policy-for-single-page-web-apps-78f2b2cf1757
- https://www.owasp.org/index.php/HTTP_Strict_Transport_Security_Cheat_Sheet
- Node Security Platform - https://nodesecurity.io/resources
- Github's CSP Journey - https://githubengineering.com/githubs-csp-journey
- Github's post-CSP Journey - https://githubengineering.com/githubs-post-csp-journey

## snuggsi.route

Expand Down
1 change: 1 addition & 0 deletions middleware/index.es
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
auth : require ('./auth')
, cors : require ('./cors')
, security : require ('./security')
, policy : require ('./policy.es') // because .json ❓❓❓
, browse : require ('./browse')
, snuggsi : require ('./snuggsi')
, route : require ('./route')
Expand Down
4 changes: 4 additions & 0 deletions middleware/index.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ require ('./cors.test')
require ('./security.test')
require ('./snuggsi.test')
require ('./route.test')
require ('./policy.test')
// require ('./compressor.test')
// require ('./negotiator.test')
//require ('./librarian.test')
require ('./assets.test')

107 changes: 107 additions & 0 deletions middleware/policy.es
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Can actually charge for this feature // https://report-uri.com/#prices

const
//schemes = ['safari-extension://', 'chrome-extension://', 'https://', 'http://']
header = 'Content-Security-Policy'
, SECURE = true
// Depending on analytics framework,
// may want to listen for securitypolicyviolation events
// with JavaScript and collect more information about the client before reporting.
, report = ['https://snuggsi.report-uri.com/r/d/csp/enforce'] // report-to // *DEPRECATED* report-uri

, defaults = ["'self'"] // default-src
, img = defaults // img-src
, style = defaults // style-src
// nonce-${nonce} ** MUST BE UNIQUE **
// https://w3c.github.io/webappsec-csp/#framework-directive-source-list
// **NEVER EXPOSE!!! Causes XSS attacks** script-src 'unsafe-inline'
// **THAT BEING SAID...For Safari 😢
// 'unsafe-inline' // THIS MAY NOT BE TRUE IN 2018
, script = defaults // script-src Script Nonce for inline <script>

, font = defaults // font-src
, media = defaults // media-src
, connect = defaults // connect-src
, child = defaults // child-src
, frame = child // frame-src
, worker = script // worker-src // script-src fallback
, object = ["'none'"] // object-src
, plugin = ['audio/*', 'video/*'] // plugin-types when object != 'none'

, form = defaults // form-action
, ancestors = defaults // frame-ancestors

, manifest = defaults // manifest-src
, base = defaults // base-uri
, sandbox = defaults ||// sandbox
[/*
allow-forms
, allow-popups
, allow-modals
, allow-scripts
, allow-same-origin
, allow-presentation
, allow-pointer-lock
, allow-top-navigation
, allow-orientation-lock
, allow-popups-to-escape-sandbox
*/]

, directives = [
// Reporting
`report-to ${ report.join ` ` }`

// Fetch
, `default-src ${ defaults.join ` ` }`
, `img-src ${ img.join ` ` }`
, `style-src ${ style.join ` ` }`
, `script-src ${ script.join ` ` }`

, `font-src ${ font.join ` ` }`
, `media-src ${ media.join ` ` }`
, `connect-src ${ connect.join ` ` }`
, `child-src ${ child.join ` ` }`
, `frame-src ${ frame.join ` ` }`
, `worker-src ${ worker.join ` ` }`
, `object-src ${ object.join ` ` }`
, !!! object.includes (`'none'`)
? `plugin-types ${ plugin.join ` ` }`
: ''

// Navigation
, `form-action ${ form.join ` ` }`
, `frame-ancestors ${ ancestors.join ` ` }`

// Document
, `base-uri ${ base.join ` ` }`
, `manifest-src ${ manifest.join ` ` }`
// `sandbox ...` is not supported in the <meta> element
// or by the Content-Security-policy-Report-Only header field.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/sandbox
, `sandbox ${ sandbox.join ` ` }`

// Other
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/upgrade-insecure-requests
, SECURE
? `block-all-mixed-content`
: `update-insecure-requests`
// https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/require-sri-for
//, `require-sri-for ${ integrities.join ` ` }`
// DEPRECATED!! See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
//, `referrer`
]


module.exports = async (context, next, policy) => {

policy = directives.filter (Boolean).join `; `

context.set ( header, policy)

'report'
in context.request.query
&& context.set ( `${header}-Report-Only`, policy)

await next (context)
}
22 changes: 22 additions & 0 deletions middleware/policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"secure" : true

, "report-uri"
: "https://snuggsi.report-uri.com/r/d/csp/enforce"

, "default-src" : [
"'self'"
]

, "img-src" : [
"'self'"
]

, "style-src" : [
"'self'"
]

, "script-src" : [
"'self'"
]
}
Loading