Handling unparsable Expires Cookie values
See original GitHub issueHello all,
Looking at the issue #563 and the comment made by @martingith regarding a desire to handle Expires=0
made me look back the section of the Cookie spec relating to handling of Expires attribute
https://tools.ietf.org/html/rfc6265#section-5.2.1
The third paragraph of the section says that if the attribute value is NOT parsable into a valid value that it should be ignored. This means that we should NOT throw a (confusing) “can not be null” exception and stop the response processing
So I propose that the code of the CookieMatcher.groovy
be adjusted as follows
} else if(equalsIgnoreCase(name, EXPIRES)) {
value = trim(StringUtils.remove(value, "\""))
Date parsedDate = DateUtils.parseDate(value)
if (parsedDate != null) {
builder.setExpiryDate(parsedDate)
} else {
log.info("Ignoring the following unparsable 'Expires' attribute value: " + value)
}
}
Note: the logging of the bad value is optional (but helpful) the important item is to avoid the setting of the ExpiryDate on the Builder, when the date is not parsable, thereby avoiding the exception.
And apologizes in advance for not being able to do the change/PR myself. I am still working through my company process for participating in OSS on company time.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top GitHub Comments
ok, I’ll add a log statement for now with the condition that it may be removed in the future.
As for “should we log” I am changing my mind on it…
I think logging in this situation is relevant because it lets the user know that we encountered (and are ignoring) some data that was received in the response. I don’t expect this condition to occur frequently but I (personally) would like to know when it did occur in case of where I am building a service and I don’t realize that my cookie expires attribute value is not spec-compliant (so that I can fix it 😃)