@mherod/get-cookie 2.0.0-rc.3 → 2.0.0-rc.5

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/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  var $7oI3p$lodash = require("lodash");
3
3
  var $7oI3p$lrucache = require("lru-cache");
4
+ var $7oI3p$colorette = require("colorette");
4
5
  var $7oI3p$fs = require("fs");
5
6
  var $7oI3p$crypto = require("crypto");
6
7
  var $7oI3p$path = require("path");
7
8
  var $7oI3p$child_process = require("child_process");
8
9
  var $7oI3p$sqlite3 = require("sqlite3");
9
10
  var $7oI3p$toughcookie = require("tough-cookie");
11
+ var $7oI3p$toughcookiefilestore = require("tough-cookie-file-store");
10
12
  var $7oI3p$jsonwebtoken = require("jsonwebtoken");
11
13
  var $7oI3p$crossfetch = require("cross-fetch");
12
14
  var $7oI3p$destr = require("destr");
@@ -181,7 +183,16 @@ function $d66f40b581ba8bfa$export$963c8d651337e4a4(obj) {
181
183
  }
182
184
 
183
185
 
186
+ function $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb(s) {
187
+ const s1 = s.replaceAll(/\./gi, ".");
188
+ const s2 = s1.replace(/%/g, ".*");
189
+ const s3 = s2.replace(/\*/g, ".*");
190
+ return new RegExp(s3);
191
+ }
192
+
193
+
184
194
  class $269fe42bfd555305$export$2e2bcd8739ae039 {
195
+ browserName = "Chrome";
185
196
  async queryCookies(name, domain) {
186
197
  if (process.platform !== "darwin") throw new Error("This only works on macOS");
187
198
  if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) return [];
@@ -260,15 +271,23 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
260
271
  const wildcardRegexp = /^([*%])$/i;
261
272
  const specifiedName = name.match(wildcardRegexp) == null;
262
273
  const specifiedDomain = domain.match(wildcardRegexp) == null;
263
- if (specifiedName || specifiedDomain) {
274
+ const wildcardDomain = domain.match(/[%*]/) != null;
275
+ const queryDomain = specifiedDomain && !wildcardDomain;
276
+ // if we have a wildcard domain, we need to use a regexp
277
+ if (specifiedName || queryDomain) {
264
278
  sql += ` WHERE `;
265
279
  if (specifiedName) {
266
280
  sql += `name = '${name}'`;
267
- if (specifiedDomain) sql += ` AND `;
281
+ if (queryDomain) sql += ` AND `;
282
+ }
283
+ if (queryDomain) {
284
+ // leading dot replaced with % to match subdomains
285
+ const sqlEmbedDomain = domain.replace(/^[.%]?/, "%");
286
+ sql += `host_key LIKE '${sqlEmbedDomain}';`;
268
287
  }
269
- if (specifiedDomain) sql += `host_key LIKE '${domain}';`;
270
288
  }
271
- return (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)({
289
+ console.log("sql", sql);
290
+ const sqliteQuery1 = await (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)({
272
291
  file: file,
273
292
  sql: sql,
274
293
  rowTransform: (row)=>{
@@ -279,6 +298,9 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
279
298
  };
280
299
  }
281
300
  });
301
+ return sqliteQuery1.filter((row)=>{
302
+ return row.domain.match((0, $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb)(domain)) != null;
303
+ });
282
304
  }
283
305
  async function $269fe42bfd555305$var$getChromePassword() {
284
306
  return (0, $25b78d6746d4ad48$export$8d71c74f97c0202e)('security find-generic-password -w -s "Chrome Safe Storage"');
@@ -355,6 +377,7 @@ function $b744d19cc39f964e$export$da22813e5a2ec500({ name: name , domain: domain
355
377
 
356
378
 
357
379
  class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 {
380
+ browserName = "Firefox";
358
381
  async queryCookies(name, domain) {
359
382
  if (process.platform !== "darwin") throw new Error("This only works on macOS");
360
383
  if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).CHROME_ONLY) return [];
@@ -424,6 +447,7 @@ class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 {
424
447
 
425
448
 
426
449
  class $fad6f51bd5c7bae2$export$2e2bcd8739ae039 {
450
+ browserName = "Safari";
427
451
  async queryCookies(name, domain) {
428
452
  return [];
429
453
  }
@@ -432,39 +456,48 @@ class $fad6f51bd5c7bae2$export$2e2bcd8739ae039 {
432
456
 
433
457
 
434
458
 
435
- const $0fd79d7b9f7bb064$export$231f8b179925e6a5 = new (0, $7oI3p$toughcookie.MemoryCookieStore)();
436
- const $0fd79d7b9f7bb064$export$928a906645f9d018 = new (0, $7oI3p$toughcookie.CookieJar)($0fd79d7b9f7bb064$export$231f8b179925e6a5);
437
459
 
438
460
 
439
- class $0d3ccbe1f68c2e3d$export$2e2bcd8739ae039 {
461
+ var $53a3bcc99a05dfcf$require$FileCookieStore = $7oI3p$toughcookiefilestore.FileCookieStore;
462
+ const $53a3bcc99a05dfcf$export$6c62df16f2e9c7e8 = new $53a3bcc99a05dfcf$require$FileCookieStore(`${(0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3)["HOME"]}/cookie-star.json`);
463
+ const $53a3bcc99a05dfcf$export$928a906645f9d018 = new (0, $7oI3p$toughcookie.CookieJar)($53a3bcc99a05dfcf$export$6c62df16f2e9c7e8);
464
+
465
+
466
+
467
+ class $e4efb16e005540de$export$2e2bcd8739ae039 {
468
+ browserName = "internal";
440
469
  async queryCookies(name, domain) {
441
- if (name == "%" && domain == "%") {
442
- const cookies = await (0, $0fd79d7b9f7bb064$export$231f8b179925e6a5).getAllCookies();
443
- return cookies.map((cookie)=>{
444
- return this.#extracted(cookie, {
445
- name: name,
446
- domain: domain
447
- });
470
+ const exportedCookies = [];
471
+ // if (name.match(/[%*]/) || domain.match(/[%*]/)) {
472
+ const cookies = await this.#getAllCookies();
473
+ const allExportedCookies = cookies.map((cookie)=>{
474
+ return this.#extracted(cookie, {
475
+ name: name,
476
+ domain: domain
448
477
  });
449
- }
478
+ });
479
+ exportedCookies.push(...allExportedCookies);
480
+ // }
481
+ const wildcardRegexp = /^([*%])$/i;
482
+ if (name.match(wildcardRegexp) && domain.match(wildcardRegexp)) return exportedCookies;
450
483
  const path = "/";
451
- if (name == "%") {
452
- const cookies1 = await (0, $0fd79d7b9f7bb064$export$231f8b179925e6a5).findCookies(domain, path);
453
- return cookies1.map((cookie)=>{
484
+ if (domain != "%") {
485
+ const domain1 = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
486
+ const url = new URL("https://" + domain1);
487
+ url.pathname = path;
488
+ const cookies1 = await this.#getCookies(url.href);
489
+ const domainCookies = cookies1.map((cookie)=>{
454
490
  return this.#extracted(cookie, {
455
- name: name,
456
- domain: domain
491
+ domain: domain,
492
+ name: name
457
493
  });
458
494
  });
495
+ exportedCookies.push(...domainCookies);
459
496
  }
460
- const cookie = await (0, $0fd79d7b9f7bb064$export$231f8b179925e6a5).findCookie(domain, path, name);
461
- if (cookie) return [
462
- this.#extracted(cookie, {
463
- name: name,
464
- domain: domain
465
- })
466
- ];
467
- else return [];
497
+ if (name == "%") return exportedCookies;
498
+ return exportedCookies.filter((cookie)=>{
499
+ return cookie.name.match((0, $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb)(name)) && cookie.domain.match((0, $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb)(domain));
500
+ });
468
501
  }
469
502
  #extracted(cookie, cookieSpec) {
470
503
  return {
@@ -476,18 +509,38 @@ class $0d3ccbe1f68c2e3d$export$2e2bcd8739ae039 {
476
509
  }
477
510
  };
478
511
  }
512
+ #getCookies(url) {
513
+ return new Promise((resolve, reject)=>{
514
+ // @ts-ignore
515
+ return (0, $53a3bcc99a05dfcf$export$928a906645f9d018).getCookies(url, (err, cookies)=>{
516
+ if (err) reject(err);
517
+ else resolve(cookies ?? []);
518
+ });
519
+ });
520
+ }
521
+ #getAllCookies() {
522
+ return new Promise((resolve, reject)=>{
523
+ // @ts-ignore
524
+ return (0, $53a3bcc99a05dfcf$export$6c62df16f2e9c7e8).getAllCookies((err, cookies)=>{
525
+ if (err) reject(err);
526
+ else resolve(cookies ?? []);
527
+ });
528
+ });
529
+ }
479
530
  }
480
531
 
481
532
 
533
+
482
534
  const $f72befa528c23ca7$var$cache = new (0, ($parcel$interopDefault($7oI3p$lrucache)))({
483
535
  ttl: 2000,
484
536
  max: 10
485
537
  });
486
538
  class $f72befa528c23ca7$export$2e2bcd8739ae039 {
539
+ browserName = "all";
487
540
  #strategies;
488
541
  constructor(){
489
542
  this.#strategies = [
490
- (0, $0d3ccbe1f68c2e3d$export$2e2bcd8739ae039),
543
+ (0, $e4efb16e005540de$export$2e2bcd8739ae039),
491
544
  (0, $269fe42bfd555305$export$2e2bcd8739ae039),
492
545
  (0, $7bb7da9a77b2fd99$export$2e2bcd8739ae039),
493
546
  (0, $fad6f51bd5c7bae2$export$2e2bcd8739ae039),
@@ -496,13 +549,18 @@ class $f72befa528c23ca7$export$2e2bcd8739ae039 {
496
549
  });
497
550
  }
498
551
  async queryCookies(name, domain) {
552
+ // domain = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
499
553
  const key = `${name}:${domain}`;
500
554
  const cached = $f72befa528c23ca7$var$cache.get(key);
501
555
  if (cached) return cached;
556
+ console.log("Querying cookies:", name, domain);
502
557
  const results = await Promise.all(this.#strategies.map(async (strategy)=>{
503
558
  // @ts-ignore
504
559
  const cookies = strategy.queryCookies(name, domain);
505
- return cookies.catch(()=>[]);
560
+ return cookies.catch((e)=>{
561
+ console.log((0, $7oI3p$colorette.red)(`Error querying ${strategy.browserName} cookies`), e);
562
+ return [];
563
+ });
506
564
  }));
507
565
  const flat = results.flat();
508
566
  $f72befa528c23ca7$var$cache.set(`${name}:${domain}`, flat);
@@ -618,7 +676,7 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
618
676
  value
619
677
  ]);
