cloudcms-server 0.9.275 → 3.2.278

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.
Files changed (46) hide show
  1. package/LICENSE +1 -1
  2. package/middleware/proxy/proxy.js +1 -11
  3. package/package.json +8 -11
  4. package/util/proxy-factory.js +212 -178
  5. package/temp/http-proxy/.auto-changelog +0 -6
  6. package/temp/http-proxy/.gitattributes +0 -1
  7. package/temp/http-proxy/CHANGELOG.md +0 -1872
  8. package/temp/http-proxy/CODE_OF_CONDUCT.md +0 -74
  9. package/temp/http-proxy/LICENSE +0 -23
  10. package/temp/http-proxy/README.md +0 -568
  11. package/temp/http-proxy/codecov.yml +0 -10
  12. package/temp/http-proxy/index.js +0 -13
  13. package/temp/http-proxy/lib/http-proxy/common.js +0 -220
  14. package/temp/http-proxy/lib/http-proxy/index.js +0 -174
  15. package/temp/http-proxy/lib/http-proxy/passes/web-incoming.js +0 -174
  16. package/temp/http-proxy/lib/http-proxy/passes/web-outgoing.js +0 -135
  17. package/temp/http-proxy/lib/http-proxy/passes/ws-incoming.js +0 -141
  18. package/temp/http-proxy/lib/index.js +0 -13
  19. package/temp/http-proxy/package.json +0 -46
  20. package/temp/http-proxy/renovate.json +0 -19
  21. package/temp/node-http-proxy/.eslintignore +0 -3
  22. package/temp/node-http-proxy/.eslintrc.js +0 -21
  23. package/temp/node-http-proxy/.github/workflows/ci.yml +0 -30
  24. package/temp/node-http-proxy/.prettierrc +0 -7
  25. package/temp/node-http-proxy/CODE_OF_CONDUCT.md +0 -74
  26. package/temp/node-http-proxy/LICENSE +0 -23
  27. package/temp/node-http-proxy/README.md +0 -568
  28. package/temp/node-http-proxy/codecov.yml +0 -10
  29. package/temp/node-http-proxy/dist/http-proxy/common.js +0 -220
  30. package/temp/node-http-proxy/dist/http-proxy/index.js +0 -174
  31. package/temp/node-http-proxy/dist/http-proxy/passes/web-incoming.js +0 -174
  32. package/temp/node-http-proxy/dist/http-proxy/passes/web-outgoing.js +0 -135
  33. package/temp/node-http-proxy/dist/http-proxy/passes/ws-incoming.js +0 -141
  34. package/temp/node-http-proxy/dist/index.js +0 -13
  35. package/temp/node-http-proxy/lib/http-proxy/common.js +0 -265
  36. package/temp/node-http-proxy/lib/http-proxy/index.ts +0 -242
  37. package/temp/node-http-proxy/lib/http-proxy/passes/web-incoming.js +0 -208
  38. package/temp/node-http-proxy/lib/http-proxy/passes/web-outgoing.js +0 -163
  39. package/temp/node-http-proxy/lib/http-proxy/passes/ws-incoming.js +0 -179
  40. package/temp/node-http-proxy/lib/index.ts +0 -13
  41. package/temp/node-http-proxy/lib/types.d.ts +0 -277
  42. package/temp/node-http-proxy/package-lock.json +0 -5028
  43. package/temp/node-http-proxy/package.json +0 -47
  44. package/temp/node-http-proxy/tsconfig.build.json +0 -4
  45. package/temp/node-http-proxy/tsconfig.json +0 -115
  46. package/temp/node-http-proxy/vitest.config.ts +0 -9
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  Cloud CMS Application Server Module
2
2
 
3
- Copyright 2019 Gitana Software, Inc.
3
+ Copyright 2022 Gitana Software, Inc.
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License");
6
6
  you may not use this file except in compliance with the License.
@@ -1,16 +1,6 @@
1
1
  var path = require('path');
2
- // var fs = require('fs');
3
- // var http = require('http');
4
- // var https = require('https');
5
-
6
- // var httpProxy = require('http-proxy');
7
-
8
- // var oauth2 = require("../../util/oauth2")();
9
-
10
- // var async = require("async");
11
2
 
12
3
  var util = require("../../util/util");
13
- // var auth = require("../../util/auth");
14
4
 
15
5
  var proxyFactory = require("../../util/proxy-factory");
16
6
 
@@ -211,7 +201,7 @@ exports = module.exports = function()
211
201
  contentStore.writeFile(filePath + ".cache", JSON.stringify(cacheInfo), function() {
212
202
  _end.call(res, data, encoding);
213
203
  });
