Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
qgolsteyn opened this issue Jun 1, 2024 · 1 comment · Fixed by #271
Closed

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

qgolsteyn opened this issue Jun 1, 2024 · 1 comment · Fixed by #271
Milestone

Comments

@qgolsteyn
Copy link
Contributor

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

@qgolsteyn qgolsteyn changed the title [Bug]: Libraries does not parse cookie values containing '=' correctly [Bug]: Library does not parse cookie values containing '=' correctly Jun 1, 2024
@naorpeled
Copy link
Collaborator

Hey @qgolsteyn
this makes sense imo, feel free to open a PR 🙏

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants