You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Restana ships with secure defaults out of the box:
62
+
-**Error handling**: The default error handler returns a generic `Internal Server Error` message, preventing internal details (stack traces, database errors, file paths) from leaking to clients. Provide a custom `errorHandler` to control what gets exposed.
63
+
-**Stream safety**: Stream errors are handled gracefully, preventing connection leaks.
64
+
-**Immutable config**: `getConfigOptions()` returns a frozen copy, preventing middleware from mutating internal framework options.
65
+
60
66
# More
61
67
- Website and documentation: https://restana.21no.de
-`errorHandler`: Optional global error handler function. Default value: `(err, req, res) => res.send({ code, message: 'Internal Server Error' }, code)`. The default handler returns a generic error message to prevent leaking sensitive internal details (e.g. database connection strings, file paths, stack traces). The appropriate HTTP status code is still preserved from `err.status`, `err.code`, or `err.statusCode`.
84
84
-`routerCacheSize`: The router matching cache size, indicates how many request matches will be kept in memory. Default value: `2000`
> `getConfigOptions()` returns a frozen shallow copy of the configuration options. This prevents third-party middleware from accidentally or maliciously modifying internal framework options at runtime.
- Stream (errors on the stream are handled gracefully, terminating the response instead of leaving the connection hanging)
173
+
- Promise (recursive promise resolution is capped at a depth of 3 to prevent event loop starvation)
168
174
169
175
Example usage:
170
176
```js
@@ -192,6 +198,9 @@ res.send(
192
198
> `res.send(401)`
193
199
194
200
## Global error handling
201
+
By default, restana returns a generic `Internal Server Error` message to the client, preventing internal details from being leaked. The HTTP status code is preserved from `err.status`, `err.code`, or `err.statusCode` (defaults to `500`).
202
+
203
+
To customize error responses, provide your own `errorHandler`:
> **Note:** When using `res.send(err)` in a custom error handler, the error's `message` and `data` properties will be serialized and sent to the client. Make sure your custom handler only exposes information you intend to be public.
> Restana version 5.x includes important security hardening while remaining backward compatible for most users.
472
+
473
+
Changed:
474
+
- The default `errorHandler` no longer sends `err.message` or `err.data` to clients. It now returns a generic `{ code, message: 'Internal Server Error' }` response. If you need the previous behavior, provide a custom `errorHandler`.
475
+
-`getConfigOptions()` now returns a frozen shallow copy of the options object instead of a direct mutable reference.
476
+
- Stream responses (`res.send(stream)`) now handle stream errors gracefully, terminating the response instead of leaving the connection hanging.
477
+
- Promise resolution in `res.send()` is now capped at a depth of 3 to prevent event loop starvation from deeply nested promise chains.
478
+
460
479
## 4.x
461
480
> Restana version 4.x is much more simple to maintain, mature and faster!
0 commit comments