-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix truncated cookie #5215
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
ext-src/swoole_http_response.cc
Outdated
cookie_size += sizeof(max_age); | ||
char *new_cookie = (char *) emalloc(cookie_size); | ||
strlcpy(new_cookie, cookie, cookie_size); | ||
efree(cookie); | ||
cookie = new_cookie; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 🧐
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
9380b3b
to
01faf30
Compare
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.
01faf30
to
af1a66a
Compare
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.
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.
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