@rapidrest/service-core 2.2.0 → 2.3.0

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.
@@ -14,11 +14,21 @@ export declare class RouteUtils {
14
14
  protected rateLimiter?: RateLimiter;
15
15
  protected trustedRoles: string[];
16
16
  protected trustedProxies: string[];
17
+ protected csrfConfig: any;
18
+ protected corsConfig: any;
17
19
  /**
18
20
  * Creates a middleware function that checks if the user has elevated privileges and if not
19
21
  * throws the `AUTH_REQUIRES_ELEVATION` error.
20
22
  */
21
23
  checkElevation(lastStart?: number): RequestHandler;
24
+ /**
25
+ * Creates a middleware function that enforces CSRF protection for a state-changing request whose only
26
+ * credential came from the `jwt` cookie (`req.auth?.source === "cookie"`.
27
+ * See `JWTAuthResult`/`JWTStrategy`). A request authenticated via an `Authorization` header, API key,
28
+ * or query-string token never had that cookie automatically attached by the browser, so it was never
29
+ * exposed to this class of forgery and is left untouched here.
30
+ */
31
+ checkCsrf(): RequestHandler;
22
32
  /**
23
33
  * Returns a canonical form of a request path for use in rate limit identifiers. The router percent-decodes
24
34
  * `:param` values, so `/clients/%61bc` and `/clients/abc` reach the same handler. Keying on the raw path would
@@ -71,6 +81,26 @@ export declare class RouteUtils {
71
81
  * @param requiredScopes The list of scopes of which the authenticated user's token must carry at least one.
72
82
  */
73
83
  checkRequiredScopes(requiredScopes: string[]): RequestHandler;
84
+ /**
85
+ * Creates a WebSocket-specific error-sanitizing middleware, appended as the last item in every
86
+ * `@WebSocket()` route's handler chain (see `registerRoute()`'s WS branch below). Mirrors what
87
+ * `Server.ts`'s `handleError()`/`serializeError()` already do for ordinary HTTP routes: an
88
+ * `ApiError`'s own status/code/message pass through unchanged (it's meant to reach the client),
89
+ * but anything else — a raw DB driver error, an unexpected throw from `RateLimiter`,
90
+ * `ACLUtils.findACL()`, or any other non-`ApiError` thrown by a middleware in the chain — is
91
+ * replaced with a generic internal error before `runChain()`'s own end-of-chain fallback can turn
92
+ * it into a response.
93
+ *
94
+ * This matters specifically for WebSocket routes because `runChain()`'s fallback response, for a
95
+ * WS route, ends up as the literal WebSocket close reason (`ws.close(1002, message)` — see
96
+ * `Router.ts`/`BunRouter.ts`'s `ws()` `open` handlers), visible to any client via the browser
97
+ * close event's `event.reason`. An ordinary HTTP route gets the same sanitization for free
98
+ * because `Server.ts` registers `handleError` as global middleware, which `registerRoute()`
99
+ * concatenates onto every HTTP route's own handler chain — but `app.ws()` is never given
100
+ * `globalMiddleware` (only the WS-specific chain built here), so WS routes need their own copy of
101
+ * the same safety net.
102
+ */
103
+ sanitizeWsError(): RequestHandler;
74
104
  /**
75
105
  * Converts the given array of string or Function objects to functions bound to the given route object.
76
106
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rapidrest/service-core",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Provides all core functionality for RapidREST based backend services.",
5
5
  "repository": "https://github.com/rapidrest/service-core.git",
6
6
  "author": "RapidREST <rapidrests@gmail.com>",