620
678
  });
621
- for (const [key, value] of headers)if (key === "set-cookie") await (0, $0fd79d7b9f7bb064$export$928a906645f9d018).setCookie(value, url2);
679
+ for (const [key, value] of headers)if (key === "set-cookie") await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).setCookie(value, url2);
622
680
  const newUrl = res.headers.get("location");
623
681
  if (res.redirected || newUrl && newUrl !== url2) return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(newUrl, newOptions1);
624
682
  const arrayBuffer1 = res.arrayBuffer();
package/package-lock.json CHANGED
@@ -1,18 +1,23 @@
1
1
  {
2
2
  "name": "@mherod/get-cookie",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-rc.3",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@mherod/get-cookie",
9
- "version": "2.0.0-beta.3",
9
+ "version": "2.0.0-rc.3",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "colorette": "^2.0.19",
13
+ "cross-fetch": "^3.1.5",
14
+ "destr": "^1.1.1",
13
15
  "jsonwebtoken": "^8.5.1",
14
16
  "lodash": "^4.17.21",
15
- "sqlite3": "^5.1.1"
17
+ "lru-cache": "^7.14.0",
18
+ "minimist": "^1.2.6",
19
+ "sqlite3": "^5.1.1",
20
+ "tough-cookie": "^4.1.2"
16
21
  },
