@mherod/get-cookie 2.0.0-rc.6 → 2.0.0-rc.7
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 +85 -69
- package/package.json +3 -2
- package/src/argv.ts +4 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +12 -12
- package/src/browsers/CompositeCookieQueryStrategy.ts +23 -9
- package/src/cli.ts +1 -4
- package/src/doSqliteQuery1.ts +2 -1
- package/src/fetchWithCookies.ts +10 -2
- package/src/findAllFiles.ts +5 -8
- package/src/getChromeCookie.ts +3 -3
- package/src/getGroupedRenderedCookies.ts +17 -20
- package/src/isValidJwt.ts +2 -2
- package/src/queryCookies.ts +14 -10
- package/src/utils.ts +1 -25
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var $7oI3p$lodash = require("lodash");
|
|
3
|
+
var $7oI3p$minimist = require("minimist");
|
|
3
4
|
var $7oI3p$lrucache = require("lru-cache");
|
|
4
5
|
var $7oI3p$colorette = require("colorette");
|
|
5
6
|
var $7oI3p$fs = require("fs");
|
|
@@ -12,6 +13,7 @@ var $7oI3p$toughcookiefilestore = require("tough-cookie-file-store");
|
|
|
12
13
|
var $7oI3p$jsonwebtoken = require("jsonwebtoken");
|
|
13
14
|
var $7oI3p$crossfetch = require("cross-fetch");
|
|
14
15
|
var $7oI3p$destr = require("destr");
|
|
16
|
+
var $7oI3p$useragents = require("user-agents");
|
|
15
17
|
|
|
16
18
|
function $parcel$export(e, n, v, s) {
|
|
17
19
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
@@ -42,11 +44,9 @@ $parcel$export(module.exports, "getFirefoxCookie", () => $f9b70200901ad17d$expor
|
|
|
42
44
|
$parcel$export(module.exports, "getGroupedRenderedCookies", () => $300d8b33187a203c$export$4d2e9997e2c23417);
|
|
43
45
|
$parcel$export(module.exports, "fetchWithCookies", () => $cfc07ae4aa2c7e44$export$b24a545a0b39f491);
|
|
44
46
|
|
|
45
|
-
const $fac425c10fbbada5$export$a7b6bc01c63cdfc3 = {};
|
|
46
|
-
(0, $7oI3p$lodash.merge)($fac425c10fbbada5$export$a7b6bc01c63cdfc3, process.env);
|
|
47
|
-
const $fac425c10fbbada5$export$a7c5707626fc90f = $fac425c10fbbada5$export$a7b6bc01c63cdfc3["HOME"];
|
|
48
|
-
if (!$fac425c10fbbada5$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
|
|
49
47
|
|
|
48
|
+
const $ef3d5dc2fd8022f5$export$6f4ae1207c703045 = process.argv ?? [];
|
|
49
|
+
const $ef3d5dc2fd8022f5$export$c348dfaf65040d9b = (0, ($parcel$interopDefault($7oI3p$minimist)))($ef3d5dc2fd8022f5$export$6f4ae1207c703045.slice(2));
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
@@ -68,35 +68,26 @@ async function $25b78d6746d4ad48$export$8d71c74f97c0202e(command) {
|
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
function $25b78d6746d4ad48$export$d53bf2de587a369(result) {
|
|
72
|
-
if (result == null) return null;
|
|
73
|
-
if (process.env.VERBOSE) console.log("result", result);
|
|
74
|
-
if (typeof result === "string" && result.length > 0) return result;
|
|
75
|
-
if (result.slice && result.toString) // noinspection JSCheckFunctionSignatures
|
|
76
|
-
return result.toString("utf8");
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
function $25b78d6746d4ad48$export$99ce3e33a555daf1(input) {
|
|
80
|
-
return typeof input !== "string" || input.length === 0;
|
|
81
|
-
}
|
|
82
|
-
function $25b78d6746d4ad48$export$5348b46700dd771c(input) {
|
|
83
|
-
return typeof input == "string" && input.length > 0;
|
|
84
|
-
}
|
|
85
71
|
|
|
86
72
|
|
|
87
73
|
|
|
74
|
+
const $fac425c10fbbada5$export$a7b6bc01c63cdfc3 = {};
|
|
75
|
+
(0, $7oI3p$lodash.merge)($fac425c10fbbada5$export$a7b6bc01c63cdfc3, process.env);
|
|
76
|
+
const $fac425c10fbbada5$export$a7c5707626fc90f = $fac425c10fbbada5$export$a7b6bc01c63cdfc3["HOME"];
|
|
77
|
+
if (!$fac425c10fbbada5$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
|
|
78
|
+
|
|
79
|
+
|
|
88
80
|
|
|
89
81
|
|
|
90
82
|
|
|
91
83
|
async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: name , maxDepth: maxDepth = 2 }) {
|
|
92
84
|
const rootSegments = path.split("/").length;
|
|
93
|
-
if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
|
|
94
85
|
const files = [];
|
|
95
86
|
let readdirSync;
|
|
96
87
|
try {
|
|
97
88
|
readdirSync = $7oI3p$fs.readdirSync(path);
|
|
98
89
|
} catch (e) {
|
|
99
|
-
if ((0, $
|
|
90
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`Error reading ${path}`, e);
|
|
100
91
|
return [];
|
|
101
92
|
}
|
|
102
93
|
for (const file of readdirSync){
|
|
@@ -105,7 +96,7 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
|
|
|
105
96
|
try {
|
|
106
97
|
stat = $7oI3p$fs.statSync(filePath);
|
|
107
98
|
} catch (e1) {
|
|
108
|
-
if ((0, $
|
|
99
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.error(`Error getting stat for ${filePath}`, e1);
|
|
109
100
|
continue;
|
|
110
101
|
}
|
|
111
102
|
if (stat.isDirectory()) {
|
|
@@ -117,11 +108,11 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
|
|
|
117
108
|
});
|
|
118
109
|
files.push(...subFiles);
|
|
119
110
|
} catch (e2) {
|
|
120
|
-
if ((0, $
|
|
111
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.error(e2);
|
|
121
112
|
}
|
|
122
113
|
} else if (file === name) files.push(filePath);
|
|
123
114
|
}
|
|
124
|
-
if ((0, $
|
|
115
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) {
|
|
125
116
|
if (files.length > 0) {
|
|
126
117
|
console.log(`Found ${files.length} ${name} files`);
|
|
127
118
|
console.log(files);
|
|
@@ -136,6 +127,7 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
|
|
|
136
127
|
|
|
137
128
|
|
|
138
129
|
|
|
130
|
+
|
|
139
131
|
async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
140
132
|
if (!file || file && !$7oI3p$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
141
133
|
const db = new $7oI3p$sqlite3.Database(file);
|
|
@@ -163,7 +155,7 @@ async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql
|
|
|
163
155
|
resolve(cookieRows);
|
|
164
156
|
return;
|
|
165
157
|
}
|
|
166
|
-
if (
|
|
158
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
167
159
|
resolve([
|
|
168
160
|
rows1
|
|
169
161
|
]);
|
|
@@ -191,6 +183,7 @@ function $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb(s) {
|
|
|
191
183
|
}
|
|
192
184
|
|
|
193
185
|
|
|
186
|
+
|
|
194
187
|
class $269fe42bfd555305$export$2e2bcd8739ae039 {
|
|
195
188
|
browserName = "Chrome";
|
|
196
189
|
async queryCookies(name, domain) {
|
|
@@ -211,7 +204,7 @@ async function $269fe42bfd555305$var$getPromise1(name, domain, file) {
|
|
|
211
204
|
file: file
|
|
212
205
|
});
|
|
213
206
|
} catch (e) {
|
|
214
|
-
if ((0, $
|
|
207
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error getting encrypted cookie", e);
|
|
215
208
|
return [];
|
|
216
209
|
}
|
|
217
210
|
}
|
|
@@ -225,7 +218,7 @@ async function $269fe42bfd555305$var$getPromise(name, domain) {
|
|
|
225
218
|
const results1 = await Promise.all(promises);
|
|
226
219
|
return results1.flat().filter((0, $af69dfb8766652d8$export$bc926c43858bd3cb));
|
|
227
220
|
} catch (error) {
|
|
228
|
-
if ((0, $
|
|
221
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("error", error);
|
|
229
222
|
return [];
|
|
230
223
|
}
|
|
231
224
|
}
|
|
@@ -234,7 +227,7 @@ async function $269fe42bfd555305$var$decryptValue(password, encryptedValue) {
|
|
|
234
227
|
try {
|
|
235
228
|
d = await $269fe42bfd555305$var$decrypt(password, encryptedValue);
|
|
236
229
|
} catch (e) {
|
|
237
|
-
if ((0, $
|
|
230
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error decrypting cookie", e);
|
|
238
231
|
d = null;
|
|
239
232
|
}
|
|
240
233
|
return d ?? encryptedValue.toString("utf-8");
|
|
@@ -255,13 +248,13 @@ async function $269fe42bfd555305$var$getChromeCookies({ name: name , domain: dom
|
|
|
255
248
|
};
|
|
256
249
|
});
|
|
257
250
|
const results = (await Promise.all(decrypted)).filter((0, $d66f40b581ba8bfa$export$963c8d651337e4a4));
|
|
258
|
-
if ((0, $
|
|
251
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("results", results);
|
|
259
252
|
return results;
|
|
260
253
|
}
|
|
261
254
|
const $269fe42bfd555305$var$chromeLocal = $7oI3p$path.join((0, $fac425c10fbbada5$export$a7c5707626fc90f), "Library", "Application Support", "Google", "Chrome");
|
|
262
255
|
async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $7oI3p$path.join($269fe42bfd555305$var$chromeLocal, "Default", "Cookies") }) {
|
|
263
256
|
if (!(0, $7oI3p$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
|
|
264
|
-
if ((0, $
|
|
257
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) {
|
|
265
258
|
const s = file.split("/").slice(-3).join("/");
|
|
266
259
|
console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);
|
|
267
260
|
}
|
|
@@ -286,7 +279,6 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
286
279
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
287
280
|
}
|
|
288
281
|
}
|
|
289
|
-
console.log("sql", sql);
|
|
290
282
|
const sqliteQuery1 = await (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)({
|
|
291
283
|
file: file,
|
|
292
284
|
sql: sql,
|
|
@@ -313,21 +305,21 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
313
305
|
if (!(encryptedData1 instanceof Buffer)) {
|
|
314
306
|
if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
|
|
315
307
|
[encryptedData1] = encryptedData1;
|
|
316
|
-
if ((0, $
|
|
308
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
|
|
317
309
|
} else throw new Error("encryptedData must be a Buffer: " + encryptedData1);
|
|
318
310
|
encryptedData1 = Buffer.from(encryptedData1);
|
|
319
311
|
}
|
|
320
|
-
if ((0, $
|
|
312
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`Trying to decrypt with password ${password}`);
|
|
321
313
|
return new Promise((resolve, reject)=>{
|
|
322
314
|
$7oI3p$crypto.pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
|
|
323
315
|
try {
|
|
324
316
|
if (error) {
|
|
325
|
-
if ((0, $
|
|
317
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2", error);
|
|
326
318
|
reject(error);
|
|
327
319
|
return;
|
|
328
320
|
}
|
|
329
321
|
if (buffer.length !== 16) {
|
|
330
|
-
if ((0, $
|
|
322
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
|
|
331
323
|
reject(new Error("Buffer length is not 16"));
|
|
332
324
|
return;
|
|
333
325
|
}
|
|
@@ -337,7 +329,7 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
337
329
|
decipher.setAutoPadding(false);
|
|
338
330
|
if (encryptedData1 && encryptedData1.slice) encryptedData1 = encryptedData1.slice(3);
|
|
339
331
|
if (encryptedData1.length % 16 !== 0) {
|
|
340
|
-
if ((0, $
|
|
332
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
|
|
341
333
|
reject(new Error("encryptedData length is not a multiple of 16"));
|
|
342
334
|
return;
|
|
343
335
|
}
|
|
@@ -345,7 +337,7 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
345
337
|
try {
|
|
346
338
|
decipher.final("utf-8");
|
|
347
339
|
} catch (e) {
|
|
348
|
-
if ((0, $
|
|
340
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Error doing decipher.final()", e);
|
|
349
341
|
reject(e);
|
|
350
342
|
return;
|
|
351
343
|
}
|
|
@@ -531,6 +523,8 @@ class $e4efb16e005540de$export$2e2bcd8739ae039 {
|
|
|
531
523
|
|
|
532
524
|
|
|
533
525
|
|
|
526
|
+
|
|
527
|
+
|
|
534
528
|
const $f72befa528c23ca7$var$cache = new (0, ($parcel$interopDefault($7oI3p$lrucache)))({
|
|
535
529
|
ttl: 2000,
|
|
536
530
|
max: 10
|
|
@@ -553,11 +547,18 @@ class $f72befa528c23ca7$export$2e2bcd8739ae039 {
|
|
|
553
547
|
const key = `${name}:${domain}`;
|
|
554
548
|
const cached = $f72befa528c23ca7$var$cache.get(key);
|
|
555
549
|
if (cached) return cached;
|
|
556
|
-
console.log("Querying cookies:", name, domain);
|
|
550
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("Querying cookies:", name, domain);
|
|
557
551
|
const results = await Promise.all(this.#strategies.map(async (strategy)=>{
|
|
558
552
|
// @ts-ignore
|
|
559
|
-
|
|
560
|
-
|
|
553
|
+
return strategy.queryCookies(name, domain).then((cookies)=>{
|
|
554
|
+
return cookies.map((cookie)=>{
|
|
555
|
+
return (0, $7oI3p$lodash.merge)(cookie, {
|
|
556
|
+
meta: {
|
|
557
|
+
browser: strategy.browserName
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
}).catch((e)=>{
|
|
561
562
|
console.log((0, $7oI3p$colorette.red)(`Error querying ${strategy.browserName} cookies`), e);
|
|
562
563
|
return [];
|
|
563
564
|
});
|
|
@@ -576,7 +577,7 @@ function $9a6b2ace073cf1d7$export$2e2bcd8739ae039(token) {
|
|
|
576
577
|
const result = (0, ($parcel$interopDefault($7oI3p$jsonwebtoken))).decode(token, {
|
|
577
578
|
complete: true
|
|
578
579
|
});
|
|
579
|
-
if ((0, $
|
|
580
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose && result) console.log(result);
|
|
580
581
|
const payload = result?.payload;
|
|
581
582
|
if (payload) {
|
|
582
583
|
const exp = payload.exp;
|
|
@@ -594,16 +595,19 @@ function $9a6b2ace073cf1d7$export$2e2bcd8739ae039(token) {
|
|
|
594
595
|
|
|
595
596
|
async function $7a068a32d4710f0b$export$e6d428437cf2cacb({ name: name , domain: domain }, strategy = new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)()) {
|
|
596
597
|
const results = await strategy.queryCookies(name, domain);
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
598
|
+
const allCookies = (0, $7oI3p$lodash.uniqBy)(results, JSON.stringify);
|
|
599
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["require-jwt"]) {
|
|
600
|
+
const jwtCookies = [];
|
|
601
|
+
for (const result of allCookies){
|
|
602
|
+
const value = result.value;
|
|
603
|
+
if ((0, $9a6b2ace073cf1d7$export$2e2bcd8739ae039)(value)) jwtCookies.push(result);
|
|
604
|
+
}
|
|
605
|
+
return (0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["single"] ? [
|
|
606
|
+
jwtCookies[0]
|
|
607
|
+
] : jwtCookies;
|
|
608
|
+
} else return (0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["single"] ? [
|
|
609
|
+
allCookies[0]
|
|
610
|
+
] : allCookies;
|
|
607
611
|
}
|
|
608
612
|
|
|
609
613
|
|
|
@@ -617,10 +621,11 @@ async function $8481e2034946cc4b$export$4be65e66cfa2648a(params) {
|
|
|
617
621
|
|
|
618
622
|
|
|
619
623
|
|
|
624
|
+
|
|
620
625
|
async function $1a92ef2038b55530$export$e5637297e9eb6f2e(params) {
|
|
621
626
|
const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $269fe42bfd555305$export$2e2bcd8739ae039)());
|
|
622
|
-
if (
|
|
623
|
-
|
|
627
|
+
if (cookies.length == 0) throw new Error("Cookie not found");
|
|
628
|
+
return cookies.find((0, $d66f40b581ba8bfa$export$963c8d651337e4a4));
|
|
624
629
|
}
|
|
625
630
|
|
|
626
631
|
|
|
@@ -636,29 +641,27 @@ async function $f9b70200901ad17d$export$c44c5fdef43f0941(params) {
|
|
|
636
641
|
|
|
637
642
|
|
|
638
643
|
|
|
639
|
-
|
|
640
644
|
function $9c43c2ed82e63570$export$9abc0a414b0d8b8f(results) {
|
|
641
645
|
return (0, $7oI3p$lodash.uniqBy)(results, (r)=>r.name).map((r)=>r.name + "=" + r.value).join("; ");
|
|
642
646
|
}
|
|
643
647
|
|
|
644
648
|
|
|
645
|
-
|
|
646
|
-
{ name: name , domain: domain }) {
|
|
649
|
+
|
|
650
|
+
async function $300d8b33187a203c$export$4d2e9997e2c23417({ name: name , domain: domain }) {
|
|
647
651
|
const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
648
652
|
name: name,
|
|
649
653
|
domain: domain
|
|
650
654
|
}, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
|
|
651
|
-
if (
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
} else throw new Error("Cookie not found");
|
|
655
|
+
if (cookies.length == 0) throw new Error("Cookie not found");
|
|
656
|
+
const results = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
657
|
+
name: name,
|
|
658
|
+
domain: domain
|
|
659
|
+
});
|
|
660
|
+
const groupedByFile = (0, $7oI3p$lodash.groupBy)(results, (r)=>r.meta?.file);
|
|
661
|
+
return Object.keys(groupedByFile).map((file)=>{
|
|
662
|
+
const results = groupedByFile[file];
|
|
663
|
+
return (0, $9c43c2ed82e63570$export$9abc0a414b0d8b8f)(results);
|
|
664
|
+
});
|
|
662
665
|
}
|
|
663
666
|
|
|
664
667
|
|
|
@@ -667,10 +670,13 @@ async function $300d8b33187a203c$export$4d2e9997e2c23417(//
|
|
|
667
670
|
|
|
668
671
|
|
|
669
672
|
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
670
676
|
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch)) {
|
|
671
677
|
const defaultOptions = {
|
|
672
678
|
headers: {
|
|
673
|
-
"User-Agent":
|
|
679
|
+
"User-Agent": new (0, ($parcel$interopDefault($7oI3p$useragents)))().toString()
|
|
674
680
|
},
|
|
675
681
|
redirect: "manual"
|
|
676
682
|
};
|
|
@@ -699,9 +705,19 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
699
705
|
value
|
|
700
706
|
]);
|
|
701
707
|
});
|
|
702
|
-
for (const [key, value] of headers)if (key === "set-cookie")
|
|
708
|
+
for (const [key, value] of headers)if (key === "set-cookie") {
|
|
709
|
+
await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).setCookie(value, url2);
|
|
710
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Set-Cookie: ${(0, $7oI3p$colorette.yellow)(value)} ${(0, $7oI3p$colorette.yellow)(url2)}`));
|
|
711
|
+
// const cookie = tough.parse(value);
|
|
712
|
+
// if (cookie instanceof Cookie) {
|
|
713
|
+
// await memoryCookieStore.putCookie(cookie);
|
|
714
|
+
// }
|
|
715
|
+
}
|
|
703
716
|
const newUrl = res.headers.get("location");
|
|
704
|
-
if (res.redirected || newUrl && newUrl !== url2)
|
|
717
|
+
if (res.redirected || newUrl && newUrl !== url2) {
|
|
718
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
|
|
719
|
+
return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(newUrl, newOptions1);
|
|
720
|
+
}
|
|
705
721
|
const arrayBuffer1 = res.arrayBuffer();
|
|
706
722
|
async function arrayBuffer() {
|
|
707
723
|
return arrayBuffer1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mherod/get-cookie",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.7",
|
|
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
|
"minimist": "^1.2.6",
|
|
68
68
|
"sqlite3": "^5.1.1",
|
|
69
69
|
"tough-cookie": "^4.1.2",
|
|
70
|
-
"tough-cookie-file-store": "^2.0.3"
|
|
70
|
+
"tough-cookie-file-store": "^2.0.3",
|
|
71
|
+
"user-agents": "^1.0.1165"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"@parcel/packager-ts": "^2.7.0",
|
package/src/argv.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { isExportedCookie } from "../IsExportedCookie";
|
|
|
12
12
|
import CookieRow from "../CookieRow";
|
|
13
13
|
import ExportedCookie from "../ExportedCookie";
|
|
14
14
|
import { stringToRegex } from "../StringToRegex";
|
|
15
|
+
import { parsedArgs } from "../argv";
|
|
15
16
|
|
|
16
17
|
export default class ChromeCookieQueryStrategy implements CookieQueryStrategy {
|
|
17
18
|
browserName = "Chrome";
|
|
@@ -43,7 +44,7 @@ async function getPromise1(
|
|
|
43
44
|
file: file,
|
|
44
45
|
});
|
|
45
46
|
} catch (e) {
|
|
46
|
-
if (
|
|
47
|
+
if (parsedArgs.verbose) {
|
|
47
48
|
console.log("Error getting encrypted cookie", e);
|
|
48
49
|
}
|
|
49
50
|
return [];
|
|
@@ -62,7 +63,7 @@ async function getPromise(name: string, domain: string): Promise<CookieRow[]> {
|
|
|
62
63
|
const results1: CookieRow[][] = await Promise.all(promises);
|
|
63
64
|
return results1.flat().filter(isCookieRow);
|
|
64
65
|
} catch (error) {
|
|
65
|
-
if (
|
|
66
|
+
if (parsedArgs.verbose) {
|
|
66
67
|
console.log("error", error);
|
|
67
68
|
}
|
|
68
69
|
return [];
|
|
@@ -74,7 +75,7 @@ async function decryptValue(password: string, encryptedValue: Buffer) {
|
|
|
74
75
|
try {
|
|
75
76
|
d = await decrypt(password, encryptedValue);
|
|
76
77
|
} catch (e) {
|
|
77
|
-
if (
|
|
78
|
+
if (parsedArgs.verbose) {
|
|
78
79
|
console.log("Error decrypting cookie", e);
|
|
79
80
|
}
|
|
80
81
|
d = null;
|
|
@@ -112,7 +113,7 @@ Promise<ExportedCookie[]> {
|
|
|
112
113
|
const results: ExportedCookie[] = (await Promise.all(decrypted)).filter(
|
|
113
114
|
isExportedCookie
|
|
114
115
|
);
|
|
115
|
-
if (
|
|
116
|
+
if (parsedArgs.verbose) {
|
|
116
117
|
console.log("results", results);
|
|
117
118
|
}
|
|
118
119
|
return results;
|
|
@@ -139,7 +140,7 @@ async function getEncryptedChromeCookie({
|
|
|
139
140
|
if (!existsSync(file)) {
|
|
140
141
|
throw new Error(`File ${file} does not exist`);
|
|
141
142
|
}
|
|
142
|
-
if (
|
|
143
|
+
if (parsedArgs.verbose) {
|
|
143
144
|
const s = file.split("/").slice(-3).join("/");
|
|
144
145
|
console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);
|
|
145
146
|
}
|
|
@@ -167,7 +168,6 @@ async function getEncryptedChromeCookie({
|
|
|
167
168
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
|
-
console.log("sql", sql);
|
|
171
171
|
const sqliteQuery1: CookieRow[] = await doSqliteQuery1({
|
|
172
172
|
file: file,
|
|
173
173
|
sql: sql,
|
|
@@ -205,7 +205,7 @@ async function decrypt(
|
|
|
205
205
|
if (!(encryptedData1 instanceof Buffer)) {
|
|
206
206
|
if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
|
|
207
207
|
[encryptedData1] = encryptedData1;
|
|
208
|
-
if (
|
|
208
|
+
if (parsedArgs.verbose) {
|
|
209
209
|
console.log(
|
|
210
210
|
`encryptedData is an array of buffers, selected first: ${encryptedData1}`
|
|
211
211
|
);
|
|
@@ -215,14 +215,14 @@ async function decrypt(
|
|
|
215
215
|
}
|
|
216
216
|
encryptedData1 = Buffer.from(encryptedData1);
|
|
217
217
|
}
|
|
218
|
-
if (
|
|
218
|
+
if (parsedArgs.verbose) {
|
|
219
219
|
console.log(`Trying to decrypt with password ${password}`);
|
|
220
220
|
}
|
|
221
221
|
return new Promise((resolve, reject) => {
|
|
222
222
|
crypto.pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer) => {
|
|
223
223
|
try {
|
|
224
224
|
if (error) {
|
|
225
|
-
if (
|
|
225
|
+
if (parsedArgs.verbose) {
|
|
226
226
|
console.log("Error doing pbkdf2", error);
|
|
227
227
|
}
|
|
228
228
|
reject(error);
|
|
@@ -230,7 +230,7 @@ async function decrypt(
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
if (buffer.length !== 16) {
|
|
233
|
-
if (
|
|
233
|
+
if (parsedArgs.verbose) {
|
|
234
234
|
console.log(
|
|
235
235
|
"Error doing pbkdf2, buffer length is not 16",
|
|
236
236
|
buffer.length
|
|
@@ -250,7 +250,7 @@ async function decrypt(
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
if (encryptedData1.length % 16 !== 0) {
|
|
253
|
-
if (
|
|
253
|
+
if (parsedArgs.verbose) {
|
|
254
254
|
console.log(
|
|
255
255
|
"Error doing pbkdf2, encryptedData length is not a multiple of 16",
|
|
256
256
|
encryptedData1.length
|
|
@@ -264,7 +264,7 @@ async function decrypt(
|
|
|
264
264
|
try {
|
|
265
265
|
decipher.final("utf-8");
|
|
266
266
|
} catch (e) {
|
|
267
|
-
if (
|
|
267
|
+
if (parsedArgs.verbose) {
|
|
268
268
|
console.log("Error doing decipher.final()", e);
|
|
269
269
|
}
|
|
270
270
|
reject(e);
|
|
@@ -6,6 +6,8 @@ import ExportedCookie from "../ExportedCookie";
|
|
|
6
6
|
import LRUCache from "lru-cache";
|
|
7
7
|
import CookieStoreQueryStrategy from "./CookieStoreQueryStrategy";
|
|
8
8
|
import { red } from "colorette";
|
|
9
|
+
import { merge } from "lodash";
|
|
10
|
+
import { parsedArgs } from "../argv";
|
|
9
11
|
|
|
10
12
|
const cache = new LRUCache<string, ExportedCookie[]>({
|
|
11
13
|
ttl: 1000 * 2,
|
|
@@ -37,18 +39,30 @@ export default class CompositeCookieQueryStrategy
|
|
|
37
39
|
if (cached) {
|
|
38
40
|
return cached;
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
if (parsedArgs.verbose) {
|
|
43
|
+
console.log("Querying cookies:", name, domain);
|
|
44
|
+
}
|
|
41
45
|
const results: ExportedCookie[][] = await Promise.all(
|
|
42
46
|
this.#strategies.map(async (strategy: CookieQueryStrategy) => {
|
|
43
47
|
// @ts-ignore
|
|
44
|
-
|
|
45
|
-
name,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
return strategy
|
|
49
|
+
.queryCookies(name, domain)
|
|
50
|
+
.then((cookies: ExportedCookie[]) => {
|
|
51
|
+
return cookies.map((cookie: ExportedCookie) => {
|
|
52
|
+
return merge(cookie, {
|
|
53
|
+
meta: {
|
|
54
|
+
browser: strategy.browserName,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.catch((e) => {
|
|
60
|
+
console.log(
|
|
61
|
+
red(`Error querying ${strategy.browserName} cookies`),
|
|
62
|
+
e
|
|
63
|
+
);
|
|
64
|
+
return [];
|
|
65
|
+
});
|
|
52
66
|
})
|
|
53
67
|
);
|
|
54
68
|
const flat: ExportedCookie[] = results.flat();
|
package/src/cli.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { argv } from "./argv";
|
|
3
|
+
import { argv, parsedArgs } from "./argv";
|
|
5
4
|
import { queryCookies } from "./queryCookies";
|
|
6
5
|
import { groupBy } from "lodash";
|
|
7
6
|
import { green, red, yellow } from "colorette";
|
|
@@ -10,8 +9,6 @@ import { fetchWithCookies } from "./fetchWithCookies";
|
|
|
10
9
|
import { unpackHeaders } from "./unpackHeaders";
|
|
11
10
|
import CookieSpec from "./CookieSpec";
|
|
12
11
|
|
|
13
|
-
const parsedArgs: minimist.ParsedArgs = minimist(argv.slice(2));
|
|
14
|
-
|
|
15
12
|
async function cliQueryCookies({ name, domain }: CookieSpec) {
|
|
16
13
|
try {
|
|
17
14
|
const results = await queryCookies({ name, domain });
|
package/src/doSqliteQuery1.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as fs from "fs";
|
|
|
2
2
|
import * as sqlite3 from "sqlite3";
|
|
3
3
|
import CookieRow from "./CookieRow";
|
|
4
4
|
import { merge } from "lodash";
|
|
5
|
+
import { parsedArgs } from "./argv";
|
|
5
6
|
|
|
6
7
|
interface DoSqliteQuery1Params {
|
|
7
8
|
file: string;
|
|
@@ -42,7 +43,7 @@ export async function doSqliteQuery1({
|
|
|
42
43
|
resolve(cookieRows);
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
|
-
if (
|
|
46
|
+
if (parsedArgs.verbose) {
|
|
46
47
|
console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
47
48
|
}
|
|
48
49
|
resolve([rows1]);
|
package/src/fetchWithCookies.ts
CHANGED
|
@@ -7,6 +7,9 @@ import destr from "destr";
|
|
|
7
7
|
import CookieSpec from "./CookieSpec";
|
|
8
8
|
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
9
9
|
import { cookieJar } from "./CookieStore";
|
|
10
|
+
import UserAgent from "user-agents";
|
|
11
|
+
import { parsedArgs } from "./argv";
|
|
12
|
+
import { blue, yellow } from "colorette";
|
|
10
13
|
|
|
11
14
|
export async function fetchWithCookies(
|
|
12
15
|
url: RequestInfo | URL,
|
|
@@ -15,8 +18,7 @@ export async function fetchWithCookies(
|
|
|
15
18
|
): Promise<Response> {
|
|
16
19
|
const defaultOptions: RequestInit = {
|
|
17
20
|
headers: {
|
|
18
|
-
"User-Agent":
|
|
19
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
|
|
21
|
+
"User-Agent": new UserAgent().toString(),
|
|
20
22
|
},
|
|
21
23
|
redirect: "manual",
|
|
22
24
|
};
|
|
@@ -47,6 +49,9 @@ export async function fetchWithCookies(
|
|
|
47
49
|
for (const [key, value] of headers) {
|
|
48
50
|
if (key === "set-cookie") {
|
|
49
51
|
await cookieJar.setCookie(value, url2);
|
|
52
|
+
if (parsedArgs.verbose) {
|
|
53
|
+
console.log(blue(`Set-Cookie: ${yellow(value)} ${yellow(url2)}`));
|
|
54
|
+
}
|
|
50
55
|
// const cookie = tough.parse(value);
|
|
51
56
|
// if (cookie instanceof Cookie) {
|
|
52
57
|
// await memoryCookieStore.putCookie(cookie);
|
|
@@ -56,6 +61,9 @@ export async function fetchWithCookies(
|
|
|
56
61
|
|
|
57
62
|
const newUrl: string = res.headers.get("location") as string;
|
|
58
63
|
if (res.redirected || (newUrl && newUrl !== url2)) {
|
|
64
|
+
if (parsedArgs.verbose) {
|
|
65
|
+
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
66
|
+
}
|
|
59
67
|
return fetchWithCookies(newUrl, newOptions1);
|
|
60
68
|
}
|
|
61
69
|
|
package/src/findAllFiles.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { env } from "./global";
|
|
2
2
|
import * as fs from "fs";
|
|
3
|
+
import { parsedArgs } from "./argv";
|
|
3
4
|
|
|
4
5
|
export async function findAllFiles({
|
|
5
6
|
path,
|
|
@@ -12,16 +13,12 @@ export async function findAllFiles({
|
|
|
12
13
|
maxDepth?: number;
|
|
13
14
|
}): Promise<string[]> {
|
|
14
15
|
const rootSegments = path.split("/").length;
|
|
15
|
-
|
|
16
|
-
if (env.VERBOSE) {
|
|
17
|
-
console.log(`Searching for ${name} in ${path}`);
|
|
18
|
-
}
|
|
19
16
|
const files: string[] = [];
|
|
20
17
|
let readdirSync;
|
|
21
18
|
try {
|
|
22
19
|
readdirSync = fs.readdirSync(path);
|
|
23
20
|
} catch (e) {
|
|
24
|
-
if (
|
|
21
|
+
if (parsedArgs.verbose) {
|
|
25
22
|
console.log(`Error reading ${path}`, e);
|
|
26
23
|
}
|
|
27
24
|
return [];
|
|
@@ -32,7 +29,7 @@ export async function findAllFiles({
|
|
|
32
29
|
try {
|
|
33
30
|
stat = fs.statSync(filePath);
|
|
34
31
|
} catch (e) {
|
|
35
|
-
if (
|
|
32
|
+
if (parsedArgs.verbose) {
|
|
36
33
|
console.error(`Error getting stat for ${filePath}`, e);
|
|
37
34
|
}
|
|
38
35
|
continue;
|
|
@@ -47,7 +44,7 @@ export async function findAllFiles({
|
|
|
47
44
|
});
|
|
48
45
|
files.push(...subFiles);
|
|
49
46
|
} catch (e) {
|
|
50
|
-
if (
|
|
47
|
+
if (parsedArgs.verbose) {
|
|
51
48
|
console.error(e);
|
|
52
49
|
}
|
|
53
50
|
}
|
|
@@ -56,7 +53,7 @@ export async function findAllFiles({
|
|
|
56
53
|
files.push(filePath);
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
if (
|
|
56
|
+
if (parsedArgs.verbose) {
|
|
60
57
|
if (files.length > 0) {
|
|
61
58
|
console.log(`Found ${files.length} ${name} files`);
|
|
62
59
|
console.log(files);
|
package/src/getChromeCookie.ts
CHANGED
|
@@ -2,6 +2,7 @@ import CookieSpec from "./CookieSpec";
|
|
|
2
2
|
import ExportedCookie from "./ExportedCookie";
|
|
3
3
|
import { queryCookies } from "./queryCookies";
|
|
4
4
|
import ChromeCookieQueryStrategy from "./browsers/ChromeCookieQueryStrategy";
|
|
5
|
+
import { isExportedCookie } from "./IsExportedCookie";
|
|
5
6
|
|
|
6
7
|
export async function getChromeCookie(
|
|
7
8
|
params: CookieSpec
|
|
@@ -11,9 +12,8 @@ export async function getChromeCookie(
|
|
|
11
12
|
new ChromeCookieQueryStrategy()
|
|
12
13
|
//
|
|
13
14
|
);
|
|
14
|
-
if (
|
|
15
|
-
return cookies.find((cookie) => cookie != null);
|
|
16
|
-
} else {
|
|
15
|
+
if (cookies.length == 0) {
|
|
17
16
|
throw new Error("Cookie not found");
|
|
18
17
|
}
|
|
18
|
+
return cookies.find(isExportedCookie);
|
|
19
19
|
}
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import { queryCookies } from "./queryCookies";
|
|
2
|
-
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
3
1
|
import { groupBy } from "lodash";
|
|
2
|
+
import { queryCookies } from "./queryCookies";
|
|
4
3
|
import { resultsRendered } from "./resultsRendered";
|
|
4
|
+
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
5
5
|
import CookieSpec from "./CookieSpec";
|
|
6
6
|
import ExportedCookie from "./ExportedCookie";
|
|
7
7
|
|
|
8
|
-
export async function getGroupedRenderedCookies(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
domain,
|
|
13
|
-
}: //
|
|
14
|
-
CookieSpec
|
|
15
|
-
): //
|
|
16
|
-
Promise<string[]> {
|
|
8
|
+
export async function getGroupedRenderedCookies({
|
|
9
|
+
name,
|
|
10
|
+
domain,
|
|
11
|
+
}: CookieSpec): Promise<string[]> {
|
|
17
12
|
const cookies: ExportedCookie[] = await queryCookies(
|
|
18
|
-
{
|
|
13
|
+
{
|
|
14
|
+
name,
|
|
15
|
+
domain,
|
|
16
|
+
},
|
|
19
17
|
new CompositeCookieQueryStrategy()
|
|
20
18
|
//
|
|
21
19
|
);
|
|
22
|
-
if (
|
|
23
|
-
const results: ExportedCookie[] = await queryCookies({ name, domain });
|
|
24
|
-
const groupedByFile = groupBy(results, (r) => r.meta?.file);
|
|
25
|
-
return Object.keys(groupedByFile).map((file: string) => {
|
|
26
|
-
const results: ExportedCookie[] = groupedByFile[file];
|
|
27
|
-
return resultsRendered(results);
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
20
|
+
if (cookies.length == 0) {
|
|
30
21
|
throw new Error("Cookie not found");
|
|
31
22
|
}
|
|
23
|
+
const results: ExportedCookie[] = await queryCookies({ name, domain });
|
|
24
|
+
const groupedByFile = groupBy(results, (r: ExportedCookie) => r.meta?.file);
|
|
25
|
+
return Object.keys(groupedByFile).map((file: string) => {
|
|
26
|
+
const results: ExportedCookie[] = groupedByFile[file];
|
|
27
|
+
return resultsRendered(results);
|
|
28
|
+
});
|
|
32
29
|
}
|
package/src/isValidJwt.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import jsonwebtoken, { JwtPayload } from "jsonwebtoken";
|
|
2
|
-
import {
|
|
2
|
+
import { parsedArgs } from "./argv";
|
|
3
3
|
|
|
4
4
|
export default function isValidJwt(token: any) {
|
|
5
5
|
try {
|
|
6
6
|
const result = jsonwebtoken.decode(token, { complete: true });
|
|
7
|
-
if (
|
|
7
|
+
if (parsedArgs.verbose && result) {
|
|
8
8
|
console.log(result);
|
|
9
9
|
}
|
|
10
10
|
const payload: JwtPayload = result?.payload as JwtPayload;
|
package/src/queryCookies.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { env } from "./global";
|
|
2
1
|
import { uniqBy } from "lodash";
|
|
2
|
+
import { parsedArgs } from "./argv";
|
|
3
3
|
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
4
4
|
import CookieQueryStrategy from "./browsers/CookieQueryStrategy";
|
|
5
5
|
import isValidJwt from "./isValidJwt";
|
|
@@ -9,16 +9,20 @@ import ExportedCookie from "./ExportedCookie";
|
|
|
9
9
|
export async function queryCookies(
|
|
10
10
|
{ name, domain }: CookieSpec,
|
|
11
11
|
strategy: CookieQueryStrategy = new CompositeCookieQueryStrategy()
|
|
12
|
-
) {
|
|
12
|
+
): Promise<ExportedCookie[]> {
|
|
13
13
|
const results: ExportedCookie[] = await strategy.queryCookies(name, domain);
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const allCookies: ExportedCookie[] = uniqBy(results, JSON.stringify);
|
|
15
|
+
|
|
16
|
+
if (parsedArgs["require-jwt"]) {
|
|
17
|
+
const jwtCookies = [];
|
|
18
|
+
for (const result of allCookies) {
|
|
19
|
+
const value: string = result.value;
|
|
20
|
+
if (isValidJwt(value)) {
|
|
21
|
+
jwtCookies.push(result);
|
|
22
|
+
}
|
|
20
23
|
}
|
|
24
|
+
return parsedArgs["single"] ? [jwtCookies[0]] : jwtCookies;
|
|
25
|
+
} else {
|
|
26
|
+
return parsedArgs["single"] ? [allCookies[0]] : allCookies;
|
|
21
27
|
}
|
|
22
|
-
const resultsUniq = env.REQUIRE_JWT ? jwtCookies : results1;
|
|
23
|
-
return env.SINGLE ? [resultsUniq[0]] : resultsUniq;
|
|
24
28
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// noinspection JSUnusedGlobalSymbols
|
|
2
2
|
|
|
3
3
|
import { exec, ExecException } from "child_process";
|
|
4
|
+
import { parsedArgs } from "./argv";
|
|
4
5
|
|
|
5
6
|
export async function execSimple(command: string): Promise<string> {
|
|
6
7
|
return new Promise((resolve, reject) => {
|
|
@@ -23,28 +24,3 @@ export async function execSimple(command: string): Promise<string> {
|
|
|
23
24
|
);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
export function toStringOrNull(result: any) {
|
|
28
|
-
if (result == null) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
if (process.env.VERBOSE) {
|
|
32
|
-
console.log("result", result);
|
|
33
|
-
}
|
|
34
|
-
if (typeof result === "string" && result.length > 0) {
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
if (result.slice && result.toString) {
|
|
38
|
-
// noinspection JSCheckFunctionSignatures
|
|
39
|
-
return result.toString("utf8");
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function invalidString(input: any): boolean {
|
|
45
|
-
return typeof input !== "string" || input.length === 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function validString(input: any): input is string {
|
|
49
|
-
return typeof input == "string" && input.length > 0;
|
|
50
|
-
}
|