Skip to content

form-urlencoded requests do not proxy correctly if content-type contains a semi-colonΒ #488

@codefactor

Description

@codefactor

If the content-type header of the request is like "application/x-www-form-urlencoded; charset=UTF-8" the following logic is not functioning properly in the sendProxyRequest.js:

      if (bodyContent.length) {
        var body = bodyContent;
        var contentType = proxyReq.getHeader('Content-Type');
        if (contentType === 'x-www-form-urlencoded' || contentType === 'application/x-www-form-urlencoded') {
          try {
            var params = JSON.parse(body);
            body = Object.keys(params).map(function(k) { return k + '=' + params[k]; }).join('&');
          } catch (e) {
            // bodyContent is not json-format
          }
        }

What ends up happening is the bodyContent is a JSON and it gets sent improperly.

The body-parser seems to have no issues with this content-type.

The contentType detection of urlencoded should not break if there is a semi-colon followed by the charset or other segments of the contentType.

As a work around - I can add a custom proxyReqOptDecorator and capture the content-type from the caller and "sanitize" the content-type and remove the semi-colon segment as a temporary fix. But I should not need to do that.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions