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

Bug inside the RFC6265 S5.1.1 date parser parseDate() on days 29, 30, 31 #28

Closed
syndr0m opened this issue Feb 27, 2015 · 2 comments
Closed

Comments

@syndr0m
Copy link

syndr0m commented Feb 27, 2015

Every date on a day 29, 30 or 31 are wrongly parsed if the current date month has less days than the parsed one.

Small exemple of a cookie expiring on Mars 29 parsed Mars 01 :

$> git clone https://github.com/goinstant/tough-cookie.git && cd tough-cookie && npm install # latest

# current date is february 
$>node -e 'console.log(new Date())'  
Fri Feb 27 2015 15:35:53 GMT+0100 (CET)

# wrongly parsed cookie example
$> node -e "console.log(require('./lib/cookie').Cookie.parse('foo=bar; path=/; expires=Sun, 29 Mar 2015 15:13:10 GMT;'));"
Cookie="foo=bar; Expires=Sun, 01 Mar 2015 15:13:10 GMT; Path=/; hostOnly=?; aAge=?; cAge=0ms"

This is a bug inside parseDate() ( https://github.com/goinstant/tough-cookie/blob/master/lib/cookie.js#L91 )

The parser is looping on date's tokens : "Sun", "29", "Mar", "2015", "15:13:10", "GMT"
The parser is using the tokens to modify a date object : new Date();
but this date object is initialized with the current date, (currently "February")
so, when processing "29", it tries to set day 29 of month february which cause the bug :

date before setUTCDate() : Fri Feb 27 2015 16:31:16 GMT+0100 (CET)
date.setUTCDate(result[1]);
date after setUTCDate() : Sun Mar 01 2015 16:31:16 GMT+0100 (CET)
``


@stash
Copy link
Collaborator

stash commented Mar 30, 2015

Sorry for the delayed response. This seems pretty serious so I'll try to get a fix going right away.

@inikulin
Copy link
Contributor

Fixed in #30. Released with tough-cookie@0.13.0.

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

No branches or pull requests

3 participants