Skip to content

Commit

Permalink
Add a test for the function processRequest with a maliciously malfo…
Browse files Browse the repository at this point in the history
…rmed multipart request.
  • Loading branch information
jaydenseric committed May 27, 2022
1 parent 5d4c758 commit 7906f95
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Patch

- Updated the [`typescript`](https://npm.im/typescript) dev dependency.
- Added a test for the function `processRequest` with a maliciously malformed multipart request.

## 14.0.0

Expand Down
41 changes: 41 additions & 0 deletions processRequest.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,4 +1552,45 @@ export default (tests) => {
}
}
);

tests.add(
"`processRequest` with a maliciously malformed multipart request.",
async () => {
let serverError;

const server = createServer(async (request, response) => {
try {
await rejects(processRequest(request, response), {
name: "Error",
message: "Malformed part header",
});
} catch (error) {
serverError = error;
} finally {
response.end();
}
});

const { port, close } = await listen(server);

try {
const boundary = "abcde";

await fetch(`http://localhost:${port}`, {
method: "POST",
headers: {
"Content-Type": `multipart/form-data; boundary=${boundary}`,
},
body: `--${boundary}\r\n Content-Disposition: form-data;`,
// ^
// Invalid space char at the header name start. See:
// https://github.com/jaydenseric/graphql-upload/issues/311#issuecomment-1139513829
});

if (serverError) throw serverError;
} finally {
close();
}
}
);
};

0 comments on commit 7906f95

Please sign in to comment.