@riocrypto/common-server 1.0.1908 → 1.0.1910

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.
@@ -5,23 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.sendWithXSSGuard = void 0;
7
7
  const xss_1 = __importDefault(require("xss"));
8
+ const lodash_1 = __importDefault(require("lodash"));
8
9
  function sendWithXSSGuard(res, data, statusCode) {
9
- const sanitize = (input) => {
10
- if (typeof input === "string") {
11
- return (0, xss_1.default)(input);
10
+ const seen = new WeakSet();
11
+ const sanitizedData = lodash_1.default.cloneDeepWith(data, (value) => {
12
+ if (typeof value === "string") {
13
+ return (0, xss_1.default)(value);
12
14
  }
13
- else if (typeof input === "object" && input !== null) {
14
- const sanitizedObject = {};
15
- for (const key in input) {
16
- if (input.hasOwnProperty(key)) {
17
- sanitizedObject[key] = sanitize(input[key]);
18
- }
15
+ if (typeof value === "object" && value !== null) {
16
+ if (seen.has(value)) {
17
+ // Handle circular references by returning the already processed object
18
+ return value;
19
19
  }
20
- return sanitizedObject;
20
+ seen.add(value);
21
21
  }
22
- return input;
23
- };
24
- const sanitizedData = sanitize(data);
22
+ // Returning undefined tells lodash to handle cloning this value
23
+ return undefined;
24
+ });
25
25
  res.status(statusCode).send(sanitizedData);
26
26
  }
27
27
  exports.sendWithXSSGuard = sendWithXSSGuard;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1908",
3
+ "version": "1.0.1910",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -19,6 +19,7 @@
19
19
  "@types/csurf": "^1.11.5",
20
20
  "@types/he": "^1.2.0",
21
21
  "@types/jsonwebtoken": "^8.5.8",
22
+ "@types/lodash": "^4.17.12",
22
23
  "@types/uuid": "^9.0.1",
23
24
  "del-cli": "^5.0.0",
24
25
  "typescript": "^4.7.4"
@@ -38,6 +39,7 @@
38
39
  "googleapis": "^135.1.0",
39
40
  "he": "^1.2.0",
40
41
  "jsonwebtoken": "^9.0.1",
42
+ "lodash": "^4.17.21",
41
43
  "mongoose": "^8.0.0",
42
44
  "node-cache": "^5.1.2",
43
45
  "uuid": "^9.0.0",