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

domainMatch() breaks for URLs with TLD in substring of subdomain #235

Closed
davidofwatkins opened this issue Apr 15, 2022 · 1 comment · Fixed by #236
Closed

domainMatch() breaks for URLs with TLD in substring of subdomain #235

davidofwatkins opened this issue Apr 15, 2022 · 1 comment · Fixed by #236
Assignees

Comments

@davidofwatkins
Copy link

There's a bug where domainMatch() returns false unexpectedly when the domStr argument (top-level-domain) can be found elsewhere in the domain (str argument). For example:

❌ Broken:

require('tough-cookie').domainMatch('computer.com', 'com'); // false - should be true

✅ Working:

require('tough-cookie').domainMatch('c0mputer.com', 'com'); // true

The issue appears to come from the indexOf() check here:

const idx = str.indexOf(domStr);

...causing this calculation to fail:

tough-cookie/lib/cookie.js

Lines 379 to 381 in 30246e6

if (str.length !== domStr.length + idx) {
return false; // it's not a suffix
}

@colincasey
Copy link
Contributor

Thanks for the bug report @davidofwatkins. I'll look into this as soon as possible. But don't let that deter you from submitting your own PR with a fix if you have one.

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