tough-cookie 2.2.2 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -3
- package/lib/cookie.js +13 -14
- package/lib/pubsuffix.js +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
[RFC6265](https://tools.ietf.org/html/rfc6265) Cookies and CookieJar for Node.js
|
|
2
2
|
|
|
3
|
-
[](https://nodei.co/npm/tough-cookie/)
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
[](https://travis-ci.org/salesforce/tough-cookie)
|
|
7
6
|
|
|
8
7
|
# Synopsis
|
|
9
8
|
|
|
@@ -30,6 +29,10 @@ It's _so_ easy!
|
|
|
30
29
|
|
|
31
30
|
Why the name? NPM modules `cookie`, `cookies` and `cookiejar` were already taken.
|
|
32
31
|
|
|
32
|
+
## Version Support
|
|
33
|
+
|
|
34
|
+
Support for versions of node.js will follow that of the [request](https://www.npmjs.com/package/request) module.
|
|
35
|
+
|
|
33
36
|
# API
|
|
34
37
|
|
|
35
38
|
## tough
|
|
@@ -131,6 +134,9 @@ else
|
|
|
131
134
|
cookies = [Cookie.parse(res.headers['set-cookie'])];
|
|
132
135
|
```
|
|
133
136
|
|
|
137
|
+
_Potentially non-standard behavior:_ currently, tough-cookie will limit the number of spaces before the `=` to 256 characters.
|
|
138
|
+
See [Issue 92](https://github.com/salesforce/tough-cookie/issues/92)
|
|
139
|
+
|
|
134
140
|
### Properties
|
|
135
141
|
|
|
136
142
|
Cookie object properties:
|
|
@@ -426,6 +432,17 @@ Inherits from `Store`.
|
|
|
426
432
|
|
|
427
433
|
A just-in-memory CookieJar synchronous store implementation, used by default. Despite being a synchronous implementation, it's usable with both the synchronous and asynchronous forms of the `CookieJar` API.
|
|
428
434
|
|
|
435
|
+
## Community Cookie Stores
|
|
436
|
+
|
|
437
|
+
These are some Store implementations authored and maintained by the community. They aren't official and we don't vouch for them but you may be interested to have a look:
|
|
438
|
+
|
|
439
|
+
- [`db-cookie-store`](https://github.com/JSBizon/db-cookie-store): SQL including SQLite-based databases
|
|
440
|
+
- [`file-cookie-store`](https://github.com/JSBizon/file-cookie-store): Netscape cookie file format on disk
|
|
441
|
+
- [`redis-cookie-store`](https://github.com/benkroeger/redis-cookie-store): Redis
|
|
442
|
+
- [`tough-cookie-filestore`](https://github.com/mitsuru/tough-cookie-filestore): JSON on disk
|
|
443
|
+
- [`tough-cookie-web-storage-store`](https://github.com/exponentjs/tough-cookie-web-storage-store): DOM localStorage and sessionStorage
|
|
444
|
+
|
|
445
|
+
|
|
429
446
|
# Serialization Format
|
|
430
447
|
|
|
431
448
|
**NOTE**: if you want to have custom `Cookie` properties serialized, add the property name to `Cookie.serializableProperties`.
|
package/lib/cookie.js
CHANGED
|
@@ -53,24 +53,25 @@ var COOKIE_OCTETS = new RegExp('^'+COOKIE_OCTET.source+'+$');
|
|
|
53
53
|
|
|
54
54
|
var CONTROL_CHARS = /[\x00-\x1F]/;
|
|
55
55
|
|
|
56
|
+
// For COOKIE_PAIR and LOOSE_COOKIE_PAIR below, the number of spaces has been
|
|
57
|
+
// restricted to 256 to side-step a ReDoS issue reported here:
|
|
58
|
+
// https://github.com/salesforce/tough-cookie/issues/92
|
|
59
|
+
|
|
56
60
|
// Double quotes are part of the value (see: S4.1.1).
|
|
57
61
|
// '\r', '\n' and '\0' should be treated as a terminator in the "relaxed" mode
|
|
58
62
|
// (see: https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L60)
|
|
59
63
|
// '=' and ';' are attribute/values separators
|
|
60
64
|
// (see: https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L64)
|
|
61
|
-
var COOKIE_PAIR = /^(([^=;]+))\s
|
|
65
|
+
var COOKIE_PAIR = /^(([^=;]+))\s{0,256}=\s*([^\n\r\0]*)/;
|
|
62
66
|
|
|
63
67
|
// Used to parse non-RFC-compliant cookies like '=abc' when given the `loose`
|
|
64
68
|
// option in Cookie.parse:
|
|
65
|
-
var LOOSE_COOKIE_PAIR = /^((?:=)?([^=;]*)\s
|
|
69
|
+
var LOOSE_COOKIE_PAIR = /^((?:=)?([^=;]*)\s{0,256}=\s*)?([^\n\r\0]*)/;
|
|
66
70
|
|
|
67
71
|
// RFC6265 S4.1.1 defines path value as 'any CHAR except CTLs or ";"'
|
|
68
72
|
// Note ';' is \x3B
|
|
69
73
|
var PATH_VALUE = /[\x20-\x3A\x3C-\x7E]+/;
|
|
70
74
|
|
|
71
|
-
// Used for checking whether or not there is a trailing semi-colon
|
|
72
|
-
var TRAILING_SEMICOLON = /;+$/;
|
|
73
|
-
|
|
74
75
|
var DAY_OF_MONTH = /^(\d{1,2})[^\d]*$/;
|
|
75
76
|
var TIME = /^(\d{1,2})[^\d]*:(\d{1,2})[^\d]*:(\d{1,2})[^\d]*$/;
|
|
76
77
|
var MONTH = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i;
|
|
@@ -327,12 +328,6 @@ function parse(str, options) {
|
|
|
327
328
|
}
|
|
328
329
|
str = str.trim();
|
|
329
330
|
|
|
330
|
-
// S4.1.1 Trailing semi-colons are not part of the specification.
|
|
331
|
-
var semiColonCheck = TRAILING_SEMICOLON.exec(str);
|
|
332
|
-
if (semiColonCheck) {
|
|
333
|
-
str = str.slice(0, semiColonCheck.index);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
331
|
// We use a regex to parse the "name-value-pair" part of S5.2
|
|
337
332
|
var firstSemi = str.indexOf(';'); // S5.2 step 1
|
|
338
333
|
var pairRe = options.loose ? LOOSE_COOKIE_PAIR : COOKIE_PAIR;
|
|
@@ -362,7 +357,7 @@ function parse(str, options) {
|
|
|
362
357
|
// S5.2.3 "unparsed-attributes consist of the remainder of the set-cookie-string
|
|
363
358
|
// (including the %x3B (";") in question)." plus later on in the same section
|
|
364
359
|
// "discard the first ";" and trim".
|
|
365
|
-
var unparsed = str.slice(firstSemi).
|
|
360
|
+
var unparsed = str.slice(firstSemi + 1).trim();
|
|
366
361
|
|
|
367
362
|
// "If the unparsed-attributes string is empty, skip the rest of these
|
|
368
363
|
// steps."
|
|
@@ -378,9 +373,12 @@ function parse(str, options) {
|
|
|
378
373
|
* cookie-attribute-list". Therefore, in this implementation, we overwrite
|
|
379
374
|
* the previous value.
|
|
380
375
|
*/
|
|
381
|
-
var cookie_avs = unparsed.split(
|
|
376
|
+
var cookie_avs = unparsed.split(';');
|
|
382
377
|
while (cookie_avs.length) {
|
|
383
|
-
var av = cookie_avs.shift();
|
|
378
|
+
var av = cookie_avs.shift().trim();
|
|
379
|
+
if (av.length === 0) { // happens if ";;" appears
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
384
382
|
var av_sep = av.indexOf('=');
|
|
385
383
|
var av_key, av_value;
|
|
386
384
|
|
|
@@ -1212,6 +1210,7 @@ CookieJar.prototype._importCookies = function(serialized, cb) {
|
|
|
1212
1210
|
if (!cookies || !Array.isArray(cookies)) {
|
|
1213
1211
|
return cb(new Error('serialized jar has no cookies array'));
|
|
1214
1212
|
}
|
|
1213
|
+
cookies = cookies.slice(); // do not modify the original
|
|
1215
1214
|
|
|
1216
1215
|
function putNext(err) {
|
|
1217
1216
|
if (err) {
|