graphql-upload 18.0.0 → 18.0.2

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.
@@ -60,10 +60,12 @@ export default function graphqlUploadExpress({
60
60
  // Todo: Find a less hacky way that avoids monkey patching.
61
61
  const { send } = response;
62
62
  response.send = (...args) => {
63
- requestFinished(request).then(() => {
64
- response.send = send;
65
- response.send(...args);
66
- });
63
+ requestFinished(request)
64
+ .then(() => {
65
+ response.send = send;
66
+ response.send(...args);
67
+ })
68
+ .catch(next);
67
69
 
68
70
  return response;
69
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-upload",
3
- "version": "18.0.0",
3
+ "version": "18.0.2",
4
4
  "description": "Middleware and a scalar Upload to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -92,7 +92,7 @@
92
92
  "prettier": "prettier -c .",
93
93
  "eslint": "eslint",
94
94
  "types": "tsc -p jsconfig.json",
95
- "test": "node --test --experimental-test-coverage --test-coverage-lines=100 --test-coverage-branches=100 --test-coverage-functions=100 --test-coverage-exclude='**/*.test.*' --test-reporter=spec",
95
+ "test": "node --test --experimental-test-coverage --test-coverage-lines=100 --test-coverage-branches=100 --test-coverage-functions=100 --test-coverage-exclude='**/*.test.*' --test-reporter=spec --test-timeout=10000",
96
96
  "check": "node --run prettier && node --run eslint && node --run types && node --run test",
97
97
  "prepublishOnly": "node --run check"
98
98
  }
@@ -202,6 +202,34 @@ export default function processRequest(
202
202
  );
203
203
 
204
204
  try {
205
+ // Check the upload’s mapped path in the operations is safe
206
+ // before setting it.
207
+
208
+ const keys = path.split(".");
209
+
210
+ /** @type {unknown} */
211
+ let pathValue = operations;
212
+
213
+ for (const [keyIndex, key] of keys.entries()) {
214
+ // Forbid `__proto__` keys to prevent prototype manipulation
215
+ // that could make client-supplied objects pass
216
+ // `instanceof Upload` checks.
217
+ if (key === "__proto__")
218
+ throw new TypeError("Object path has a `__proto__` key.");
219
+
220
+ // Forbid setting an upload within an already set upload, but
221
+ // allow a total replacement.
222
+ if (keyIndex < keys.length - 1) {
223
+ pathValue = objectPath.get(
224
+ /** @type {object} */ (pathValue),
225
+ [key],
226
+ );
227
+
228
+ if (pathValue instanceof Upload)
229
+ throw new TypeError("Object path traverses an upload.");
230
+ }
231
+ }
232
+
205
233
  operationsPath.set(path, map.get(fieldName));
206
234
  } catch {
207
235
  return exit(
@@ -234,9 +262,9 @@ export default function processRequest(
234
262
 
235
263
  const upload = map.get(fieldName);
236
264
 
237
- if (!upload) {
238
- // The file is extraneous. As the rest can still be processed, just
239
- // ignore it and don’t exit with an error.
265
+ if (!upload || upload.file) {
266
+ // The file is extraneous or a duplicate. As the rest can still be
267
+ // processed, just ignore it and don’t exit with an error.
240
268
  ignoreStream(stream);
241
269
  return;
242
270
  }