@mherod/get-cookie 2.0.0-rc.7 → 2.0.0-rc.8
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 +101 -47
- package/package.json +2 -2
- package/src/CookieRow.ts +1 -0
- package/src/ExportedCookie.ts +1 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +61 -4
- package/src/browsers/CookieStoreQueryStrategy.ts +2 -1
- package/src/doSqliteQuery1.ts +1 -6
- package/src/doSqliteQuery1Params.ts +7 -0
- package/src/findAllFiles.ts +0 -1
- package/src/resultsRendered.ts +6 -3
- package/src/utils.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ var $7oI3p$colorette = require("colorette");
|
|
|
6
6
|
var $7oI3p$fs = require("fs");
|
|
7
7
|
var $7oI3p$crypto = require("crypto");
|
|
8
8
|
var $7oI3p$path = require("path");
|
|
9
|
-
var $7oI3p$child_process = require("child_process");
|
|
10
9
|
var $7oI3p$sqlite3 = require("sqlite3");
|
|
10
|
+
var $7oI3p$child_process = require("child_process");
|
|
11
11
|
var $7oI3p$toughcookie = require("tough-cookie");
|
|
12
12
|
var $7oI3p$toughcookiefilestore = require("tough-cookie-file-store");
|
|
13
13
|
var $7oI3p$jsonwebtoken = require("jsonwebtoken");
|
|
@@ -125,46 +125,6 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
|
|
|
125
125
|
|
|
126
126
|
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
132
|
-
if (!file || file && !$7oI3p$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
133
|
-
const db = new $7oI3p$sqlite3.Database(file);
|
|
134
|
-
return new Promise((resolve, reject)=>{
|
|
135
|
-
db.all(sql, (err, rows)=>{
|
|
136
|
-
if (err) {
|
|
137
|
-
reject(err);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const rows1 = rows;
|
|
141
|
-
if (rows1 == null || rows1.length === 0) {
|
|
142
|
-
resolve([]);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (Array.isArray(rows1)) {
|
|
146
|
-
const cookieRows = rows1.map((row)=>{
|
|
147
|
-
const newVar = {
|
|
148
|
-
meta: {
|
|
149
|
-
file: file
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const cookieRow = rowTransform(row);
|
|
153
|
-
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
154
|
-
});
|
|
155
|
-
resolve(cookieRows);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
159
|
-
resolve([
|
|
160
|
-
rows1
|
|
161
|
-
]);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
128
|
function $af69dfb8766652d8$export$bc926c43858bd3cb(obj) {
|
|
169
129
|
return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
|
|
170
130
|
}
|
|
@@ -184,6 +144,8 @@ function $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb(s) {
|
|
|
184
144
|
|
|
185
145
|
|
|
186
146
|
|
|
147
|
+
|
|
148
|
+
|
|
187
149
|
class $269fe42bfd555305$export$2e2bcd8739ae039 {
|
|
188
150
|
browserName = "Chrome";
|
|
189
151
|
async queryCookies(name, domain) {
|
|
@@ -240,12 +202,17 @@ async function $269fe42bfd555305$var$getChromeCookies({ name: name , domain: dom
|
|
|
240
202
|
const decryptedValue = await $269fe42bfd555305$var$decryptValue(password, encryptedValue);
|
|
241
203
|
const meta = {};
|
|
242
204
|
(0, $7oI3p$lodash.merge)(meta, cookieRow.meta ?? {});
|
|
243
|
-
|
|
205
|
+
const exportedCookie = {
|
|
244
206
|
domain: cookieRow.domain,
|
|
245
207
|
name: cookieRow.name,
|
|
246
208
|
value: decryptedValue,
|
|
247
209
|
meta: meta
|
|
248
210
|
};
|
|
211
|
+
const expiry = cookieRow.expiry;
|
|
212
|
+
if (expiry) (0, $7oI3p$lodash.merge)(exportedCookie, {
|
|
213
|
+
expiry: new Date(expiry)
|
|
214
|
+
});
|
|
215
|
+
return exportedCookie;
|
|
249
216
|
});
|
|
250
217
|
const results = (await Promise.all(decrypted)).filter((0, $d66f40b581ba8bfa$export$963c8d651337e4a4));
|
|
251
218
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("results", results);
|
|
@@ -260,7 +227,8 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
260
227
|
}
|
|
261
228
|
let sql;
|
|
262
229
|
//language=SQL
|
|
263
|
-
sql = "SELECT
|
|
230
|
+
sql = "SELECT * FROM cookies";
|
|
231
|
+
// sql = "SELECT encrypted_value, name, host_key FROM cookies";
|
|
264
232
|
const wildcardRegexp = /^([*%])$/i;
|
|
265
233
|
const specifiedName = name.match(wildcardRegexp) == null;
|
|
266
234
|
const specifiedDomain = domain.match(wildcardRegexp) == null;
|
|
@@ -279,15 +247,18 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
279
247
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
280
248
|
}
|
|
281
249
|
}
|
|
282
|
-
const sqliteQuery1 = await
|
|
250
|
+
const sqliteQuery1 = await $269fe42bfd555305$export$bd52b72df8d0d261({
|
|
283
251
|
file: file,
|
|
284
252
|
sql: sql,
|
|
285
253
|
rowTransform: (row)=>{
|
|
286
|
-
|
|
254
|
+
const cookieRow = {
|
|
255
|
+
expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
|
|
287
256
|
domain: row["host_key"],
|
|
288
257
|
name: row["name"],
|
|
289
258
|
value: row["encrypted_value"]
|
|
290
259
|
};
|
|
260
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("CookieRow", cookieRow);
|
|
261
|
+
return cookieRow;
|
|
291
262
|
}
|
|
292
263
|
});
|
|
293
264
|
return sqliteQuery1.filter((row)=>{
|
|
@@ -352,6 +323,43 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
352
323
|
});
|
|
353
324
|
});
|
|
354
325
|
}
|
|
326
|
+
async function $269fe42bfd555305$export$bd52b72df8d0d261({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
327
|
+
if (!file || file && !(0, ($parcel$interopDefault($7oI3p$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
328
|
+
const db = new $7oI3p$sqlite3.Database(file);
|
|
329
|
+
return new Promise((resolve, reject)=>{
|
|
330
|
+
db.all(sql, (err, rows)=>{
|
|
331
|
+
if (err) {
|
|
332
|
+
reject(err);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const rows1 = rows;
|
|
336
|
+
if (rows1 == null || rows1.length === 0) {
|
|
337
|
+
resolve([]);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (Array.isArray(rows1)) {
|
|
341
|
+
const cookieRows = rows1.map((row)=>{
|
|
342
|
+
const newVar = {
|
|
343
|
+
meta: {
|
|
344
|
+
file: file
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
const cookieRow = rowTransform(row);
|
|
348
|
+
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
349
|
+
});
|
|
350
|
+
resolve(cookieRows);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
354
|
+
resolve([
|
|
355
|
+
rows1
|
|
356
|
+
]);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
355
363
|
|
|
356
364
|
|
|
357
365
|
|
|
@@ -359,6 +367,42 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
359
367
|
|
|
360
368
|
|
|
361
369
|
|
|
370
|
+
async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
371
|
+
if (!file || file && !$7oI3p$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
372
|
+
const db = new $7oI3p$sqlite3.Database(file);
|
|
373
|
+
return new Promise((resolve, reject)=>{
|
|
374
|
+
db.all(sql, (err, rows)=>{
|
|
375
|
+
if (err) {
|
|
376
|
+
reject(err);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const rows1 = rows;
|
|
380
|
+
if (rows1 == null || rows1.length === 0) {
|
|
381
|
+
resolve([]);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (Array.isArray(rows1)) {
|
|
385
|
+
const cookieRows = rows1.map((row)=>{
|
|
386
|
+
const newVar = {
|
|
387
|
+
meta: {
|
|
388
|
+
file: file
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const cookieRow = rowTransform(row);
|
|
392
|
+
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
393
|
+
});
|
|
394
|
+
resolve(cookieRows);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
398
|
+
resolve([
|
|
399
|
+
rows1
|
|
400
|
+
]);
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
|
|
362
406
|
function $b744d19cc39f964e$export$da22813e5a2ec500({ name: name , domain: domain }) {
|
|
363
407
|
const wildcardRegexp = /^([*%])$/i;
|
|
364
408
|
return {
|
|
@@ -496,8 +540,9 @@ class $e4efb16e005540de$export$2e2bcd8739ae039 {
|
|
|
496
540
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
497
541
|
name: cookie.key ?? cookieSpec.name,
|
|
498
542
|
value: cookie.value,
|
|
543
|
+
expiry: cookie.expires ?? Infinity,
|
|
499
544
|
meta: {
|
|
500
|
-
file: "
|
|
545
|
+
file: "tough-cookie"
|
|
501
546
|
}
|
|
502
547
|
};
|
|
503
548
|
}
|
|
@@ -642,7 +687,16 @@ async function $f9b70200901ad17d$export$c44c5fdef43f0941(params) {
|
|
|
642
687
|
|
|
643
688
|
|
|
644
689
|
function $9c43c2ed82e63570$export$9abc0a414b0d8b8f(results) {
|
|
645
|
-
|
|
690
|
+
// sort by name and expiry descending
|
|
691
|
+
// takes the latest expiry for each name
|
|
692
|
+
const orderedResults = (0, $7oI3p$lodash.orderBy)(results, [
|
|
693
|
+
"name",
|
|
694
|
+
"expiry"
|
|
695
|
+
], [
|
|
696
|
+
"asc",
|
|
697
|
+
"desc"
|
|
698
|
+
]);
|
|
699
|
+
return (0, $7oI3p$lodash.uniqBy)(orderedResults, (r)=>r.name).map((r)=>r.name + "=" + r.value).join("; ");
|
|
646
700
|
}
|
|
647
701
|
|
|
648
702
|
|
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.8",
|
|
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",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"clean": "git clean -
|
|
14
|
+
"clean": "git clean -fdX && rm -rf node_modules dist && yarn install",
|
|
15
15
|
"build": "parcel build",
|
|
16
16
|
"prepare": "npm run build && npm run prettier",
|
|
17
17
|
"test": "jest",
|
package/src/CookieRow.ts
CHANGED
package/src/ExportedCookie.ts
CHANGED
|
@@ -13,6 +13,9 @@ import CookieRow from "../CookieRow";
|
|
|
13
13
|
import ExportedCookie from "../ExportedCookie";
|
|
14
14
|
import { stringToRegex } from "../StringToRegex";
|
|
15
15
|
import { parsedArgs } from "../argv";
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
import * as sqlite3 from "sqlite3";
|
|
18
|
+
import { DoSqliteQuery1Params } from "../doSqliteQuery1Params";
|
|
16
19
|
|
|
17
20
|
export default class ChromeCookieQueryStrategy implements CookieQueryStrategy {
|
|
18
21
|
browserName = "Chrome";
|
|
@@ -103,12 +106,19 @@ Promise<ExportedCookie[]> {
|
|
|
103
106
|
const decryptedValue = await decryptValue(password, encryptedValue);
|
|
104
107
|
const meta = {};
|
|
105
108
|
merge(meta, cookieRow.meta ?? {});
|
|
106
|
-
|
|
109
|
+
const exportedCookie: ExportedCookie = {
|
|
107
110
|
domain: cookieRow.domain,
|
|
108
111
|
name: cookieRow.name,
|
|
109
112
|
value: decryptedValue,
|
|
110
113
|
meta: meta,
|
|
111
114
|
};
|
|
115
|
+
const expiry = cookieRow.expiry;
|
|
116
|
+
if (expiry) {
|
|
117
|
+
merge(exportedCookie, {
|
|
118
|
+
expiry: new Date(expiry),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return exportedCookie;
|
|
112
122
|
});
|
|
113
123
|
const results: ExportedCookie[] = (await Promise.all(decrypted)).filter(
|
|
114
124
|
isExportedCookie
|
|
@@ -146,7 +156,8 @@ async function getEncryptedChromeCookie({
|
|
|
146
156
|
}
|
|
147
157
|
let sql;
|
|
148
158
|
//language=SQL
|
|
149
|
-
sql = "SELECT
|
|
159
|
+
sql = "SELECT * FROM cookies";
|
|
160
|
+
// sql = "SELECT encrypted_value, name, host_key FROM cookies";
|
|
150
161
|
|
|
151
162
|
const wildcardRegexp = /^([*%])$/i;
|
|
152
163
|
const specifiedName = name.match(wildcardRegexp) == null;
|
|
@@ -168,15 +179,20 @@ async function getEncryptedChromeCookie({
|
|
|
168
179
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
169
180
|
}
|
|
170
181
|
}
|
|
171
|
-
const sqliteQuery1: CookieRow[] = await
|
|
182
|
+
const sqliteQuery1: CookieRow[] = await doChromeSqliteQuery1({
|
|
172
183
|
file: file,
|
|
173
184
|
sql: sql,
|
|
174
185
|
rowTransform: (row) => {
|
|
175
|
-
|
|
186
|
+
const cookieRow = {
|
|
187
|
+
expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
|
|
176
188
|
domain: row["host_key"],
|
|
177
189
|
name: row["name"],
|
|
178
190
|
value: row["encrypted_value"],
|
|
179
191
|
};
|
|
192
|
+
if (parsedArgs.verbose) {
|
|
193
|
+
console.log("CookieRow", cookieRow);
|
|
194
|
+
}
|
|
195
|
+
return cookieRow;
|
|
180
196
|
},
|
|
181
197
|
});
|
|
182
198
|
return sqliteQuery1.filter((row) => {
|
|
@@ -284,3 +300,44 @@ async function decrypt(
|
|
|
284
300
|
});
|
|
285
301
|
});
|
|
286
302
|
}
|
|
303
|
+
|
|
304
|
+
export async function doChromeSqliteQuery1({
|
|
305
|
+
file,
|
|
306
|
+
sql,
|
|
307
|
+
rowTransform,
|
|
308
|
+
}: DoSqliteQuery1Params): Promise<CookieRow[]> {
|
|
309
|
+
if (!file || (file && !fs.existsSync(file))) {
|
|
310
|
+
throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
311
|
+
}
|
|
312
|
+
const db = new sqlite3.Database(file);
|
|
313
|
+
return new Promise((resolve, reject) => {
|
|
314
|
+
db.all(sql, (err: Error, rows: any[]) => {
|
|
315
|
+
if (err) {
|
|
316
|
+
reject(err);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const rows1: any[] = rows;
|
|
320
|
+
if (rows1 == null || rows1.length === 0) {
|
|
321
|
+
resolve([]);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (Array.isArray(rows1)) {
|
|
325
|
+
const cookieRows: CookieRow[] = rows1.map((row: any) => {
|
|
326
|
+
const newVar = {
|
|
327
|
+
meta: {
|
|
328
|
+
file: file,
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
const cookieRow: CookieRow = rowTransform(row);
|
|
332
|
+
return merge(newVar, cookieRow);
|
|
333
|
+
});
|
|
334
|
+
resolve(cookieRows);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (parsedArgs.verbose) {
|
|
338
|
+
console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
339
|
+
}
|
|
340
|
+
resolve([rows1]);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
@@ -57,8 +57,9 @@ export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
|
57
57
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
58
58
|
name: cookie.key ?? cookieSpec.name,
|
|
59
59
|
value: cookie.value,
|
|
60
|
+
expiry: cookie.expires ?? Infinity,
|
|
60
61
|
meta: {
|
|
61
|
-
file: "
|
|
62
|
+
file: "tough-cookie",
|
|
62
63
|
},
|
|
63
64
|
};
|
|
64
65
|
}
|
package/src/doSqliteQuery1.ts
CHANGED
|
@@ -3,12 +3,7 @@ import * as sqlite3 from "sqlite3";
|
|
|
3
3
|
import CookieRow from "./CookieRow";
|
|
4
4
|
import { merge } from "lodash";
|
|
5
5
|
import { parsedArgs } from "./argv";
|
|
6
|
-
|
|
7
|
-
interface DoSqliteQuery1Params {
|
|
8
|
-
file: string;
|
|
9
|
-
sql: string;
|
|
10
|
-
rowTransform: (row: any) => CookieRow;
|
|
11
|
-
}
|
|
6
|
+
import { DoSqliteQuery1Params } from "./doSqliteQuery1Params";
|
|
12
7
|
|
|
13
8
|
export async function doSqliteQuery1({
|
|
14
9
|
file,
|
package/src/findAllFiles.ts
CHANGED
package/src/resultsRendered.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { uniqBy } from "lodash";
|
|
1
|
+
import { orderBy, uniqBy } from "lodash";
|
|
2
2
|
import ExportedCookie from "./ExportedCookie";
|
|
3
3
|
|
|
4
4
|
export function resultsRendered(results: ExportedCookie[]) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// sort by name and expiry descending
|
|
6
|
+
// takes the latest expiry for each name
|
|
7
|
+
const orderedResults = orderBy(results, ["name", "expiry"], ["asc", "desc"]);
|
|
8
|
+
return uniqBy(orderedResults, (r: ExportedCookie) => r.name)
|
|
9
|
+
.map((r: ExportedCookie) => r.name + "=" + r.value)
|
|
7
10
|
.join("; ");
|
|
8
11
|
}
|
package/src/utils.ts
CHANGED