Skip to content

[Bug]: Library does not parse cookie values containing '=' correctly #269

@qgolsteyn

Description

@qgolsteyn

First of all, great project!

I am working on a project where some requests include a base64 encoded cookie. These base64 values contains '=' in the cookie value. Unfortunately, when that is the case, the cookie value made available in req.cookies() is missing any character including and after the '='.

For example, we received a request with header:

Cookie: 'shopify_app_state=1231231231231; shopify_app_state.sig=aabbbbccccc='

lambda-api will return the following when calling req.cookies():

{
  "shopify_app_state": "1231231231231",
  "shopify_app_state.sig": "aabbbbccccc"
}

Note the missing '='.

I have identified the issue to https://github.com/jeremydaly/lambda-api/blob/main/lib/request.js#L164. We should split on the first '=' but should join the remaining string together to form the correct cookie value.

So, instead of:

cookie = cookie.trim().split('=');
return Object.assign(acc, {
        [cookie[0]]: UTILS.parseBody(decodeURIComponent(cookie[1])),
      });

We can do:

cookie = cookie.trim().split('=');
return Object.assign(acc, {
        [cookie[0]]: UTILS.parseBody(decodeURIComponent(cookie.slice(1).join('=')),
      });

I can push a PR if you are okay with this solution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions