@middy/http-multipart-body-parser 6.0.0 → 6.1.1

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +22 -6
  3. package/package.json +5 -4
package/README.md CHANGED
@@ -39,7 +39,7 @@
39
39
 
40
40
  ## License
41
41
 
42
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2024 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
42
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2025 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
43
43
 
44
44
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
45
45
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import BusBoy from '@fastify/busboy'
2
2
  import { createError } from '@middy/util'
3
3
 
4
- const mimePattern = /^multipart\/form-data(;.*)?$/
4
+ const mimePattern = /^multipart\/form-data; boundary=[-]*[a-zA-Z0-9]*$/
5
5
  const fieldnamePattern = /(.+)\[(.*)]$/
6
6
 
7
7
  const defaults = {
@@ -15,16 +15,26 @@ const httpMultipartBodyParserMiddleware = (opts = {}) => {
15
15
  const options = { ...defaults, ...opts }
16
16
 
17
17
  const httpMultipartBodyParserMiddlewareBefore = async (request) => {
18
- const { headers } = request.event
18
+ const { headers, body } = request.event
19
+ if (typeof body === 'undefined') {
20
+ throw createError(
21
+ 415,
22
+ 'Invalid or malformed multipart/form-data was provided',
23
+ { cause: { package: '@middy/http-multipart-body-parser', data: body } }
24
+ )
25
+ }
19
26
 
20
- const contentType = headers?.['Content-Type'] ?? headers?.['content-type']
27
+ const contentType = headers?.['content-type'] ?? headers?.['Content-Type']
21
28
 
22
29
  if (!mimePattern.test(contentType)) {
23
30
  if (options.disableContentTypeError) {
24
31
  return
25
32
  }
26
33
  throw createError(415, 'Unsupported Media Type', {
27
- cause: { package: '@middy/multipart-body-parser', data: contentType }
34
+ cause: {
35
+ package: '@middy/http-multipart-body-parser',
36
+ data: contentType
37
+ }
28
38
  })
29
39
  }
30
40
 
@@ -38,7 +48,13 @@ const httpMultipartBodyParserMiddleware = (opts = {}) => {
38
48
  throw createError(
39
49
  415,
40
50
  'Invalid or malformed multipart/form-data was provided',
41
- { cause: { package: '@middy/multipart-body-parser', data: err } }
51
+ {
52
+ cause: {
53
+ package: '@middy/http-multipart-body-parser',
54
+ data: body,
55
+ message: err.message
56
+ }
57
+ }
42
58
  )
43
59
  })
44
60
  }
@@ -56,7 +72,7 @@ const parseMultipartData = (event, options) => {
56
72
  ...options.busboy,
57
73
  headers: {
58
74
  'content-type':
59
- event.headers?.['Content-Type'] ?? event.headers?.['content-type']
75
+ event.headers?.['content-type'] ?? event.headers?.['Content-Type']
60
76
  }
61
77
  })
62
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-multipart-body-parser",
3
- "version": "6.0.0",
3
+ "version": "6.1.1",
4
4
  "description": "Http event normalizer middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -28,8 +28,9 @@
28
28
  "index.d.ts"
29
29
  ],
30
30
  "scripts": {
31
- "test": "npm run test:unit",
31
+ "test": "npm run test:unit && npm run test:fuzz",
32
32
  "test:unit": "node --test __tests__/index.js",
33
+ "test:fuzz": "node --test __tests__/fuzz.js",
33
34
  "test:benchmark": "node __benchmarks__/index.js"
34
35
  },
35
36
  "license": "MIT",
@@ -51,7 +52,7 @@
51
52
  },
52
53
  "repository": {
53
54
  "type": "git",
54
- "url": "github:middyjs/middy",
55
+ "url": "git+https://github.com/middyjs/middy.git",
55
56
  "directory": "packages/http-multipart-body-parser"
56
57
  },
57
58
  "bugs": {
@@ -63,7 +64,7 @@
63
64
  "url": "https://github.com/sponsors/willfarrell"
64
65
  },
65
66
  "dependencies": {
66
- "@fastify/busboy": "3.0.0"
67
+ "@fastify/busboy": "3.1.1"
67
68
  },
68
69
  "devDependencies": {
69
70
  "@types/aws-lambda": "^8.10.101",