1
1
import * as config from "./config" ;
2
2
import * as uuid from "uuid" ;
3
3
4
- var CspStrategy : any = { }
4
+ const CspStrategy : any = { }
5
5
6
- var defaultDirectives = {
6
+ const defaultDirectives = {
7
7
defaultSrc : [ '\'self\'' ] ,
8
8
scriptSrc : [ '\'self\'' , 'vimeo.com' , 'https://gist.github.com' , 'www.slideshare.net' , 'https://query.yahooapis.com' , '\'unsafe-eval\'' ] ,
9
9
// ^ TODO: Remove unsafe-eval - webpack script-loader issues https://github.com/hackmdio/codimd/issues/594
@@ -16,28 +16,28 @@ var defaultDirectives = {
16
16
connectSrc : [ '*' ]
17
17
}
18
18
19
- var dropboxDirectives = {
19
+ const dropboxDirectives = {
20
20
scriptSrc : [ 'https://www.dropbox.com' ]
21
21
}
22
22
23
- var cdnDirectives = {
23
+ const cdnDirectives = {
24
24
scriptSrc : [ 'https://cdnjs.cloudflare.com' , 'https://cdn.jsdelivr.net' , 'https://cdn.mathjax.org' ] ,
25
25
styleSrc : [ 'https://cdnjs.cloudflare.com' , 'https://cdn.jsdelivr.net' , 'https://fonts.googleapis.com' ] ,
26
26
fontSrc : [ 'https://cdnjs.cloudflare.com' , 'https://fonts.gstatic.com' ]
27
27
}
28
28
29
- var disqusDirectives = {
29
+ const disqusDirectives = {
30
30
scriptSrc : [ 'https://disqus.com' , 'https://*.disqus.com' , 'https://*.disquscdn.com' ] ,
31
31
styleSrc : [ 'https://*.disquscdn.com' ] ,
32
32
fontSrc : [ 'https://*.disquscdn.com' ]
33
33
}
34
34
35
- var googleAnalyticsDirectives = {
35
+ const googleAnalyticsDirectives = {
36
36
scriptSrc : [ 'https://www.google-analytics.com' ]
37
37
}
38
38
39
39
CspStrategy . computeDirectives = function ( ) {
40
- var directives = { }
40
+ const directives = { }
41
41
mergeDirectives ( directives , config . csp . directives )
42
42
mergeDirectivesIf ( config . csp . addDefaults , directives , defaultDirectives )
43
43
mergeDirectivesIf ( config . useCDN , directives , cdnDirectives )
@@ -53,10 +53,10 @@ CspStrategy.computeDirectives = function () {
53
53
}
54
54
55
55
function mergeDirectives ( existingDirectives , newDirectives ) {
56
- for ( var propertyName in newDirectives ) {
57
- var newDirective = newDirectives [ propertyName ]
56
+ for ( const propertyName in newDirectives ) {
57
+ const newDirective = newDirectives [ propertyName ]
58
58
if ( newDirective ) {
59
- var existingDirective = existingDirectives [ propertyName ] || [ ]
59
+ const existingDirective = existingDirectives [ propertyName ] || [ ]
60
60
existingDirectives [ propertyName ] = existingDirective . concat ( newDirective )
61
61
}
62
62
}
@@ -86,10 +86,10 @@ function getCspNonce(req, res) {
86
86
function addUpgradeUnsafeRequestsOptionTo ( directives ) {
87
87
if ( config . csp . upgradeInsecureRequests === 'auto' && config . useSSL ) {
88
88
directives . upgradeInsecureRequests = true
89
- } else { // @ts -ignore
89
+ } else {
90
90
if ( config . csp . upgradeInsecureRequests === true ) {
91
- directives . upgradeInsecureRequests = true
92
- }
91
+ directives . upgradeInsecureRequests = true
92
+ }
93
93
}
94
94
}
95
95
0 commit comments