cloudcms-server 3.2.325 → 3.2.327

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/index.js CHANGED
@@ -29,6 +29,28 @@ process.logInfo = process.log = function(text, level)
29
29
  systemLogger.log(text, level);
30
30
  };
31
31
 
32
+ var debugMiddleware = process.debugMiddleware = function(message)
33
+ {
34
+ return function(req, res, next)
35
+ {
36
+ var text = "[" + req.id + "] URL: " + req.url;
37
+ // if (req.headers)
38
+ // {
39
+ // text += ", HEADERS: " + JSON.stringify(req.headers);
40
+ // }
41
+ if (req.query)
42
+ {
43
+ text += ", QUERY: " + JSON.stringify(req.query);
44
+ }
45
+ text += ", MESSAGE: " + message;
46
+
47
+ console.log(text);
48
+
49
+ next();
50
+ }
51
+ }
52
+
53
+
32
54
 
33
55
  // by default, set up Gitana driver so that it limits to five concurrent HTTP requests back to Cloud CMS API at at time
34
56
  var Gitana = require("gitana");
@@ -306,43 +328,82 @@ exports = module.exports = function()
306
328
 
307
329
  r.common1 = function(app)
308
330
  {
331
+ // DEBUG
332
+ app.use(debugMiddleware("DEBUG x1"));
333
+
309
334
  // app config interceptor
310
335
  applyApplicationConfiguration(app);
311
336
 
337
+ // DEBUG
338
+ app.use(debugMiddleware("DEBUG x2"));
339
+
312
340
  // sets locale onto the request
313
341
  app.use(locale.localeInterceptor());
314
342
 
343
+ // DEBUG
344
+ app.use(debugMiddleware("DEBUG x3"));
345
+
315
346
  // sets host onto the request
316
347
  app.use(host.hostInterceptor());
348
+
349
+ // DEBUG
350
+ app.use(debugMiddleware("DEBUG x4"));
317
351
  };
318
352
 
319
353
  r.common2 = function(app)
320
354
  {
355
+ // DEBUG
356
+ app.use(debugMiddleware("DEBUG y1"));
357
+
321
358
  // bind stores into the request
322
359
  app.use(storeService.storesInterceptor());
323
360
 
361
+ // DEBUG
362
+ app.use(debugMiddleware("DEBUG y2"));
363
+
324
364
  // puts req.descriptor into the request and req.virtualFiles = true
325
365
  app.use(virtualFiles.interceptor());
326
366
 
367
+ // DEBUG
368
+ app.use(debugMiddleware("DEBUG y3"));
369
+
327
370
  // puts req.runtime into the request
328
371
  app.use(runtime.interceptor());
329
372
 
373
+ // DEBUG
374
+ app.use(debugMiddleware("DEBUG y4"));
375
+
330
376
  // if virtual hosting is enabled, loads "gitana.json" from cloud cms and places it into rootStore
331
377
  // for convenience, also populates req.gitanaConfig
332
378
  app.use(virtualConfig.interceptor());
333
379
 
380
+ // DEBUG
381
+ app.use(debugMiddleware("DEBUG y5"));
382
+
334
383
  // general method for finding "gitana.json" in root store and populating req.gitanaConfig
335
384
  app.use(driverConfig.interceptor());
385
+
386
+ // DEBUG
387
+ app.use(debugMiddleware("DEBUG y6"));
336
388
  };
337
389
 
338
390
  r.common3 = function(app)
339
391
  {
392
+ // DEBUG
393
+ app.use(debugMiddleware("DEBUG z1"));
394
+
340
395
  // binds "req.gitana" into the request for the loaded "req.gitanaConfig"
341
396
  app.use(driver.driverInterceptor());
397
+
398
+ // DEBUG
399
+ app.use(debugMiddleware("DEBUG z2"));
342
400
  };
343
401
 
344
402
  r.common4 = function(app, includeCloudCMS)
345
403
  {
404
+ // DEBUG
405
+ app.use(debugMiddleware("DEBUG v1"));
406
+
346
407
  var configuration = app.configuration;
347
408
 
348
409
  if (includeCloudCMS)
@@ -375,6 +436,9 @@ exports = module.exports = function()
375
436
 
376
437
  // graphql
377
438
  app.use(graphql.interceptor());
439
+
440
+ // DEBUG
441
+ app.use(debugMiddleware("DEBUG v2"));
378
442
  };
379
443
 
380
444
  r.perf1 = function(app)
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "name": "cloudcms-server",
8
8
  "description": "Cloud CMS Application Server Module",
9
- "version": "3.2.325",
9
+ "version": "3.2.327",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "git://github.com/gitana/cloudcms-server.git"
package/server/index.js CHANGED
@@ -729,6 +729,8 @@ var initSession = function(initDone)
729
729
  }
730
730
  };
731
731
 
