tough-cookie 6.0.2 → 6.1.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 +41 -13
- package/dist/index.cjs +52 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -32
- package/dist/index.d.ts +55 -32
- package/dist/index.js +52 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,16 @@ declare const PrefixSecurityEnum: {
|
|
|
16
16
|
readonly STRICT: "strict";
|
|
17
17
|
readonly DISABLED: "unsafe-disabled";
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Prefix security enforcement mode for a CookieJar per RFC 6265bis.
|
|
21
|
+
*
|
|
22
|
+
* - `'silent'` - Enable cookie prefix checking but silently ignores the cookie if conditions are not met. Default.
|
|
23
|
+
* - `'strict'` - Enables cookie prefix checking and will raise an error if conditions are not met.
|
|
24
|
+
* - `'unsafe-disabled'` - Disables cookie prefix checking.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
type PrefixSecurityMode = (typeof PrefixSecurityEnum)[keyof typeof PrefixSecurityEnum];
|
|
19
29
|
/**
|
|
20
30
|
* A JSON representation of a {@link CookieJar}.
|
|
21
31
|
* @public
|
|
@@ -212,6 +222,10 @@ declare class Cookie {
|
|
|
212
222
|
*
|
|
213
223
|
* @remarks
|
|
214
224
|
* Works for a few things, but is by no means comprehensive.
|
|
225
|
+
* Checks that the cookie name is a non-empty token as defined in RFC 6265 Section 4.1.1.
|
|
226
|
+
* Nameless cookies (including those parsed in loose mode or created with `new Cookie({ value })`)
|
|
227
|
+
* and names containing characters outside the token grammar (such as `a b`) return `false`.
|
|
228
|
+
* Parsing and storage remain permissive; this check only applies to explicit validation.
|
|
215
229
|
*
|
|
216
230
|
* @beta
|
|
217
231
|
*/
|
|
@@ -370,6 +384,7 @@ declare class Cookie {
|
|
|
370
384
|
static sameSiteCanonical: {
|
|
371
385
|
readonly strict: "Strict";
|
|
372
386
|
readonly lax: "Lax";
|
|
387
|
+
readonly none: "None";
|
|
373
388
|
};
|
|
374
389
|
/**
|
|
375
390
|
* Cookie properties that will be serialized when using {@link Cookie.fromJSON} and {@link Cookie.toJSON}.
|
|
@@ -928,7 +943,7 @@ declare class ParameterError extends Error {
|
|
|
928
943
|
* The version of `tough-cookie`
|
|
929
944
|
* @public
|
|
930
945
|
*/
|
|
931
|
-
declare const version = "6.0
|
|
946
|
+
declare const version = "6.1.0";
|
|
932
947
|
|
|
933
948
|
/**
|
|
934
949
|
* Transforms a domain name into a canonical domain name. The canonical domain name is a domain name
|
|
@@ -1150,11 +1165,11 @@ interface CreateCookieJarOptions {
|
|
|
1150
1165
|
*/
|
|
1151
1166
|
looseMode?: boolean | undefined;
|
|
1152
1167
|
/**
|
|
1153
|
-
* Controls how cookie prefixes are handled. See {@link
|
|
1168
|
+
* Controls how cookie prefixes are handled. See {@link PrefixSecurityMode}.
|
|
1154
1169
|
*
|
|
1155
1170
|
* Defaults to `silent` if not specified.
|
|
1156
1171
|
*/
|
|
1157
|
-
prefixSecurity?:
|
|
1172
|
+
prefixSecurity?: PrefixSecurityMode | undefined;
|
|
1158
1173
|
/**
|
|
1159
1174
|
* Accepts {@link https://datatracker.ietf.org/doc/html/rfc6761 | special-use domains } such as `local`.
|
|
1160
1175
|
* This is not in the standard, but is used sometimes on the web and is accepted by most browsers. It is
|
|
@@ -1164,10 +1179,10 @@ interface CreateCookieJarOptions {
|
|
|
1164
1179
|
*/
|
|
1165
1180
|
allowSpecialUseDomain?: boolean | undefined;
|
|
1166
1181
|
/**
|
|
1167
|
-
* Flag to indicate if localhost and loopback addresses with an
|
|
1182
|
+
* Flag to indicate if localhost and loopback addresses with an insecure scheme should store and retrieve `Secure` cookies.
|
|
1168
1183
|
*
|
|
1169
1184
|
* If `true`, localhost, loopback addresses or similarly local addresses are treated as secure contexts
|
|
1170
|
-
* and thus will store and retrieve `Secure` cookies even with an
|
|
1185
|
+
* and thus will store and retrieve `Secure` cookies even with an insecure scheme.
|
|
1171
1186
|
*
|
|
1172
1187
|
* If `false`, only secure schemes (`https` and `wss`) will store and retrieve `Secure` cookies.
|
|
1173
1188
|
*
|
|
@@ -1176,6 +1191,24 @@ interface CreateCookieJarOptions {
|
|
|
1176
1191
|
* algorithm is followed to determine if a URL is considered a secure context.
|
|
1177
1192
|
*/
|
|
1178
1193
|
allowSecureOnLocal?: boolean | undefined;
|
|
1194
|
+
/**
|
|
1195
|
+
* Flag to indicate if `Secure` cookies set from an unsecure origin should be rejected.
|
|
1196
|
+
*
|
|
1197
|
+
* If `true`, a cookie with the `Secure` attribute is only stored when it is set from a secure context
|
|
1198
|
+
* (see {@link CreateCookieJarOptions.allowSecureOnLocal}). This applies to all `Secure` cookies, not just
|
|
1199
|
+
* those with a `__Secure-` or `__Host-` prefix, and is independent of {@link CreateCookieJarOptions.prefixSecurity}.
|
|
1200
|
+
*
|
|
1201
|
+
* If `false`, `Secure` cookies are stored regardless of the origin they were set from.
|
|
1202
|
+
*
|
|
1203
|
+
* This only affects storage. On retrieval, `Secure` cookies are only returned for secure contexts
|
|
1204
|
+
* regardless of this setting.
|
|
1205
|
+
*
|
|
1206
|
+
* Defaults to `true` if not specified.
|
|
1207
|
+
*
|
|
1208
|
+
* @remarks
|
|
1209
|
+
* See {@link https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-22#section-5.7-3.13.1 | RFC6265bis draft -22, Section 5.7 step 13}.
|
|
1210
|
+
*/
|
|
1211
|
+
enforceSecureOriginOnStorage?: boolean | undefined;
|
|
1179
1212
|
}
|
|
1180
1213
|
/**
|
|
1181
1214
|
* A CookieJar is for storage and retrieval of {@link Cookie} objects as defined in
|
|
@@ -1189,12 +1222,13 @@ declare class CookieJar {
|
|
|
1189
1222
|
private readonly enableLooseMode;
|
|
1190
1223
|
private readonly allowSpecialUseDomain;
|
|
1191
1224
|
private readonly allowSecureOnLocal;
|
|
1225
|
+
private readonly enforceSecureOriginOnStorage;
|
|
1192
1226
|
/**
|
|
1193
1227
|
* The configured {@link Store} for the {@link CookieJar}.
|
|
1194
1228
|
*/
|
|
1195
1229
|
readonly store: Store;
|
|
1196
1230
|
/**
|
|
1197
|
-
* The configured {@link
|
|
1231
|
+
* The configured {@link PrefixSecurityMode} value for the {@link CookieJar}.
|
|
1198
1232
|
*/
|
|
1199
1233
|
readonly prefixSecurity: string;
|
|
1200
1234
|
/**
|
|
@@ -1291,19 +1325,7 @@ declare class CookieJar {
|
|
|
1291
1325
|
* @param options - Configuration settings to use when storing the cookie.
|
|
1292
1326
|
* @public
|
|
1293
1327
|
*/
|
|
1294
|
-
setCookieSync(cookie: string | Cookie, url: string, options?: SetCookieOptions): Cookie | undefined;
|
|
1295
|
-
/**
|
|
1296
|
-
* Retrieve the list of cookies that can be sent in a Cookie header for the
|
|
1297
|
-
* current URL.
|
|
1298
|
-
*
|
|
1299
|
-
* @remarks
|
|
1300
|
-
* - The array of cookies returned will be sorted according to {@link cookieCompare}.
|
|
1301
|
-
*
|
|
1302
|
-
* - The {@link Cookie.lastAccessed} property will be updated on all returned cookies.
|
|
1303
|
-
*
|
|
1304
|
-
* @param url - The domain to store the cookie with.
|
|
1305
|
-
*/
|
|
1306
|
-
getCookies(url: string): Promise<Cookie[]>;
|
|
1328
|
+
setCookieSync(cookie: string | Cookie, url: string | URL, options?: SetCookieOptions): Cookie | undefined;
|
|
1307
1329
|
/**
|
|
1308
1330
|
* Retrieve the list of cookies that can be sent in a Cookie header for the
|
|
1309
1331
|
* current URL.
|
|
@@ -1316,7 +1338,7 @@ declare class CookieJar {
|
|
|
1316
1338
|
* @param url - The domain to store the cookie with.
|
|
1317
1339
|
* @param callback - A function to call after a cookie has been successfully retrieved.
|
|
1318
1340
|
*/
|
|
1319
|
-
getCookies(url: string, callback: Callback<Cookie[]>): void;
|
|
1341
|
+
getCookies(url: string | URL, callback: Callback<Cookie[]>): void;
|
|
1320
1342
|
/**
|
|
1321
1343
|
* Retrieve the list of cookies that can be sent in a Cookie header for the
|
|
1322
1344
|
* current URL.
|
|
@@ -1362,7 +1384,7 @@ declare class CookieJar {
|
|
|
1362
1384
|
* @param url - The domain to store the cookie with.
|
|
1363
1385
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1364
1386
|
*/
|
|
1365
|
-
getCookiesSync(url: string, options?: GetCookiesOptions): Cookie[];
|
|
1387
|
+
getCookiesSync(url: string | URL, options?: GetCookiesOptions): Cookie[];
|
|
1366
1388
|
/**
|
|
1367
1389
|
* Accepts the same options as `.getCookies()` but returns a string suitable for a
|
|
1368
1390
|
* `Cookie` header rather than an Array.
|
|
@@ -1371,7 +1393,7 @@ declare class CookieJar {
|
|
|
1371
1393
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1372
1394
|
* @param callback - A function to call after the `Cookie` header string has been created.
|
|
1373
1395
|
*/
|
|
1374
|
-
getCookieString(url: string, options: GetCookiesOptions, callback: Callback<string | undefined>): void;
|
|
1396
|
+
getCookieString(url: string | URL, options: GetCookiesOptions, callback: Callback<string | undefined>): void;
|
|
1375
1397
|
/**
|
|
1376
1398
|
* Accepts the same options as `.getCookies()` but returns a string suitable for a
|
|
1377
1399
|
* `Cookie` header rather than an Array.
|
|
@@ -1379,7 +1401,7 @@ declare class CookieJar {
|
|
|
1379
1401
|
* @param url - The domain to store the cookie with.
|
|
1380
1402
|
* @param callback - A function to call after the `Cookie` header string has been created.
|
|
1381
1403
|
*/
|
|
1382
|
-
getCookieString(url: string, callback: Callback<string | undefined>): void;
|
|
1404
|
+
getCookieString(url: string | URL, callback: Callback<string | undefined>): void;
|
|
1383
1405
|
/**
|
|
1384
1406
|
* Accepts the same options as `.getCookies()` but returns a string suitable for a
|
|
1385
1407
|
* `Cookie` header rather than an Array.
|
|
@@ -1387,11 +1409,11 @@ declare class CookieJar {
|
|
|
1387
1409
|
* @param url - The domain to store the cookie with.
|
|
1388
1410
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1389
1411
|
*/
|
|
1390
|
-
getCookieString(url: string, options?: GetCookiesOptions): Promise<string>;
|
|
1412
|
+
getCookieString(url: string | URL, options?: GetCookiesOptions): Promise<string>;
|
|
1391
1413
|
/**
|
|
1392
1414
|
* @internal No doc because this is an overload that supports the implementation
|
|
1393
1415
|
*/
|
|
1394
|
-
getCookieString(url: string, options: GetCookiesOptions | Callback<string | undefined>, callback?: Callback<string | undefined>): unknown;
|
|
1416
|
+
getCookieString(url: string | URL, options: GetCookiesOptions | Callback<string | undefined>, callback?: Callback<string | undefined>): unknown;
|
|
1395
1417
|
/**
|
|
1396
1418
|
* Synchronous version of `.getCookieString()`. Accepts the same options as `.getCookies()` but returns a string suitable for a
|
|
1397
1419
|
* `Cookie` header rather than an Array.
|
|
@@ -1401,7 +1423,7 @@ declare class CookieJar {
|
|
|
1401
1423
|
* @param url - The domain to store the cookie with.
|
|
1402
1424
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1403
1425
|
*/
|
|
1404
|
-
getCookieStringSync(url: string, options?: GetCookiesOptions): string;
|
|
1426
|
+
getCookieStringSync(url: string | URL, options?: GetCookiesOptions): string;
|
|
1405
1427
|
/**
|
|
1406
1428
|
* Returns an array of strings suitable for `Set-Cookie` headers. Accepts the same options
|
|
1407
1429
|
* as `.getCookies()`.
|
|
@@ -1409,7 +1431,7 @@ declare class CookieJar {
|
|
|
1409
1431
|
* @param url - The domain to store the cookie with.
|
|
1410
1432
|
* @param callback - A function to call after the `Set-Cookie` header strings have been created.
|
|
1411
1433
|
*/
|
|
1412
|
-
getSetCookieStrings(url: string, callback: Callback<string[] | undefined>): void;
|
|
1434
|
+
getSetCookieStrings(url: string | URL, callback: Callback<string[] | undefined>): void;
|
|
1413
1435
|
/**
|
|
1414
1436
|
* Returns an array of strings suitable for `Set-Cookie` headers. Accepts the same options
|
|
1415
1437
|
* as `.getCookies()`.
|
|
@@ -1418,7 +1440,7 @@ declare class CookieJar {
|
|
|
1418
1440
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1419
1441
|
* @param callback - A function to call after the `Set-Cookie` header strings have been created.
|
|
1420
1442
|
*/
|
|
1421
|
-
getSetCookieStrings(url: string, options: GetCookiesOptions, callback: Callback<string[] | undefined>): void;
|
|
1443
|
+
getSetCookieStrings(url: string | URL, options: GetCookiesOptions, callback: Callback<string[] | undefined>): void;
|
|
1422
1444
|
/**
|
|
1423
1445
|
* Returns an array of strings suitable for `Set-Cookie` headers. Accepts the same options
|
|
1424
1446
|
* as `.getCookies()`.
|
|
@@ -1426,11 +1448,11 @@ declare class CookieJar {
|
|
|
1426
1448
|
* @param url - The domain to store the cookie with.
|
|
1427
1449
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1428
1450
|
*/
|
|
1429
|
-
getSetCookieStrings(url: string, options?: GetCookiesOptions): Promise<string[] | undefined>;
|
|
1451
|
+
getSetCookieStrings(url: string | URL, options?: GetCookiesOptions): Promise<string[] | undefined>;
|
|
1430
1452
|
/**
|
|
1431
1453
|
* @internal No doc because this is an overload that supports the implementation
|
|
1432
1454
|
*/
|
|
1433
|
-
getSetCookieStrings(url: string, options: GetCookiesOptions, callback?: Callback<string[] | undefined>): unknown;
|
|
1455
|
+
getSetCookieStrings(url: string | URL, options: GetCookiesOptions, callback?: Callback<string[] | undefined>): unknown;
|
|
1434
1456
|
/**
|
|
1435
1457
|
* Synchronous version of `.getSetCookieStrings()`. Returns an array of strings suitable for `Set-Cookie` headers.
|
|
1436
1458
|
* Accepts the same options as `.getCookies()`.
|
|
@@ -1440,7 +1462,7 @@ declare class CookieJar {
|
|
|
1440
1462
|
* @param url - The domain to store the cookie with.
|
|
1441
1463
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1442
1464
|
*/
|
|
1443
|
-
getSetCookieStringsSync(url: string, options?: GetCookiesOptions): string[];
|
|
1465
|
+
getSetCookieStringsSync(url: string | URL, options?: GetCookiesOptions): string[];
|
|
1444
1466
|
/**
|
|
1445
1467
|
* Serialize the CookieJar if the underlying store supports `.getAllCookies`.
|
|
1446
1468
|
* @param callback - A function to call after the CookieJar has been serialized
|
|
@@ -1803,4 +1825,5 @@ declare function parse(str: string, options?: ParseCookieOptions): Cookie | unde
|
|
|
1803
1825
|
*/
|
|
1804
1826
|
declare function fromJSON(str: unknown): Cookie | undefined;
|
|
1805
1827
|
|
|
1806
|
-
export {
|
|
1828
|
+
export { Cookie, CookieJar, MemoryCookieStore, ParameterError, PrefixSecurityEnum, Store, canonicalDomain, cookieCompare, defaultPath, domainMatch, formatDate, fromJSON, getPublicSuffix, parse, parseDate, pathMatch, permuteDomain, permutePath, version };
|
|
1829
|
+
export type { Callback, CreateCookieJarOptions, CreateCookieOptions, ErrorCallback, GetCookiesOptions, GetPublicSuffixOptions, MemoryCookieStoreIndex, Nullable, ParseCookieOptions, PrefixSecurityMode, SerializedCookie, SerializedCookieJar, SetCookieOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,16 @@ declare const PrefixSecurityEnum: {
|
|
|
16
16
|
readonly STRICT: "strict";
|
|
17
17
|
readonly DISABLED: "unsafe-disabled";
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Prefix security enforcement mode for a CookieJar per RFC 6265bis.
|
|
21
|
+
*
|
|
22
|
+
* - `'silent'` - Enable cookie prefix checking but silently ignores the cookie if conditions are not met. Default.
|
|
23
|
+
* - `'strict'` - Enables cookie prefix checking and will raise an error if conditions are not met.
|
|
24
|
+
* - `'unsafe-disabled'` - Disables cookie prefix checking.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
type PrefixSecurityMode = (typeof PrefixSecurityEnum)[keyof typeof PrefixSecurityEnum];
|
|
19
29
|
/**
|
|
20
30
|
* A JSON representation of a {@link CookieJar}.
|
|
21
31
|
* @public
|
|
@@ -212,6 +222,10 @@ declare class Cookie {
|
|
|
212
222
|
*
|
|
213
223
|
* @remarks
|
|
214
224
|
* Works for a few things, but is by no means comprehensive.
|
|
225
|
+
* Checks that the cookie name is a non-empty token as defined in RFC 6265 Section 4.1.1.
|
|
226
|
+
* Nameless cookies (including those parsed in loose mode or created with `new Cookie({ value })`)
|
|
227
|
+
* and names containing characters outside the token grammar (such as `a b`) return `false`.
|
|
228
|
+
* Parsing and storage remain permissive; this check only applies to explicit validation.
|
|
215
229
|
*
|
|
216
230
|
* @beta
|
|
217
231
|
*/
|
|
@@ -370,6 +384,7 @@ declare class Cookie {
|
|
|
370
384
|
static sameSiteCanonical: {
|
|
371
385
|
readonly strict: "Strict";
|
|
372
386
|
readonly lax: "Lax";
|
|
387
|
+
readonly none: "None";
|
|
373
388
|
};
|
|
374
389
|
/**
|
|
375
390
|
* Cookie properties that will be serialized when using {@link Cookie.fromJSON} and {@link Cookie.toJSON}.
|
|
@@ -928,7 +943,7 @@ declare class ParameterError extends Error {
|
|
|
928
943
|
* The version of `tough-cookie`
|
|
929
944
|
* @public
|
|
930
945
|
*/
|
|
931
|
-
declare const version = "6.0
|
|
946
|
+
declare const version = "6.1.0";
|
|
932
947
|
|
|
933
948
|
/**
|
|
934
949
|
* Transforms a domain name into a canonical domain name. The canonical domain name is a domain name
|
|
@@ -1150,11 +1165,11 @@ interface CreateCookieJarOptions {
|
|
|
1150
1165
|
*/
|
|
1151
1166
|
looseMode?: boolean | undefined;
|
|
1152
1167
|
/**
|
|
1153
|
-
* Controls how cookie prefixes are handled. See {@link
|
|
1168
|
+
* Controls how cookie prefixes are handled. See {@link PrefixSecurityMode}.
|
|
1154
1169
|
*
|
|
1155
1170
|
* Defaults to `silent` if not specified.
|
|
1156
1171
|
*/
|
|
1157
|
-
prefixSecurity?:
|
|
1172
|
+
prefixSecurity?: PrefixSecurityMode | undefined;
|
|
1158
1173
|
/**
|
|
1159
1174
|
* Accepts {@link https://datatracker.ietf.org/doc/html/rfc6761 | special-use domains } such as `local`.
|
|
1160
1175
|
* This is not in the standard, but is used sometimes on the web and is accepted by most browsers. It is
|
|
@@ -1164,10 +1179,10 @@ interface CreateCookieJarOptions {
|
|
|
1164
1179
|
*/
|
|
1165
1180
|
allowSpecialUseDomain?: boolean | undefined;
|
|
1166
1181
|
/**
|
|
1167
|
-
* Flag to indicate if localhost and loopback addresses with an
|
|
1182
|
+
* Flag to indicate if localhost and loopback addresses with an insecure scheme should store and retrieve `Secure` cookies.
|
|
1168
1183
|
*
|
|
1169
1184
|
* If `true`, localhost, loopback addresses or similarly local addresses are treated as secure contexts
|
|
1170
|
-
* and thus will store and retrieve `Secure` cookies even with an
|
|
1185
|
+
* and thus will store and retrieve `Secure` cookies even with an insecure scheme.
|
|
1171
1186
|
*
|
|
1172
1187
|
* If `false`, only secure schemes (`https` and `wss`) will store and retrieve `Secure` cookies.
|
|
1173
1188
|
*
|
|
@@ -1176,6 +1191,24 @@ interface CreateCookieJarOptions {
|
|
|
1176
1191
|
* algorithm is followed to determine if a URL is considered a secure context.
|
|
1177
1192
|
*/
|
|
1178
1193
|
allowSecureOnLocal?: boolean | undefined;
|
|
1194
|
+
/**
|
|
1195
|
+
* Flag to indicate if `Secure` cookies set from an unsecure origin should be rejected.
|
|
1196
|
+
*
|
|
1197
|
+
* If `true`, a cookie with the `Secure` attribute is only stored when it is set from a secure context
|
|
1198
|
+
* (see {@link CreateCookieJarOptions.allowSecureOnLocal}). This applies to all `Secure` cookies, not just
|
|
1199
|
+
* those with a `__Secure-` or `__Host-` prefix, and is independent of {@link CreateCookieJarOptions.prefixSecurity}.
|
|
1200
|
+
*
|
|
1201
|
+
* If `false`, `Secure` cookies are stored regardless of the origin they were set from.
|
|
1202
|
+
*
|
|
1203
|
+
* This only affects storage. On retrieval, `Secure` cookies are only returned for secure contexts
|
|
1204
|
+
* regardless of this setting.
|
|
1205
|
+
*
|
|
1206
|
+
* Defaults to `true` if not specified.
|
|
1207
|
+
*
|
|
1208
|
+
* @remarks
|
|
1209
|
+
* See {@link https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-22#section-5.7-3.13.1 | RFC6265bis draft -22, Section 5.7 step 13}.
|
|
1210
|
+
*/
|
|
1211
|
+
enforceSecureOriginOnStorage?: boolean | undefined;
|
|
1179
1212
|
}
|
|
1180
1213
|
/**
|
|
1181
1214
|
* A CookieJar is for storage and retrieval of {@link Cookie} objects as defined in
|
|
@@ -1189,12 +1222,13 @@ declare class CookieJar {
|
|
|
1189
1222
|
private readonly enableLooseMode;
|
|
1190
1223
|
private readonly allowSpecialUseDomain;
|
|
1191
1224
|
private readonly allowSecureOnLocal;
|
|
1225
|
+
private readonly enforceSecureOriginOnStorage;
|
|
1192
1226
|
/**
|
|
1193
1227
|
* The configured {@link Store} for the {@link CookieJar}.
|
|
1194
1228
|
*/
|
|
1195
1229
|
readonly store: Store;
|
|
1196
1230
|
/**
|
|
1197
|
-
* The configured {@link
|
|
1231
|
+
* The configured {@link PrefixSecurityMode} value for the {@link CookieJar}.
|
|
1198
1232
|
*/
|
|
1199
1233
|
readonly prefixSecurity: string;
|
|
1200
1234
|
/**
|
|
@@ -1291,19 +1325,7 @@ declare class CookieJar {
|
|
|
1291
1325
|
* @param options - Configuration settings to use when storing the cookie.
|
|
1292
1326
|
* @public
|
|
1293
1327
|
*/
|
|
1294
|
-
setCookieSync(cookie: string | Cookie, url: string, options?: SetCookieOptions): Cookie | undefined;
|
|
1295
|
-
/**
|
|
1296
|
-
* Retrieve the list of cookies that can be sent in a Cookie header for the
|
|
1297
|
-
* current URL.
|
|
1298
|
-
*
|
|
1299
|
-
* @remarks
|
|
1300
|
-
* - The array of cookies returned will be sorted according to {@link cookieCompare}.
|
|
1301
|
-
*
|
|
1302
|
-
* - The {@link Cookie.lastAccessed} property will be updated on all returned cookies.
|
|
1303
|
-
*
|
|
1304
|
-
* @param url - The domain to store the cookie with.
|
|
1305
|
-
*/
|
|
1306
|
-
getCookies(url: string): Promise<Cookie[]>;
|
|
1328
|
+
setCookieSync(cookie: string | Cookie, url: string | URL, options?: SetCookieOptions): Cookie | undefined;
|
|
1307
1329
|
/**
|
|
1308
1330
|
* Retrieve the list of cookies that can be sent in a Cookie header for the
|
|
1309
1331
|
* current URL.
|
|
@@ -1316,7 +1338,7 @@ declare class CookieJar {
|
|
|
1316
1338
|
* @param url - The domain to store the cookie with.
|
|
1317
1339
|
* @param callback - A function to call after a cookie has been successfully retrieved.
|
|
1318
1340
|
*/
|
|
1319
|
-
getCookies(url: string, callback: Callback<Cookie[]>): void;
|
|
1341
|
+
getCookies(url: string | URL, callback: Callback<Cookie[]>): void;
|
|
1320
1342
|
/**
|
|
1321
1343
|
* Retrieve the list of cookies that can be sent in a Cookie header for the
|
|
1322
1344
|
* current URL.
|
|
@@ -1362,7 +1384,7 @@ declare class CookieJar {
|
|
|
1362
1384
|
* @param url - The domain to store the cookie with.
|
|
1363
1385
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1364
1386
|
*/
|
|
1365
|
-
getCookiesSync(url: string, options?: GetCookiesOptions): Cookie[];
|
|
1387
|
+
getCookiesSync(url: string | URL, options?: GetCookiesOptions): Cookie[];
|
|
1366
1388
|
/**
|
|
1367
1389
|
* Accepts the same options as `.getCookies()` but returns a string suitable for a
|
|
1368
1390
|
* `Cookie` header rather than an Array.
|
|
@@ -1371,7 +1393,7 @@ declare class CookieJar {
|
|
|
1371
1393
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1372
1394
|
* @param callback - A function to call after the `Cookie` header string has been created.
|
|
1373
1395
|
*/
|
|
1374
|
-
getCookieString(url: string, options: GetCookiesOptions, callback: Callback<string | undefined>): void;
|
|
1396
|
+
getCookieString(url: string | URL, options: GetCookiesOptions, callback: Callback<string | undefined>): void;
|
|
1375
1397
|
/**
|
|
1376
1398
|
* Accepts the same options as `.getCookies()` but returns a string suitable for a
|
|
1377
1399
|
* `Cookie` header rather than an Array.
|
|
@@ -1379,7 +1401,7 @@ declare class CookieJar {
|
|
|
1379
1401
|
* @param url - The domain to store the cookie with.
|
|
1380
1402
|
* @param callback - A function to call after the `Cookie` header string has been created.
|
|
1381
1403
|
*/
|
|
1382
|
-
getCookieString(url: string, callback: Callback<string | undefined>): void;
|
|
1404
|
+
getCookieString(url: string | URL, callback: Callback<string | undefined>): void;
|
|
1383
1405
|
/**
|
|
1384
1406
|
* Accepts the same options as `.getCookies()` but returns a string suitable for a
|
|
1385
1407
|
* `Cookie` header rather than an Array.
|
|
@@ -1387,11 +1409,11 @@ declare class CookieJar {
|
|
|
1387
1409
|
* @param url - The domain to store the cookie with.
|
|
1388
1410
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1389
1411
|
*/
|
|
1390
|
-
getCookieString(url: string, options?: GetCookiesOptions): Promise<string>;
|
|
1412
|
+
getCookieString(url: string | URL, options?: GetCookiesOptions): Promise<string>;
|
|
1391
1413
|
/**
|
|
1392
1414
|
* @internal No doc because this is an overload that supports the implementation
|
|
1393
1415
|
*/
|
|
1394
|
-
getCookieString(url: string, options: GetCookiesOptions | Callback<string | undefined>, callback?: Callback<string | undefined>): unknown;
|
|
1416
|
+
getCookieString(url: string | URL, options: GetCookiesOptions | Callback<string | undefined>, callback?: Callback<string | undefined>): unknown;
|
|
1395
1417
|
/**
|
|
1396
1418
|
* Synchronous version of `.getCookieString()`. Accepts the same options as `.getCookies()` but returns a string suitable for a
|
|
1397
1419
|
* `Cookie` header rather than an Array.
|
|
@@ -1401,7 +1423,7 @@ declare class CookieJar {
|
|
|
1401
1423
|
* @param url - The domain to store the cookie with.
|
|
1402
1424
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1403
1425
|
*/
|
|
1404
|
-
getCookieStringSync(url: string, options?: GetCookiesOptions): string;
|
|
1426
|
+
getCookieStringSync(url: string | URL, options?: GetCookiesOptions): string;
|
|
1405
1427
|
/**
|
|
1406
1428
|
* Returns an array of strings suitable for `Set-Cookie` headers. Accepts the same options
|
|
1407
1429
|
* as `.getCookies()`.
|
|
@@ -1409,7 +1431,7 @@ declare class CookieJar {
|
|
|
1409
1431
|
* @param url - The domain to store the cookie with.
|
|
1410
1432
|
* @param callback - A function to call after the `Set-Cookie` header strings have been created.
|
|
1411
1433
|
*/
|
|
1412
|
-
getSetCookieStrings(url: string, callback: Callback<string[] | undefined>): void;
|
|
1434
|
+
getSetCookieStrings(url: string | URL, callback: Callback<string[] | undefined>): void;
|
|
1413
1435
|
/**
|
|
1414
1436
|
* Returns an array of strings suitable for `Set-Cookie` headers. Accepts the same options
|
|
1415
1437
|
* as `.getCookies()`.
|
|
@@ -1418,7 +1440,7 @@ declare class CookieJar {
|
|
|
1418
1440
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1419
1441
|
* @param callback - A function to call after the `Set-Cookie` header strings have been created.
|
|
1420
1442
|
*/
|
|
1421
|
-
getSetCookieStrings(url: string, options: GetCookiesOptions, callback: Callback<string[] | undefined>): void;
|
|
1443
|
+
getSetCookieStrings(url: string | URL, options: GetCookiesOptions, callback: Callback<string[] | undefined>): void;
|
|
1422
1444
|
/**
|
|
1423
1445
|
* Returns an array of strings suitable for `Set-Cookie` headers. Accepts the same options
|
|
1424
1446
|
* as `.getCookies()`.
|
|
@@ -1426,11 +1448,11 @@ declare class CookieJar {
|
|
|
1426
1448
|
* @param url - The domain to store the cookie with.
|
|
1427
1449
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1428
1450
|
*/
|
|
1429
|
-
getSetCookieStrings(url: string, options?: GetCookiesOptions): Promise<string[] | undefined>;
|
|
1451
|
+
getSetCookieStrings(url: string | URL, options?: GetCookiesOptions): Promise<string[] | undefined>;
|
|
1430
1452
|
/**
|
|
1431
1453
|
* @internal No doc because this is an overload that supports the implementation
|
|
1432
1454
|
*/
|
|
1433
|
-
getSetCookieStrings(url: string, options: GetCookiesOptions, callback?: Callback<string[] | undefined>): unknown;
|
|
1455
|
+
getSetCookieStrings(url: string | URL, options: GetCookiesOptions, callback?: Callback<string[] | undefined>): unknown;
|
|
1434
1456
|
/**
|
|
1435
1457
|
* Synchronous version of `.getSetCookieStrings()`. Returns an array of strings suitable for `Set-Cookie` headers.
|
|
1436
1458
|
* Accepts the same options as `.getCookies()`.
|
|
@@ -1440,7 +1462,7 @@ declare class CookieJar {
|
|
|
1440
1462
|
* @param url - The domain to store the cookie with.
|
|
1441
1463
|
* @param options - Configuration settings to use when retrieving the cookies.
|
|
1442
1464
|
*/
|
|
1443
|
-
getSetCookieStringsSync(url: string, options?: GetCookiesOptions): string[];
|
|
1465
|
+
getSetCookieStringsSync(url: string | URL, options?: GetCookiesOptions): string[];
|
|
1444
1466
|
/**
|
|
1445
1467
|
* Serialize the CookieJar if the underlying store supports `.getAllCookies`.
|
|
1446
1468
|
* @param callback - A function to call after the CookieJar has been serialized
|
|
@@ -1803,4 +1825,5 @@ declare function parse(str: string, options?: ParseCookieOptions): Cookie | unde
|
|
|
1803
1825
|
*/
|
|
1804
1826
|
declare function fromJSON(str: unknown): Cookie | undefined;
|
|
1805
1827
|
|
|
1806
|
-
export {
|
|
1828
|
+
export { Cookie, CookieJar, MemoryCookieStore, ParameterError, PrefixSecurityEnum, Store, canonicalDomain, cookieCompare, defaultPath, domainMatch, formatDate, fromJSON, getPublicSuffix, parse, parseDate, pathMatch, permuteDomain, permutePath, version };
|
|
1829
|
+
export type { Callback, CreateCookieJarOptions, CreateCookieOptions, ErrorCallback, GetCookiesOptions, GetPublicSuffixOptions, MemoryCookieStoreIndex, Nullable, ParseCookieOptions, PrefixSecurityMode, SerializedCookie, SerializedCookieJar, SetCookieOptions };
|
package/dist/index.js
CHANGED
|
@@ -384,7 +384,7 @@ var ParameterError = class extends Error {
|
|
|
384
384
|
};
|
|
385
385
|
|
|
386
386
|
// lib/version.ts
|
|
387
|
-
var version = "6.0
|
|
387
|
+
var version = "6.1.0";
|
|
388
388
|
|
|
389
389
|
// lib/cookie/constants.ts
|
|
390
390
|
var PrefixSecurityEnum = {
|
|
@@ -438,6 +438,17 @@ function formatDate(date) {
|
|
|
438
438
|
return date.toUTCString();
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
// lib/cookie/cookieName.ts
|
|
442
|
+
var INVALID_TOKEN_CHARACTER = /[^\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]/;
|
|
443
|
+
var CookieName = {
|
|
444
|
+
parse(input) {
|
|
445
|
+
if (input.length === 0 || INVALID_TOKEN_CHARACTER.test(input)) {
|
|
446
|
+
return void 0;
|
|
447
|
+
}
|
|
448
|
+
return input;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
441
452
|
// lib/cookie/parseDate.ts
|
|
442
453
|
function parseDate(cookieDate) {
|
|
443
454
|
if (!cookieDate) {
|
|
@@ -612,8 +623,8 @@ function parse(str, options) {
|
|
|
612
623
|
return c;
|
|
613
624
|
}
|
|
614
625
|
const cookie_avs = unparsed.split(";");
|
|
615
|
-
|
|
616
|
-
const av =
|
|
626
|
+
for (const cookie_av of cookie_avs) {
|
|
627
|
+
const av = cookie_av.trim();
|
|
617
628
|
if (av.length === 0) {
|
|
618
629
|
continue;
|
|
619
630
|
}
|
|
@@ -896,10 +907,17 @@ var _Cookie = class _Cookie {
|
|
|
896
907
|
*
|
|
897
908
|
* @remarks
|
|
898
909
|
* Works for a few things, but is by no means comprehensive.
|
|
910
|
+
* Checks that the cookie name is a non-empty token as defined in RFC 6265 Section 4.1.1.
|
|
911
|
+
* Nameless cookies (including those parsed in loose mode or created with `new Cookie({ value })`)
|
|
912
|
+
* and names containing characters outside the token grammar (such as `a b`) return `false`.
|
|
913
|
+
* Parsing and storage remain permissive; this check only applies to explicit validation.
|
|
899
914
|
*
|
|
900
915
|
* @beta
|
|
901
916
|
*/
|
|
902
917
|
validate() {
|
|
918
|
+
if (CookieName.parse(this.key) === void 0) {
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
903
921
|
if (!this.value || !COOKIE_OCTETS.test(this.value)) {
|
|
904
922
|
return false;
|
|
905
923
|
}
|
|
@@ -918,7 +936,7 @@ var _Cookie = class _Cookie {
|
|
|
918
936
|
return false;
|
|
919
937
|
}
|
|
920
938
|
const suffix = getPublicSuffix(cdomain);
|
|
921
|
-
if (suffix == null) {
|
|
939
|
+
if (suffix == null && !IP_V4_REGEX_OBJECT.test(cdomain) && !IP_V6_REGEX_OBJECT.test(cdomain)) {
|
|
922
940
|
return false;
|
|
923
941
|
}
|
|
924
942
|
}
|
|
@@ -994,11 +1012,13 @@ var _Cookie = class _Cookie {
|
|
|
994
1012
|
if (this.httpOnly) {
|
|
995
1013
|
str += "; HttpOnly";
|
|
996
1014
|
}
|
|
997
|
-
if (this.sameSite
|
|
1015
|
+
if (this.sameSite) {
|
|
998
1016
|
if (this.sameSite.toLowerCase() === _Cookie.sameSiteCanonical.lax.toLowerCase()) {
|
|
999
1017
|
str += `; SameSite=${_Cookie.sameSiteCanonical.lax}`;
|
|
1000
1018
|
} else if (this.sameSite.toLowerCase() === _Cookie.sameSiteCanonical.strict.toLowerCase()) {
|
|
1001
1019
|
str += `; SameSite=${_Cookie.sameSiteCanonical.strict}`;
|
|
1020
|
+
} else if (this.sameSite.toLowerCase() === _Cookie.sameSiteCanonical.none.toLowerCase()) {
|
|
1021
|
+
str += `; SameSite=${_Cookie.sameSiteCanonical.none}`;
|
|
1002
1022
|
} else {
|
|
1003
1023
|
str += `; SameSite=${this.sameSite}`;
|
|
1004
1024
|
}
|
|
@@ -1045,6 +1065,9 @@ var _Cookie = class _Cookie {
|
|
|
1045
1065
|
*/
|
|
1046
1066
|
expiryTime(now) {
|
|
1047
1067
|
if (this.maxAge != null) {
|
|
1068
|
+
if (this.maxAge === "Infinity") {
|
|
1069
|
+
return Infinity;
|
|
1070
|
+
}
|
|
1048
1071
|
const relativeTo = now || this.lastAccessed || /* @__PURE__ */ new Date();
|
|
1049
1072
|
const maxAge = typeof this.maxAge === "number" ? this.maxAge : -Infinity;
|
|
1050
1073
|
const age = maxAge <= 0 ? -Infinity : maxAge * 1e3;
|
|
@@ -1177,7 +1200,8 @@ _Cookie.sameSiteLevel = {
|
|
|
1177
1200
|
*/
|
|
1178
1201
|
_Cookie.sameSiteCanonical = {
|
|
1179
1202
|
strict: "Strict",
|
|
1180
|
-
lax: "Lax"
|
|
1203
|
+
lax: "Lax",
|
|
1204
|
+
none: "None"
|
|
1181
1205
|
};
|
|
1182
1206
|
/**
|
|
1183
1207
|
* Cookie properties that will be serialized when using {@link Cookie.fromJSON} and {@link Cookie.toJSON}.
|
|
@@ -1336,9 +1360,14 @@ var defaultGetCookieOptions = {
|
|
|
1336
1360
|
var SAME_SITE_CONTEXT_VAL_ERR = 'Invalid sameSiteContext option for getCookies(); expected one of "strict", "lax", or "none"';
|
|
1337
1361
|
function getCookieContext(url) {
|
|
1338
1362
|
if (url && typeof url === "object" && "hostname" in url && typeof url.hostname === "string" && "pathname" in url && typeof url.pathname === "string" && "protocol" in url && typeof url.protocol === "string") {
|
|
1363
|
+
let pathname = url.pathname;
|
|
1364
|
+
try {
|
|
1365
|
+
pathname = decodeURI(pathname);
|
|
1366
|
+
} catch {
|
|
1367
|
+
}
|
|
1339
1368
|
return {
|
|
1340
1369
|
hostname: url.hostname,
|
|
1341
|
-
pathname
|
|
1370
|
+
pathname,
|
|
1342
1371
|
protocol: url.protocol
|
|
1343
1372
|
};
|
|
1344
1373
|
} else if (typeof url === "string") {
|
|
@@ -1372,7 +1401,7 @@ function isSecurePrefixConditionMet(cookie) {
|
|
|
1372
1401
|
function isHostPrefixConditionMet(cookie) {
|
|
1373
1402
|
const startsWithHostPrefix = typeof cookie.key === "string" && cookie.key.startsWith("__Host-");
|
|
1374
1403
|
return !startsWithHostPrefix || Boolean(
|
|
1375
|
-
cookie.secure && cookie.hostOnly && cookie.path != null && cookie.path === "/"
|
|
1404
|
+
cookie.secure && cookie.hostOnly && cookie.path != null && cookie.path === "/" && !cookie.pathIsDefault
|
|
1376
1405
|
);
|
|
1377
1406
|
}
|
|
1378
1407
|
function getNormalizedPrefixSecurity(prefixSecurity) {
|
|
@@ -1405,6 +1434,7 @@ var CookieJar = class _CookieJar {
|
|
|
1405
1434
|
this.enableLooseMode = options?.looseMode ?? false;
|
|
1406
1435
|
this.allowSpecialUseDomain = options?.allowSpecialUseDomain ?? true;
|
|
1407
1436
|
this.allowSecureOnLocal = options?.allowSecureOnLocal ?? true;
|
|
1437
|
+
this.enforceSecureOriginOnStorage = options?.enforceSecureOriginOnStorage ?? true;
|
|
1408
1438
|
this.prefixSecurity = getNormalizedPrefixSecurity(
|
|
1409
1439
|
options?.prefixSecurity ?? "silent"
|
|
1410
1440
|
);
|
|
@@ -1492,7 +1522,7 @@ var CookieJar = class _CookieJar {
|
|
|
1492
1522
|
allowSpecialUseDomain: this.allowSpecialUseDomain,
|
|
1493
1523
|
ignoreError: options?.ignoreError
|
|
1494
1524
|
}) : null;
|
|
1495
|
-
if (suffix == null && !IP_V6_REGEX_OBJECT.test(
|
|
1525
|
+
if (suffix == null && !IP_V4_REGEX_OBJECT.test(cdomain ?? "") && !IP_V6_REGEX_OBJECT.test(cdomain ?? "")) {
|
|
1496
1526
|
const err = new Error("Cookie has domain set to a public suffix");
|
|
1497
1527
|
return options?.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
|
|
1498
1528
|
}
|
|
@@ -1521,6 +1551,12 @@ var CookieJar = class _CookieJar {
|
|
|
1521
1551
|
cookie.path = defaultPath(context.pathname);
|
|
1522
1552
|
cookie.pathIsDefault = true;
|
|
1523
1553
|
}
|
|
1554
|
+
if (this.enforceSecureOriginOnStorage && cookie.secure && !isPotentiallyTrustworthy(url, this.allowSecureOnLocal)) {
|
|
1555
|
+
const err = new Error(
|
|
1556
|
+
"Cookie is Secure but this is not a secure connection"
|
|
1557
|
+
);
|
|
1558
|
+
return options?.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
|
|
1559
|
+
}
|
|
1524
1560
|
if (options?.http === false && cookie.httpOnly) {
|
|
1525
1561
|
const err = new Error("Cookie is HttpOnly and this isn't an HTTP API");
|
|
1526
1562
|
return options.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
|
|
@@ -1845,6 +1881,7 @@ var CookieJar = class _CookieJar {
|
|
|
1845
1881
|
rejectPublicSuffixes: this.rejectPublicSuffixes,
|
|
1846
1882
|
enableLooseMode: this.enableLooseMode,
|
|
1847
1883
|
allowSpecialUseDomain: this.allowSpecialUseDomain,
|
|
1884
|
+
enforceSecureOriginOnStorage: this.enforceSecureOriginOnStorage,
|
|
1848
1885
|
prefixSecurity: getNormalizedPrefixSecurity(this.prefixSecurity),
|
|
1849
1886
|
// this gets filled from getAllCookies:
|
|
1850
1887
|
cookies: []
|
|
@@ -2091,6 +2128,9 @@ var CookieJar = class _CookieJar {
|
|
|
2091
2128
|
rejectPublicSuffixes: readSerializedBoolean("rejectPublicSuffixes"),
|
|
2092
2129
|
looseMode: readSerializedBoolean("enableLooseMode"),
|
|
2093
2130
|
allowSpecialUseDomain: readSerializedBoolean("allowSpecialUseDomain"),
|
|
2131
|
+
enforceSecureOriginOnStorage: readSerializedBoolean(
|
|
2132
|
+
"enforceSecureOriginOnStorage"
|
|
2133
|
+
),
|
|
2094
2134
|
prefixSecurity: getNormalizedPrefixSecurity(
|
|
2095
2135
|
readSerializedString("prefixSecurity") ?? "silent"
|
|
2096
2136
|
)
|
|
@@ -2136,6 +2176,9 @@ var CookieJar = class _CookieJar {
|
|
|
2136
2176
|
rejectPublicSuffixes: readSerializedBoolean("rejectPublicSuffixes"),
|
|
2137
2177
|
looseMode: readSerializedBoolean("enableLooseMode"),
|
|
2138
2178
|
allowSpecialUseDomain: readSerializedBoolean("allowSpecialUseDomain"),
|
|
2179
|
+
enforceSecureOriginOnStorage: readSerializedBoolean(
|
|
2180
|
+
"enforceSecureOriginOnStorage"
|
|
2181
|
+
),
|
|
2139
2182
|
prefixSecurity: getNormalizedPrefixSecurity(
|
|
2140
2183
|
readSerializedString("prefixSecurity") ?? "silent"
|
|
2141
2184
|
)
|