@mherod/get-cookie 2.1.3 → 4.0.2
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/.husky/commit-msg +2 -0
- package/.husky/pre-commit +4 -0
- package/.husky/pre-push +4 -0
- package/README.md +163 -18
- package/commitlint.config.js +12 -0
- package/dist/chunk-56Z35D5R.js +2 -0
- package/dist/chunk-56Z35D5R.js.map +1 -0
- package/dist/chunk-5FUMK7M3.js +4 -0
- package/dist/chunk-5FUMK7M3.js.map +1 -0
- package/dist/chunk-5ZT2G45S.js +2 -0
- package/dist/chunk-5ZT2G45S.js.map +1 -0
- package/dist/chunk-FR2MKDHT.js +2 -0
- package/dist/chunk-FR2MKDHT.js.map +1 -0
- package/dist/chunk-HMKSQBDC.js +2 -0
- package/dist/chunk-HMKSQBDC.js.map +1 -0
- package/dist/chunk-VMBA4NVU.js +2 -0
- package/dist/chunk-VMBA4NVU.js.map +1 -0
- package/dist/chunk-W3JALMAX.js +2 -0
- package/dist/chunk-W3JALMAX.js.map +1 -0
- package/dist/cli.cjs +19 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/getChromeCookie-4ZWACG6M.js +2 -0
- package/dist/getChromeCookie-4ZWACG6M.js.map +1 -0
- package/dist/getChromePassword-GTIXL733.js +2 -0
- package/dist/getChromePassword-GTIXL733.js.map +1 -0
- package/dist/getCookie-43FKMQEZ.js +2 -0
- package/dist/getCookie-43FKMQEZ.js.map +1 -0
- package/dist/getFirefoxCookie-OJYYZFZP.js +2 -0
- package/dist/getFirefoxCookie-OJYYZFZP.js.map +1 -0
- package/dist/getGroupedRenderedCookies-P5VZXZUC.js +2 -0
- package/dist/getGroupedRenderedCookies-P5VZXZUC.js.map +1 -0
- package/dist/getMergedRenderedCookies-C6TXK2I4.js +2 -0
- package/dist/getMergedRenderedCookies-C6TXK2I4.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +252 -0
- package/dist/index.d.ts +252 -0
- package/dist/index.js +2 -24712
- package/dist/index.js.map +1 -0
- package/eslint.config.js +243 -0
- package/jest.setup.js +11 -0
- package/package.json +87 -36
- package/tsconfig.build.json +9 -0
- package/tsup.cli.ts +27 -0
- package/tsup.config.ts +27 -0
- package/tsup.lib.ts +27 -0
- package/typedoc.json +22 -0
- package/.parcelrc +0 -7
- package/.prettierignore +0 -5
- package/.prettierrc +0 -12
- package/.terserrc +0 -26
- package/build-indexes.ts +0 -108
- package/bun.lockb +0 -0
- package/dist/cli.js +0 -18319
- package/dist/types.d.ts +0 -361
- package/jest.config.ts +0 -14
- package/package-lock.json +0 -5608
- package/src/CookieRow.ts +0 -43
- package/src/CookieSpec.ts +0 -42
- package/src/ExportedCookie.ts +0 -19
- package/src/FetchResponse.ts +0 -13
- package/src/SpecialCases.ts +0 -15
- package/src/StringToRegex.ts +0 -16
- package/src/argv.ts +0 -30
- package/src/browsers/CompositeCookieQueryStrategy.ts +0 -76
- package/src/browsers/CookieQueryStrategy.ts +0 -7
- package/src/browsers/CookieStoreQueryStrategy.ts +0 -115
- package/src/browsers/QuerySqliteThenTransform.ts +0 -48
- package/src/browsers/chrome/ChromeApplicationSupport.ts +0 -14
- package/src/browsers/chrome/ChromeCookieQueryStrategy.ts +0 -158
- package/src/browsers/chrome/decrypt.ts +0 -154
- package/src/browsers/chrome/getChromePassword.ts +0 -28
- package/src/browsers/firefox/FirefoxCookieQueryStrategy.ts +0 -109
- package/src/browsers/getEncryptedChromeCookie.ts +0 -122
- package/src/browsers/index.ts +0 -12
- package/src/browsers/mock/MockCookieQueryStrategy.ts +0 -22
- package/src/browsers/safari/SafariCookieQueryStrategy.ts +0 -42
- package/src/cli.ts +0 -94
- package/src/cliQueryCookies.ts +0 -65
- package/src/comboQueryCookieSpec.test.ts +0 -92
- package/src/comboQueryCookieSpec.ts +0 -26
- package/src/cookieQueryOptions.ts +0 -27
- package/src/cookieSpecsFromUrl.test.ts +0 -65
- package/src/cookieSpecsFromUrl.ts +0 -73
- package/src/decodeBinaryCookies.ts +0 -72
- package/src/execSimple.ts +0 -12
- package/src/fetchWithCookies.test.ts +0 -32
- package/src/fetchWithCookies.ts +0 -217
- package/src/findAllFiles.ts +0 -48
- package/src/getChromeCookie.ts +0 -19
- package/src/getCookie.ts +0 -22
- package/src/getFirefoxCookie.ts +0 -25
- package/src/getGroupedRenderedCookies.ts +0 -42
- package/src/getMergedRenderedCookies.test.ts +0 -43
- package/src/getMergedRenderedCookies.ts +0 -19
- package/src/global.ts +0 -8
- package/src/index.ts +0 -16
- package/src/isValidJwt.ts +0 -26
- package/src/listChromeProfiles.ts +0 -53
- package/src/logger.ts +0 -12
- package/src/processBeforeReturn.ts +0 -29
- package/src/queryCookies.ts +0 -41
- package/src/resultsRendered.ts +0 -24
- package/src/unpackHeaders.ts +0 -18
- package/src/util/flatMapAsync.test.ts +0 -55
- package/src/util/flatMapAsync.ts +0 -41
- package/src/util/index.ts +0 -1
- package/tsconfig.json +0 -26
package/src/CookieRow.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import consola from "./logger";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The CookieRow interface represents the structure of a cookie row object.
|
|
5
|
-
*/
|
|
6
|
-
export default interface CookieRow {
|
|
7
|
-
expiry?: number;
|
|
8
|
-
domain: string;
|
|
9
|
-
name: string;
|
|
10
|
-
value: Uint8Array | Buffer;
|
|
11
|
-
meta?: Record<string, unknown>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Type guard to check if an object is a CookieRow.
|
|
16
|
-
* @param obj - The object to check.
|
|
17
|
-
* @returns True if the object is a CookieRow, false otherwise.
|
|
18
|
-
*/
|
|
19
|
-
export function isCookieRow(obj: any): obj is CookieRow {
|
|
20
|
-
if (typeof obj !== "object" || obj === null) {
|
|
21
|
-
consola.warn("Object is not an object or is null:", obj);
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const { domain, name, value } = obj as CookieRow;
|
|
26
|
-
|
|
27
|
-
if (typeof domain !== "string") {
|
|
28
|
-
consola.warn("Domain is not a string:", domain);
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (typeof name !== "string") {
|
|
33
|
-
consola.warn("Name is not a string:", name);
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!(value instanceof Uint8Array) && !Buffer.isBuffer(value)) {
|
|
38
|
-
consola.warn("Value is not a Uint8Array or Buffer:", value);
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return true;
|
|
43
|
-
}
|
package/src/CookieSpec.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Define the CookieSpec interface with domain and name properties
|
|
3
|
-
*/
|
|
4
|
-
export default interface CookieSpec {
|
|
5
|
-
domain: string;
|
|
6
|
-
name: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Function to check if an object is of type CookieSpec
|
|
11
|
-
* @param obj - The object to check
|
|
12
|
-
* @returns True if the object is of type CookieSpec, otherwise false
|
|
13
|
-
*/
|
|
14
|
-
export function isCookieSpec(obj: unknown): obj is CookieSpec {
|
|
15
|
-
const cookie = obj as CookieSpec;
|
|
16
|
-
return typeof cookie.domain === "string" && typeof cookie.name === "string";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Define a type that can be either a single CookieSpec or an array of CookieSpecs
|
|
21
|
-
*/
|
|
22
|
-
export type MultiCookieSpec = CookieSpec | CookieSpec[];
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Function to check if an object is of type MultiCookieSpec
|
|
26
|
-
* @param obj - The object to check
|
|
27
|
-
* @returns True if the object is of type MultiCookieSpec, otherwise false
|
|
28
|
-
*/
|
|
29
|
-
export function isMultiCookieSpec(obj: unknown): obj is MultiCookieSpec {
|
|
30
|
-
if (isCookieSpec(obj)) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
if (Array.isArray(obj)) {
|
|
34
|
-
for (let i = 0; i < obj.length; i++) {
|
|
35
|
-
if (!isCookieSpec(obj[i])) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
package/src/ExportedCookie.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default interface ExportedCookie {
|
|
2
|
-
domain: string;
|
|
3
|
-
name: string;
|
|
4
|
-
value: string;
|
|
5
|
-
expiry?: Date | "Infinity";
|
|
6
|
-
meta?: any;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function isExportedCookie(obj: any): obj is ExportedCookie {
|
|
10
|
-
return (
|
|
11
|
-
typeof obj.domain === "string" &&
|
|
12
|
-
typeof obj.name === "string" &&
|
|
13
|
-
typeof obj.value === "string" &&
|
|
14
|
-
(obj.expiry === undefined ||
|
|
15
|
-
obj.expiry instanceof Date ||
|
|
16
|
-
obj.expiry === "Infinity") &&
|
|
17
|
-
(obj.meta === undefined || typeof obj.meta === "object")
|
|
18
|
-
);
|
|
19
|
-
}
|
package/src/FetchResponse.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
2
|
-
|
|
3
|
-
export default interface FetchResponse {
|
|
4
|
-
status: number;
|
|
5
|
-
statusText: string;
|
|
6
|
-
headers: Headers;
|
|
7
|
-
url: string;
|
|
8
|
-
text: () => Promise<string>;
|
|
9
|
-
json: () => Promise<any>;
|
|
10
|
-
formData: () => Promise<URLSearchParams>;
|
|
11
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
12
|
-
buffer: () => Promise<Buffer>;
|
|
13
|
-
}
|
package/src/SpecialCases.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import CookieSpec from "./CookieSpec";
|
|
2
|
-
|
|
3
|
-
export function specialCases({ name, domain }: CookieSpec): {
|
|
4
|
-
specifiedName: boolean;
|
|
5
|
-
specifiedDomain: boolean;
|
|
6
|
-
} {
|
|
7
|
-
const wildcardRegexp: RegExp = /^([*%])$/i;
|
|
8
|
-
const specifiedName: boolean = name.match(wildcardRegexp) == null;
|
|
9
|
-
const specifiedDomain: boolean = domain.match(wildcardRegexp) == null;
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
specifiedName,
|
|
13
|
-
specifiedDomain,
|
|
14
|
-
};
|
|
15
|
-
}
|
package/src/StringToRegex.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// This function converts a string into a regular expression
|
|
2
|
-
export function stringToRegex(s: string): RegExp {
|
|
3
|
-
// Replace all occurrences of '.' with a literal '\.'
|
|
4
|
-
let s1: string = s.replace(/\./g, "\\.");
|
|
5
|
-
// Replace all occurrences of '%' with '.*' to match any number of any characters
|
|
6
|
-
let s2: string = s1.replace(/%/g, ".*");
|
|
7
|
-
// Replace all occurrences of '*' with '.*' to match any number of any characters
|
|
8
|
-
let s3: string = s2.replace(/\*/g, ".*");
|
|
9
|
-
// Return the new string as a RegExp object
|
|
10
|
-
return new RegExp(s3);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
%.example.com -> .*\.example\.com
|
|
15
|
-
example.com -> example\.com
|
|
16
|
-
*/
|
package/src/argv.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import minimist from "minimist";
|
|
2
|
-
import { merge } from "lodash";
|
|
3
|
-
|
|
4
|
-
export interface MyParsedArgs extends minimist.ParsedArgs {
|
|
5
|
-
verbose: boolean;
|
|
6
|
-
render?: string;
|
|
7
|
-
fetch?: string;
|
|
8
|
-
cs?: string;
|
|
9
|
-
dump?: string;
|
|
10
|
-
"dump-request-headers"?: string;
|
|
11
|
-
"dump-response-headers"?: string;
|
|
12
|
-
"dump-response-body"?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/*
|
|
16
|
-
Usage: get-cookie [name] [domain] [options]
|
|
17
|
-
Options:
|
|
18
|
-
-h, --help: Show this help
|
|
19
|
-
-v, --verbose: Show verbose output
|
|
20
|
-
-d, --dump: Dump all results
|
|
21
|
-
-D, --dump-grouped: Dump all results, grouped by profile
|
|
22
|
-
-r, --render: Render all results
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export const argv: string[] = process.argv ?? [];
|
|
26
|
-
const minimistArgs: minimist.ParsedArgs = minimist(argv.slice(2));
|
|
27
|
-
const defaultOptions = {
|
|
28
|
-
verbose: false,
|
|
29
|
-
};
|
|
30
|
-
export const parsedArgs: MyParsedArgs = merge(defaultOptions, minimistArgs);
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import ChromeCookieQueryStrategy from "./chrome/ChromeCookieQueryStrategy";
|
|
2
|
-
import FirefoxCookieQueryStrategy from "./firefox/FirefoxCookieQueryStrategy";
|
|
3
|
-
import SafariCookieQueryStrategy from "./safari/SafariCookieQueryStrategy";
|
|
4
|
-
import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
5
|
-
import ExportedCookie from "../ExportedCookie";
|
|
6
|
-
import LRUCache from "lru-cache";
|
|
7
|
-
import { merge } from "lodash";
|
|
8
|
-
import { flatMapAsync } from "../util/flatMapAsync";
|
|
9
|
-
import consola from "../logger";
|
|
10
|
-
|
|
11
|
-
const cache: LRUCache<string, ExportedCookie[]> = new LRUCache<
|
|
12
|
-
string,
|
|
13
|
-
ExportedCookie[]
|
|
14
|
-
>({
|
|
15
|
-
ttl: 1000 * 10, // 10 seconds
|
|
16
|
-
max: 10,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export default class CompositeCookieQueryStrategy
|
|
20
|
-
implements CookieQueryStrategy
|
|
21
|
-
{
|
|
22
|
-
browserName: string = "all";
|
|
23
|
-
|
|
24
|
-
private readonly strategies: CookieQueryStrategy[];
|
|
25
|
-
|
|
26
|
-
constructor() {
|
|
27
|
-
this.strategies = [
|
|
28
|
-
ChromeCookieQueryStrategy,
|
|
29
|
-
FirefoxCookieQueryStrategy,
|
|
30
|
-
SafariCookieQueryStrategy,
|
|
31
|
-
].map((Strategy) => new Strategy());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
35
|
-
const key: string = `${name}:${domain}`;
|
|
36
|
-
consola.info(`Querying cookies for name: ${name}, domain: ${domain}`);
|
|
37
|
-
if (cache.has(key)) {
|
|
38
|
-
const cached: ExportedCookie[] | undefined = cache.get(key);
|
|
39
|
-
if (cached) {
|
|
40
|
-
consola.info(
|
|
41
|
-
`Cache hit for key: ${key}, returning ${cached.length} cookies`,
|
|
42
|
-
);
|
|
43
|
-
return cached;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const results: ExportedCookie[] = await flatMapAsync(
|
|
47
|
-
this.strategies,
|
|
48
|
-
async (strategy) => {
|
|
49
|
-
try {
|
|
50
|
-
const cookies: ExportedCookie[] = await strategy.queryCookies(
|
|
51
|
-
name,
|
|
52
|
-
domain,
|
|
53
|
-
);
|
|
54
|
-
return cookies.map((cookie: ExportedCookie) =>
|
|
55
|
-
merge(cookie, {
|
|
56
|
-
meta: {
|
|
57
|
-
browser: strategy.browserName,
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
consola.error(
|
|
63
|
-
`Error querying cookies for ${name} on ${domain} using ${strategy.browserName}`,
|
|
64
|
-
e,
|
|
65
|
-
);
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
);
|
|
70
|
-
cache.set(key, results);
|
|
71
|
-
consola.info(
|
|
72
|
-
`Query result size for key: ${key} is ${results.length} cookies`,
|
|
73
|
-
);
|
|
74
|
-
return results;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
2
|
-
import CookieSpec from "../CookieSpec";
|
|
3
|
-
import ExportedCookie from "../ExportedCookie";
|
|
4
|
-
import { Cookie, Store } from "tough-cookie";
|
|
5
|
-
import { cookieJarPromise, cookieStorePromise } from "../CookieStore";
|
|
6
|
-
import { stringToRegex } from "../StringToRegex";
|
|
7
|
-
|
|
8
|
-
export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
9
|
-
browserName: string = "internal";
|
|
10
|
-
|
|
11
|
-
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
12
|
-
const exportedCookies: ExportedCookie[] = await this.getAllExportedCookies(
|
|
13
|
-
name,
|
|
14
|
-
domain,
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const wildcardRegexp: RegExp = /^([*%])$/i;
|
|
18
|
-
if (name.match(wildcardRegexp) && domain.match(wildcardRegexp)) {
|
|
19
|
-
return exportedCookies;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (domain !== "%") {
|
|
23
|
-
const domainCookies: ExportedCookie[] = await this.getDomainCookies(
|
|
24
|
-
name,
|
|
25
|
-
domain,
|
|
26
|
-
);
|
|
27
|
-
exportedCookies.push(...domainCookies);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return this.filterCookies(exportedCookies, name, domain);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private async getAllExportedCookies(
|
|
34
|
-
name: string,
|
|
35
|
-
domain: string,
|
|
36
|
-
): Promise<ExportedCookie[]> {
|
|
37
|
-
const cookies: Cookie[] = await this.getAllCookies();
|
|
38
|
-
return cookies.map((cookie: Cookie) =>
|
|
39
|
-
this.extractCookie(cookie, { name, domain }),
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private async getDomainCookies(
|
|
44
|
-
name: string,
|
|
45
|
-
domain: string,
|
|
46
|
-
): Promise<ExportedCookie[]> {
|
|
47
|
-
const path: string = "/";
|
|
48
|
-
const domain1: string = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
|
|
49
|
-
const url: URL = new URL("https://" + domain1);
|
|
50
|
-
url.pathname = path;
|
|
51
|
-
const cookies: Cookie[] = await this.getCookies(url.href);
|
|
52
|
-
return cookies.map((cookie: Cookie) =>
|
|
53
|
-
this.extractCookie(cookie, { domain, name }),
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private filterCookies(
|
|
58
|
-
exportedCookies: ExportedCookie[],
|
|
59
|
-
name: string,
|
|
60
|
-
domain: string,
|
|
61
|
-
): ExportedCookie[] {
|
|
62
|
-
if (name === "%") {
|
|
63
|
-
return exportedCookies.filter((cookie: ExportedCookie) =>
|
|
64
|
-
cookie.domain.match(stringToRegex(domain)),
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return exportedCookies.filter(
|
|
69
|
-
(cookie: ExportedCookie) =>
|
|
70
|
-
cookie.name.match(stringToRegex(name)) &&
|
|
71
|
-
cookie.domain.match(stringToRegex(domain)),
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private extractCookie(
|
|
76
|
-
cookie: Cookie,
|
|
77
|
-
cookieSpec: CookieSpec,
|
|
78
|
-
): ExportedCookie {
|
|
79
|
-
return {
|
|
80
|
-
domain: cookie.domain ?? cookieSpec.domain,
|
|
81
|
-
name: cookie.key ?? cookieSpec.name,
|
|
82
|
-
value: cookie.value,
|
|
83
|
-
expiry: cookie.expires ?? "Infinity",
|
|
84
|
-
meta: {
|
|
85
|
-
file: "tough-cookie",
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private async getCookies(url: string): Promise<Cookie[]> {
|
|
91
|
-
const cookieJar = await cookieJarPromise;
|
|
92
|
-
return new Promise((resolve, reject) => {
|
|
93
|
-
cookieJar.getCookies(url, (err: Error | null, cookies: Cookie[]) => {
|
|
94
|
-
if (err) {
|
|
95
|
-
reject(err);
|
|
96
|
-
} else {
|
|
97
|
-
resolve(cookies ?? []);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private async getAllCookies(): Promise<Cookie[]> {
|
|
104
|
-
const cookieStore: Store = await cookieStorePromise;
|
|
105
|
-
return new Promise((resolve, reject) => {
|
|
106
|
-
cookieStore.getAllCookies((err: Error | null, cookies: Cookie[]) => {
|
|
107
|
-
if (err) {
|
|
108
|
-
reject(err);
|
|
109
|
-
} else {
|
|
110
|
-
resolve(cookies ?? []);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import CookieRow from "../CookieRow";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { merge } from "lodash";
|
|
4
|
-
import { Database } from "bun:sqlite";
|
|
5
|
-
|
|
6
|
-
interface FnOptions {
|
|
7
|
-
file: string;
|
|
8
|
-
sql: string;
|
|
9
|
-
rowFilter?: (row: any) => boolean;
|
|
10
|
-
rowTransform: (row: any) => CookieRow;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async function checkFileExistence(file: string): Promise<void> {
|
|
14
|
-
if (!file || !fs.existsSync(file))
|
|
15
|
-
throw new Error(`File ${file} does not exist`);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function transformRows(
|
|
19
|
-
rows: any[],
|
|
20
|
-
rowFilter: (row: any) => boolean,
|
|
21
|
-
rowTransform: (row: any) => CookieRow,
|
|
22
|
-
file: string,
|
|
23
|
-
): Promise<CookieRow[]> {
|
|
24
|
-
const filteredRows = rows.filter(rowFilter);
|
|
25
|
-
const transformedRows = filteredRows.map((row) =>
|
|
26
|
-
merge({ meta: { file } }, rowTransform(row)),
|
|
27
|
-
);
|
|
28
|
-
return transformedRows;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function querySqliteThenTransform({
|
|
32
|
-
file,
|
|
33
|
-
sql,
|
|
34
|
-
rowFilter = () => true,
|
|
35
|
-
rowTransform,
|
|
36
|
-
}: FnOptions): Promise<CookieRow[]> {
|
|
37
|
-
await checkFileExistence(file);
|
|
38
|
-
const db = new Database(file);
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
const rows: any[] = db.query(sql).all();
|
|
42
|
-
if (!rows || rows.length === 0) return [];
|
|
43
|
-
|
|
44
|
-
return await transformRows(rows, rowFilter, rowTransform, file);
|
|
45
|
-
} catch (err: any) {
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { join } from "path";
|
|
2
|
-
import { HOME } from "../../global";
|
|
3
|
-
|
|
4
|
-
if (HOME === undefined) {
|
|
5
|
-
throw new Error("HOME environment variable is not defined");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const chromeApplicationSupport: string = join(
|
|
9
|
-
HOME,
|
|
10
|
-
"Library",
|
|
11
|
-
"Application Support",
|
|
12
|
-
"Google",
|
|
13
|
-
"Chrome",
|
|
14
|
-
);
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import CookieQueryStrategy from "../CookieQueryStrategy";
|
|
2
|
-
import CookieRow, { isCookieRow } from "../../CookieRow";
|
|
3
|
-
import ExportedCookie from "../../ExportedCookie";
|
|
4
|
-
import { chromeApplicationSupport } from "./ChromeApplicationSupport";
|
|
5
|
-
import { decrypt } from "./decrypt";
|
|
6
|
-
import { env } from "../../global";
|
|
7
|
-
import { findAllFiles } from "../../findAllFiles";
|
|
8
|
-
import { getChromePassword } from "./getChromePassword";
|
|
9
|
-
import { isExportedCookie } from "../../ExportedCookie";
|
|
10
|
-
import { merge } from "lodash";
|
|
11
|
-
import { parsedArgs } from "../../argv";
|
|
12
|
-
import { flatMapAsync } from "../../util/flatMapAsync";
|
|
13
|
-
import { getEncryptedChromeCookie } from "../getEncryptedChromeCookie";
|
|
14
|
-
import logger from "../../logger";
|
|
15
|
-
|
|
16
|
-
export const consola = logger.withTag("ChromeCookieQueryStrategy");
|
|
17
|
-
|
|
18
|
-
export default class ChromeCookieQueryStrategy implements CookieQueryStrategy {
|
|
19
|
-
browserName: string = "Chrome";
|
|
20
|
-
|
|
21
|
-
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
22
|
-
this.ensurePlatformIsMacOS();
|
|
23
|
-
if (env.FIREFOX_ONLY) {
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
return this.getChromeCookies({
|
|
27
|
-
requireJwt: false,
|
|
28
|
-
name,
|
|
29
|
-
domain,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private ensurePlatformIsMacOS(): void {
|
|
34
|
-
if (process.platform !== "darwin") {
|
|
35
|
-
throw new Error("This only works on macOS");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private async getChromeCookies({
|
|
40
|
-
name,
|
|
41
|
-
domain = "%",
|
|
42
|
-
requireJwt = false,
|
|
43
|
-
}: {
|
|
44
|
-
name: string;
|
|
45
|
-
domain: string;
|
|
46
|
-
requireJwt: boolean | undefined;
|
|
47
|
-
}): Promise<ExportedCookie[]> {
|
|
48
|
-
const encryptedDataItems: CookieRow[] = await this.getEncryptedCookies(
|
|
49
|
-
name,
|
|
50
|
-
domain,
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const password: string = await getChromePassword();
|
|
54
|
-
const decryptedCookies: ExportedCookie[] = await this.decryptCookies(
|
|
55
|
-
encryptedDataItems,
|
|
56
|
-
password,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
return decryptedCookies;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private async getEncryptedCookies(
|
|
63
|
-
name: string,
|
|
64
|
-
domain: string,
|
|
65
|
-
): Promise<CookieRow[]> {
|
|
66
|
-
try {
|
|
67
|
-
const files: string[] = findAllFiles({
|
|
68
|
-
path: chromeApplicationSupport,
|
|
69
|
-
name: "Cookies",
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const results: CookieRow[] = await flatMapAsync(files, async (file) => {
|
|
73
|
-
return await this.getCookiesFromFile(name, domain, file);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return results.filter(isCookieRow);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
consola.warn("Error finding encrypted cookies", error);
|
|
79
|
-
return [];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private async getCookiesFromFile(
|
|
84
|
-
name: string,
|
|
85
|
-
domain: string,
|
|
86
|
-
file: string,
|
|
87
|
-
): Promise<CookieRow[]> {
|
|
88
|
-
try {
|
|
89
|
-
return await getEncryptedChromeCookie({
|
|
90
|
-
name: name,
|
|
91
|
-
domain: domain,
|
|
92
|
-
file: file,
|
|
93
|
-
});
|
|
94
|
-
} catch (e) {
|
|
95
|
-
consola.warn("Error getting encrypted cookie from file", e);
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private async decryptCookies(
|
|
101
|
-
encryptedDataItems: CookieRow[],
|
|
102
|
-
password: string,
|
|
103
|
-
): Promise<ExportedCookie[]> {
|
|
104
|
-
const decrypted: Promise<ExportedCookie | null>[] = encryptedDataItems
|
|
105
|
-
.filter(({ value }) => value != null && value.length > 0)
|
|
106
|
-
.map(async (cookieRow: CookieRow) => {
|
|
107
|
-
const encryptedValue: Uint8Array | Buffer = cookieRow.value;
|
|
108
|
-
const decryptedValue = await this.decryptValue(
|
|
109
|
-
password,
|
|
110
|
-
encryptedValue,
|
|
111
|
-
);
|
|
112
|
-
return this.createExportedCookie(cookieRow, decryptedValue);
|
|
113
|
-
});
|
|
114
|
-
return (await Promise.all(decrypted)).filter(isExportedCookie);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private async decryptValue(
|
|
118
|
-
password: string,
|
|
119
|
-
encryptedValue: Uint8Array | Buffer,
|
|
120
|
-
): Promise<string> {
|
|
121
|
-
let decrypted: string | null;
|
|
122
|
-
try {
|
|
123
|
-
const bufferValue = Buffer.isBuffer(encryptedValue)
|
|
124
|
-
? encryptedValue
|
|
125
|
-
: Buffer.from(encryptedValue);
|
|
126
|
-
decrypted = await decrypt(password, bufferValue);
|
|
127
|
-
} catch (e) {
|
|
128
|
-
consola.warn("Error decrypting cookie", e);
|
|
129
|
-
decrypted = null;
|
|
130
|
-
}
|
|
131
|
-
return decrypted ?? encryptedValue.toString("utf-8");
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private createExportedCookie(
|
|
135
|
-
cookieRow: CookieRow,
|
|
136
|
-
decryptedValue: string,
|
|
137
|
-
): ExportedCookie {
|
|
138
|
-
const meta = {};
|
|
139
|
-
merge(meta, cookieRow.meta ?? {});
|
|
140
|
-
const exportedCookie: ExportedCookie = {
|
|
141
|
-
domain: cookieRow.domain,
|
|
142
|
-
name: cookieRow.name,
|
|
143
|
-
value: decryptedValue,
|
|
144
|
-
meta: meta,
|
|
145
|
-
};
|
|
146
|
-
const expiry = cookieRow.expiry;
|
|
147
|
-
const mergeExpiry =
|
|
148
|
-
expiry != null && expiry > 0
|
|
149
|
-
? {
|
|
150
|
-
expiry: new Date(expiry),
|
|
151
|
-
}
|
|
152
|
-
: {
|
|
153
|
-
expiry: "Infinity",
|
|
154
|
-
};
|
|
155
|
-
merge(exportedCookie, mergeExpiry);
|
|
156
|
-
return exportedCookie;
|
|
157
|
-
}
|
|
158
|
-
}
|