Class: default
An Adonis middleware which accepts and decodes requests encoded using the Resourceful encoding utility.
Decoding never rehydrates functions: encoded fns:d records are rejected with E_UNDECODABLE_VALUE, so a crafted request body cannot execute code.
Decoding is bounded by the configured resource limits (or the encoder's defaults: 16 MiB of inflated data, depth 32, 1,048,576 array entries; unsafe keys are rejected). These limits apply to every encoded payload decoded during the request (body, shortcut URLs, and choices) and only on routes where this middleware is registered. A limit violation in the body or a shortcut URL throws E_ENCODED_BODY_TOO_LARGE (HTTP 413); choices requests keep their existing HTTP 400 for any decode failure, including a limit violation.
Security
This middleware decodes request bodies at router level, which in AdonisJS runs before authentication middleware. It is therefore reachable by untrusted callers when registered globally (e.g. via configure/.adonisrc.json), and decoding arbitrarily large or hostile payloads is a denial-of-service surface. For apps with untrusted callers, either lower ResourcefulEncodedRequestMiddleware.limit, or register the middleware only on authenticated route groups instead of globally.
The raw-body size limit applies after Content-Encoding decompression, so it caps decompressed bytes and rejects oversized expanded bodies before decoding. The raw body limit can be tuned in two ways:
- set the static default:
ResourcefulEncodedRequestMiddleware.limit = '1mb' - (or) per registration when Adonis passes middleware options to
handle():{ limit: '512kb' }
Decode resource limits can similarly be tuned:
- static default:
ResourcefulEncodedRequestMiddleware.decodeLimits = { maxDepth: 64 } - (or) per registration:
{ decodeLimits: { maxDepth: 64 } }
The default body limit remains '100mb' for backwards compatibility.
Constructors
Constructor
new default(): ResourcefulEncodedRequestMiddleware;Returns
ResourcefulEncodedRequestMiddleware
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
decodeLimits? | static | DecodeLimits | undefined | Default decode resource limits passed to @nhtio/encoder's decode. When undefined, the encoder's built-in defaults (DEFAULT_DECODE_LIMITS) apply. Change this static property to adjust limits across all registrations that do not supply their own options. |
limit | static | string | number | '100mb' | Default maximum accepted decompressed body size, passed to raw-body after Content-Encoding inflation. Accepts any value supported by the bytes package (e.g. '100mb', '512kb') or a plain byte count. Change this static property to tighten (or loosen) the limit for every registration that does not pass its own options. |
Methods
handle()
handle(
ctx: HttpContext,
next: NextFn,
options?: ResourcefulEncodedRequestMiddlewareOptions): Promise<any>;Parameters
| Parameter | Type |
|---|---|
ctx | HttpContext |
next | NextFn |
options? | ResourcefulEncodedRequestMiddlewareOptions |
Returns
Promise<any>