214
- `` };
204
+ };
215
205
 
216
206
  callback();
217
207
  });
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": "0.9.275",
9
+ "version": "3.2.278",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "git://github.com/gitana/cloudcms-server.git"
@@ -16,7 +16,7 @@
16
16
  "@socket.io/redis-adapter": "^7.2.0",
17
17
  "@socket.io/sticky": "^1.0.1",
18
18
  "accepts": "^1.3.7",
19
- "agentkeepalive": "^4.1.3",
19
+ "agentkeepalive": "^4.2.1",
20
20
  "alpaca": "^1.5.27",
21
21
  "archiver": "^1.3.0",
22
22
  "async": "^3.2.3",
@@ -40,13 +40,14 @@
40
40
  "express-session": "^1.17.3",
41
41
  "express-useragent": "^1.0.13",
42
42
  "extend-with-super": "^2.0.0",
43
+ "finalhandler": "^1.2.0",
43
44
  "gitana": "^1.0.322",
44
45
  "handlebars": "^4.4.2",
45
46
  "hbs": "^4.0.5",
46
47
  "helmet": "^4.6.0",
47
- "install": "^0.13.0",
48
+ "http2-proxy": "^5.0.53",
48
49
  "ioredis": "4.28.5",
49
- "json5": "^1.0.1",
50
+ "json5": "^2.2.1",
50
51
  "jsonwebtoken": "^8.5.1",
51
52
  "klaw": "^1.3.1",
52
53
  "lru-cache": "^4.1.5",
@@ -56,7 +57,6 @@
56
57
  "mkdirp": "^0.5.1",
57
58
  "moment": "^2.24.0",
58
59
  "morgan": "^1.9.1",
59
- "npm": "^8.15.0",
60
60
  "object-hash": "^1.3.1",
61
61
  "object-merge": "^2.5.1",
62
62
  "on-headers": "^1.0.2",
@@ -76,7 +76,7 @@
76
76
  "recursive-readdir": "^2.2.2",
77
77
  "redis": "^4.2.0",
78
78
  "redlock": "4.2.0",
79
- "request": "^2.88.0",
79
+ "request": "^2.88.2",
80
80
  "request-param": "^1.0.1",
81
81
  "response-time": "^2.3.2",
82
82
  "semver": "^7.3.7",
@@ -89,13 +89,10 @@
89
89
  "targz": "^1.0.1",
90
90
  "temp": "^0.8.3",
91
91
  "toobusy-js": "^0.5.1",
92
- "uuid": "^3.3.2",
92
+ "uuid": "^8.3.2",
93
93
  "vm2": "^3.8.4",
94
94
  "watch": "^0.13.0",
95
- "winston": "^3.3.3",
96
- "eventemitter3": "^4.0.7",
97
- "requires-port": "^1.0.0",
98
- "follow-redirects": "^1.15.1"
95
+ "winston": "^3.3.3"
99
96
  },
100
97
  "contributors": [
101
98
  {
@@ -2,14 +2,13 @@ var http = require("http");
2
2
  var https = require("https");
3
3
  var path = require("path");
4
4
 
5
- var httpProxy = require("../temp/http-proxy");
6
-
7
5
  var auth = require("./auth");
8
6
  var util = require("./util");
9
7
 
10
8
  var oauth2 = require("./oauth2")();
11
9
 
12
10
  var urlTool = require("url");
11
+ const finalhandler = require("finalhandler");
13
12
 
14
13
  var exports = module.exports;
15
14
 
@@ -64,84 +63,141 @@ var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pa
64
63
  });
65
64
  };
66
65
 
66
+
67
+
68
+
67
69
  var createProxyHandler = function(proxyTarget, pathPrefix)