17
22
  "bin": {
18
23
  "get-cookie": "dist/cli.js"
@@ -22,7 +27,10 @@
22
27
  "@parcel/transformer-typescript-types": "^2.7.0",
23
28
  "@types/jsonwebtoken": "^8.5.9",
24
29
  "@types/lodash": "^4.14.186",
30
+ "@types/minimist": "^1.2.2",
25
31
  "@types/node": "^18.8.2",
32
+ "@types/tough-cookie": "^4.0.2",
33
+ "@types/user-agents": "^1.0.2",
26
34
  "jest": "^29.0.3",
27
35
  "parcel": "^2.7.0",
28
36
  "prettier": "^2.7.1",
@@ -2726,10 +2734,16 @@
2726
2734
  "integrity": "sha512-eHcVlLXP0c2FlMPm56ITode2AgLMSa6aJ05JTTbYbI+7EMkCEE5qk2E41d5g2lCVTqRe0GnnRFurmlCsDODrPw==",
2727
2735
  "dev": true
2728
2736
  },
2737
+ "node_modules/@types/minimist": {
2738
+ "version": "1.2.2",
2739
+ "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz",
2740
+ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==",
2741
+ "dev": true
2742
+ },
2729
2743
  "node_modules/@types/node": {
2730
- "version": "18.8.3",
2731
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.3.tgz",
2732
- "integrity": "sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w==",
2744
+ "version": "18.8.4",
2745
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.4.tgz",
2746
+ "integrity": "sha512-WdlVphvfR/GJCLEMbNA8lJ0lhFNBj4SW3O+O5/cEGw9oYrv0al9zTwuQsq+myDUXgNx2jgBynoVgZ2MMJ6pbow==",
2733
2747
  "dev": true
2734
2748
  },
2735
2749
  "node_modules/@types/parse-json": {
@@ -2750,6 +2764,18 @@
2750
2764
  "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==",
2751
2765
  "dev": true
2752
2766
  },
2767
+ "node_modules/@types/tough-cookie": {
2768
+ "version": "4.0.2",
2769
+ "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.2.tgz",
2770
+ "integrity": "sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw==",
2771
+ "dev": true
2772
+ },
2773
+ "node_modules/@types/user-agents": {
2774
+ "version": "1.0.2",
2775
+ "resolved": "https://registry.npmjs.org/@types/user-agents/-/user-agents-1.0.2.tgz",
2776
+ "integrity": "sha512-WOoL2UJTI6RxV8RB2kS3ZhxjjijI5G1i7mgU7mtlm4LsC1XGCfiV56h+GV4VZnAUkkkLQ4gbFGR/dggT01n0RA==",
2777
+ "dev": true
2778
+ },
2753
2779
  "node_modules/@types/yargs": {
2754
2780
  "version": "17.0.13",
2755
2781
  "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.13.tgz",
@@ -3127,6 +3153,18 @@
3127
3153
  "node": ">= 10"
3128
3154
  }
3129
3155
  },
3156
+ "node_modules/cacache/node_modules/lru-cache": {
3157
+ "version": "6.0.0",
3158
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
3159
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
3160
+ "optional": true,
3161
+ "dependencies": {
3162
+ "yallist": "^4.0.0"
3163
+ },
3164
+ "engines": {
3165
+ "node": ">=10"
3166
+ }
3167
+ },
3130
3168
  "node_modules/callsites": {
3131
3169
  "version": "3.1.0",
3132
3170
  "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
@@ -3350,6 +3388,14 @@
3350
3388
  "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
3351
3389
  "dev": true
3352
3390
  },
3391
+ "node_modules/cross-fetch": {
3392
+ "version": "3.1.5",
3393
+ "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
3394
+ "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==",
3395
+ "dependencies": {
3396
+ "node-fetch": "2.6.7"
3397
+ }
3398
+ },
3353
3399
  "node_modules/cross-spawn": {
3354
3400
  "version": "7.0.3",
3355
3401
  "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -3462,6 +3508,11 @@
3462
3508
  "node": ">= 0.6"
3463
3509
  }
3464
3510
  },
3511
+ "node_modules/destr": {
3512
+ "version": "1.1.1",
3513
+ "resolved": "https://registry.npmjs.org/destr/-/destr-1.1.1.tgz",
3514
+ "integrity": "sha512-QqkneF8LrYmwATMdnuD2MLI3GHQIcBnG6qFC2q9bSH430VTCDAVjcspPmUaKhPGtAtPAftIUFqY1obQYQuwmbg=="
3515
+ },
3465
3516
  "node_modules/detect-libc": {
3466
3517
  "version": "2.0.1",
3467
3518
  "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz",
@@ -5257,14 +5308,11 @@
5257
5308
  "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
5258
5309
  },
