tough-cookie 5.1.2 → 6.0.0-rc.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/dist/cookie/canonicalDomain.d.ts +1 -1
- package/dist/cookie/canonicalDomain.js +3 -6
- package/dist/cookie/constants.d.ts +1 -0
- package/dist/cookie/constants.js +5 -6
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +16 -43
- package/dist/cookie/cookieCompare.d.ts +1 -1
- package/dist/cookie/cookieCompare.js +1 -4
- package/dist/cookie/cookieJar.d.ts +25 -11
- package/dist/cookie/cookieJar.js +77 -89
- package/dist/cookie/defaultPath.d.ts +1 -1
- package/dist/cookie/defaultPath.js +1 -4
- package/dist/cookie/domainMatch.d.ts +1 -1
- package/dist/cookie/domainMatch.js +4 -7
- package/dist/cookie/formatDate.js +1 -4
- package/dist/cookie/index.d.ts +19 -19
- package/dist/cookie/index.js +22 -44
- package/dist/cookie/parseDate.d.ts +1 -1
- package/dist/cookie/parseDate.js +1 -4
- package/dist/cookie/permutePath.js +1 -4
- package/dist/cookie/secureContext.d.ts +15 -0
- package/dist/cookie/secureContext.js +79 -0
- package/dist/getPublicSuffix.js +3 -6
- package/dist/memstore.d.ts +3 -3
- package/dist/memstore.js +15 -18
- package/dist/pathMatch.js +1 -4
- package/dist/permuteDomain.js +3 -6
- package/dist/store.d.ts +2 -2
- package/dist/store.js +1 -5
- package/dist/utils.js +6 -13
- package/dist/validators.d.ts +1 -1
- package/dist/validators.js +11 -22
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -4
- package/package.json +18 -23
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Nullable } from '../utils';
|
|
1
|
+
import type { Nullable } from '../utils.js';
|
|
2
2
|
/**
|
|
3
3
|
* Transforms a domain name into a canonical domain name. The canonical domain name is a domain name
|
|
4
4
|
* that has been trimmed, lowercased, stripped of leading dot, and optionally punycode-encoded
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.canonicalDomain = canonicalDomain;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
1
|
+
import { IP_V6_REGEX_OBJECT } from './constants.js';
|
|
5
2
|
/**
|
|
6
3
|
* Normalizes a domain to lowercase and punycode-encoded.
|
|
7
4
|
* Runtime-agnostic equivalent to node's `domainToASCII`.
|
|
@@ -41,12 +38,12 @@ function domainToASCII(domain) {
|
|
|
41
38
|
* @param domainName - the domain name to generate the canonical domain from
|
|
42
39
|
* @public
|
|
43
40
|
*/
|
|
44
|
-
function canonicalDomain(domainName) {
|
|
41
|
+
export function canonicalDomain(domainName) {
|
|
45
42
|
if (domainName == null) {
|
|
46
43
|
return undefined;
|
|
47
44
|
}
|
|
48
45
|
let str = domainName.trim().replace(/^\./, ''); // S4.1.2.3 & S5.2.3: ignore leading .
|
|
49
|
-
if (
|
|
46
|
+
if (IP_V6_REGEX_OBJECT.test(str)) {
|
|
50
47
|
if (!str.startsWith('[')) {
|
|
51
48
|
str = '[' + str;
|
|
52
49
|
}
|
|
@@ -17,6 +17,7 @@ export declare const PrefixSecurityEnum: {
|
|
|
17
17
|
readonly DISABLED: "unsafe-disabled";
|
|
18
18
|
};
|
|
19
19
|
export declare const IP_V6_REGEX_OBJECT: RegExp;
|
|
20
|
+
export declare const IP_V4_REGEX_OBJECT: RegExp;
|
|
20
21
|
/**
|
|
21
22
|
* A JSON representation of a {@link CookieJar}.
|
|
22
23
|
* @public
|
package/dist/cookie/constants.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IP_V6_REGEX_OBJECT = exports.PrefixSecurityEnum = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the
|
|
6
3
|
* first few characters of the cookie's name. These are defined in {@link https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-13#section-4.1.3 | RFC6265bis - Section 4.1.3}.
|
|
@@ -14,12 +11,12 @@ exports.IP_V6_REGEX_OBJECT = exports.PrefixSecurityEnum = void 0;
|
|
|
14
11
|
* - `unsafe-disabled` - Disables cookie prefix checking.
|
|
15
12
|
* @public
|
|
16
13
|
*/
|
|
17
|
-
|
|
14
|
+
export const PrefixSecurityEnum = {
|
|
18
15
|
SILENT: 'silent',
|
|
19
16
|
STRICT: 'strict',
|
|
20
17
|
DISABLED: 'unsafe-disabled',
|
|
21
18
|
};
|
|
22
|
-
Object.freeze(
|
|
19
|
+
Object.freeze(PrefixSecurityEnum);
|
|
23
20
|
const IP_V6_REGEX = `
|
|
24
21
|
\\[?(?:
|
|
25
22
|
(?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|
|
|
@@ -35,4 +32,6 @@ const IP_V6_REGEX = `
|
|
|
35
32
|
.replace(/\s*\/\/.*$/gm, '')
|
|
36
33
|
.replace(/\n/g, '')
|
|
37
34
|
.trim();
|
|
38
|
-
|
|
35
|
+
export const IP_V6_REGEX_OBJECT = new RegExp(`^${IP_V6_REGEX}$`);
|
|
36
|
+
const IP_V4_REGEX = `(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])`;
|
|
37
|
+
export const IP_V4_REGEX_OBJECT = new RegExp(`^${IP_V4_REGEX}$`);
|
package/dist/cookie/cookie.d.ts
CHANGED
package/dist/cookie/cookie.js
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Cookie = void 0;
|
|
27
1
|
/*!
|
|
28
2
|
* Copyright (c) 2015-2020, Salesforce.com, Inc.
|
|
29
3
|
* All rights reserved.
|
|
@@ -54,12 +28,12 @@ exports.Cookie = void 0;
|
|
|
54
28
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
55
29
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
56
30
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
31
|
+
import { getPublicSuffix } from '../getPublicSuffix.js';
|
|
32
|
+
import * as validators from '../validators.js';
|
|
33
|
+
import { inOperator } from '../utils.js';
|
|
34
|
+
import { formatDate } from './formatDate.js';
|
|
35
|
+
import { parseDate } from './parseDate.js';
|
|
36
|
+
import { canonicalDomain } from './canonicalDomain.js';
|
|
63
37
|
// From RFC6265 S4.1.1
|
|
64
38
|
// note that it excludes \x3B ";"
|
|
65
39
|
const COOKIE_OCTETS = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]+$/;
|
|
@@ -174,7 +148,7 @@ function parse(str, options) {
|
|
|
174
148
|
switch (av_key) {
|
|
175
149
|
case 'expires': // S5.2.1
|
|
176
150
|
if (av_value) {
|
|
177
|
-
const exp =
|
|
151
|
+
const exp = parseDate(av_value);
|
|
178
152
|
// "If the attribute-value failed to parse as a cookie date, ignore the
|
|
179
153
|
// cookie-av."
|
|
180
154
|
if (exp) {
|
|
@@ -277,12 +251,12 @@ function fromJSON(str) {
|
|
|
277
251
|
}
|
|
278
252
|
const c = new Cookie();
|
|
279
253
|
Cookie.serializableProperties.forEach((prop) => {
|
|
280
|
-
if (obj && typeof obj === 'object' &&
|
|
254
|
+
if (obj && typeof obj === 'object' && inOperator(prop, obj)) {
|
|
281
255
|
const val = obj[prop];
|
|
282
256
|
if (val === undefined) {
|
|
283
257
|
return;
|
|
284
258
|
}
|
|
285
|
-
if (
|
|
259
|
+
if (inOperator(prop, cookieDefaults) && val === cookieDefaults[prop]) {
|
|
286
260
|
return;
|
|
287
261
|
}
|
|
288
262
|
switch (prop) {
|
|
@@ -364,7 +338,7 @@ const cookieDefaults = {
|
|
|
364
338
|
* It is defined in {@link https://www.rfc-editor.org/rfc/rfc6265.html | RFC6265}.
|
|
365
339
|
* @public
|
|
366
340
|
*/
|
|
367
|
-
class Cookie {
|
|
341
|
+
export class Cookie {
|
|
368
342
|
/**
|
|
369
343
|
* Create a new Cookie instance.
|
|
370
344
|
* @public
|
|
@@ -500,7 +474,7 @@ class Cookie {
|
|
|
500
474
|
}
|
|
501
475
|
if (this.expires != 'Infinity' &&
|
|
502
476
|
!(this.expires instanceof Date) &&
|
|
503
|
-
!
|
|
477
|
+
!parseDate(this.expires)) {
|
|
504
478
|
return false;
|
|
505
479
|
}
|
|
506
480
|
if (this.maxAge != null &&
|
|
@@ -516,7 +490,7 @@ class Cookie {
|
|
|
516
490
|
if (cdomain.match(/\.$/)) {
|
|
517
491
|
return false; // S4.1.2.3 suggests that this is bad. domainMatch() tests confirm this
|
|
518
492
|
}
|
|
519
|
-
const suffix =
|
|
493
|
+
const suffix = getPublicSuffix(cdomain);
|
|
520
494
|
if (suffix == null) {
|
|
521
495
|
// it's a public suffix
|
|
522
496
|
return false;
|
|
@@ -538,7 +512,7 @@ class Cookie {
|
|
|
538
512
|
this.expires = exp;
|
|
539
513
|
}
|
|
540
514
|
else {
|
|
541
|
-
this.expires =
|
|
515
|
+
this.expires = parseDate(exp) || 'Infinity';
|
|
542
516
|
}
|
|
543
517
|
}
|
|
544
518
|
/**
|
|
@@ -579,7 +553,7 @@ class Cookie {
|
|
|
579
553
|
let str = this.cookieString();
|
|
580
554
|
if (this.expires != 'Infinity') {
|
|
581
555
|
if (this.expires instanceof Date) {
|
|
582
|
-
str += `; Expires=${
|
|
556
|
+
str += `; Expires=${formatDate(this.expires)}`;
|
|
583
557
|
}
|
|
584
558
|
}
|
|
585
559
|
if (this.maxAge != null && this.maxAge != Infinity) {
|
|
@@ -719,14 +693,14 @@ class Cookie {
|
|
|
719
693
|
*/
|
|
720
694
|
canonicalizedDomain() {
|
|
721
695
|
// Mostly S5.1.2 and S5.2.3:
|
|
722
|
-
return
|
|
696
|
+
return canonicalDomain(this.domain);
|
|
723
697
|
}
|
|
724
698
|
/**
|
|
725
699
|
* Alias for {@link Cookie.canonicalizedDomain}
|
|
726
700
|
* @public
|
|
727
701
|
*/
|
|
728
702
|
cdomain() {
|
|
729
|
-
return
|
|
703
|
+
return canonicalDomain(this.domain);
|
|
730
704
|
}
|
|
731
705
|
/**
|
|
732
706
|
* Parses a string into a Cookie object.
|
|
@@ -792,7 +766,6 @@ class Cookie {
|
|
|
792
766
|
return fromJSON(str);
|
|
793
767
|
}
|
|
794
768
|
}
|
|
795
|
-
exports.Cookie = Cookie;
|
|
796
769
|
Cookie.cookiesCreated = 0;
|
|
797
770
|
/**
|
|
798
771
|
* @internal
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Cookie } from './cookie';
|
|
1
|
+
import type { Cookie } from './cookie.js';
|
|
2
2
|
/**
|
|
3
3
|
* A comparison function that can be used with {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | Array.sort()},
|
|
4
4
|
* which orders a list of cookies into the recommended order given in Step 2 of {@link https://www.rfc-editor.org/rfc/rfc6265.html#section-5.4 | RFC6265 - Section 5.4}.
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cookieCompare = cookieCompare;
|
|
4
1
|
/**
|
|
5
2
|
* The maximum timestamp a cookie, in milliseconds. The value is (2^31 - 1) seconds since the Unix
|
|
6
3
|
* epoch, corresponding to 2038-01-19.
|
|
@@ -62,7 +59,7 @@ const MAX_TIME = 2147483647000;
|
|
|
62
59
|
* @param b - the second Cookie for comparison
|
|
63
60
|
* @public
|
|
64
61
|
*/
|
|
65
|
-
function cookieCompare(a, b) {
|
|
62
|
+
export function cookieCompare(a, b) {
|
|
66
63
|
let cmp;
|
|
67
64
|
// descending for length: b CMP a
|
|
68
65
|
const aPathLen = a.path ? a.path.length : 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Store } from '../store';
|
|
2
|
-
import { Cookie } from './cookie';
|
|
3
|
-
import { Callback, ErrorCallback, Nullable } from '../utils';
|
|
4
|
-
import { SerializedCookieJar } from './constants';
|
|
1
|
+
import { Store } from '../store.js';
|
|
2
|
+
import { Cookie } from './cookie.js';
|
|
3
|
+
import { Callback, ErrorCallback, Nullable } from '../utils.js';
|
|
4
|
+
import { SerializedCookieJar } from './constants.js';
|
|
5
5
|
/**
|
|
6
6
|
* Configuration options used when calling `CookieJar.setCookie(...)`
|
|
7
7
|
* @public
|
|
@@ -25,7 +25,7 @@ export interface SetCookieOptions {
|
|
|
25
25
|
*
|
|
26
26
|
* - `'none'` - This indicates a cross-origin request.
|
|
27
27
|
*
|
|
28
|
-
* - `undefined` - SameSite is not
|
|
28
|
+
* - `undefined` - SameSite is not enforced! This can be a valid use-case for when
|
|
29
29
|
* CSRF isn't in the threat model of the system being built.
|
|
30
30
|
*
|
|
31
31
|
* Defaults to `undefined` if not provided.
|
|
@@ -71,7 +71,7 @@ export interface GetCookiesOptions {
|
|
|
71
71
|
*
|
|
72
72
|
* @remarks
|
|
73
73
|
* - Using `false` returns expired cookies and does not remove them from the
|
|
74
|
-
* store which is potentially useful for replaying `Set-Cookie` headers.
|
|
74
|
+
* store, which is potentially useful for replaying `Set-Cookie` headers.
|
|
75
75
|
*
|
|
76
76
|
* Defaults to `true` if not provided.
|
|
77
77
|
*/
|
|
@@ -96,7 +96,7 @@ export interface GetCookiesOptions {
|
|
|
96
96
|
*
|
|
97
97
|
* - `'none'` - This indicates a cross-origin request.
|
|
98
98
|
*
|
|
99
|
-
* - `undefined` - SameSite is not
|
|
99
|
+
* - `undefined` - SameSite is not enforced! This can be a valid use-case for when
|
|
100
100
|
* CSRF isn't in the threat model of the system being built.
|
|
101
101
|
*
|
|
102
102
|
* Defaults to `undefined` if not provided.
|
|
@@ -144,6 +144,19 @@ export interface CreateCookieJarOptions {
|
|
|
144
144
|
* Defaults to `true` if not specified.
|
|
145
145
|
*/
|
|
146
146
|
allowSpecialUseDomain?: boolean | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Flag to indicate if localhost and loopback addresses with an unsecure scheme should store and retrieve `Secure` cookies.
|
|
149
|
+
*
|
|
150
|
+
* If `true`, localhost, loopback addresses or similarly local addresses are treated as secure contexts
|
|
151
|
+
* and thus will store and retrieve `Secure` cookies even with an unsecure scheme.
|
|
152
|
+
*
|
|
153
|
+
* If `false`, only secure schemes (`https` and `wss`) will store and retrieve `Secure` cookies.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* When set to `true`, the {@link https://w3c.github.io/webappsec-secure-contexts/#potentially-trustworthy-origin | potentially trustworthy}
|
|
157
|
+
* algorithm is followed to determine if a URL is considered a secure context.
|
|
158
|
+
*/
|
|
159
|
+
allowSecureOnLocal?: boolean | undefined;
|
|
147
160
|
}
|
|
148
161
|
/**
|
|
149
162
|
* A CookieJar is for storage and retrieval of {@link Cookie} objects as defined in
|
|
@@ -156,6 +169,7 @@ export declare class CookieJar {
|
|
|
156
169
|
private readonly rejectPublicSuffixes;
|
|
157
170
|
private readonly enableLooseMode;
|
|
158
171
|
private readonly allowSpecialUseDomain;
|
|
172
|
+
private readonly allowSecureOnLocal;
|
|
159
173
|
/**
|
|
160
174
|
* The configured {@link Store} for the {@link CookieJar}.
|
|
161
175
|
*/
|
|
@@ -185,7 +199,7 @@ export declare class CookieJar {
|
|
|
185
199
|
* properties.
|
|
186
200
|
*
|
|
187
201
|
* - As per the RFC, the {@link Cookie.hostOnly} flag is set if there was no `Domain={value}`
|
|
188
|
-
*
|
|
202
|
+
* attribute on the cookie string. The {@link Cookie.domain} property is set to the
|
|
189
203
|
* fully-qualified hostname of `currentUrl` in this case. Matching this cookie requires an
|
|
190
204
|
* exact hostname match (not a {@link domainMatch} as per usual)
|
|
191
205
|
*
|
|
@@ -204,7 +218,7 @@ export declare class CookieJar {
|
|
|
204
218
|
* properties.
|
|
205
219
|
*
|
|
206
220
|
* - As per the RFC, the {@link Cookie.hostOnly} flag is set if there was no `Domain={value}`
|
|
207
|
-
*
|
|
221
|
+
* attribute on the cookie string. The {@link Cookie.domain} property is set to the
|
|
208
222
|
* fully-qualified hostname of `currentUrl` in this case. Matching this cookie requires an
|
|
209
223
|
* exact hostname match (not a {@link domainMatch} as per usual)
|
|
210
224
|
*
|
|
@@ -224,7 +238,7 @@ export declare class CookieJar {
|
|
|
224
238
|
* properties.
|
|
225
239
|
*
|
|
226
240
|
* - As per the RFC, the {@link Cookie.hostOnly} flag is set if there was no `Domain={value}`
|
|
227
|
-
*
|
|
241
|
+
* attribute on the cookie string. The {@link Cookie.domain} property is set to the
|
|
228
242
|
* fully-qualified hostname of `currentUrl` in this case. Matching this cookie requires an
|
|
229
243
|
* exact hostname match (not a {@link domainMatch} as per usual)
|
|
230
244
|
*
|
|
@@ -249,7 +263,7 @@ export declare class CookieJar {
|
|
|
249
263
|
* properties.
|
|
250
264
|
*
|
|
251
265
|
* - As per the RFC, the {@link Cookie.hostOnly} flag is set if there was no `Domain={value}`
|
|
252
|
-
*
|
|
266
|
+
* attribute on the cookie string. The {@link Cookie.domain} property is set to the
|
|
253
267
|
* fully-qualified hostname of `currentUrl` in this case. Matching this cookie requires an
|
|
254
268
|
* exact hostname match (not a {@link domainMatch} as per usual)
|
|
255
269
|
*
|