68
70
  {
69
- ////////////////////////////////////////////////////////////////////////////
70
- //
71
- // HTTP/HTTPS Proxy Server to Cloud CMS
72
- // Facilitates Cross-Domain communication between Browser and Cloud Server
73
- // This must appear at the top of the app.js file (ahead of config) for things to work
74
- //
75
- ////////////////////////////////////////////////////////////////////////////
71
+ const proxy = require("http2-proxy");
72
+ const finalhandler = require('finalhandler')
76
73
 
77
- // parse the target to get host
78
- var proxyHost = urlTool.parse(proxyTarget).host;
74
+ const defaultWebHandler = function(err, req, res) {
75
+ if (err)
76
+ {
77
+ console.log("A web proxy error was caught, path: " + req.path + ", err: ", err);
78
+ try { res.status(500); } catch (e) { }
79
+ try { res.end('Something went wrong while proxying the request.'); } catch (e) { }
80
+ }
79
81
 
80
- // NOTE: changeOrigin must be true because of the way that we set host to host:port
81
- // in http-proxy's common.js line 102, the host is only properly set up if changeOrigin is set to true
82
- // this sets the "host" header and it has to match what is set at the network/transport level in a way
83
- // (inner workings of Node http request)
84
- //
85
- var proxyConfig = {
86
- "target": proxyTarget,
87
- "agent": http.globalAgent,
88
- "xfwd": false,
89
- "proxyTimeout": process.defaultHttpTimeoutMs,
90
- //"changeOrigin": true
91
- "headers": {
92
- "host": proxyHost
93
- },
94
- "cookieDomainRewrite": true
82
+ finalhandler(req, res)(err);
95
83
  };
96
-
97
- // use https?
98
- if (util.isHttps(proxyTarget))
99
- {
100
- proxyConfig = {
101
- "target": proxyTarget,
102
- "agent": https.globalAgent,
103
- "xfwd": false,
104
- "proxyTimeout": process.defaultHttpTimeoutMs,
105
- "headers": {
106
- "host": proxyHost
107
- },
108
- "cookieDomainRewrite": true
109
- };
110
- }
111
-
112
- // create proxy server instance
113
- var proxyServer = new httpProxy.createProxyServer(proxyConfig);
114
-
115
- // error handling
116
- proxyServer.on("error", function(err, req, res) {
117
- console.log("A proxy error was caught: " + err + ", json: " + JSON.stringify(err) + ", path: " + req.path);
118
-
119
- // do our best to send something back
120
- try
121
- {
122
- res.writeHead(500, {
123
- 'Content-Type': 'text/plain'
124
- });
84
+
85
+ // const defaultWsHandler = function(err, req, socket, head) {
86
+ // if (err) {
87
+ // console.error('proxy error (ws)', err);
88
+ // socket.destroy();
89
+ // }
90
+ // };
91
+
92
+ //console.log("Proxy Target: " + proxyTarget);
93
+
94
+ var hostname = urlTool.parse(proxyTarget).hostname;
95
+ var port = urlTool.parse(proxyTarget).port;
96
+ var protocol = urlTool.parse(proxyTarget).protocol;
97
+
98
+ // web
99
+ var webConfig = {};
100
+ webConfig.hostname = hostname;
101
+ webConfig.port = port;
102
+ webConfig.protocol = protocol;
103
+ //webConfig.path = null;
104
+ webConfig.proxyTimeout = 120000;
105
+ webConfig.proxyName = "Cloud CMS UI Proxy";
106
+ webConfig.onReq = function(req, options) {
107
+
108
+ if (!options.headers) {
109
+ options.headers = {};
125
110
  }
126
- catch (e) { }
111
+ var headers = options.headers;
127
112
 
128
- try
129
- {
130
- res.end('Something went wrong while proxying the request.');
113
+ if (options.path && options.path.startsWith("/proxy")) {
114
+ options.path = options.path.substring(6);
115
+ }
116
+
117
+ if (pathPrefix) {
118
+ options.path = path.join(pathPrefix, options.path);
131
119
  }
132
- catch (e) { }
133
- });
134
-
135
- // if we're using auth credentials that are picked up in SSO chain, then we listen for a 401
136
- // and if we hear it, we automatically invalidate the SSO chain so that the next request
137
- // will continue to work
138
- proxyServer.on("proxyRes", function (proxyRes, req, res) {
139
120
 
140
- console.log("proxyRes.1");
121
+ // used to auto-assign the client header for /oauth/token requests
122
+ oauth2.autoProxy(req);
123
+
124
+ // copy domain host into "x-cloudcms-domainhost"
125
+ if (req.domainHost) {
126
+ headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
127
+ }
128
+
129
+ // copy virtual host into "x-cloudcms-virtualhost"
130
+ if (req.virtualHost) {
131
+ headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
132
+ }
133
+
134
+ // copy deployment descriptor info
135
+ if (req.descriptor)
136
+ {
137
+ if (req.descriptor.tenant)
138
+ {
139
+ if (req.descriptor.tenant.id)
140
+ {
141
+ headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
142
+ }
143
+
144
+ if (req.descriptor.tenant.title)
145
+ {
146
+ headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
147
+ }
148
+ }
141
149
 
150
+ if (req.descriptor.application)
151
+ {
152
+ if (req.descriptor.application.id)
153
+ {
154
+ headers["x-cloudcms-application-id"] = req.descriptor.application.id;
155
+ }
156
+
157
+ if (req.descriptor.application.title)
158
+ {
159
+ headers["x-cloudcms-application-title"] = req.descriptor.application.title;
160
+ }
161
+ }
162
+ }
163
+
164
+ // set optional "x-cloudcms-origin" header
165
+ var cloudcmsOrigin = null;
166
+ if (req.virtualHost)
167
+ {
168
+ cloudcmsOrigin = req.virtualHost;
169
+ }
170
+ if (cloudcmsOrigin)
171
+ {
172
+ headers["x-cloudcms-origin"] = cloudcmsOrigin;
173
+ }
174
+
175
+ // set x-cloudcms-server-version header
176
+ headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
177
+
178
+ // keep alive
179
+ //req.headers["connection"] = "keep-alive";
180
+
181
+ // if the incoming request didn't have an "Authorization" header
182
+ // and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
183
+ if (!req.headers["authorization"])
184
+ {
185
+ if (req.gitana_user)
186
+ {
187
+ headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
188
+ }
189
+ else if (req.gitana_proxy_access_token)
190
+ {
191
+ headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
192
+ }
193
+ }
194
+ };
195
+ webConfig.onRes = function(req, res, proxyRes) {
196
+
142
197
  if (req.gitana_user)
143
198
  {
144
199
  var chunks = [];
200
+
145
201
  // triggers on data receive
146
202
  proxyRes.on('data', function(chunk) {
147
203
  // add received chunk to chunks array
@@ -149,8 +205,6 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
149
205
  });
150
206
 
151
207
  proxyRes.on("end", function () {
152
-
153
- console.log("proxyRes.end, code: " + proxyRes.statusCode);
154
208
 
155
209
  if (proxyRes.statusCode === 401)
156
210
  {
@@ -160,15 +214,16 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
160
214
  var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
161
215
 
162
216
  _LOCK([identifier], function(err, releaseLockFn) {
163
-
217
+
164
218
  if (err)
165
219
  {
166
220
  // failed to acquire lock
167
221
  console.log("FAILED TO ACQUIRE LOCK", err);
168
222
  req.log("FAILED TO ACQUIRE LOCK", err);
223
+ try { releaseLockFn(); } catch (e) { }
169
224
  return;
170
225
  }
171
-
226
+
172
227
  var cleanup = function (full)
173
228
  {
174
229
  delete Gitana.APPS[req.identity_properties.token];
@@ -186,8 +241,7 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
186
241
  if (err) {
187
242
  cleanup(true);
188
243
  req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
189
- releaseLockFn();
190
- return;
244
+ return releaseLockFn();
191
245
  }
192
246
 
193
247
  req.gitana_user.getDriver().reloadAuthInfo(function () {
@@ -202,112 +256,92 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
202
256
  }
203
257
  });
204
258
  }
205
- });
206
-
207
- var proxyHandlerServer = http.createServer(function(req, res) {
208
-
209
- console.log("proxy.1: " + req.url);
210
- if (req.headers)
211
- {
212
- for (var k in req.headers)
213
- {
214
- console.log("proxy.2 header " + k + " = " + req.headers[k]);
215
- }
216
- }
217
-
218
- // used to auto-assign the client header for /oauth/token requests
219
- oauth2.autoProxy(req);
220
-
221
- // copy domain host into "x-cloudcms-domainhost"
222
- if (req.domainHost)
223
- {
224
- req.headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
225
- }
226
-
227
- // copy virtual host into "x-cloudcms-virtualhost"
228
- if (req.virtualHost)
229
- {
230
- req.headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
231
- }
232
-
233
- // copy deployment descriptor info
234
- if (req.descriptor)
235
- {
236
- if (req.descriptor.tenant)
237
- {
238
- if (req.descriptor.tenant.id)
239
- {
240
- req.headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
241
- }
242
-
243
- if (req.descriptor.tenant.title)
244
- {
245
- req.headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
246
- }
247
- }
248
-
249
- if (req.descriptor.application)
250
- {
251
- if (req.descriptor.application.id)
252
- {
253
- req.headers["x-cloudcms-application-id"] = req.descriptor.application.id;
254
- }
255
-
256
- if (req.descriptor.application.title)
257
- {
258
- req.headers["x-cloudcms-application-title"] = req.descriptor.application.title;
259
- }
260
- }
261
- }
262
-
263
- // set optional "x-cloudcms-origin" header
264
- var cloudcmsOrigin = null;
265
- if (req.virtualHost)
266
- {
267
- cloudcmsOrigin = req.virtualHost;
268
- }
269
- if (cloudcmsOrigin)
270
- {
271
- req.headers["x-cloudcms-origin"] = cloudcmsOrigin;
272
- }
273
-
274
- // set x-cloudcms-server-version header
275
- req.headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
276
-
277
- // keep alive
278
- req.headers["connection"] = "keep-alive";
279
-
280
- // if the incoming request didn't have an "Authorization" header
281
- // and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
282
- if (!req.headers["authorization"])
283
- {
284
- if (req.gitana_user)
285
- {
286
- req.headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
287
- }
288
- else if (req.gitana_proxy_access_token)
289
- {
290
- req.headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
291
- }
292
- }
293
259
 
294
- if (pathPrefix) {
295
- req.url = path.join(pathPrefix, req.url);
296
- }
260
+ //res.setHeader('x-powered-by', 'cloudcms');
261
+ res.writeHead(proxyRes.statusCode, proxyRes.headers)
262
+ proxyRes.pipe(res)
263
+ };
297
264
 
298
- console.log("proxy.4: " + req.url);
299
- if (req.headers)
300
- {
301
- for (var k in req.headers)
302
- {
303
- console.log("proxy.4 header " + k + " = " + req.headers[k]);
304
- }
305
- }
306
-
307
- proxyServer.web(req, res);
308
-
309
- console.log("proxy.5");
310
- });
265
+ var proxyRequestHandler = function(req, res) {
266
+ proxy.web(req, res, webConfig, function(err, req, res) {
267
+ defaultWebHandler(err, req, res);
268
+ });
269
+ };
270
+
271
+
272
+ // cookie domain rewrite?
273
+
274
+ // // if we're using auth credentials that are picked up in SSO chain, then we listen for a 401
275
+ // // and if we hear it, we automatically invalidate the SSO chain so that the next request
276
+ // // will continue to work
277
+ // proxyServer.on("proxyRes", function (proxyRes, req, res) {
278
+ //
279
+ // console.log("proxyRes.1");
280
+ //
281
+ // if (req.gitana_user)
282
+ // {
283
+ // var chunks = [];
284
+ // // triggers on data receive
285
+ // proxyRes.on('data', function(chunk) {
286
+ // // add received chunk to chunks array
287
+ // chunks.push(chunk);
288
+ // });
289
+ //
290
+ // proxyRes.on("end", function () {
291
+ //
292
+ // console.log("proxyRes.end, code: " + proxyRes.statusCode);
293
+ //
294
+ // if (proxyRes.statusCode === 401)
295
+ // {
296
+ // var text = "" + Buffer.concat(chunks);
297
+ // if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
298
+ // {
299
+ // var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
300
+ //
301
+ // _LOCK([identifier], function(err, releaseLockFn) {
302
+ //
303
+ // if (err)
304
+ // {
305
+ // // failed to acquire lock
306
+ // console.log("FAILED TO ACQUIRE LOCK", err);
307
+ // req.log("FAILED TO ACQUIRE LOCK", err);
308
+ // return;
309
+ // }
310
+ //
311
+ // var cleanup = function (full)
312
+ // {
313
+ // delete Gitana.APPS[req.identity_properties.token];
314
+ // delete Gitana.PLATFORM_CACHE[req.identity_properties.token];
315
+ //
316
+ // if (full) {
317
+ // auth.removeUserCacheEntry(identifier);
318
+ // }
319
+ // };
320
+ //
321
+ // // null out the access token
322
+ // // this will force the refresh token to be used to get a new one on the next request
323
+ // req.gitana_user.getDriver().http.refresh(function (err) {
324
+ //
325
+ // if (err) {
326
+ // cleanup(true);
327
+ // req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
328
+ // releaseLockFn();
329
+ // return;
330
+ // }
331
+ //
332
+ // req.gitana_user.getDriver().reloadAuthInfo(function () {
333
+ // cleanup(true);
334
+ // req.log("Refreshed token for gitana user: " + req.identity_properties.token);
335
+ // releaseLockFn();
336
+ // });
337
+ // });
338
+ // });
339
+ // }
340
+ //
341
+ // }
342
+ // });
343
+ // }
344
+ // });
311
345
 
312
- return proxyHandlerServer.listeners('request')[0];
346
+ return proxyRequestHandler;
313
347
  };
@@ -1,6 +0,0 @@
1
- {
2
- "output": "CHANGELOG.md",
3
- "template": "keepachangelog",
4
- "unreleased": true,
5
- "commitLimit": false
6
- }
@@ -1 +0,0 @@
1
- package-lock.json binary