Skip to content

clientHttpServer has potential issue with multi-chunk bodies #82

Description

@thomashondema

I’m not sure how often this happens in real-world deployments, but the HTTP handler currently appears to assume that the full request body arrives in a single data event. That is not guaranteed by Node/HTTP.
I was able to reproduce a 400 Bad Request with a valid JSON body by sending the same request body in multiple chunks:
./httpTest.sh 0
No delay between writes. The body is received as one chunk and accepted.
./httpTest.sh 1
Adds a 1-second delay between body writes. This makes the valid body arrive in multiple chunks, and the service responds with 400 Bad Request.
The issue appears to be in clientHttpServer.js: request parsing occurs within the req.on('data') handler. If the first chunk is smaller than Content-Length, the code enters the Bad request branch before the remaining chunks arrive.
A safer approach would be to append chunks in data, then parse and queue the request only from req.on('end'), when the full body has been received. However, I don't know if the issue is big enough to justify the rewrite, and I don't know the code well enough.

httpTest.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions