tough-cookie 3.0.1 → 4.0.0

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm package](https://nodei.co/npm/tough-cookie.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/tough-cookie/)
4
4
 
5
- [![Build Status](https://travis-ci.org/salesforce/tough-cookie.png?branch=master)](https://travis-ci.org/salesforce/tough-cookie)
5
+ [![Build Status](https://travis-ci.org/salesforce/tough-cookie.svg?branch=master)](https://travis-ci.org/salesforce/tough-cookie)
6
6
 
7
7
  # Synopsis
8
8
 
@@ -149,6 +149,7 @@ Cookie object properties:
149
149
  * _path_ - string - the `Path=` of the cookie
150
150
  * _secure_ - boolean - the `Secure` cookie flag
151
151
  * _httpOnly_ - boolean - the `HttpOnly` cookie flag
152
+ * _sameSite_ - string - the `SameSite` cookie attribute (from [RFC6265bis]); must be one of `none`, `lax`, or `strict`
152
153
  * _extensions_ - `Array` - any unrecognized cookie attributes as strings (even if equal-signs inside)
153
154
  * _creation_ - `Date` - when this cookie was constructed
154
155
  * _creationIndex_ - number - set at construction, used to provide greater sort precision (please see `cookieCompare(a,b)` for a full explanation)
@@ -251,6 +252,8 @@ The `options` object can be omitted and can have the following properties:
251
252
 
252
253
  * _rejectPublicSuffixes_ - boolean - default `true` - reject cookies with domains like "com" and "co.uk"
253
254
  * _looseMode_ - boolean - default `false` - accept malformed cookies like `bar` and `=bar`, which have an implied empty name.
255
+ * _prefixSecurity_ - string - default `silent` - set to `'unsafe-disabled'`, `'silent'`, or `'strict'`. See [Cookie Prefixes] below.
256
+ * _allowSpecialUseDomain_ - boolean - default `false` - accepts special-use domain suffixes, such as `local`. Useful for testing purposes.
254
257
  This is not in the standard, but is used sometimes on the web and is accepted by (most) browsers.
255
258
 
256
259
  Since eventually this module would like to support database/remote/etc. CookieJars, continuation passing style is used for CookieJar methods.
@@ -265,6 +268,7 @@ The `options` object can be omitted and can have the following properties:
265
268
  * _secure_ - boolean - autodetect from url - indicates if this is a "Secure" API. If the currentUrl starts with `https:` or `wss:` then this is defaulted to `true`, otherwise `false`.
266
269
  * _now_ - Date - default `new Date()` - what to use for the creation/access time of cookies
267
270
  * _ignoreError_ - boolean - default `false` - silently ignore things like parse errors and invalid domains. `Store` errors aren't ignored by this option.
271
+ * _sameSiteContext_ - string - default unset - set to `'none'`, `'lax'`, or `'strict'` See [SameSite Cookies] below.
268
272
 
269
273
  As per the RFC, the `.hostOnly` property is set if there was no "Domain=" parameter in the cookie string (or `.domain` was null on the Cookie object). The `.domain` property is set to the fully-qualified hostname of `currentUrl` in this case. Matching this cookie requires an exact hostname match (not a `domainMatch` as per usual).
270
274
 
@@ -285,6 +289,7 @@ The `options` object can be omitted and can have the following properties:
285
289
  * _now_ - Date - default `new Date()` - what to use for the creation/access time of cookies
286
290
  * _expire_ - boolean - default `true` - perform expiry-time checking of cookies and asynchronously remove expired cookies from the store. Using `false` will return expired cookies and **not** remove them from the store (which is useful for replaying Set-Cookie headers, potentially).
287
291
  * _allPaths_ - boolean - default `false` - if `true`, do not scope cookies by path. The default uses RFC-compliant path scoping. **Note**: may not be supported by the underlying store (the default `MemoryCookieStore` supports it).
292
+ * _sameSiteContext_ - string - default unset - Set this to `'none'`, `'lax'` or `'strict'` to enforce SameSite cookies upon retrival. See [SameSite Cookies] below.
288
293
 
289
294
  The `.lastAccessed` property of the returned cookies will have been updated.
290
295
 
@@ -491,6 +496,56 @@ These are some Store implementations authored and maintained by the community. T
491
496
  }
492
497
  ```
493
498
 
499
+ # RFC6265bis
500
+
501
+ Support for RFC6265bis revision 02 is being developed. Since this is a bit of an omnibus revision to the RFC6252, support is broken up into the functional areas.
502
+
503
+ ## Leave Secure Cookies Alone
504
+
505
+ Not yet supported.
506
+
507
+ This change makes it so that if a cookie is sent from the server to the client with a `Secure` attribute, the channel must also be secure or the cookie is ignored.
508
+
509
+ ## SameSite Cookies
510
+
511
+ Supported.
512
+
513
+ This change makes it possible for servers, and supporting clients, to mitigate certain types of CSRF attacks by disallowing `SameSite` cookies from being sent cross-origin.
514
+
515
+ On the Cookie object itself, you can get/set the `.sameSite` attribute, which will be serialized into the `SameSite=` cookie attribute. When unset or `undefined`, no `SameSite=` attribute will be serialized. The valid values of this attribute are `'none'`, `'lax'`, or `'strict'`. Other values will be serialized as-is.
516
+
517
+ When parsing cookies with a `SameSite` cookie attribute, values other than `'lax'` or `'strict'` are parsed as `'none'`. For example, `SomeCookie=SomeValue; SameSite=garbage` will parse so that `cookie.sameSite === 'none'`.
518
+
519
+ In order to support SameSite cookies, you must provide a `sameSiteContext` option to _both_ `setCookie` and `getCookies`. Valid values for this option are just like for the Cookie object, but have particular meanings:
520
+ 1. `'strict'` mode - If the request is on the same "site for cookies" (see the RFC draft for what this means), pass this option to add a layer of defense against CSRF.
521
+ 2. `'lax'` mode - If the request is from another site, _but_ is directly because of navigation by the user, e.g., `<link type=prefetch>` or `<a href="...">`, pass `sameSiteContext: 'lax'`.
522
+ 3. `'none'` - Otherwise, pass `sameSiteContext: 'none'` (this indicates a cross-origin request).
523
+ 4. unset/`undefined` - SameSite **will not** be enforced! This can be a valid use-case for when CSRF isn't in the threat model of the system being built.
524
+
525
+ It is highly recommended that you read RFC 6265bis for fine details on SameSite cookies. In particular [Section 8.8](https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-02#section-8.8) discusses security considerations and defense in depth.
526
+
527
+ ## Cookie Prefixes
528
+
529
+ Supported.
530
+
531
+ Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the first few characters of the cookie's name.
532
+
533
+ Cookie prefixes are defined in [Section 4.1.3 of 6265bis](https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.3). Two prefixes are defined:
534
+
535
+ 1. `"__Secure-" Prefix`: If a cookie's name begins with a case-sensitive match for the string "__Secure-", then the cookie will have been set with a "Secure" attribute.
536
+ 2. `"__Host-" Prefix`: If a cookie's name begins with a case-sensitive match for the string "__Host-", then the cookie will have been set with a "Secure" attribute, a "Path" attribute with a value of "/", and no "Domain" attribute.
537
+
538
+ If `prefixSecurity` is enabled for `CookieJar`, then cookies that match the prefixes defined above but do not obey the attribute restrictions will not be added.
539
+
540
+ You can define this functionality by passing in `prefixSecurity` option to `CookieJar`. It can be one of 3 values:
541
+
542
+ 1. `silent`: Enable cookie prefix checking but silently fail to add the cookie if conditions not met. Default.
543
+ 2. `strict`: Enable cookie prefix checking and error out if conditions not met.
544
+ 3. `unsafe-disabled`: Disable cookie prefix checking.
545
+
546
+ Note that if `ignoreError` is passed in as `true` then the error will be silent regardless of `prefixSecurity` option (assuming it's enabled).
547
+
548
+
494
549
  # Copyright and License
495
550
 
496
551
  BSD-3-Clause: