@things-factory/shell 6.2.165 → 6.2.167

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": "6.2.165",
3
+ "version": "6.2.167",
4
4
  "description": "Core module for framework",
5
5
  "bin": {
6
6
  "things-factory": "bin/things-factory",
@@ -134,5 +134,5 @@
134
134
  "pg": "^8.7.3",
135
135
  "sqlite3": "^5.0.8"
136
136
  },
137
- "gitHead": "7c1bf77d9da08bda3a74d11a0c62cac678c9720f"
137
+ "gitHead": "c0b528ac67d7cd766d901e0e2f74ae39ef648cab"
138
138
  }
@@ -26,6 +26,7 @@ import { historyApiFallback } from 'koa2-connect-history-api-fallback'
26
26
  import { WebSocketServer } from 'ws'
27
27
  import co from 'co'
28
28
  import http from 'http'
29
+ import crypto from 'crypto'
29
30
 
30
31
  import koaWebpack from '@hatiolab/koa-webpack'
31
32
  import cors from '@koa/cors'
@@ -113,6 +114,23 @@ const bootstrap = async () => {
113
114
  })
114
115
  )
115
116
 
117
+ app.use(async (ctx, next) => {
118
+ ctx.set('X-Content-Type-Options', 'nosniff')
119
+
120
+ const { directives = {} } = config.get('CSP') || {}
121
+
122
+ const nonce = crypto.randomBytes(16).toString('base64')
123
+ ctx.state.nonce = nonce
124
+
125
+ const cspHeader = Object.entries(directives as { [key: string]: string[] })
126
+ .map(([key, value]) => `${key} ${value.join(' ')}`)
127
+ .join('; ')
128
+
129
+ ctx.set('Content-Security-Policy', cspHeader)
130
+
131
+ await next()
132
+ })
133
+
116
134
  var subscriptionMiddleware = []
117
135
  process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)
118
136
 
package/server/server.ts CHANGED
@@ -26,6 +26,7 @@ import { historyApiFallback } from 'koa2-connect-history-api-fallback'
26
26
  import { WebSocketServer } from 'ws'
27
27
  import co from 'co'
28
28
  import http from 'http'
29
+ import crypto from 'crypto'
29
30
 
30
31
  import cors from '@koa/cors'
31
32
  import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
@@ -88,6 +89,23 @@ const bootstrap = async () => {
88
89
  })
89
90
  )
90
91
 
92
+ app.use(async (ctx, next) => {
93
+ ctx.set('X-Content-Type-Options', 'nosniff')
94
+
95
+ const { directives = {} } = config.get('CSP') || {}
96
+
97
+ const nonce = crypto.randomBytes(16).toString('base64')
98
+ ctx.state.nonce = nonce
99
+
100
+ const cspHeader = Object.entries(directives as { [key: string]: string[] })
101
+ .map(([key, value]) => `${key} ${value.join(' ')}`)
102
+ .join('; ')
103
+
104
+ ctx.set('Content-Security-Policy', cspHeader)
105
+
106
+ await next()
107
+ })
108
+
91
109
  var subscriptionMiddleware = []
92
110
  process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)
93
111
 
@@ -0,0 +1,5 @@
1
+ if ('serviceWorker' in navigator) {
2
+ navigator.serviceWorker.register('/service-worker.js', {
3
+ scope: '/'
4
+ })
5
+ }
@@ -1,8 +1,16 @@
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
15
  <script>
8
16
  var model = <%- JSON.stringify(model) %>;
@@ -1,4 +1,4 @@
1
- <style>
1
+ <style nonce="<%= nonce %>">
2
2
  svg {
3
3
  width: 100%;
4
4
  height: 100%;
@@ -34,7 +34,7 @@
34
34
  <script src="//d3js.org/d3.v3.min.js"></script>
35
35
  <script src="//cdn.jsdelivr.net/npm/d3-graphviz@2.6.1/build/d3-graphviz.min.js"></script>
36
36
 
37
- <script>
37
+ <script nonce="<%= nonce %>">
38
38
  var model = <%- JSON.stringify(model) %>;
39
39
 
40
40
  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 %>',
@@ -1,4 +1,4 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8" />
@@ -54,28 +54,7 @@
54
54
  <link href="/node_modules/@material-design-icons/font/index.css" rel="stylesheet" />
55
55
  <link rel="stylesheet" href="/theme.css" />
56
56
 
57
- <style>
58
- body {
59
- margin: 0;
60
- padding: 0;
61
- overflow: auto;
62
-
63
- /* This is a font-stack that tries to use the system-default sans-serifs first */
64
- font-family: Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
65
- line-height: 1.5;
66
- -webkit-font-smoothing: antialiased;
67
-
68
- accent-color: var(--primary-color);
69
- }
70
- </style>
71
-
72
- <script>
73
- if ('serviceWorker' in navigator) {
74
- navigator.serviceWorker.register('/service-worker.js', {
75
- scope: '/'
76
- })
77
- }
78
- </script>
57
+ <script src="/static/index.js" defer></script>
79
58
 
80
59
  <!--- prefetch -->
81
60
  <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;