5259
5310
  "node_modules/lru-cache": {
5260
- "version": "6.0.0",
5261
- "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
5262
- "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
5263
- "dependencies": {
5264
- "yallist": "^4.0.0"
5265
- },
5311
+ "version": "7.14.0",
5312
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.0.tgz",
5313
+ "integrity": "sha512-EIRtP1GrSJny0dqb50QXRUNBxHJhcpxHC++M5tD7RYbvLLn5KVWKsbyswSSqDuU15UFi3bgTQIY8nhDMeF6aDQ==",
5266
5314
  "engines": {
5267
- "node": ">=10"
5315
+ "node": ">=12"
5268
5316
  }
5269
5317
  },
5270
5318
  "node_modules/make-dir": {
@@ -5322,6 +5370,18 @@
5322
5370
  "node": ">= 10"
5323
5371
  }
5324
5372
  },
5373
+ "node_modules/make-fetch-happen/node_modules/lru-cache": {
5374
+ "version": "6.0.0",
5375
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
5376
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
5377
+ "optional": true,
5378
+ "dependencies": {
5379
+ "yallist": "^4.0.0"
5380
+ },
5381
+ "engines": {
5382
+ "node": ">=10"
5383
+ }
5384
+ },
5325
5385
  "node_modules/makeerror": {
5326
5386
  "version": "1.0.12",
5327
5387
  "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz",
@@ -5376,6 +5436,11 @@
5376
5436
  "node": "*"
5377
5437
  }
5378
5438
  },
5439
+ "node_modules/minimist": {
5440
+ "version": "1.2.6",
5441
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
5442
+ "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
5443
+ },
5379
5444
  "node_modules/minipass": {
5380
5445
  "version": "3.1.6",
5381
5446
  "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.6.tgz",
@@ -6092,6 +6157,24 @@
6092
6157
  "node": ">= 6"
6093
6158
  }
6094
6159
  },
6160
+ "node_modules/psl": {
6161
+ "version": "1.9.0",
6162
+ "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
6163
+ "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag=="
6164
+ },
6165
+ "node_modules/punycode": {
6166
+ "version": "2.1.1",
6167
+ "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
6168
+ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
6169
+ "engines": {
6170
+ "node": ">=6"
6171
+ }
6172
+ },
6173
+ "node_modules/querystringify": {
6174
+ "version": "2.2.0",
6175
+ "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
6176
+ "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ=="
6177
+ },
6095
6178
  "node_modules/react-error-overlay": {
6096
6179
  "version": "6.0.9",
6097
6180
  "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz",
@@ -6141,6 +6224,11 @@
6141
6224
  "node": ">=0.10.0"
6142
6225
  }
6143
6226
  },
6227
+ "node_modules/requires-port": {
6228
+ "version": "1.0.0",
6229
+ "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
6230
+ "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ=="
6231
+ },
6144
6232
  "node_modules/resolve": {
6145
6233
  "version": "1.22.1",
6146
6234
  "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz",
@@ -6250,6 +6338,17 @@
6250
6338
  "node": ">=10"
6251
6339
  }
6252
6340
  },
6341
+ "node_modules/semver/node_modules/lru-cache": {
6342
+ "version": "6.0.0",
6343
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
6344
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
6345
+ "dependencies": {
6346
+ "yallist": "^4.0.0"
6347
+ },
6348
+ "engines": {
6349
+ "node": ">=10"
6350
+ }
6351
+ },
6253
6352
  "node_modules/set-blocking": {
6254
6353
  "version": "2.0.0",
6255
6354
  "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
@@ -6670,6 +6769,20 @@
6670
6769
  "node": ">=8.0"
6671
6770
  }
6672
6771
  },
6772
+ "node_modules/tough-cookie": {
6773
+ "version": "4.1.2",
6774
+ "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz",
6775
+ "integrity": "sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==",
6776
+ "dependencies": {
6777
+ "psl": "^1.1.33",
6778
+ "punycode": "^2.1.1",
6779
+ "universalify": "^0.2.0",
6780
+ "url-parse": "^1.5.3"
6781
+ },
6782
+ "engines": {
6783
+ "node": ">=6"
6784
+ }
6785
+ },
6673
6786
  "node_modules/tr46": {
6674
6787
  "version": "0.0.3",
6675
6788
  "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
@@ -6776,6 +6889,14 @@
6776
6889
  "imurmurhash": "^0.1.4"
6777
6890
  }
6778
6891
  },
6892
+ "node_modules/universalify": {
6893
+ "version": "0.2.0",
6894
+ "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz",
6895
+ "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==",
6896
+ "engines": {
6897
+ "node": ">= 4.0.0"
6898
+ }
6899
+ },
6779
6900
  "node_modules/update-browserslist-db": {
6780
6901
  "version": "1.0.10",
6781
6902
  "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz",
@@ -6802,6 +6923,15 @@
6802
6923
  "browserslist": ">= 4.21.0"
6803
6924
  }
6804
6925
  },
6926
+ "node_modules/url-parse": {
6927
+ "version": "1.5.10",
6928
+ "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz",
6929
+ "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==",
6930
+ "dependencies": {
6931
+ "querystringify": "^2.1.1",
6932
+ "requires-port": "^1.0.0"
6933
+ }
6934
+ },
6805
6935
  "node_modules/util-deprecate": {
6806
6936
  "version": "1.0.2",
6807
6937
  "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
@@ -8926,10 +9056,16 @@
8926
9056
  "integrity": "sha512-eHcVlLXP0c2FlMPm56ITode2AgLMSa6aJ05JTTbYbI+7EMkCEE5qk2E41d5g2lCVTqRe0GnnRFurmlCsDODrPw==",
8927
9057
  "dev": true
8928
9058
  },
