Skip to content

Commit 83bd4ea

Browse files
committed
Support multipart maxParts option
1 parent 0d8d651 commit 83bd4ea

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

API.md

+6
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,12 @@ Default value: `1048576` (1MB).
30483048
Limits the size of incoming payloads to the specified byte count. Allowing very large payloads may
30493049
cause the server to run out of memory.
30503050

3051+
#### <a name="route.options.payload.maxParts" /> `route.options.payload.maxParts`
3052+
3053+
Default value: `1000`.
3054+
3055+
Limits the number of parts allowed in multipart payloads.
3056+
30513057
#### <a name="route.options.payload.multipart" /> `route.options.payload.multipart`
30523058

30533059
Default value: `false`.

lib/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ internals.routeBase = Validate.object({
153153
override: Validate.string(),
154154
protoAction: Validate.valid('error', 'remove', 'ignore').default('error'),
155155
maxBytes: Validate.number().integer().positive().default(1024 * 1024),
156+
maxParts: Validate.number().integer().positive().default(1000),
156157
uploads: Validate.string().default(Os.tmpdir()),
157158
failAction: internals.failAction,
158159
timeout: Validate.number().integer().positive().allow(false).default(10 * 1000),

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@hapi/shot": "^6.0.1",
3939
"@hapi/somever": "^4.1.1",
4040
"@hapi/statehood": "^8.0.1",
41-
"@hapi/subtext": "^8.0.1",
41+
"@hapi/subtext": "^8.1.0",
4242
"@hapi/teamwork": "^6.0.0",
4343
"@hapi/topo": "^6.0.1",
4444
"@hapi/validate": "^2.0.1"

test/payload.js

+13
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,19 @@ describe('Payload', () => {
686686
expect(res.result.pics).to.exist();
687687
});
688688

689+
it('places default limit on max parts in multipart payloads', async () => {
690+
691+
const part = '--AaB03x\r\n' + 'content-disposition: form-data; name="x"\r\n\r\n' + 'x\r\n';
692+
const multipartPayload = part.repeat(1001) + '--AaB03x--\r\n';
693+
694+
const server = Hapi.server({ routes: { payload: { multipart: true } } });
695+
server.route({ method: 'POST', path: '/', handler: () => null });
696+
697+
const res = await server.inject({ method: 'POST', url: '/', payload: multipartPayload, headers: { 'content-type': 'multipart/form-data; boundary=AaB03x' } });
698+
expect(res.statusCode).to.equal(400);
699+
expect(res.result.message).to.equal('Invalid multipart payload format');
700+
});
701+
689702
it('signals connection close when payload is unconsumed', async () => {
690703

691704
const payload = Buffer.alloc(1024);

0 commit comments

Comments
 (0)