
Cloud Vulnerability DB
A community-led vulnerabilities database
There is a vulnerability in the function processRequest (used by the middleware created by the functions graphqlUploadExpress and graphqlUploadKoa) when processing GraphQL multipart requests.
Duplicate file multipart form fields cause temporary file and file descriptor leaks because new resources are created each time duplicate files are processed, and only references to the final duplicate resources are retained for cleanup when the response closes or the Node.js process gracefully exits.
While processing multipart request files, the file field name is used to retrieve the relevant Upload instance from the upload map:
https://github.com/jaydenseric/graphql-upload/blob/4824216bf46c94516e9f36d3e88ed0d5ae412126/processRequest.mjs#L235
Because there is no check if the same upload has already been processed, if the option maxFiles set to > 1, when a duplicate is processed a new capacitor is created:
https://github.com/jaydenseric/graphql-upload/blob/4824216bf46c94516e9f36d3e88ed0d5ae412126/processRequest.mjs#L247
The file upload stream is piped into it and the same Upload instance is resolved again:
https://github.com/jaydenseric/graphql-upload/blob/4824216bf46c94516e9f36d3e88ed0d5ae412126/processRequest.mjs#L288-L289
This overwrites the original file upload resource reference with the new duplicate one:
https://github.com/jaydenseric/graphql-upload/blob/4824216bf46c94516e9f36d3e88ed0d5ae412126/Upload.mjs#L23-L38
Later file upload resource cleanup only processes the final duplicate resources:
https://github.com/jaydenseric/graphql-upload/blob/4824216bf46c94516e9f36d3e88ed0d5ae412126/processRequest.mjs#L330-L338
Each earlier capacitor is no longer reachable from map. fs-capacitor unlinks the temp file on destroy() or release() and on a graceful process exit; a signal leaves it. The readme's deduplication note covers one file referenced multiple times in operations, not several files using the same multipart request form field name:
https://github.com/jaydenseric/graphql-upload/blob/4824216bf46c94516e9f36d3e88ed0d5ae412126/readme.md?plain=1#L43
Save as server.mjs:
import express from "express";
import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.mjs";
const app = express();
app.use(
"/graphql",
graphqlUploadExpress({ maxFiles: 10, maxFileSize: 10000000 }),
(req, res) => res.json({ ok: true }),
);
app.listen(3000, "127.0.0.1");Install, create the two 500 KB files, and run:
npm i express@5.3.0 graphql@17.1.0 graphql-upload@18.0.1
head -c 500000 /dev/zero > a.bin; head -c 500000 /dev/zero > b.bin
mkdir tmp; TMPDIR=$PWD/tmp node server.mjs &curl -s -o /dev/null -w '%{http_code}\n' \
-F 'operations={"query":"{ ping }"}' \
-F 'map={"0":["variables.file"]}' \
-F '0=@a.bin;filename=a.bin' \
-F '0=@b.bin;filename=b.bin' \
http://127.0.0.1:3000/graphqlIt prints:
200
$ ls -l tmp
-rw------- 1 user user 500000 ... capacitor-45d9c5a47fc7ea70af7943b5bdb1a7df.tmpThe response arrives and 1 500000-byte temp file remains in tmp. The same request with map {"0":["variables.file"],"1":["variables.other"]} and distinct names 0 and 1 leaves tmp empty.
Applications accepting GraphQL multipart requests using the functions processRequest, graphqlUploadExpress, or graphqlUploadKoa from affected versions of graphql-upload configured with the option maxFiles > 1 are vulnerable to denial of service.
Multipart requests with duplicate file multipart form fields with the same name in the file upload map cause temporary files and open file descriptors to remain allocated after request/response completion. Repeated requests can exhaust disk space or available file descriptors, preventing the application from handling legitimate requests.
With finite limits for maxFiles and maxFileSize configured, a single request can leave approximately (maxFiles - 1) × maxFileSize bytes of temporary file data on disk when maxFiles is > 1; the default limits impose no finite upper bound.
Exploitation does not require successful GraphQL operation execution. Authentication is required only if the application enforces it before upload processing.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."