Skip to content

Content length not stripped from body in chunked transfer-encoding mode for POST json #2632

@lamyseba

Description

@lamyseba

When phusion passenger receives a request in "chunked" mode, it does not strip out the content length infos from the body he is transmitting to the app.

In chunked mode, the requester does not send the content-length, instead it sends content split into packets, each packets beginning with its length information. The last packet must be empty and have a length of zero.

As of version 6.0.27, Phusion does not strip this length informations. So when Phusion Passenger receives a POST request with json content in chunked mode, the body it transmits to my ruby app looks like:

45
{
     "email": "[email protected]",
     "event": "unsubscribe"
     }
0

Where "45" and "0" are unexpected content-length informations that gets my app into trouble when trying to parse json. My app was a ruby rack application using roda routing toolkit.

A sample curl request to reproduce the bug:

curl -v \ 
     --url http://localhost/ \
     --header 'transfer-encoding: chunked' \
     --header 'content-length:' \
     --header 'content-type: application/json' \
     --data '{
     "email": "[email protected]",
     "event": "unsubscribe"
     }'

In my case, I needed to make the request two or three times with curl to have a real chunked mode request. The first time curl makes the request, it sends a "normal" request, with a content-length header, and no transfer-encoding header

Metadata

Metadata

Assignees

No one assigned

    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