cli icon indicating copy to clipboard operation
cli copied to clipboard

isBase64Encoded = true in "netlify dev" even though it shouldnt

Open logemann opened this issue 2 years ago • 2 comments

Describe the bug

This bug looks a lot like https://github.com/netlify/cli/pull/398. I experienced a strange bug when doing a JSON post to a Netlify function. isBase64Encoded is true, even though the JSON payload is not base64. This broke a middy middleware (jsonBodyParser) in my function.

To Reproduce

  1. Create a function
  2. do a POST on a function with Content-Type: application/json; charset=utf-8 and a simple JSON payload.
  3. console.log(event.isBase64Encoded) in function

Logging reveals "true" even though the payload in body is simple JSON text.

Configuration

System: OS: macOS 12.1 CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Memory: 1.56 GB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 15.14.0 - ~/.nvm/versions/node/v15.14.0/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 7.20.3 - ~/.nvm/versions/node/v15.14.0/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman npmGlobalPackages: netlify-cli: 8.6.15

Expected behavior

isBase64Encoded = false

Example Payload

POST /.netlify/functions/invite-user HTTP/1.1 Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkZpbGVtYWtlciIsImlhdCI6MTUxNjIzOTAyMn0.IXFd5MmMcgkbI6k01bx6p_ejIu-cWE5IDEHGOnGmzRU Content-Type: application/json; charset=utf-8 Host: localhost:8888 Connection: close User-Agent: Paw/3.3.2 (Macintosh; OS X/12.1.0) GCDHTTPRequest Content-Length: 41

{"email":"[email protected]","foo":"bar"}

logemann avatar Jan 08 '22 02:01 logemann

don't mean to hijack, but i'm seeing something weird like this today too and maybe the following can help netlify troubleshoot. i'm sending the following via a rest client:

{
targetURL: "google.com"
}

and this is from functions log (in prod):

    queryStringParameters: {},
    multiValueQueryStringParameters: {},
    body: 'ewogICAgInRhcmdldFVSTCI6Imdvb2dsZS5jb20iCiAgICAK',
    isBase64Encoded: true
  },

the encoded body returns an incomplete json string:

{
    "targetURL":"google.com"

which breaks anything i'm trying to do with JSON.parse

TotalLag avatar Jan 08 '22 22:01 TotalLag

@logemann Can you update netlify-cli & check if this issue is still occurring? I haven't been able to reproduce it at my end.

If the issue is still occurring, could a share a public repository with the reproduction?

tinfoil-knight avatar Aug 06 '22 12:08 tinfoil-knight

cant reproduce after CLI update.

logemann avatar Aug 29 '22 14:08 logemann