@riocrypto/common-server 1.0.1904 → 1.0.1906
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.
|
@@ -21,9 +21,15 @@ const verifyCsrfToken = (req, res, next) => __awaiter(void 0, void 0, void 0, fu
|
|
|
21
21
|
if (!CSRF_TOKEN_SECRET) {
|
|
22
22
|
throw new common_1.SecretManagerError();
|
|
23
23
|
}
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
// Check for the presence of accessToken or adminAccessToken cookies
|
|
25
|
+
const hasAccessToken = req.cookies.accessToken || req.cookies.adminAccessToken;
|
|
26
|
+
// Only apply CSRF check if accessToken or adminAccessToken cookies are present
|
|
27
|
+
if (hasAccessToken &&
|
|
28
|
+
["POST", "PUT", "PATCH", "DELETE"].includes(req.method.toUpperCase())) {
|
|
29
|
+
// Retrieve CSRF token from the header
|
|
30
|
+
const csrfToken = Array.isArray(req.headers["X-CSRF-TOKEN"])
|
|
31
|
+
? req.headers["X-CSRF-TOKEN"][0]
|
|
32
|
+
: req.headers["X-CSRF-TOKEN"];
|
|
27
33
|
if (!csrfToken) {
|
|
28
34
|
return res.status(403).json({ error: "CSRF token missing" });
|
|
29
35
|
}
|
|
@@ -36,7 +42,7 @@ const verifyCsrfToken = (req, res, next) => __awaiter(void 0, void 0, void 0, fu
|
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
else {
|
|
39
|
-
next(); // Skip CSRF check
|
|
45
|
+
next(); // Skip CSRF check if no relevant cookies are present
|
|
40
46
|
}
|
|
41
47
|
});
|
|
42
48
|
exports.verifyCsrfToken = verifyCsrfToken;
|