tough-cookie 6.0.0-rc.2 → 6.0.1
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 -0
- package/dist/index.cjs +95 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -85
- package/dist/index.d.ts +8 -85
- package/dist/index.js +95 -126
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -134,6 +134,44 @@ await cookieJar.setCookie(
|
|
|
134
134
|
> [!NOTE]
|
|
135
135
|
> It is highly recommended that you read [RFC6265bis - Section 4.1.3][cookie-prefixes-implementation] for more details on Cookie Prefixes.
|
|
136
136
|
|
|
137
|
+
### Potentially Trustworthy Origins are considered "Secure"
|
|
138
|
+
|
|
139
|
+
The definition of a "Secure" connection is not explicitly defined by [RFC6265bis][rfc6265bis-tracker] but the following text is
|
|
140
|
+
provided in [RFC6265bis - Section 5.8.3][secure-connection-note]:
|
|
141
|
+
|
|
142
|
+
> [!NOTE]
|
|
143
|
+
> Typically, user agents consider a connection secure if the connection makes use of transport-layer security, such as
|
|
144
|
+
> SSL or TLS, or if the host is trusted. For example, most user agents consider "https" to be a scheme that denotes a
|
|
145
|
+
> secure protocol and "localhost" to be trusted host.
|
|
146
|
+
|
|
147
|
+
As well as a note to [Appendix A. Changes from RFC6265][secure-connection-appendix-a] which refers to **"potentially trustworthy
|
|
148
|
+
origins"** which are defined in the [Secure Contexts - W3C Candidate Recommendation Draft][potentially-trustworthy-origin]:
|
|
149
|
+
|
|
150
|
+
> [!Note]
|
|
151
|
+
> Considers potentially trustworthy origins as "secure".
|
|
152
|
+
|
|
153
|
+
Since most web browsers treat `localhost` as a trustworthy origin, by default, so does `tough-cookie`. To disable this
|
|
154
|
+
behavior, the `CookieStore` must be configured with:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { CookieJar, MemoryCookieStore } from 'tough-cookie'
|
|
158
|
+
|
|
159
|
+
const cookieJar = new CookieJar(new MemoryCookieStore(), {
|
|
160
|
+
// add configuration so localhost will not be considered trustworthy
|
|
161
|
+
// (fyi - this doesn't apply to https cookies on localhost as those use a secure protocol)
|
|
162
|
+
allowSecureOnLocal: false,
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
// this cookie will be persisted to storage
|
|
166
|
+
await cookieJar.setCookie(
|
|
167
|
+
'SID=12345; Domain=localhost; Secure;',
|
|
168
|
+
'http://localhost',
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
// but, on retrieval, it will not be returned
|
|
172
|
+
await cookieJar.getCookiesSync('http://localhost')
|
|
173
|
+
```
|
|
174
|
+
|
|
137
175
|
## Node.js Version Support
|
|
138
176
|
|
|
139
177
|
We follow the [Node.js release schedule](https://github.com/nodejs/Release#release-schedule) and support
|
|
@@ -150,5 +188,8 @@ for older versions of node, and we will do so in consultation with our community
|
|
|
150
188
|
[rfc6265bis-tracker]: https://datatracker.ietf.org/doc/draft-ietf-httpbis-rfc6265bis/
|
|
151
189
|
[samesite-implementation]: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-8.8
|
|
152
190
|
[cookie-prefixes-implementation]: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.3
|
|
191
|
+
[secure-connection-note]: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-19#section-5.8.3-2.1.2.3.1
|
|
192
|
+
[secure-connection-appendix-a]: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-19#appendix-A-1.7.1
|
|
193
|
+
[potentially-trustworthy-origin]: https://www.w3.org/TR/secure-contexts/#is-origin-trustworthy
|
|
153
194
|
[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
|
154
195
|
[yarn-repo]: https://yarnpkg.com/package?name=tough-cookie
|
package/dist/index.cjs
CHANGED
|
@@ -428,7 +428,7 @@ var ParameterError = class extends Error {
|
|
|
428
428
|
};
|
|
429
429
|
|
|
430
430
|
// lib/version.ts
|
|
431
|
-
var version = "6.0.
|
|
431
|
+
var version = "6.0.1";
|
|
432
432
|
|
|
433
433
|
// lib/cookie/constants.ts
|
|
434
434
|
var PrefixSecurityEnum = {
|
|
@@ -483,145 +483,114 @@ function formatDate(date) {
|
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
// lib/cookie/parseDate.ts
|
|
486
|
-
var DATE_DELIM = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/;
|
|
487
|
-
var MONTH_TO_NUM = {
|
|
488
|
-
jan: 0,
|
|
489
|
-
feb: 1,
|
|
490
|
-
mar: 2,
|
|
491
|
-
apr: 3,
|
|
492
|
-
may: 4,
|
|
493
|
-
jun: 5,
|
|
494
|
-
jul: 6,
|
|
495
|
-
aug: 7,
|
|
496
|
-
sep: 8,
|
|
497
|
-
oct: 9,
|
|
498
|
-
nov: 10,
|
|
499
|
-
dec: 11
|
|
500
|
-
};
|
|
501
|
-
function parseDigits(token, minDigits, maxDigits, trailingOK) {
|
|
502
|
-
let count = 0;
|
|
503
|
-
while (count < token.length) {
|
|
504
|
-
const c = token.charCodeAt(count);
|
|
505
|
-
if (c <= 47 || c >= 58) {
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
count++;
|
|
509
|
-
}
|
|
510
|
-
if (count < minDigits || count > maxDigits) {
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
if (!trailingOK && count != token.length) {
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
return parseInt(token.slice(0, count), 10);
|
|
517
|
-
}
|
|
518
|
-
function parseTime(token) {
|
|
519
|
-
const parts = token.split(":");
|
|
520
|
-
const result = [0, 0, 0];
|
|
521
|
-
if (parts.length !== 3) {
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
for (let i = 0; i < 3; i++) {
|
|
525
|
-
const trailingOK = i == 2;
|
|
526
|
-
const numPart = parts[i];
|
|
527
|
-
if (numPart === void 0) {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
const num = parseDigits(numPart, 1, 2, trailingOK);
|
|
531
|
-
if (num === void 0) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
result[i] = num;
|
|
535
|
-
}
|
|
536
|
-
return result;
|
|
537
|
-
}
|
|
538
|
-
function parseMonth(token) {
|
|
539
|
-
token = String(token).slice(0, 3).toLowerCase();
|
|
540
|
-
switch (token) {
|
|
541
|
-
case "jan":
|
|
542
|
-
return MONTH_TO_NUM.jan;
|
|
543
|
-
case "feb":
|
|
544
|
-
return MONTH_TO_NUM.feb;
|
|
545
|
-
case "mar":
|
|
546
|
-
return MONTH_TO_NUM.mar;
|
|
547
|
-
case "apr":
|
|
548
|
-
return MONTH_TO_NUM.apr;
|
|
549
|
-
case "may":
|
|
550
|
-
return MONTH_TO_NUM.may;
|
|
551
|
-
case "jun":
|
|
552
|
-
return MONTH_TO_NUM.jun;
|
|
553
|
-
case "jul":
|
|
554
|
-
return MONTH_TO_NUM.jul;
|
|
555
|
-
case "aug":
|
|
556
|
-
return MONTH_TO_NUM.aug;
|
|
557
|
-
case "sep":
|
|
558
|
-
return MONTH_TO_NUM.sep;
|
|
559
|
-
case "oct":
|
|
560
|
-
return MONTH_TO_NUM.oct;
|
|
561
|
-
case "nov":
|
|
562
|
-
return MONTH_TO_NUM.nov;
|
|
563
|
-
case "dec":
|
|
564
|
-
return MONTH_TO_NUM.dec;
|
|
565
|
-
default:
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
486
|
function parseDate(cookieDate) {
|
|
570
487
|
if (!cookieDate) {
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
for (
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
488
|
+
return void 0;
|
|
489
|
+
}
|
|
490
|
+
const flags = {
|
|
491
|
+
foundTime: void 0,
|
|
492
|
+
foundDayOfMonth: void 0,
|
|
493
|
+
foundMonth: void 0,
|
|
494
|
+
foundYear: void 0
|
|
495
|
+
};
|
|
496
|
+
const dateTokens = cookieDate.split(DELIMITER).filter((token) => token.length > 0);
|
|
497
|
+
for (const dateToken of dateTokens) {
|
|
498
|
+
if (flags.foundTime === void 0) {
|
|
499
|
+
const [, hours, minutes, seconds] = TIME.exec(dateToken) || [];
|
|
500
|
+
if (hours != void 0 && minutes != void 0 && seconds != void 0) {
|
|
501
|
+
const parsedHours = parseInt(hours, 10);
|
|
502
|
+
const parsedMinutes = parseInt(minutes, 10);
|
|
503
|
+
const parsedSeconds = parseInt(seconds, 10);
|
|
504
|
+
if (!isNaN(parsedHours) && !isNaN(parsedMinutes) && !isNaN(parsedSeconds)) {
|
|
505
|
+
flags.foundTime = {
|
|
506
|
+
hours: parsedHours,
|
|
507
|
+
minutes: parsedMinutes,
|
|
508
|
+
seconds: parsedSeconds
|
|
509
|
+
};
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
592
512
|
}
|
|
593
513
|
}
|
|
594
|
-
if (
|
|
595
|
-
const
|
|
596
|
-
if (
|
|
597
|
-
|
|
514
|
+
if (flags.foundDayOfMonth === void 0 && DAY_OF_MONTH.test(dateToken)) {
|
|
515
|
+
const dayOfMonth = parseInt(dateToken, 10);
|
|
516
|
+
if (!isNaN(dayOfMonth)) {
|
|
517
|
+
flags.foundDayOfMonth = dayOfMonth;
|
|
598
518
|
continue;
|
|
599
519
|
}
|
|
600
520
|
}
|
|
601
|
-
if (
|
|
602
|
-
const
|
|
603
|
-
if (
|
|
604
|
-
|
|
521
|
+
if (flags.foundMonth === void 0 && MONTH.test(dateToken)) {
|
|
522
|
+
const month = months.indexOf(dateToken.substring(0, 3).toLowerCase());
|
|
523
|
+
if (month >= 0 && month <= 11) {
|
|
524
|
+
flags.foundMonth = month;
|
|
605
525
|
continue;
|
|
606
526
|
}
|
|
607
527
|
}
|
|
608
|
-
if (
|
|
609
|
-
const
|
|
610
|
-
if (
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
year += 1900;
|
|
614
|
-
} else if (year >= 0 && year <= 69) {
|
|
615
|
-
year += 2e3;
|
|
616
|
-
}
|
|
528
|
+
if (flags.foundYear === void 0 && YEAR.test(dateToken)) {
|
|
529
|
+
const parsedYear = parseInt(dateToken, 10);
|
|
530
|
+
if (!isNaN(parsedYear)) {
|
|
531
|
+
flags.foundYear = parsedYear;
|
|
532
|
+
continue;
|
|
617
533
|
}
|
|
618
534
|
}
|
|
619
535
|
}
|
|
620
|
-
if (
|
|
621
|
-
|
|
536
|
+
if (flags.foundYear !== void 0 && flags.foundYear >= 70 && flags.foundYear <= 99) {
|
|
537
|
+
flags.foundYear += 1900;
|
|
538
|
+
}
|
|
539
|
+
if (flags.foundYear !== void 0 && flags.foundYear >= 0 && flags.foundYear <= 69) {
|
|
540
|
+
flags.foundYear += 2e3;
|
|
541
|
+
}
|
|
542
|
+
if (flags.foundDayOfMonth === void 0 || flags.foundMonth === void 0 || flags.foundYear === void 0 || flags.foundTime === void 0) {
|
|
543
|
+
return void 0;
|
|
544
|
+
}
|
|
545
|
+
if (flags.foundDayOfMonth < 1 || flags.foundDayOfMonth > 31) {
|
|
546
|
+
return void 0;
|
|
547
|
+
}
|
|
548
|
+
if (flags.foundYear < 1601) {
|
|
549
|
+
return void 0;
|
|
622
550
|
}
|
|
623
|
-
|
|
551
|
+
if (flags.foundTime.hours > 23) {
|
|
552
|
+
return void 0;
|
|
553
|
+
}
|
|
554
|
+
if (flags.foundTime.minutes > 59) {
|
|
555
|
+
return void 0;
|
|
556
|
+
}
|
|
557
|
+
if (flags.foundTime.seconds > 59) {
|
|
558
|
+
return void 0;
|
|
559
|
+
}
|
|
560
|
+
const date = new Date(
|
|
561
|
+
Date.UTC(
|
|
562
|
+
flags.foundYear,
|
|
563
|
+
flags.foundMonth,
|
|
564
|
+
flags.foundDayOfMonth,
|
|
565
|
+
flags.foundTime.hours,
|
|
566
|
+
flags.foundTime.minutes,
|
|
567
|
+
flags.foundTime.seconds
|
|
568
|
+
)
|
|
569
|
+
);
|
|
570
|
+
if (date.getUTCFullYear() !== flags.foundYear || date.getUTCMonth() !== flags.foundMonth || date.getUTCDate() !== flags.foundDayOfMonth) {
|
|
571
|
+
return void 0;
|
|
572
|
+
}
|
|
573
|
+
return date;
|
|
624
574
|
}
|
|
575
|
+
var months = [
|
|
576
|
+
"jan",
|
|
577
|
+
"feb",
|
|
578
|
+
"mar",
|
|
579
|
+
"apr",
|
|
580
|
+
"may",
|
|
581
|
+
"jun",
|
|
582
|
+
"jul",
|
|
583
|
+
"aug",
|
|
584
|
+
"sep",
|
|
585
|
+
"oct",
|
|
586
|
+
"nov",
|
|
587
|
+
"dec"
|
|
588
|
+
];
|
|
589
|
+
var DELIMITER = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/;
|
|
590
|
+
var TIME = /^(\d{1,2}):(\d{1,2}):(\d{1,2})(?:[\x00-\x2F\x3A-\xFF][\x00-\xFF]*)?$/;
|
|
591
|
+
var DAY_OF_MONTH = /^[0-9]{1,2}(?:[\x00-\x2F\x3A-\xFF][\x00-\xFF]*)?$/;
|
|
592
|
+
var MONTH = /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[\x00-\xFF]*$/i;
|
|
593
|
+
var YEAR = /^[\x30-\x39]{2,4}(?:[\x00-\x2F\x3A-\xFF][\x00-\xFF]*)?$/;
|
|
625
594
|
|
|
626
595
|
// lib/cookie/cookie.ts
|
|
627
596
|
var COOKIE_OCTETS = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]+$/;
|
|
@@ -886,7 +855,7 @@ var _Cookie = class _Cookie {
|
|
|
886
855
|
});
|
|
887
856
|
this.creationIndex = _Cookie.cookiesCreated;
|
|
888
857
|
}
|
|
889
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
858
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
890
859
|
const now = Date.now();
|
|
891
860
|
const hostOnly = this.hostOnly != null ? this.hostOnly.toString() : "?";
|
|
892
861
|
const createAge = this.creation && this.creation !== "Infinity" ? `${String(now - this.creation.getTime())}ms` : "?";
|