@riocrypto/common-server 1.0.1901 → 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.
@@ -0,0 +1,2 @@
1
+ import { Response } from "express";
2
+ export declare function sendWithXSSGuard(res: Response, data: any, statusCode: number): void;
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sanitizeAndSend = void 0;
6
+ exports.sendWithXSSGuard = void 0;
7
7
  const xss_1 = __importDefault(require("xss"));
8
- function sanitizeAndSend(res, data, statusCode) {
8
+ function sendWithXSSGuard(res, data, statusCode) {
9
9
  const sanitizedData = (0, xss_1.default)(data);
10
10
  res.status(statusCode).send(sanitizedData);
11
11
  }
12
- exports.sanitizeAndSend = sanitizeAndSend;
12
+ exports.sendWithXSSGuard = sendWithXSSGuard;
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";
@@ -97,4 +98,4 @@ export * from "./helpers/get-tax-rate";
97
98
  export * from "./helpers/get-asset-price";
98
99
  export * from "./helpers/generate-payment-reference";
99
100
  export * from "./helpers/get-order-from-reference";
100
- export * from "./helpers/sanitize-and-send";
101
+ export * from "./helpers/send-with-xss-guard";
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);
@@ -113,4 +114,4 @@ __exportStar(require("./helpers/get-tax-rate"), exports);
113
114
  __exportStar(require("./helpers/get-asset-price"), exports);
114
115
  __exportStar(require("./helpers/generate-payment-reference"), exports);
115
116
  __exportStar(require("./helpers/get-order-from-reference"), exports);
116
- __exportStar(require("./helpers/sanitize-and-send"), exports);
117
+ __exportStar(require("./helpers/send-with-xss-guard"), 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.1901",
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",
@@ -1,2 +0,0 @@
1
- import { Response } from "express";
2
- export declare function sanitizeAndSend(res: Response, data: any, statusCode: number): void;