Skip to content

Server crashes on POST requests with incorrect Content-Length or incorrect JSON body #298

@7eliassen

Description

@7eliassen

If you send a POST request to the server with incomplete JSON or a "Content-Length" header that is less than the actual body length, the server will crash.

Example:
curl -X POST http://localhost:1337/note \ -H "Content-Length: 3" \ -H "Content-Type: application/json" \ -d "{bodybody}"

Or

curl -X POST http://localhost:1337/note -H "Content-Type: application/json" -d "{bodybody"

Will throw a SyntaxError on the server.
Image

It happens because the server tries to parse incomplete JSON, which causes an error.
How to fix: request validation and error handling need to be added.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions