soajs.controller 4.2.36 → 4.2.37

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/lib/header.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @license
5
+ * Copyright SOAJS All Rights Reserved.
6
+ *
7
+ * Use of this source code is governed by an Apache license that can be
8
+ * found in the LICENSE file at the root of this repository
9
+ */
10
+
11
+
12
+ /**
13
+ * Encodes a string to be safely used as an HTTP header value.
14
+ * This preserves all data and is the standard, recommended method.
15
+ *
16
+ * @param {string | number | boolean} value The value to encode.
17
+ * @returns {string} The URL-encoded string.
18
+ */
19
+ function encodeHeaderValue(value) {
20
+ if (value === null || typeof value === 'undefined') {
21
+ return '';
22
+ }
23
+ return encodeURIComponent(String(value));
24
+ }
25
+
26
+ /**
27
+ * Decodes a URL-encoded string from an HTTP header.
28
+ * It safely handles potential errors if the input is malformed.
29
+ *
30
+ * @param {string} encodedValue The percent-encoded header value to decode.
31
+ * @returns {string} The decoded (original) string, or the original
32
+ * string if decoding fails.
33
+ */
34
+ function decodeHeaderValue(encodedValue) {
35
+ // Return empty string or null as is, to avoid errors.
36
+ if (!encodedValue) {
37
+ return encodedValue;
38
+ }
39
+
40
+ try {
41
+ // The standard way to decode a value encoded by encodeURIComponent.
42
+ return decodeURIComponent(encodedValue);
43
+ } catch (e) {
44
+ // This catches errors from malformed URI sequences (e.g., a lone '%').
45
+ console.error(`Failed to decode header value: "${encodedValue}"`, e);
46
+ // Return the original, undecoded value so the app doesn't crash.
47
+ return encodedValue;
48
+ }
49
+ }
50
+
51
+ module.exports = { encodeHeaderValue, decodeHeaderValue };
package/mw/mt/index.js CHANGED
@@ -12,6 +12,9 @@ const async = require("async");
12
12
 
13
13
  const utils = require("./utils");
14
14
 
15
+
16
+ const { encodeHeaderValue } = require("../../lib/header.js");
17
+
15
18
  /**
16
19
  *
17
20
  * @param configuration
@@ -247,8 +250,8 @@ module.exports = (configuration) => {
247
250
  injectObj.urac = {
248
251
  "_id": uracObj._id,
249
252
  "username": uracObj.username,
250
- "firstName": uracObj.firstName,
251
- "lastName": uracObj.lastName,
253
+ "firstName": encodeHeaderValue(uracObj.firstName),
254
+ "lastName": encodeHeaderValue(uracObj.lastName),
252
255
  "email": uracObj.email,
253
256
  "groups": uracObj.groups,
254
257
  "socialLogin": uracObj.socialLogin,
@@ -336,12 +339,14 @@ module.exports = (configuration) => {
336
339
  req.soajs.log.error(err.message);
337
340
  }
338
341
  let _h = JSON.stringify(injectObj);
339
- req.headers.soajsinjectobj = Buffer.from(_h, 'ascii').toString('utf-8');
342
+ // req.headers.soajsinjectobj = Buffer.from(_h, 'ascii').toString('utf-8');
343
+ req.headers.soajsinjectobj = _h; //encodeHeaderValue(_h);
340
344
  return next();
341
345
  });
342
346
  } else {
343
347
  let _h = JSON.stringify(injectObj);
344
- req.headers.soajsinjectobj = Buffer.from(_h, 'ascii').toString('utf-8');
348
+ // req.headers.soajsinjectobj = Buffer.from(_h, 'ascii').toString('utf-8');
349
+ req.headers.soajsinjectobj = _h; //encodeHeaderValue(_h);
345
350
  return next();
346
351
  }
347
352
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "soajs.controller",
3
3
  "description": "soajs multi tenant API gateway",
4
- "version": "4.2.36",
4
+ "version": "4.2.37",
5
5
  "author": {
6
6
  "name": "soajs team",
7
7
  "email": "team@soajs.org"
@@ -27,7 +27,7 @@ let service = {
27
27
  },
28
28
  oauth: true,
29
29
  extKeyRequired: true,
30
- urac: false,
30
+ urac: true,
31
31
  urac_Profile: false,
32
32
  urac_ACL: false,
33
33
  provision_ACL: false,
@@ -9,7 +9,7 @@ let token = {
9
9
  _id: "5c8d0c505653de3985aa0ffd",
10
10
  locked: true,
11
11
  username: "owner",
12
- firstName: "owner3",
12
+ firstName: "owner3'sèį",
13
13
  lastName: "owner",
14
14
  email: "me@localhost.com",
15
15
  "ts": new Date().getTime(),
@@ -9,7 +9,7 @@ let token = {
9
9
  _id: "5c8d0c505653de3985aa0ffd",
10
10
  locked: true,
11
11
  username: "owner",
12
- firstName: "owner3",
12
+ firstName: "owner3'sèį",
13
13
  lastName: "owner",
14
14
  email: "me@localhost.com",
15
15
  "ts": new Date().getTime(),
@@ -4,7 +4,7 @@ let user = {
4
4
  locked: true,
5
5
  username: "owner",
6
6
  password: "$2a$12$geJJfv33wkYIXEAlDkeeuOgiQ6y6MjP/YxbqLdHdDSK7LDG.7n7Pq",
7
- firstName: "owner3",
7
+ firstName: "owner3'sèį",
8
8
  lastName: "owner",
9
9
  email: "me@localhost.com",
10
10
  ts: 1552747600152,
@@ -20,15 +20,17 @@ function startServer(serverConfig, callback) {
20
20
  'lastname': "hage"
21
21
  }
22
22
  };
23
-
24
-
25
- sApp.get('/passport/login', (req, res) => res.json(sReply));
26
-
23
+
24
+
25
+ sApp.get('/passport/login', (req, res) => {
26
+ res.json(sReply);
27
+ });
28
+
27
29
  mApp.get('/heartbeat', (req, res) => res.json(mReply));
28
-
30
+
29
31
  let sAppServer = sApp.listen(serverConfig.s.port, () => console.log(`${serverConfig.name} service mock listening on port ${serverConfig.s.port}!`));
30
32
  let mAppServer = mApp.listen(serverConfig.m.port, () => console.log(`${serverConfig.name} service mock listening on port ${serverConfig.m.port}!`));
31
-
33
+
32
34
  return callback(
33
35
  {
34
36
  "sAppServer": sAppServer,
@@ -40,11 +42,11 @@ function startServer(serverConfig, callback) {
40
42
 
41
43
  function killServer(config) {
42
44
  console.log("killing server ....");
43
-
45
+
44
46
  config.mAppServer.close((err) => {
45
47
  console.log("...sAppServer: " + config.name);
46
48
  });
47
-
49
+
48
50
  config.sAppServer.close((err) => {
49
51
  console.log("...mAppServer: " + config.name);
50
52
  });
@@ -44,7 +44,7 @@
44
44
  "requestTimeoutRenewal": 5,
45
45
  "extKeyRequired": true,
46
46
  "oauth": true,
47
- "urac": false,
47
+ "urac": true,
48
48
  "urac_Profile": false,
49
49
  "urac_ACL": false,
50
50
  "tenant_Profile": false,