@riocrypto/common-server 1.0.1902 → 1.0.1903

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.
package/build/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./middlewares/not-sandbox";
6
6
  export * from "./middlewares/set-trace";
7
7
  export * from "./middlewares/require-min-role";
8
8
  export * from "./middlewares/require-min-admin-role";
9
+ export * from "./middlewares/csrf-protection";
9
10
  export * from "./services/apiKey";
10
11
  export * from "./services/password";
11
12
  export * from "./services/logger";
package/build/index.js CHANGED
@@ -22,6 +22,7 @@ __exportStar(require("./middlewares/not-sandbox"), exports);
22
22
  __exportStar(require("./middlewares/set-trace"), exports);
23
23
  __exportStar(require("./middlewares/require-min-role"), exports);
24
24
  __exportStar(require("./middlewares/require-min-admin-role"), exports);
25
+ __exportStar(require("./middlewares/csrf-protection"), exports);
25
26
  __exportStar(require("./services/apiKey"), exports);
26
27
  __exportStar(require("./services/password"), exports);
27
28
  __exportStar(require("./services/logger"), exports);
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Request, Response, NextFunction } from "express";
3
+ declare const csrfProtection: import("express-serve-static-core").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
4
+ declare const csrfErrorHandler: (err: any, req: Request, res: Response, next: NextFunction) => void;
5
+ export { csrfProtection, csrfErrorHandler };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.csrfErrorHandler = exports.csrfProtection = void 0;
7
+ const csurf_1 = __importDefault(require("csurf"));
8
+ // Initialize CSRF protection middleware
9
+ const csrfProtection = (0, csurf_1.default)();
10
+ exports.csrfProtection = csrfProtection;
11
+ // Error handling middleware for CSRF token errors
12
+ const csrfErrorHandler = (err, req, res, next) => {
13
+ if (err.code !== "EBADCSRFTOKEN")
14
+ return next(err);
15
+ // CSRF token errors
16
+ res.status(403);
17
+ res.send("Form tampered with");
18
+ };
19
+ exports.csrfErrorHandler = csrfErrorHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1902",
3
+ "version": "1.0.1903",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -16,6 +16,7 @@
16
16
  "license": "ISC",
17
17
  "devDependencies": {
18
18
  "@types/crypto-js": "^4.1.1",
19
+ "@types/csurf": "^1.11.5",
19
20
  "@types/he": "^1.2.0",
20
21
  "@types/jsonwebtoken": "^8.5.8",
21
22
  "@types/uuid": "^9.0.1",
@@ -30,6 +31,7 @@
30
31
  "@types/express": "^4.17.13",
31
32
  "axios": "^1.7.4",
32
33
  "crypto-js": "^4.2.0",
34
+ "csurf": "^1.11.0",
33
35
  "express": "^4.21.1",
34
36
  "express-validator": "^6.14.2",
35
37
  "fireblocks-sdk": "^5.13.0",