@things-factory/shell 7.0.44 → 7.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/shell",
3
- "version": "7.0.44",
3
+ "version": "7.0.49",
4
4
  "description": "Core module for framework",
5
5
  "bin": {
6
6
  "things-factory": "bin/things-factory",
@@ -133,5 +133,5 @@
133
133
  "pg": "^8.7.3",
134
134
  "sqlite3": "^5.0.8"
135
135
  },
136
- "gitHead": "15c3e1b6a2b5f33c03cca37aabdc5f4c388d7dc9"
136
+ "gitHead": "3fdc2d9c86f8ebf1470fa5d2155b7b3019df6c0d"
137
137
  }
@@ -28,6 +28,9 @@ import http from 'http'
28
28
 
29
29
  import koaWebpack from '@hatiolab/koa-webpack'
30
30
  import cors from '@koa/cors'
31
+
32
+ import crypto from 'crypto'
33
+
31
34
  import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
32
35
  import { initLicense, checkValidity } from '@things-factory/operato-license-checker'
33
36
 
@@ -118,6 +121,23 @@ const bootstrap = async () => {
118
121
  })
119
122
  )
120
123
 
124
+ app.use(async (ctx, next) => {
125
+ ctx.set('X-Content-Type-Options', 'nosniff')
126
+
127
+ const { directives = {} } = config.get('CSP') || {}
128
+
129
+ const nonce = crypto.randomBytes(16).toString('base64')
130
+ ctx.state.nonce = nonce
131
+
132
+ const cspHeader = Object.entries(directives as { [key: string]: string[] })
133
+ .map(([key, value]) => `${key} ${value.join(' ')}`)
134
+ .join('; ')
135
+
136
+ ctx.set('Content-Security-Policy', cspHeader)
137
+
138
+ await next()
139
+ })
140
+
121
141
  var subscriptionMiddleware = []
122
142
  process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)
123
143
 
package/server/server.ts CHANGED
@@ -28,6 +28,8 @@ import co from 'co'
28
28
  import http from 'http'
29
29
 
30
30
  import cors from '@koa/cors'
31
+ import crypto from 'crypto'
32
+
31
33
  import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
32
34
  import { initLicense, checkValidity } from '@things-factory/operato-license-checker'
33
35
 
@@ -95,6 +97,23 @@ const bootstrap = async () => {
95
97
  })
96
98
  )
97
99
 
100
+ app.use(async (ctx, next) => {
101
+ ctx.set('X-Content-Type-Options', 'nosniff')
102
+
103
+ const { directives = {} } = config.get('CSP') || {}
104
+
105
+ const nonce = crypto.randomBytes(16).toString('base64')
106
+ ctx.state.nonce = nonce
107
+
108
+ const cspHeader = Object.entries(directives as { [key: string]: string[] })
109
+ .map(([key, value]) => `${key} ${value.join(' ')}`)
110
+ .join('; ')
111
+
112
+ ctx.set('Content-Security-Policy', cspHeader)
113
+
114
+ await next()
115
+ })
116
+
98
117
  var subscriptionMiddleware = []
99
118
  process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)
100
119
 
@@ -0,0 +1,5 @@
1
+ if ('serviceWorker' in navigator) {
2
+ navigator.serviceWorker.register('/service-worker.js', {
3
+ scope: '/'
4
+ })
5
+ }
@@ -1,10 +1,18 @@
1
- <script src="//d3js.org/d3.v4.min.js"></script>
1
+ <script src="https://unpkg.com/d3@5.15.0/dist/d3.min.js"></script>
2
2
  <script src="https://unpkg.com/viz.js@1.8.0/viz.js" type="javascript/worker"></script>
3
3
  <script src="https://unpkg.com/d3-graphviz@1.3.1/build/d3-graphviz.min.js"></script>
4
4
 
5
- <div id="graph" style="text-align: center; width: 100%; height: 100%;"></div>
5
+ <style nonce="<%= nonce %>">
6
+ #graph {
7
+ text-align: center;
8
+ width: 100%;
9
+ height: 100%;
10
+ }
11
+ </style>
12
+
13
+ <div id="graph"></div>
6
14
 
7
- <script>
15
+ <script nonce="<%= nonce %>">
8
16
  var model = <%- JSON.stringify(model) %>;
9
17
 
10
18
  var { edges, nodes } = model
@@ -1,4 +1,4 @@
1
- <style>
1
+ <style nonce="<%= nonce %>">
2
2
  svg {
3
3
  width: 100%;
4
4
  height: 100%;
@@ -27,14 +27,18 @@
27
27
  text {
28
28
  font: 10px sans-serif;
29
29
  pointer-events: none;
30
- text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff;
30
+ text-shadow:
31
+ 0 1px 0 #fff,
32
+ 1px 0 0 #fff,
33
+ 0 -1px 0 #fff,
34
+ -1px 0 0 #fff;
31
35
  }
32
36
  </style>
33
37
 
34
38
  <script src="//d3js.org/d3.v3.min.js"></script>
35
39
  <script src="//cdn.jsdelivr.net/npm/d3-graphviz@2.6.1/build/d3-graphviz.min.js"></script>
36
40
 
37
- <script>
41
+ <script nonce="<%= nonce %>">
38
42
  var model = <%- JSON.stringify(model) %>;
39
43
 
40
44
  var { edges: links, nodes } = model
@@ -1,12 +1,18 @@
1
- <style>
1
+ <style nonce="<%= nonce %>">
2
2
  body {
3
3
  margin: 0;
4
4
  }
5
+
6
+ #embedded-sandbox {
7
+ width: 100%;
8
+ height: 100%;
9
+ }
5
10
  </style>
6
11
 
7
- <div style="width: 100%; height: 100%" id="embedded-sandbox"></div>
12
+ <div id="embedded-sandbox"></div>
13
+
8
14
  <script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js"></script>
9
- <script>
15
+ <script nonce="<%= nonce %>">
10
16
  new window.EmbeddedSandbox({
11
17
  target: '#embedded-sandbox',
12
18
  initialEndpoint: '<%- initialEndpoint %>',
@@ -56,29 +56,7 @@
56
56
  <link href="/node_modules/@fontsource/roboto/index.css" rel="stylesheet" />
57
57
  <link rel="stylesheet" href="/theme.css" />
58
58
 
59
- <style>
60
- body {
61
- margin: 0;
62
- padding: 0;
63
- overflow: auto;
64
-
65
- /* This is a font-stack that tries to use the system-default sans-serifs first */
66
- font-family: Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
67
- line-height: 1.5;
68
- -webkit-font-smoothing: antialiased;
69
-
70
- accent-color: var(--md-sys-color-primary);
71
- background-color: var(--md-sys-color-background);
72
- }
73
- </style>
74
-
75
- <script>
76
- if ('serviceWorker' in navigator) {
77
- navigator.serviceWorker.register('/service-worker.js', {
78
- scope: '/'
79
- })
80
- }
81
- </script>
59
+ <script src="/static/index.js" defer></script>
82
60
 
83
61
  <!--- prefetch -->
84
62
  <link rel="prefetch" href="/public/home.js" />
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="google" content="notranslate" />
6
6
 
7
- <style>
7
+ <style nonce="<%= nonce %>">
8
8
  html,
9
9
  body {
10
10
  margin: 0;