Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit b8737ad

Browse files
committed
careful not to interpret Buffer as json-parsed keyed object
1 parent e6fb666 commit b8737ad

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/__tests__/http-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,23 @@ describe('test harness', () => {
522522
});
523523
});
524524

525+
it('does not accept unknown pre-parsed POST raw Buffer', async () => {
526+
var app = express();
527+
app.use(bodyParser.raw({ type: '*/*' }));
528+
529+
app.use(urlString(), graphqlHTTP({ schema: TestSchema }));
530+
531+
var req = request(app)
532+
.post(urlString())
533+
.set('Content-Type', 'application/graphql');
534+
req.write(new Buffer('{ test(who: "World") }'));
535+
var error = await catchError(req);
536+
537+
expect(error.response.status).to.equal(400);
538+
expect(JSON.parse(error.response.text)).to.deep.equal({
539+
errors: [ { message: 'Must provide query string.' } ]
540+
});
541+
});
525542
});
526543

527544
describe('Pretty printing', () => {

src/parseBody.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import type { Request } from 'express';
1818

1919
export function parseBody(req: Request, next: NodeCallback): void {
2020
try {
21-
// If express has already parsed a body as an object, use it.
22-
if (typeof req.body === 'object') {
21+
// If express has already parsed a body as a keyed object, use it.
22+
if (typeof req.body === 'object' && !(req.body instanceof Buffer)) {
2323
return next(null, req.body);
2424
}
2525

0 commit comments

Comments
 (0)