fastify 5.8.0 → 5.8.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.
package/fastify.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const VERSION = '5.7.4'
3
+ const VERSION = '5.8.1'
4
4
 
5
5
  const Avvio = require('avvio')
6
6
  const http = require('node:http')
@@ -11,7 +11,9 @@ const keyValuePairsReg = /([\w!#$%&'*+.^`|~-]+)=([^;]*)/gm
11
11
 
12
12
  /**
13
13
  * typeNameReg is used to validate that the first part of the media-type
14
- * does not use disallowed characters.
14
+ * does not use disallowed characters. Types must consist solely of
15
+ * characters that match the specified character class. It must terminate
16
+ * with a matching character.
15
17
  *
16
18
  * @see https://httpwg.org/specs/rfc9110.html#rule.token.separators
17
19
  * @type {RegExp}
@@ -20,12 +22,16 @@ const typeNameReg = /^[\w!#$%&'*+.^`|~-]+$/
20
22
 
21
23
  /**
22
24
  * subtypeNameReg is used to validate that the second part of the media-type
23
- * does not use disallowed characters.
25
+ * does not use disallowed characters. Subtypes must consist solely of
26
+ * characters that match the specified character class, and optionally
27
+ * terminated with any amount of whitespace characters. Without the terminating
28
+ * anchor (`$`), the regular expression will match the leading portion of a
29
+ * string instead of the whole string.
24
30
  *
25
31
  * @see https://httpwg.org/specs/rfc9110.html#rule.token.separators
26
32
  * @type {RegExp}
27
33
  */
28
- const subtypeNameReg = /^[\w!#$%&'*+.^`|~-]+\s*/
34
+ const subtypeNameReg = /^[\w!#$%&'*+.^`|~-]+\s*$/
29
35
 
30
36
  /**
31
37
  * ContentType parses and represents the value of the content-type header.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify",
3
- "version": "5.8.0",
3
+ "version": "5.8.1",
4
4
  "description": "Fast and low overhead web framework, for Node.js",
5
5
  "main": "fastify.js",
6
6
  "type": "commonjs",
@@ -74,6 +74,44 @@ describe('ContentType class', () => {
74
74
  found = new ContentType('foo/π; param=1')
75
75
  t.assert.equal(found.isEmpty, true)
76
76
  t.assert.equal(found.isValid, false)
77
+
78
+ found = new ContentType('application/json<script>alert(1)</script>')
79
+ t.assert.equal(found.isEmpty, true)
80
+ t.assert.equal(found.isValid, false)
81
+
82
+ found = new ContentType('application/json/extra/slashes')
83
+ t.assert.equal(found.isEmpty, true)
84
+ t.assert.equal(found.isValid, false)
85
+
86
+ found = new ContentType('application/json(garbage)')
87
+ t.assert.equal(found.isEmpty, true)
88
+ t.assert.equal(found.isValid, false)
89
+
90
+ found = new ContentType('application/json@evil')
91
+ t.assert.equal(found.isEmpty, true)
92
+ t.assert.equal(found.isValid, false)
93
+
94
+ found = new ContentType('application/json\x00garbage')
95
+ t.assert.equal(found.isEmpty, true)
96
+ t.assert.equal(found.isValid, false)
97
+ })
98
+
99
+ test('subtype with multiple fields validates as incorrect', (t) => {
100
+ let found = new ContentType('application/json whatever')
101
+ t.assert.equal(found.isValid, false)
102
+ t.assert.equal(found.isEmpty, true)
103
+
104
+ found = new ContentType('application/ json whatever')
105
+ t.assert.equal(found.isValid, false)
106
+ t.assert.equal(found.isEmpty, true)
107
+
108
+ found = new ContentType('application/json whatever; foo=bar')
109
+ t.assert.equal(found.isValid, false)
110
+ t.assert.equal(found.isEmpty, true)
111
+
112
+ found = new ContentType('application/ json whatever; foo=bar')
113
+ t.assert.equal(found.isValid, false)
114
+ t.assert.equal(found.isEmpty, true)
77
115
  })
78
116
 
79
117
  test('returns a plain media type instance', (t) => {