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

Fix truncated cookie #5215

Merged
merged 1 commit into from
Dec 15, 2023
Merged

Conversation

stnguyen90
Copy link
Contributor

Previously, Max-Age was added to the cookie, but cookie_size wasn't updated to account for the additional string size. This lead to the data being truncated in cases where everything was set.

This change updates the cookie_size based on the length of max_age and then increases the size of cookie to the increased cookie_size.

Fixes #5214

Copy link

codecov bot commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fc5d7d2) 72.96% compared to head (af1a66a) 72.98%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5215      +/-   ##
==========================================
+ Coverage   72.96%   72.98%   +0.02%     
==========================================
  Files          69       69              
  Lines       14855    14855              
==========================================
+ Hits        10839    10842       +3     
+ Misses       4016     4013       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 1045 to 1049
cookie_size += sizeof(max_age);
char *new_cookie = (char *) emalloc(cookie_size);
strlcpy(new_cookie, cookie, cookie_size);
efree(cookie);
cookie = new_cookie;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size_t cookie_size = name_len /* + value_len */ + path_len + domain_len + 200 + samesite_len + priority_len;

Attempting to modify the allocated memory size here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know the exact length of max_age until expires is processed, though. 🧐

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NathanFreeman, I've updated the code to try and calculate the cookie_size. How is it now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use sizeof("") - 1 to represent the length

Previously, Max-Age was added to the cookie, but cookie_size wasn't
updated to account for the additional string size. This lead to the data
being truncated in cases where everything was set.

This change updates the cookie_size based on the length of max_age and
then increases the size of cookie to the increased cookie_size.
@matyhtf matyhtf merged commit fc68071 into swoole:master Dec 15, 2023
35 of 36 checks passed
@stnguyen90 stnguyen90 deleted the fix-truncated-cookie branch December 27, 2023 17:10
stnguyen90 added a commit to appwrite/docker-base that referenced this pull request Feb 9, 2024
This new swoole version is important because it includes a patch for
cookies (swoole/swoole-src#5215) that caused a
problem in Appwrite (appwrite/appwrite#7253)
where cookies were not being saved.
stnguyen90 added a commit to appwrite/docker-base that referenced this pull request Feb 9, 2024
This new swoole version is important because it includes a patch
for cookies (swoole/swoole-src#5215) that caused a problem in
Appwrite (appwrite/appwrite#7253) where cookies were not being saved.
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 this pull request may close these issues.

Cookie is truncated leading to a malformed/invalid cookie
4 participants