9059
+ "@types/minimist": {
9060
+ "version": "1.2.2",
9061
+ "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz",
9062
+ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==",
9063
+ "dev": true
9064
+ },
8929
9065
  "@types/node": {
8930
- "version": "18.8.3",
8931
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.3.tgz",
8932
- "integrity": "sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w==",
9066
+ "version": "18.8.4",
9067
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.4.tgz",
9068
+ "integrity": "sha512-WdlVphvfR/GJCLEMbNA8lJ0lhFNBj4SW3O+O5/cEGw9oYrv0al9zTwuQsq+myDUXgNx2jgBynoVgZ2MMJ6pbow==",
8933
9069
  "dev": true
8934
9070
  },
8935
9071
  "@types/parse-json": {
@@ -8950,6 +9086,18 @@
8950
9086
  "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==",
8951
9087
  "dev": true
8952
9088
  },
9089
+ "@types/tough-cookie": {
9090
+ "version": "4.0.2",
9091
+ "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.2.tgz",
9092
+ "integrity": "sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw==",
9093
+ "dev": true
9094
+ },
9095
+ "@types/user-agents": {
9096
+ "version": "1.0.2",
9097
+ "resolved": "https://registry.npmjs.org/@types/user-agents/-/user-agents-1.0.2.tgz",
9098
+ "integrity": "sha512-WOoL2UJTI6RxV8RB2kS3ZhxjjijI5G1i7mgU7mtlm4LsC1XGCfiV56h+GV4VZnAUkkkLQ4gbFGR/dggT01n0RA==",
9099
+ "dev": true
9100
+ },
8953
9101
  "@types/yargs": {
8954
9102
  "version": "17.0.13",
8955
9103
  "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.13.tgz",
@@ -9243,6 +9391,17 @@
9243
9391
  "ssri": "^8.0.1",
9244
9392
  "tar": "^6.0.2",
9245
9393
  "unique-filename": "^1.1.1"
9394
+ },
9395
+ "dependencies": {
9396
+ "lru-cache": {
9397
+ "version": "6.0.0",
9398
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
9399
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
9400
+ "optional": true,
9401
+ "requires": {
9402
+ "yallist": "^4.0.0"
9403
+ }
9404
+ }
9246
9405
  }
9247
9406
  },
9248
9407
  "callsites": {
@@ -9414,6 +9573,14 @@
9414
9573
  "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
9415
9574
  "dev": true
9416
9575
  },
9576
+ "cross-fetch": {
9577
+ "version": "3.1.5",
9578
+ "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
9579
+ "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==",
9580
+ "requires": {
9581
+ "node-fetch": "2.6.7"
9582
+ }
9583
+ },
9417
9584
  "cross-spawn": {
9418
9585
  "version": "7.0.3",
9419
9586
  "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -9494,6 +9661,11 @@
9494
9661
  "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=",
9495
9662
  "optional": true
9496
9663
  },
9664
+ "destr": {
9665
+ "version": "1.1.1",
9666
+ "resolved": "https://registry.npmjs.org/destr/-/destr-1.1.1.tgz",
9667
+ "integrity": "sha512-QqkneF8LrYmwATMdnuD2MLI3GHQIcBnG6qFC2q9bSH430VTCDAVjcspPmUaKhPGtAtPAftIUFqY1obQYQuwmbg=="
9668
+ },
9497
9669
  "detect-libc": {
9498
9670
  "version": "2.0.1",
9499
9671
  "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz",
@@ -10774,12 +10946,9 @@
10774
10946
  "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
10775
10947
  },
10776
10948
  "lru-cache": {
10777
- "version": "6.0.0",
10778
- "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
10779
- "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
10780
- "requires": {
10781
- "yallist": "^4.0.0"
10782
- }
10949
+ "version": "7.14.0",
10950
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.0.tgz",
10951
+ "integrity": "sha512-EIRtP1GrSJny0dqb50QXRUNBxHJhcpxHC++M5tD7RYbvLLn5KVWKsbyswSSqDuU15UFi3bgTQIY8nhDMeF6aDQ=="
10783
10952
  },
10784
10953
  "make-dir": {
10785
10954
  "version": "3.1.0",
@@ -10824,6 +10993,17 @@
10824
10993
  "promise-retry": "^2.0.1",
10825
10994
  "socks-proxy-agent": "^6.0.0",
10826
10995
  "ssri": "^8.0.0"
10996
+ },
10997
+ "dependencies": {
10998
+ "lru-cache": {
10999
+ "version": "6.0.0",
11000
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
11001
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
11002
+ "optional": true,
11003
+ "requires": {
11004
+ "yallist": "^4.0.0"
11005
+ }
11006
+ }
10827
11007
  }
10828
11008
  },
10829
11009
  "makeerror": {
@@ -10871,6 +11051,11 @@
10871
11051
  "brace-expansion": "^1.1.7"
10872
11052
  }
10873
11053
  },
11054
+ "minimist": {
11055
+ "version": "1.2.6",
11056
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
11057
+ "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q=="
11058
+ },
10874
11059
  "minipass": {
10875
11060
  "version": "3.1.6",
10876
11061
  "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.6.tgz",
@@ -11394,6 +11579,21 @@
11394
11579
  "sisteransi": "^1.0.5"
11395
11580
  }
11396
11581
  },
