@mherod/get-cookie 2.0.0-beta.8 → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +6 -0
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.js +614 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +119 -52
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +35 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +16 -5
- package/src/CookieRow.ts +5 -5
- package/src/CookieSpec.ts +4 -0
- package/src/ExportedCookie.ts +1 -1
- package/src/{fetchResponse.ts → FetchResponse.ts} +3 -1
- package/src/IsCookieRow.ts +6 -2
- package/src/IsExportedCookie.ts +6 -2
- package/src/SpecialCases.ts +14 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +107 -93
- package/src/browsers/CompositeCookieQueryStrategy.ts +22 -4
- package/src/browsers/CookieQueryStrategy.ts +2 -2
- package/src/browsers/FirefoxCookieQueryStrategy.ts +52 -46
- package/src/browsers/SafariCookieQueryStrategy.ts +1 -1
- package/src/cli.ts +76 -40
- package/src/doSqliteQuery1.ts +20 -10
- package/src/fetchWithCookies.ts +27 -11
- package/src/findAllFiles.ts +11 -13
- package/src/getGroupedRenderedCookies.ts +7 -7
- package/src/global.ts +2 -1
- package/src/index.ts +16 -20
- package/src/isValidJwt.ts +11 -1
- package/src/queryCookies.ts +3 -6
- package/src/resultsRendered.ts +1 -1
- package/src/unpackHeaders.ts +13 -0
- package/src/utils.ts +1 -7
- package/dist/main.js +0 -534
- package/dist/main.js.map +0 -1
- package/dist/types/index.ts +0 -50
- package/dist/types/index.ts.map +0 -1
- package/src/CookieRequest.ts +0 -5
package/src/doSqliteQuery1.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as sqlite3 from "sqlite3";
|
|
3
|
-
import CookieRow from "./CookieRow";
|
|
3
|
+
import { CookieRow } from "./CookieRow";
|
|
4
|
+
import { merge } from "lodash";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
interface DoSqliteQuery1Params {
|
|
7
|
+
file: string;
|
|
8
|
+
sql: string;
|
|
9
|
+
rowTransform: (row: any) => CookieRow;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function doSqliteQuery1({
|
|
13
|
+
file,
|
|
14
|
+
sql,
|
|
15
|
+
rowTransform,
|
|
16
|
+
}: DoSqliteQuery1Params): Promise<CookieRow[]> {
|
|
17
|
+
if (!file || (file && !fs.existsSync(file))) {
|
|
7
18
|
throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
8
19
|
}
|
|
9
20
|
const db = new sqlite3.Database(file);
|
|
@@ -19,15 +30,14 @@ export async function doSqliteQuery1(file: string, sql: string): Promise<CookieR
|
|
|
19
30
|
return;
|
|
20
31
|
}
|
|
21
32
|
if (Array.isArray(rows1)) {
|
|
22
|
-
const cookieRows: CookieRow[] = rows1.map((row) => {
|
|
23
|
-
|
|
24
|
-
domain: row["host_key"],
|
|
25
|
-
name: row["name"],
|
|
26
|
-
value: row["encrypted_value"],
|
|
33
|
+
const cookieRows: CookieRow[] = rows1.map((row: any) => {
|
|
34
|
+
const newVar = {
|
|
27
35
|
meta: {
|
|
28
|
-
file: file
|
|
29
|
-
}
|
|
36
|
+
file: file,
|
|
37
|
+
},
|
|
30
38
|
};
|
|
39
|
+
const cookieRow: CookieRow = rowTransform(row);
|
|
40
|
+
return merge(newVar, cookieRow);
|
|
31
41
|
});
|
|
32
42
|
resolve(cookieRows);
|
|
33
43
|
return;
|
package/src/fetchWithCookies.ts
CHANGED
|
@@ -4,32 +4,48 @@ import { fetch } from "cross-fetch";
|
|
|
4
4
|
import { merge } from "lodash";
|
|
5
5
|
// noinspection SpellCheckingInspection
|
|
6
6
|
import destr from "destr";
|
|
7
|
-
import FetchResponse from "./
|
|
7
|
+
import FetchResponse from "./FetchResponse";
|
|
8
8
|
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
9
9
|
|
|
10
10
|
export async function fetchWithCookies(
|
|
11
11
|
url: RequestInfo | URL,
|
|
12
12
|
options: RequestInit | undefined = {}
|
|
13
13
|
): Promise<FetchResponse> {
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const defaultOptions: RequestInit = {
|
|
15
|
+
headers: {
|
|
16
|
+
"User-Agent":
|
|
17
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
|
|
18
|
+
},
|
|
19
|
+
redirect: "manual",
|
|
20
|
+
};
|
|
21
|
+
const url2: string = `${url}`;
|
|
22
|
+
const url1: URL = new URL(url2);
|
|
23
|
+
const domain = url1.hostname.replace(/^.*(\.\w+\.\w+)$/, (match, p1) => {
|
|
24
|
+
return `%${p1}`;
|
|
25
|
+
});
|
|
26
|
+
const cookies: string[] = await getGroupedRenderedCookies({
|
|
16
27
|
name: "%",
|
|
17
|
-
domain:
|
|
28
|
+
domain: domain,
|
|
18
29
|
});
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
const cookie = cookies.pop();
|
|
31
|
+
const newOptions1: RequestInit = merge(defaultOptions, options, {
|
|
21
32
|
headers: {
|
|
22
|
-
Cookie: cookie
|
|
23
|
-
}
|
|
33
|
+
Cookie: cookie,
|
|
34
|
+
},
|
|
24
35
|
});
|
|
25
36
|
try {
|
|
26
|
-
const res = await fetch(
|
|
37
|
+
const res: Response = await fetch(url2, newOptions1);
|
|
38
|
+
const newUrl = res.headers.get("location") as string;
|
|
39
|
+
if (res.redirected || (newUrl && newUrl !== url2)) {
|
|
40
|
+
return fetchWithCookies(newUrl, newOptions1);
|
|
41
|
+
}
|
|
27
42
|
const arrayBuffer1 = res.arrayBuffer();
|
|
28
43
|
const arrayBuffer = async () => arrayBuffer1;
|
|
29
44
|
const buffer = async () => arrayBuffer().then(Buffer.from);
|
|
30
45
|
const text = async () => buffer().then((buffer) => buffer.toString("utf8"));
|
|
31
46
|
const json = async () => text().then(destr);
|
|
32
|
-
const formData = async () =>
|
|
47
|
+
const formData = async () =>
|
|
48
|
+
text().then((text) => new URLSearchParams(text));
|
|
33
49
|
const source2 = {
|
|
34
50
|
status: res.status,
|
|
35
51
|
statusText: res.statusText,
|
|
@@ -38,7 +54,7 @@ export async function fetchWithCookies(
|
|
|
38
54
|
buffer,
|
|
39
55
|
text,
|
|
40
56
|
json,
|
|
41
|
-
formData
|
|
57
|
+
formData,
|
|
42
58
|
//
|
|
43
59
|
};
|
|
44
60
|
return merge({}, res, source2);
|
package/src/findAllFiles.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { env } from "./global";
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
|
|
4
|
-
export async function findAllFiles(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
): Promise<string[]> {
|
|
4
|
+
export async function findAllFiles({
|
|
5
|
+
path,
|
|
6
|
+
name,
|
|
7
|
+
maxDepth = 2,
|
|
8
|
+
}: //
|
|
9
|
+
{
|
|
10
|
+
path: string;
|
|
11
|
+
name: string;
|
|
12
|
+
maxDepth?: number;
|
|
13
|
+
}): Promise<string[]> {
|
|
16
14
|
const rootSegments = path.split("/").length;
|
|
17
15
|
|
|
18
16
|
if (env.VERBOSE) {
|
|
@@ -45,7 +43,7 @@ export async function findAllFiles(
|
|
|
45
43
|
const subFiles = await findAllFiles({
|
|
46
44
|
path: filePath,
|
|
47
45
|
name: name,
|
|
48
|
-
maxDepth: 2
|
|
46
|
+
maxDepth: 2,
|
|
49
47
|
});
|
|
50
48
|
files.push(...subFiles);
|
|
51
49
|
} catch (e) {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import ExportedCookie from "./ExportedCookie";
|
|
2
1
|
import { queryCookies } from "./queryCookies";
|
|
3
2
|
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
4
3
|
import { groupBy } from "lodash";
|
|
5
4
|
import { resultsRendered } from "./resultsRendered";
|
|
6
|
-
import
|
|
5
|
+
import { CookieSpec } from "./CookieSpec";
|
|
6
|
+
import { ExportedCookie } from "./ExportedCookie";
|
|
7
7
|
|
|
8
8
|
export async function getGroupedRenderedCookies(
|
|
9
9
|
//
|
|
10
10
|
{
|
|
11
11
|
name,
|
|
12
|
-
domain
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
domain,
|
|
13
|
+
}: //
|
|
14
|
+
CookieSpec
|
|
15
|
+
): //
|
|
16
|
+
Promise<string[]> {
|
|
17
17
|
const cookies: ExportedCookie[] = await queryCookies(
|
|
18
18
|
{ name, domain },
|
|
19
19
|
new CompositeCookieQueryStrategy()
|
package/src/global.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,10 +5,14 @@ import { queryCookies } from "./queryCookies";
|
|
|
5
5
|
import FirefoxCookieQueryStrategy from "./browsers/FirefoxCookieQueryStrategy";
|
|
6
6
|
import ChromeCookieQueryStrategy from "./browsers/ChromeCookieQueryStrategy";
|
|
7
7
|
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
8
|
+
import { CookieSpec } from "./CookieSpec";
|
|
9
|
+
import { ExportedCookie } from "./ExportedCookie";
|
|
8
10
|
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
9
11
|
import { fetchWithCookies } from "./fetchWithCookies";
|
|
10
12
|
|
|
11
|
-
export async function getCookie(
|
|
13
|
+
export async function getCookie(
|
|
14
|
+
params: CookieSpec
|
|
15
|
+
): Promise<ExportedCookie | undefined> {
|
|
12
16
|
const cookies = await queryCookies(
|
|
13
17
|
params,
|
|
14
18
|
new CompositeCookieQueryStrategy()
|
|
@@ -21,12 +25,9 @@ export async function getCookie(params: { name: string; domain: string; }) {
|
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @returns {Promise<*>}
|
|
28
|
-
*/
|
|
29
|
-
export async function getFirefoxCookie(params: { name: string; domain: string; }) {
|
|
28
|
+
export async function getFirefoxCookie(
|
|
29
|
+
params: CookieSpec
|
|
30
|
+
): Promise<ExportedCookie | undefined> {
|
|
30
31
|
const cookies = await queryCookies(
|
|
31
32
|
params,
|
|
32
33
|
new FirefoxCookieQueryStrategy()
|
|
@@ -39,12 +40,9 @@ export async function getFirefoxCookie(params: { name: string; domain: string; }
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* @returns {Promise<*>}
|
|
46
|
-
*/
|
|
47
|
-
export async function getChromeCookie(params: { name: string; domain: string; }) {
|
|
43
|
+
export async function getChromeCookie(
|
|
44
|
+
params: CookieSpec
|
|
45
|
+
): Promise<ExportedCookie | undefined> {
|
|
48
46
|
const cookies = await queryCookies(
|
|
49
47
|
params,
|
|
50
48
|
new ChromeCookieQueryStrategy()
|
|
@@ -57,10 +55,8 @@ export async function getChromeCookie(params: { name: string; domain: string; })
|
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
export
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
fetchWithCookies
|
|
66
|
-
}
|
|
58
|
+
export { getGroupedRenderedCookies, fetchWithCookies };
|
|
59
|
+
|
|
60
|
+
export * from "./CookieSpec";
|
|
61
|
+
export * from "./CookieRow";
|
|
62
|
+
export * from "./ExportedCookie";
|
package/src/isValidJwt.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import jsonwebtoken from "jsonwebtoken";
|
|
1
|
+
import jsonwebtoken, { JwtPayload } from "jsonwebtoken";
|
|
2
2
|
import { env } from "./global";
|
|
3
3
|
|
|
4
4
|
export default function isValidJwt(token: any) {
|
|
@@ -7,6 +7,16 @@ export default function isValidJwt(token: any) {
|
|
|
7
7
|
if (env.VERBOSE) {
|
|
8
8
|
console.log(result);
|
|
9
9
|
}
|
|
10
|
+
const payload: JwtPayload = result?.payload as JwtPayload;
|
|
11
|
+
if (payload) {
|
|
12
|
+
const exp = payload.exp;
|
|
13
|
+
if (exp) {
|
|
14
|
+
const now = new Date().getTime() / 1000;
|
|
15
|
+
if (now > exp) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
10
20
|
return true;
|
|
11
21
|
} catch (err) {
|
|
12
22
|
return false;
|
package/src/queryCookies.ts
CHANGED
|
@@ -3,14 +3,11 @@ import { uniqBy } from "lodash";
|
|
|
3
3
|
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
4
4
|
import CookieQueryStrategy from "./browsers/CookieQueryStrategy";
|
|
5
5
|
import isValidJwt from "./isValidJwt";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import { CookieSpec } from "./CookieSpec";
|
|
7
|
+
import { ExportedCookie } from "./ExportedCookie";
|
|
8
8
|
|
|
9
9
|
export async function queryCookies(
|
|
10
|
-
{
|
|
11
|
-
name,
|
|
12
|
-
domain
|
|
13
|
-
}: CookieRequest,
|
|
10
|
+
{ name, domain }: CookieSpec,
|
|
14
11
|
strategy: CookieQueryStrategy = new CompositeCookieQueryStrategy()
|
|
15
12
|
) {
|
|
16
13
|
const results: ExportedCookie[] = await strategy.queryCookies(name, domain);
|
package/src/resultsRendered.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function unpackHeaders(headerArgs: string[] | string) {
|
|
2
|
+
const headers: any = {};
|
|
3
|
+
if (Array.isArray(headerArgs)) {
|
|
4
|
+
for (const h of headerArgs) {
|
|
5
|
+
const [key, value] = h.split("=");
|
|
6
|
+
headers[key] = value;
|
|
7
|
+
}
|
|
8
|
+
} else {
|
|
9
|
+
const [key, value] = headerArgs.split("=");
|
|
10
|
+
headers[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return headers;
|
|
13
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// noinspection JSUnusedGlobalSymbols
|
|
2
2
|
|
|
3
|
-
import {exec, ExecException} from "child_process";
|
|
3
|
+
import { exec, ExecException } from "child_process";
|
|
4
4
|
|
|
5
5
|
export async function execSimple(command: string): Promise<string> {
|
|
6
6
|
return new Promise((resolve, reject) => {
|
|
@@ -24,11 +24,6 @@ export async function execSimple(command: string): Promise<string> {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @param result
|
|
30
|
-
* @returns {string|null}
|
|
31
|
-
*/
|
|
32
27
|
export function toStringOrNull(result: any) {
|
|
33
28
|
if (result == null) {
|
|
34
29
|
return null;
|
|
@@ -50,7 +45,6 @@ export function invalidString(input: any): boolean {
|
|
|
50
45
|
return typeof input !== "string" || input.length === 0;
|
|
51
46
|
}
|
|
52
47
|
|
|
53
|
-
|
|
54
48
|
export function validString(input: any): input is string {
|
|
55
49
|
return typeof input == "string" && input.length > 0;
|
|
56
50
|
}
|