732
+ var debugMiddleware = process.debugMiddleware;
733
+
732
734
  var startServer = function(config, startServerFinishedFn)
733
735
  {
734
736
  var app = express();
@@ -889,14 +891,17 @@ var startServer = function(config, startServerFinishedFn)
889
891
  next();
890
892
  });
891
893
  */
892
-
894
+
893
895
  // increment and assign request id
894
896
  app.use(function increment_and_assign_id(req, res, next) {
895
897
  requestCounter++;
896
898
  req.id = requestCounter;
897
899
  next();
898
900
  });
899
-
901
+
902
+ // DEBUG
903
+ app.use(debugMiddleware("DEBUG 1"));
904
+
900
905
  // APPLY CUSTOM INIT FUNCTIONS
901
906
  runFunctions(config.initFunctions, [app], function (err) {
902
907
 
@@ -989,7 +994,10 @@ var startServer = function(config, startServerFinishedFn)
989
994
 
990
995
  // common interceptors and config
991
996
  main.common1(app);
992
-
997
+
998
+ // DEBUG
999
+ app.use(debugMiddleware("DEBUG 2"));
1000
+
993
1001
  // general logging of requests
994
1002
  // gather statistics on response time
995
1003
  app.use(responseTime(function (req, res, time) {
@@ -1028,17 +1036,29 @@ var startServer = function(config, startServerFinishedFn)
1028
1036
 
1029
1037
  req.log(m, warn);
1030
1038
  }));
1031
-
1039
+
1040
+ // DEBUG
1041
+ app.use(debugMiddleware("DEBUG 2a"));
1042
+
1032
1043
  // set up CORS allowances
1033
1044
  // this lets CORS requests float through the proxy
1034
1045
  app.use(main.ensureCORS());
1035
-
1046
+
1047
+ // DEBUG
1048
+ app.use(debugMiddleware("DEBUG 2b"));
1049
+
1036
1050
  // set up default security headers
1037
1051
  app.use(main.ensureHeaders());
1038
-
1052
+
1053
+ // DEBUG
1054
+ app.use(debugMiddleware("DEBUG 2c"));
1055
+
1039
1056
  // common interceptors and config
1040
1057
  main.common2(app);
1041
-
1058
+
1059
+ // DEBUG
1060
+ app.use(debugMiddleware("DEBUG 3"));
1061
+
1042
1062
  // APPLY CUSTOM DRIVER FUNCTIONS
1043
1063
  runFunctions(config.driverFunctions, [app], function(err) {
1044
1064
 
@@ -1050,7 +1070,10 @@ var startServer = function(config, startServerFinishedFn)
1050
1070
 
1051
1071
  // cloudcms things need to run here
1052
1072
  main.common4(app, true);
1053
-
1073
+
1074
+ // DEBUG
1075
+ app.use(debugMiddleware("DEBUG 4"));
1076
+
1054
1077
  // APPLY CUSTOM FILTER FUNCTIONS
1055
1078
  runFunctions(config.filterFunctions, [app], function (err) {
1056
1079
 
@@ -1065,7 +1088,10 @@ var startServer = function(config, startServerFinishedFn)
1065
1088
 
1066
1089
  // DEVELOPMENT BASED PERFORMANCE CACHING
1067
1090
  main.perf3(app);
1068
-
1091
+
1092
+ // DEBUG
1093
+ app.use(debugMiddleware("DEBUG 5"));
1094
+
1069
1095
  // standard body parsing + a special cloud cms body parser that makes a last ditch effort for anything
1070
1096
  // that might be JSON (regardless of content type)
1071
1097
  app.use(function (req, res, next) {
@@ -1087,7 +1113,10 @@ var startServer = function(config, startServerFinishedFn)
1087
1113
  app.use(initializedSession);
1088
1114
  app.use(flash());
1089
1115
  }
1090
-
1116
+
1117
+ // DEBUG
1118
+ app.use(debugMiddleware("DEBUG 6"));
1119
+
1091
1120
  // this is the same as calling
1092
1121
  // app.use(passport.initialize());
1093
1122
  // except we create a new passport each time and store on request to support multitenancy
@@ -1126,7 +1155,10 @@ var startServer = function(config, startServerFinishedFn)
1126
1155
  req.passport.session()(req, res, next);
1127
1156
  });
1128
1157
  }
1129
-
1158
+
1159
+ // DEBUG
1160
+ app.use(debugMiddleware("DEBUG 7"));
1161
+
1130
1162
  // welcome files
1131
1163
  main.welcome(app);
1132
1164
 
@@ -1137,13 +1169,22 @@ var startServer = function(config, startServerFinishedFn)
1137
1169
 
1138
1170
  // healthcheck middleware
1139
1171
  main.healthcheck(app);
1140
-
1172
+
1173
+ // DEBUG
1174
+ app.use(debugMiddleware("DEBUG 8"));
1175
+
1141
1176
  // APPLY CUSTOM ROUTES
1142
1177
  runFunctions(config.routeFunctions, [app], function (err) {
1143
-
1178
+
1179
+ // DEBUG
1180
+ app.use(debugMiddleware("DEBUG 9"));
1181
+
1144
1182
  // configure cloudcms app server handlers
1145
1183
  main.handlers(app, true);
1146
-
1184
+
1185
+ // DEBUG
1186
+ app.use(debugMiddleware("DEBUG 10"));
1187
+
1147
1188
  // register error functions
1148
1189
  runFunctions(config.errorFunctions, [app], function (err) {
1149
1190
 
@@ -1161,7 +1202,7 @@ var startServer = function(config, startServerFinishedFn)
1161
1202
  }
1162
1203
  }
1163
1204
  runFunctions(allConfigureFunctions, [app], function (err) {
1164
-
1205
+
1165
1206
  // create the server (either HTTP or HTTPS)
1166
1207
  createHttpServer(app, function(err, httpServer) {
1167
1208
 
@@ -1219,6 +1260,9 @@ var createHttpServer = function(app, done)
1219
1260
 
1220
1261
  // socket
1221
1262
  httpServer.on("connection", function (socket) {
1263
+
1264
+ console.log("[SOCKET CONNECTION] " + socket);
1265
+
1222
1266
  socket.setNoDelay(true);
1223
1267
 
1224
1268
  socket.setTimeout(requestTimeout, function(socket) {
package/util/auth.js CHANGED
@@ -5,16 +5,19 @@ var LRUCache = require("lru-cache");
5
5
 
6
6
  var request = require("./request");
7
7
 
8
+ const IsolatedVM = require("isolated-vm");
9
+ console.log("FA: " + IsolatedVM);
10
+
8
11
  // trusted profile cache size 100
9
12
  var TRUSTED_PROFILE_CACHE = new LRUCache({
10
13
  max:100,
11
- maxAge: 1000 * 60 * 15 // 15 minutes
14
+ ttl: 1000 * 60 * 15 // 15 minutes
12
15
  });
13
16
 
14
17
  // user entry cache size 100
15
18
  var USER_ENTRY_CACHE = new LRUCache({
16
19
  max: 100,
17
- maxAge: 1000 * 60 * 15 // 15 minutes
20
+ ttl: 1000 * 60 * 15 // 15 minutes
18
21
  });
19
22
 
20
23
  var Gitana = require("gitana");
@@ -652,28 +655,28 @@ var executeRule = function(req, rule, gitanaUser, callback)
652
655
  });
653
656
  };
654
657
 
655
- const {VM} = require("vm2");
656
- var vm = new VM({
657
- timeout: 5000,
658
- sandbox: {
659
- "addToProject": function(projectId, teamIdentifiers) {
660
- return addToProject(projectId, teamIdentifiers, function() {
661
- console.log("Added user: " + gitanaUser._doc + " to project: " + projectId + ", teams: " + JSON.stringify(teamIdentifiers));
662
- });
663
- },
664
- "addToPlatformTeam": function(teamIdentifier) {
665
- return addToPlatformTeams([teamIdentifier], function() {
666
- console.log("Added user: " + gitanaUser._doc + " to platform team: " + teamIdentifier);
667
- });
668
- },
669
- "addToPlatformTeams": function(teamIdentifiers) {
670
- return addToPlatformTeams(teamIdentifiers, function() {
671
- console.log("Added user: " + gitanaUser._doc + " to platform teams: " + JSON.stringify(teamIdentifiers));
672
- });
673
- }
674
- }
658
+ const isolate = new IsolatedVM.Isolate({ memoryLimit: 32 });
659
+ const context = isolate.createContextSync();
660
+ const jail = context.global;
661
+
662
+ // functions
663
+ jail.setSync('addToProject', function(projectId, teamIdentifiers) {
664
+ return addToProject(projectId, teamIdentifiers, function() {
665
+ console.log("Added user: " + gitanaUser._doc + " to project: " + projectId + ", teams: " + JSON.stringify(teamIdentifiers));
666
+ });
667
+ });
668
+ jail.setSync("addToPlatformTeam", function(teamIdentifier) {
669
+ return addToPlatformTeams([teamIdentifier], function() {
670
+ console.log("Added user: " + gitanaUser._doc + " to platform team: " + teamIdentifier);
671
+ });
675
672
  });
676
- vm.run(rule);
673
+ jail.setSync("addToPlatformTeams", function(teamIdentifiers) {
674
+ return addToPlatformTeams(teamIdentifiers, function() {
675
+ console.log("Added user: " + gitanaUser._doc + " to platform teams: " + JSON.stringify(teamIdentifiers));
676
+ });
677
+ });
678
+
679
+ context.evalSync(rule);
677
680
 
678
681
  setTimeout(function() {
679
682
  callback();