@riocrypto/common-server 1.0.1909 → 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,30 +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
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
|
|
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);
|
|
13
14
|
}
|
|
14
|
-
if (typeof
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return input.map((item) => sanitize(item, depth + 1));
|
|
19
|
-
}
|
|
20
|
-
else if (typeof input === "object" && input !== null) {
|
|
21
|
-
const sanitizedObject = {};
|
|
22
|
-
for (const key in input) {
|
|
23
|
-
if (Object.prototype.hasOwnProperty.call(input, key)) {
|
|
24
|
-
sanitizedObject[key] = sanitize(input[key], depth + 1);
|
|
25
|
-
}
|
|
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;
|
|
26
19
|
}
|
|
27
|
-
|
|
20
|
+
seen.add(value);
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
// Returning undefined tells lodash to handle cloning this value
|
|
23
|
+
return undefined;
|
|
24
|
+
});
|
|
32
25
|
res.status(statusCode).send(sanitizedData);
|
|
33
26
|
}
|
|
34
27
|
exports.sendWithXSSGuard = sendWithXSSGuard;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
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",
|