11582
+ "psl": {
11583
+ "version": "1.9.0",
11584
+ "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
11585
+ "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag=="
11586
+ },
11587
+ "punycode": {
11588
+ "version": "2.1.1",
11589
+ "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
11590
+ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
11591
+ },
11592
+ "querystringify": {
11593
+ "version": "2.2.0",
11594
+ "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
11595
+ "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ=="
11596
+ },
11397
11597
  "react-error-overlay": {
11398
11598
  "version": "6.0.9",
11399
11599
  "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz",
@@ -11434,6 +11634,11 @@
11434
11634
  "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
11435
11635
  "dev": true
11436
11636
  },
11637
+ "requires-port": {
11638
+ "version": "1.0.0",
11639
+ "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
11640
+ "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ=="
11641
+ },
11437
11642
  "resolve": {
11438
11643
  "version": "1.22.1",
11439
11644
  "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz",
@@ -11497,6 +11702,16 @@
11497
11702
  "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==",
11498
11703
  "requires": {
11499
11704
  "lru-cache": "^6.0.0"
11705
+ },
11706
+ "dependencies": {
11707
+ "lru-cache": {
11708
+ "version": "6.0.0",
11709
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
11710
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
11711
+ "requires": {
11712
+ "yallist": "^4.0.0"
11713
+ }
11714
+ }
11500
11715
  }
11501
11716
  },
11502
11717
  "set-blocking": {
@@ -11811,6 +12026,17 @@
11811
12026
  "is-number": "^7.0.0"
11812
12027
  }
11813
12028
  },
12029
+ "tough-cookie": {
12030
+ "version": "4.1.2",
12031
+ "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz",
12032
+ "integrity": "sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==",
12033
+ "requires": {
12034
+ "psl": "^1.1.33",
12035
+ "punycode": "^2.1.1",
12036
+ "universalify": "^0.2.0",
12037
+ "url-parse": "^1.5.3"
12038
+ }
12039
+ },
11814
12040
  "tr46": {
11815
12041
  "version": "0.0.3",
11816
12042
  "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
@@ -11879,6 +12105,11 @@
11879
12105
  "imurmurhash": "^0.1.4"
11880
12106
  }
11881
12107
  },
12108
+ "universalify": {
12109
+ "version": "0.2.0",
12110
+ "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz",
12111
+ "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg=="
12112
+ },
11882
12113
  "update-browserslist-db": {
11883
12114
  "version": "1.0.10",
11884
12115
  "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz",
@@ -11889,6 +12120,15 @@
11889
12120
  "picocolors": "^1.0.0"
11890
12121
  }
11891
12122
  },
12123
+ "url-parse": {
12124
+ "version": "1.5.10",
12125
+ "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz",
12126
+ "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==",
12127
+ "requires": {
12128
+ "querystringify": "^2.1.1",
12129
+ "requires-port": "^1.0.0"
12130
+ }
12131
+ },
11892
12132
  "util-deprecate": {
11893
12133
  "version": "1.0.2",
11894
12134
  "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mherod/get-cookie",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.0-rc.5",
4
4
  "description": "Node.js module for querying a local user's Chrome cookie",
5
5
  "source": "src/index.ts",
6
6
  "bin": "dist/cli.js",
@@ -67,7 +67,8 @@
67
67
  "lru-cache": "^7.14.0",
68
68
  "minimist": "^1.2.6",
69
69
  "sqlite3": "^5.1.1",
70
- "tough-cookie": "^4.1.2"
70
+ "tough-cookie": "^4.1.2",
71
+ "tough-cookie-file-store": "^2.0.3"
71
72
  },
