@riocrypto/common-server 1.0.1909 → 1.0.1911
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;
|
|
@@ -17,15 +17,15 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
|
17
17
|
const secret_manager_client_1 = require("../clients/secret-manager-client");
|
|
18
18
|
const common_1 = require("@riocrypto/common");
|
|
19
19
|
const verifyCsrfToken = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const CSRF_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("CSRF_TOKEN_SECRET");
|
|
21
|
-
if (!CSRF_TOKEN_SECRET) {
|
|
22
|
-
throw new common_1.SecretManagerError();
|
|
23
|
-
}
|
|
24
20
|
// Check for the presence of accessToken or adminAccessToken cookies
|
|
25
21
|
const hasAccessToken = req.cookies.accessToken || req.cookies.adminAccessToken;
|
|
26
22
|
// Only apply CSRF check if accessToken or adminAccessToken cookies are present
|
|
27
23
|
if (hasAccessToken &&
|
|
28
24
|
["POST", "PUT", "PATCH", "DELETE"].includes(req.method.toUpperCase())) {
|
|
25
|
+
const CSRF_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("CSRF_TOKEN_SECRET");
|
|
26
|
+
if (!CSRF_TOKEN_SECRET) {
|
|
27
|
+
throw new common_1.SecretManagerError();
|
|
28
|
+
}
|
|
29
29
|
// Retrieve CSRF token from the header
|
|
30
30
|
const csrfToken = Array.isArray(req.headers["x-csrf-token"])
|
|
31
31
|
? req.headers["x-csrf-token"][0]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1911",
|
|
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",
|