@riocrypto/common-server 1.0.1904 → 1.0.1905

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,8 +21,11 @@ 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
- // Only apply CSRF check to state-changing methods
25
- if (["POST", "PUT", "PATCH", "DELETE"].includes(req.method.toUpperCase())) {
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())) {
26
29
  const csrfToken = req.body.csrfToken;
27
30
  if (!csrfToken) {
28
31
  return res.status(403).json({ error: "CSRF token missing" });
@@ -36,7 +39,7 @@ const verifyCsrfToken = (req, res, next) => __awaiter(void 0, void 0, void 0, fu
36
39
  }
37
40
  }
38
41
  else {
39
- next(); // Skip CSRF check for non-state-changing methods
42
+ next(); // Skip CSRF check if no relevant cookies are present
40
43
  }
41
44
  });
42
45
  exports.verifyCsrfToken = verifyCsrfToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1904",
3
+ "version": "1.0.1905",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",