72
73
  "devDependencies": {
73
74
  "@parcel/packager-ts": "^2.7.0",
package/src/CookieSpec.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export default interface CookieSpec {
2
- name: string;
3
2
  domain: string;
3
+ name: string;
4
4
  }
@@ -0,0 +1,10 @@
1
+ import { CookieJar } from "tough-cookie";
2
+ import { env } from "./global";
3
+ const { FileCookieStore } = require("tough-cookie-file-store");
4
+
5
+ export const cookieStore = new FileCookieStore(
6
+ `${env["HOME"]}/cookie-star.json`
7
+ );
8
+ // export const cookieStore = new MemoryCookieStore();
9
+
10
+ export const cookieJar = new CookieJar(cookieStore);
@@ -0,0 +1,6 @@
1
+ export function stringToRegex(s: string): RegExp {
2
+ const s1 = s.replaceAll(/\./gi, ".");
3
+ const s2 = s1.replace(/%/g, ".*");
4
+ const s3 = s2.replace(/\*/g, ".*");
5
+ return new RegExp(s3);
6
+ }
@@ -11,8 +11,11 @@ import { isCookieRow } from "../IsCookieRow";
11
11
  import { isExportedCookie } from "../IsExportedCookie";
12
12
  import CookieRow from "../CookieRow";
13
13
  import ExportedCookie from "../ExportedCookie";
14
+ import { stringToRegex } from "../StringToRegex";
14
15
 
15
16
  export default class ChromeCookieQueryStrategy implements CookieQueryStrategy {
17
+ browserName = "Chrome";
18
+
16
19
  async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
17
20
  if (process.platform !== "darwin") {
18
21
  throw new Error("This only works on macOS");
@@ -56,7 +59,7 @@ async function getPromise(name: string, domain: string): Promise<CookieRow[]> {
56
59
  const promises: Promise<CookieRow[]>[] = files.map((file) =>
57
60
  getPromise1(name, domain, file)
58
61
  );
59
- const results1: Awaited<CookieRow[]>[] = await Promise.all(promises);
62
+ const results1: CookieRow[][] = await Promise.all(promises);
60
63
  return results1.flat().filter(isCookieRow);
61
64
  } catch (error) {
62
65
  if (env.VERBOSE) {
@@ -143,22 +146,29 @@ async function getEncryptedChromeCookie({
143
146
  let sql;
144
147
  //language=SQL
145
148
  sql = "SELECT encrypted_value, name, host_key FROM cookies";
149
+
146
150
  const wildcardRegexp = /^([*%])$/i;
147
151
  const specifiedName = name.match(wildcardRegexp) == null;
148
152
  const specifiedDomain = domain.match(wildcardRegexp) == null;
149
- if (specifiedName || specifiedDomain) {
153
+ const wildcardDomain = domain.match(/[%*]/) != null;
154
+ const queryDomain = specifiedDomain && !wildcardDomain;
155
+ // if we have a wildcard domain, we need to use a regexp
156
+ if (specifiedName || queryDomain) {
150
157
  sql += ` WHERE `;
151
158
  if (specifiedName) {
152
159
  sql += `name = '${name}'`;
153
- if (specifiedDomain) {
160
+ if (queryDomain) {
154
161
  sql += ` AND `;
155
162
  }
156
163
  }
157
- if (specifiedDomain) {
158
- sql += `host_key LIKE '${domain}';`;
164
+ if (queryDomain) {
165
+ // leading dot replaced with % to match subdomains
166
+ const sqlEmbedDomain = domain.replace(/^[.%]?/, "%");
167
+ sql += `host_key LIKE '${sqlEmbedDomain}';`;
159
168
  }
160
169
  }
161
- return doSqliteQuery1({
170
+ console.log("sql", sql);
171
+ const sqliteQuery1: CookieRow[] = await doSqliteQuery1({
162
172
  file: file,
163
173
  sql: sql,
164
174
  rowTransform: (row) => {
@@ -169,6 +179,9 @@ async function getEncryptedChromeCookie({
169
179
  };
170
180
  },
171
181
  });
182
+ return sqliteQuery1.filter((row) => {
183
+ return row.domain.match(stringToRegex(domain)) != null;
184
+ });
172
185
  }
173
186
 
174
187
  async function getChromePassword(): Promise<string> {
@@ -4,7 +4,8 @@ import SafariCookieQueryStrategy from "./SafariCookieQueryStrategy";
4
4
  import CookieQueryStrategy from "./CookieQueryStrategy";
5
5
  import ExportedCookie from "../ExportedCookie";
6
6
  import LRUCache from "lru-cache";
7
- import MemoryCookieStoreQueryStrategy from "./MemoryCookieJarQueryStrategy";
7
+ import CookieStoreQueryStrategy from "./CookieStoreQueryStrategy";
8
+ import { red } from "colorette";
8
9
 
9
10
  const cache = new LRUCache<string, ExportedCookie[]>({
10
11
  ttl: 1000 * 2,
@@ -14,11 +15,13 @@ const cache = new LRUCache<string, ExportedCookie[]>({
14
15
  export default class CompositeCookieQueryStrategy
15
16
  implements CookieQueryStrategy
16
17
  {
18
+ browserName = "all";
19
+
17
20
  #strategies;
18
21
 
19
22
  constructor() {
20
23
  this.#strategies = [
21
- MemoryCookieStoreQueryStrategy,
24
+ CookieStoreQueryStrategy,
22
25
  ChromeCookieQueryStrategy,
23
26
  FirefoxCookieQueryStrategy,
24
27
  SafariCookieQueryStrategy,
@@ -28,19 +31,24 @@ export default class CompositeCookieQueryStrategy
28
31
  }
29
32
 
30
33
  async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
34
+ // domain = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
31
35
  const key = `${name}:${domain}`;
32
36
  const cached = cache.get(key);
33
37
  if (cached) {
34
38
  return cached;
35
39
  }
36
- const results = await Promise.all(
37
- this.#strategies.map(async (strategy) => {
40
+ console.log("Querying cookies:", name, domain);
41
+ const results: ExportedCookie[][] = await Promise.all(
42
+ this.#strategies.map(async (strategy: CookieQueryStrategy) => {
38
43
  // @ts-ignore
39
44
  const cookies: Promise<ExportedCookie[]> = strategy.queryCookies(
40
45
  name,
41
46
  domain
42
47
  );
43
- return cookies.catch(() => []);
48
+ return cookies.catch((e) => {
49
+ console.log(red(`Error querying ${strategy.browserName} cookies`), e);
50
+ return [];
51
+ });
44
52
  })
45
53
  );
46
54
  const flat: ExportedCookie[] = results.flat();
@@ -1,5 +1,6 @@
1
1
  import ExportedCookie from "../ExportedCookie";
2
2
 
3
3
  export default interface CookieQueryStrategy {
4
+ browserName: string;
4
5
  queryCookies(name: string, domain: string): Promise<ExportedCookie[]>;
5
6
  }
@@ -0,0 +1,91 @@
1
+ import CookieQueryStrategy from "./CookieQueryStrategy";
2
+ import CookieSpec from "../CookieSpec";
3
+ import ExportedCookie from "../ExportedCookie";
4
+ import { Cookie } from "tough-cookie";
5
+ import { cookieStore, cookieJar } from "../CookieStore";
6
+ import { stringToRegex } from "../StringToRegex";
7
+
8
+ export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
9
+ browserName = "internal";
10
+
11
+ async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
12
+ const exportedCookies: ExportedCookie[] = [];
13
+
14
+ // if (name.match(/[%*]/) || domain.match(/[%*]/)) {
15
+ const cookies: Cookie[] = await this.#getAllCookies();
16
+ const allExportedCookies = cookies.map((cookie: Cookie) => {
17
+ return this.#extracted(cookie, { name, domain });
18
+ });
19
+ exportedCookies.push(...allExportedCookies);
20
+ // }
21
+
22
+ const wildcardRegexp = /^([*%])$/i;
23
+ if (name.match(wildcardRegexp) && domain.match(wildcardRegexp)) {
24
+ return exportedCookies;
25
+ }
26
+
27
+ const path = "/";
28
+
29
+ if (domain != "%") {
30
+ const domain1 = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
31
+ const url = new URL("https://" + domain1);
32
+ url.pathname = path;
33
+ const cookies: Cookie[] = await this.#getCookies(url.href);
34
+ const domainCookies = cookies.map((cookie: Cookie) => {
35
+ return this.#extracted(cookie, {
36
+ domain,
37
+ name,
38
+ });
39
+ });
40
+ exportedCookies.push(...domainCookies);
41
+ }
42
+
43
+ if (name == "%") {
44
+ return exportedCookies;
45
+ }
46
+
47
+ return exportedCookies.filter((cookie: ExportedCookie) => {
48
+ return (
49
+ cookie.name.match(stringToRegex(name)) &&
50
+ cookie.domain.match(stringToRegex(domain))
51
+ );
52
+ });
53
+ }
54
+
55
+ #extracted(cookie: Cookie, cookieSpec: CookieSpec): ExportedCookie {
56
+ return {
57
+ domain: cookie.domain ?? cookieSpec.domain,
58
+ name: cookie.key ?? cookieSpec.name,
59
+ value: cookie.value,
60
+ meta: {
61
+ file: "memory",
62
+ },
63
+ };
64
+ }
65
+
66
+ #getCookies(url: string): Promise<Cookie[]> {
67
+ return new Promise((resolve, reject) => {
68
+ // @ts-ignore
69
+ return cookieJar.getCookies(url, (err, cookies) => {
70
+ if (err) {
71
+ reject(err);
72
+ } else {
73
+ resolve(cookies ?? []);
74
+ }
75
+ });
76
+ });
77
+ }
78
+
79
+ #getAllCookies(): Promise<Cookie[]> {
80
+ return new Promise((resolve, reject) => {
81
+ // @ts-ignore
82
+ return cookieStore.getAllCookies((err, cookies) => {
83
+ if (err) {
84
+ reject(err);
85
+ } else {
86
+ resolve(cookies ?? []);
87
+ }
88
+ });
89
+ });
90
+ }
91
+ }
@@ -10,6 +10,8 @@ import CookieSpec from "../CookieSpec";
10
10
  import { specialCases } from "../SpecialCases";
11
11
 
12
12
  export default class FirefoxCookieQueryStrategy implements CookieQueryStrategy {
13
+ browserName = "Firefox";
14
+
13
15
  async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
14
16
  if (process.platform !== "darwin") {
15
17
  throw new Error("This only works on macOS");
@@ -2,6 +2,8 @@ import CookieQueryStrategy from "./CookieQueryStrategy";
2
2
  import ExportedCookie from "../ExportedCookie";
3
3
 
4
4
  export default class SafariCookieQueryStrategy implements CookieQueryStrategy {
5
+ browserName = "Safari";
6
+
5
7
  async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
6
8
  return [];
7
9
  }
@@ -6,7 +6,7 @@ import { merge } from "lodash";
6
6
  import destr from "destr";
7
7
  import CookieSpec from "./CookieSpec";
8
8
  import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
9
- import { cookieJar } from "./MemoryCookieStore";
9
+ import { cookieJar } from "./CookieStore";
10
10
 
11
11
  export async function fetchWithCookies(
12
12
  url: RequestInfo | URL,
@@ -1,5 +0,0 @@
1
- import { CookieJar, MemoryCookieStore } from "tough-cookie";
2
-
3
- export const memoryCookieStore = new MemoryCookieStore();
4
-
5
- export const cookieJar = new CookieJar(memoryCookieStore);
@@ -1,53 +0,0 @@
1
- import ExportedCookie from "../ExportedCookie";
2
- import CookieQueryStrategy from "./CookieQueryStrategy";
3
- import { Cookie } from "tough-cookie";
4
- import CookieSpec from "../CookieSpec";
5
- import { memoryCookieStore } from "../MemoryCookieStore";
6
-
7
- export default class MemoryCookieStoreQueryStrategy
8
- implements CookieQueryStrategy
9
- {
10
- async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
11
- if (name == "%" && domain == "%") {
12
- const cookies: Cookie[] = await memoryCookieStore.getAllCookies();
13
- return cookies.map((cookie) => {
14
- return this.#extracted(cookie, { name, domain });
15
- });
16
- }
17
-
18
- const path = "/";
19
-
20
- if (name == "%") {
21
- const cookies: Cookie[] = await memoryCookieStore.findCookies(
22
- domain,
23
- path
24
- );
25
- return cookies.map((cookie) => {
26
- return this.#extracted(cookie, { name, domain });
27
- });
28
- }
29
-
30
- const cookie: Cookie | null = await memoryCookieStore.findCookie(
31
- domain,
32
- path,
33
- name
34
- );
35
-
36
- if (cookie) {
37
- return [this.#extracted(cookie, { name, domain })];
38
- } else {
39
- return [];
40
- }
41
- }
42
-
43
- #extracted(cookie: Cookie, cookieSpec: CookieSpec): ExportedCookie {
44
- return {
45
- domain: cookie.domain ?? cookieSpec.domain,
46
- name: cookie.key ?? cookieSpec.name,
47
- value: cookie.value,
48
- meta: {
49
- file: "memory",
50
- },
51
- };
52
- }
53
- }