@vulkano/core 1.7.0 → 1.8.1

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.
@@ -43,6 +43,7 @@ module.exports = function getExpressConfiguration() {
43
43
  cookies: {},
44
44
  csp: {},
45
45
  jwt: {},
46
+ session: {},
46
47
  permissionPolicy: {},
47
48
  sockets: {},
48
49
  redis: {},
@@ -15,6 +15,7 @@ const helmet = require('helmet');
15
15
  const timeout = require('connect-timeout');
16
16
  const useragent = require('express-useragent');
17
17
  const cookieParser = require('cookie-parser');
18
+ const expressSession = require('express-session');
18
19
  const { createClient: socketRedis } = require('redis');
19
20
  const socketMongoose = require('mongoose');
20
21
  const { createAdapter: socketRedisAdapter } = require('@socket.io/redis-adapter');
@@ -86,12 +87,22 @@ module.exports = function loadServer() {
86
87
  // ---------------
87
88
  // COOKIES - File: app/config/express/cookies.js
88
89
  // ---------------
89
- if (expressConfig.cookies && expressConfig.cookies.enabled) {
90
- const cookiesSecretKey = COOKIES_SECRET_KEY || expressConfig.cookies.key || expressConfig.cookies.secret || '';
90
+ const {
91
+ enabled: cookiesEnabled
92
+ } = expressConfig.cookies || {};
93
+
94
+ let cookiesSecretKey = null;
95
+
96
+ if (cookiesEnabled) {
97
+
98
+ cookiesSecretKey = COOKIES_SECRET_KEY || expressConfig.cookies.key || expressConfig.cookies.secret || '';
99
+
91
100
  if (!cookiesSecretKey) {
92
101
  console.log(' \x1b[33mWARNING\x1b[0m: Set the secret key in the config/express/cookie.js file or COOKIES_SECRET_KEY in the .env file.');
93
102
  }
103
+
94
104
  vulkano.use(cookieParser(cookiesSecretKey));
105
+
95
106
  }
96
107
 
97
108
  // ---------------
@@ -232,6 +243,26 @@ module.exports = function loadServer() {
232
243
  });
233
244
  }
234
245
 
246
+ // ---------------
247
+ // Express Session - File: app/config/express/session.js
248
+ // ---------------
249
+ const {
250
+ enabled: sessionEnabled
251
+ } = expressConfig.session || {};
252
+
253
+ if (sessionEnabled) {
254
+
255
+ if (!cookiesEnabled) {
256
+ console.log(' \x1b[41mERROR\x1b[0m: Can not load the Express Session because the Cookies aren\'t enabled');
257
+ return;
258
+ }
259
+
260
+ delete expressConfig.session.enabled;
261
+
262
+ vulkano.use(expressSession({ ...expressConfig.session, secret: cookiesSecretKey }));
263
+
264
+ }
265
+
235
266
  // ---------------
236
267
  // Content Security Policy - File: app/config/express/csp.js
237
268
  // ---------------
@@ -241,14 +272,35 @@ module.exports = function loadServer() {
241
272
  rules: cspRules
242
273
  } = expressConfig.csp || {};
243
274
 
244
- if (cspEnabled) {
275
+ if (cspEnabled && cspRules) {
276
+
277
+ const cspRulesHeader = [];
278
+
279
+ if (Array.isArray(cspRules) && cspRules.length > 0) {
280
+
281
+ for ( let i = 0; i < cspRules.length; i += 1) {
282
+ cspRulesHeader.push(cspRules[i]);
283
+ }
284
+
285
+ } else if (typeof cspRules === 'object') {
286
+
287
+ Object.keys(cspRules).forEach( (r) => {
288
+ const tmpValues = cspRules[r];
289
+ if (Array.isArray(tmpValues)) {
290
+ cspRulesHeader.push(`${r} ${tmpValues.join(' ')}`);
291
+ } else if (typeof tmpValues === 'string') {
292
+ cspRulesHeader.push(`${r} ${tmpValues}`);
293
+ }
294
+ });
295
+
296
+ } else if (typeof cspRules === 'string') {
297
+
298
+ cspRulesHeader.push(cspRules);
245
299
 
246
- if (!Array.isArray(cspRules)) {
247
- console.error('Vulkano Error: ', 'The Content Security Policy Rules must be an array');
248
- return;
249
300
  }
250
301
 
251
- if (cspRules.length > 0) {
302
+ // Has Rules
303
+ if (cspRulesHeader.length > 0) {
252
304
 
253
305
  vulkano.use( (req, res, next) => {
254
306
 
@@ -256,7 +308,7 @@ module.exports = function loadServer() {
256
308
  res.setHeader('Report-To', JSON.stringify(cspReportTo));
257
309
  }
258
310
 
259
- res.setHeader('Content-Security-Policy', cspRules.join('; '));
311
+ res.setHeader('Content-Security-Policy', cspRulesHeader.join('; '));
260
312
 
261
313
  next();
262
314
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulkano/core",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "A MVC framework using Express 4",
5
5
  "license": "MIT",
6
6
  "author": "Vulkano Team",
@@ -41,6 +41,7 @@
41
41
  "dotenv": "^16.4.5",
42
42
  "express": "^4.19.2",
43
43
  "express-jwt": "^8.4.1",
44
+ "express-session": "^1.18.0",
44
45
  "express-useragent": "^1.0.15",
45
46
  "frameguard": "^4.0.0",
46
47
  "fs": "^0.0.1-security",