-
-
Notifications
You must be signed in to change notification settings - Fork 17.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
A Cookie maxAge
of undefined
causes incorrect behavior.
#3935
Comments
Yep, makes sense. To throw or to coerce would depend on what happens currently with the various types. Ideally we should throw, but if there are other types currently working or the set-cookie header is still valid then we may just need to coerce for now. When it is |
The relavent two lines are: opts.expires = new Date(Date.now() + opts.maxAge);
opts.maxAge /= 1000; If |
Ok, so it already throws when maxAge is set to a non number? That would seem to me to be the expected behavior. Is it just that the error message thrown is confusing or something? |
Throwing is good, and the error is clear, however, there is a dependency on a downstream dependent library to behave correctly instead of Express actually doing the right thing. Express should never be asking for The only symptom I had was Express would never return. This was exspecially strange because, due to a refactor, this value was being set to |
Gotcha. So thinking a bit more of it, do you think that |
The only problem with that is, the setting of Really, my problem came from thinking that under the hood Perhaps instead of |
Right. The code is from before I working on Express, so cannot answer as to why it was done that way. But that doesn't take away from some of the concerns which is mainly (1) not break current use cases and (2) what should be the right resolution. |
The main downside to using
So just the property existing on the global prototype makes it return |
That is exactly my point, which is why I made the PR the way I did. It doesn't break any current use-cases, but it does causes |
It just feels weird. Because if it makes it 0, then the cookie will immediately expire. That change would make there be no possible way to explicitly state that the cookie should be a session length cookie, then? |
That is a very good point... If the goal is to get It seems if we want to preserve session cookies and the current Is this a breaking change that should go in v.Next? |
If it's a breaking change, then yes. If not, we can land in 4.x. We would want to land as much as possible in 4.x, ideally. If there is a breaking change here, we'll want to lay it out what is changing and such so it's documented for when the 4 to 5 migration guide is written. |
Technically all of this is a change in behavior, but I think we can probably change My case where I expected Thus the question is: is I'll update my PR at your direction. |
Yes, I mean, fixing a bug is typically always a breaking change in the pure sense. That doesn't mean we don't fix them anyway, of course :) If it's iffy but desirable, they are typically included in minor versions instead of patch versions, but still fixed within the major.
So in a way we relay on javascript details for almost everything, since this is javascript. I know that's not what you mean, but just not sure how to really answer that question generically. For the specific of "should we be dividing a non-number by a number, I would say no, unless there is some special reason, we should above it. That would mean the act of doing Assuming that is passed in doesn't have a special This would, to me, say everything except numbers and I would say from that, we have two divisions of changes: (1) stop dividing all non-numbers and non-null values and let (2) ideally |
I follow your logic and would vote against option 2a for sure, that just pushes the problem down the road. For option 1, I would say that is a rather significant breaking change because the units that are used in If we are going to fix this behavior in the 5.0 branch, then I say we just put a deprecation warning here identifying the desired behavior (must pass a number, else |
I think you may have mis-read my number 1 (or maybe I wasn't clear?). Numbers would still be divided and expires still calculated with number 1. |
I now see what you mean. In that case, this does now seem to make sense. That seems like it would be the right long-term solution (if |
no discussion for some time on the issue, closing. |
I'm still interested in this being resolved. Please reopen. |
I would like to add that we are working hard to get 5.0 out the door as soon as possible. Unless something critical comes up, 4.18 will be the last minor release of 4.x prior to the final 5.0, which means that for the underlying breaking change to even be considered for 5.0 at this point, we would want to get a 4.x-targeting deprecation ready quickly to get into the 4.18 release. There is always 6.0, and don't let that scare you, either; we have also been at work discussing and then planning after 5.0 in order for 6.0 to not sit anywhere near as long as 5.0 did 😂 |
This isn't much notice, especially given how long this item has sat dormant. I'll see what I can do about a deprecation notice in the next day or two. Just to be clear, what we are looking for right now in the 4.x branch is to have a deprecated warning issued if any non-number is passed in. Then, in the 5.x branch, detect if the value passed in is a non-number, and then avoid division on that number and pass it directly to Is that what we'd all like to see? |
Just checking again before I proceed; is the above how we'd like to proceed? |
Last night I was just going over this issue again to try and wrap my mind around all the topics we spoke about. Before I write up my thoughts here, I did want to ask to confirm something. From your POV, what do you believe the goal is? This is just to get back in sync with each other. I believe at least one goal (maybe the only one?) is that setting maxAge to If that is the case, I think we need to revisit a little bit, as that is counter to what the underlying cookie module does on that value. Typically in javascript I believe that a specific As for For other non numbers like strings and stuff, those should error out for sure. I believe the underlying module will already do this, but we could likely guard for it higher? |
Goals:
The problem is that some of these might be considered a breaking change, though I would argue that really we just have a bug. The other problem is for 3, what should the correct behavior be? Should they be coalesced to 0, or sent to the downstream library. If they are just sent along, how do we handle the case of Does that make sense? |
I know this has kind of gotten forgotten in the pile of issues, but I am here trying to go through them all :) So yea, the goals there I think make sense. Basically this module is using This makes it such that |
In
lib/response.js
inres.cookie()
some assumptions are made that the incomingmaxAge
option will always be a number. However, ifmaxAge
is set toundefined
through some process,opts.maxAge /= 1000
returnsNaN
.maxAge
should be verified and/or coerced to be numeric.The text was updated successfully, but these errors were encountered: