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

Storing wrong domain when calling setCokies() with IPv6 address #153

Closed
vikiCoder opened this issue Apr 11, 2019 · 2 comments
Closed

Storing wrong domain when calling setCokies() with IPv6 address #153

vikiCoder opened this issue Apr 11, 2019 · 2 comments
Assignees

Comments

@vikiCoder
Copy link

Hi,

I noticed that while storing cookies for URL with IPv6 address (i.e. http://[::1]/foo), tough-cookie stores domain name without [ ] (i.e. ::1) in the store. It should store the domain as it is like Chrome does (i.e. [::1]).

Because of this behavior, I get error Error: Cookie not in this host's domain. Cookie:[::1] Request:::1 while executing following code snippet:

var tough = require('tough-cookie');
var jar = new tough.CookieJar();
var cookieString = 'my_cookie=hello_world; path=/; domain=[::1]; Expires=Sat, 11 May 2019 11:05:21 GMT;';
var url = 'http://[::1]/';

jar.setCookie(cookieString, url, (e) => {
    console.log(e)
});
@vikiCoder
Copy link
Author

I further looked up in the source code for this.

I think the reason behind this behavior is Node's url.parse() function which is being used in getCookieContext() of cookie.js file.

url.parse() removes [ ] from hostname. I think it should use the WHATWG URL API of Node (which more closely resembles the parsing behavior of most browsers) instead of deprecated legacy URL API. (i.e. use new url.URL() in place of url.parse()) This will solve the problem as far as I know.

Correct me if I am missing something.

@awaterma awaterma added this to To do in 4.x Release Jul 1, 2019
@awaterma awaterma removed this from To do in 4.x Release Dec 9, 2019
@awaterma awaterma self-assigned this Apr 20, 2020
@awaterma awaterma assigned ruoho-sfdc and unassigned awaterma Oct 20, 2020
@awaterma awaterma moved this from To do to In progress in 4.01/4.1 Release Plan Jan 25, 2021
@medelibero-sfdc medelibero-sfdc self-assigned this Mar 29, 2021
medelibero-sfdc added a commit that referenced this issue Apr 2, 2021
@awaterma awaterma moved this from In progress to Review in progress in 4.01/4.1 Release Plan Jun 21, 2021
@awaterma awaterma moved this from Review in progress to Reviewer approved in 4.01/4.1 Release Plan Jun 21, 2021
awaterma pushed a commit that referenced this issue Sep 27, 2021
* Fix for issue #153
* Added some more IPv6 tests
@awaterma awaterma moved this from Reviewer approved to Done in 4.01/4.1 Release Plan Sep 27, 2021
@awaterma
Copy link
Member

Closing out; issue was fixed in a merged p/r.

wjhsf pushed a commit that referenced this issue Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

4 participants