@shriyanss/js-recon 1.2.2-alpha.1 → 1.2.2-alpha.11
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/CHANGELOG.md +128 -0
- package/build/endpoints/index.js +1 -0
- package/build/endpoints/index.js.map +1 -1
- package/build/globalConfig.js +2 -1
- package/build/globalConfig.js.map +1 -1
- package/build/index.js +7 -1
- package/build/index.js.map +1 -1
- package/build/lazyLoad/angular/angular_getFromMainJs.js +55 -0
- package/build/lazyLoad/angular/angular_getFromMainJs.js.map +1 -0
- package/build/lazyLoad/angular/angular_getFromPageSource.js +43 -0
- package/build/lazyLoad/angular/angular_getFromPageSource.js.map +1 -0
- package/build/lazyLoad/downloadFilesUtil.js +7 -4
- package/build/lazyLoad/downloadFilesUtil.js.map +1 -1
- package/build/lazyLoad/index.js +201 -12
- package/build/lazyLoad/index.js.map +1 -1
- package/build/lazyLoad/next_js/next_GetJSScript.js +2 -3
- package/build/lazyLoad/next_js/next_GetJSScript.js.map +1 -1
- package/build/lazyLoad/next_js/next_GetLazyResourcesBuildManifestJs.js +32 -23
- package/build/lazyLoad/next_js/next_GetLazyResourcesBuildManifestJs.js.map +1 -1
- package/build/lazyLoad/next_js/next_GetLazyResourcesWebpackJs.js +1 -1
- package/build/lazyLoad/next_js/next_GetLazyResourcesWebpackJs.js.map +1 -1
- package/build/lazyLoad/next_js/next_SubsequentRequests.js +54 -4
- package/build/lazyLoad/next_js/next_SubsequentRequests.js.map +1 -1
- package/build/lazyLoad/next_js/next_bruteForceJsFiles.js +32 -0
- package/build/lazyLoad/next_js/next_bruteForceJsFiles.js.map +1 -0
- package/build/lazyLoad/next_js/next_buildId.js +9 -1
- package/build/lazyLoad/next_js/next_buildId.js.map +1 -1
- package/build/lazyLoad/next_js/next_parseLayoutJs.js +116 -0
- package/build/lazyLoad/next_js/next_parseLayoutJs.js.map +1 -0
- package/build/lazyLoad/next_js/next_promiseResolve.js +76 -0
- package/build/lazyLoad/next_js/next_promiseResolve.js.map +1 -0
- package/build/lazyLoad/next_js/next_scriptTagsSubsequentRequests.js +34 -0
- package/build/lazyLoad/next_js/next_scriptTagsSubsequentRequests.js.map +1 -0
- package/build/lazyLoad/sourcemap.js +188 -0
- package/build/lazyLoad/sourcemap.js.map +1 -0
- package/build/lazyLoad/techDetect/index.js +117 -3
- package/build/lazyLoad/techDetect/index.js.map +1 -1
- package/build/lazyLoad/vue/vue_RuntimeJs.js +101 -0
- package/build/lazyLoad/vue/vue_RuntimeJs.js.map +1 -0
- package/build/lazyLoad/vue/vue_SingleJsFileOnHome.js +98 -0
- package/build/lazyLoad/vue/vue_SingleJsFileOnHome.js.map +1 -0
- package/build/lazyLoad/vue/vue_jsImports.js +70 -0
- package/build/lazyLoad/vue/vue_jsImports.js.map +1 -0
- package/build/lazyLoad/vue/vue_reconstructSourceMaps.js +56 -0
- package/build/lazyLoad/vue/vue_reconstructSourceMaps.js.map +1 -0
- package/build/lazyLoad/vue/vue_severalJsFilesHome.js +52 -0
- package/build/lazyLoad/vue/vue_severalJsFilesHome.js.map +1 -0
- package/build/lazyLoad/vue/vue_sourcemapExtract.js +166 -0
- package/build/lazyLoad/vue/vue_sourcemapExtract.js.map +1 -0
- package/build/map/next_js/getAxiosInstances.js +1 -1
- package/build/map/next_js/getAxiosInstances.js.map +1 -1
- package/build/map/next_js/getWebpackConnections.js +1 -1
- package/build/map/next_js/getWebpackConnections.js.map +1 -1
- package/build/map/next_js/interactive_helpers/commandHelpers.js +1 -1
- package/build/map/next_js/interactive_helpers/commandHelpers.js.map +1 -1
- package/build/map/next_js/resolveAxios.js +61 -17
- package/build/map/next_js/resolveAxios.js.map +1 -1
- package/build/map/next_js/resolveAxiosHelpers/directCallsWithoutAssignment.js +48 -0
- package/build/map/next_js/resolveAxiosHelpers/directCallsWithoutAssignment.js.map +1 -0
- package/build/map/next_js/resolveAxiosHelpers/findAxiosClients.js +8 -8
- package/build/map/next_js/resolveAxiosHelpers/findAxiosClients.js.map +1 -1
- package/build/map/next_js/resolveAxiosHelpers/findCrossChunkParams.js +302 -0
- package/build/map/next_js/resolveAxiosHelpers/findCrossChunkParams.js.map +1 -0
- package/build/map/next_js/resolveAxiosHelpers/handleAxiosCreate.js +48 -8
- package/build/map/next_js/resolveAxiosHelpers/handleAxiosCreate.js.map +1 -1
- package/build/map/next_js/resolveAxiosHelpers/handleZDotCreate.js +261 -0
- package/build/map/next_js/resolveAxiosHelpers/handleZDotCreate.js.map +1 -0
- package/build/map/next_js/resolveAxiosHelpers/processAxiosCall.js +10 -3
- package/build/map/next_js/resolveAxiosHelpers/processAxiosCall.js.map +1 -1
- package/build/map/next_js/resolveAxiosHelpers/processDirectAxiosCall.js +113 -0
- package/build/map/next_js/resolveAxiosHelpers/processDirectAxiosCall.js.map +1 -0
- package/build/map/next_js/resolveAxiosHelpers/processExportedEndpoints.js +274 -0
- package/build/map/next_js/resolveAxiosHelpers/processExportedEndpoints.js.map +1 -0
- package/build/map/next_js/resolveAxiosHelpers/traceAxiosInstanceExports.js +506 -0
- package/build/map/next_js/resolveAxiosHelpers/traceAxiosInstanceExports.js.map +1 -0
- package/build/map/next_js/resolveFetch.js +243 -4
- package/build/map/next_js/resolveFetch.js.map +1 -1
- package/build/map/next_js/utils.js +867 -11
- package/build/map/next_js/utils.js.map +1 -1
- package/build/run/index.js +12 -7
- package/build/run/index.js.map +1 -1
- package/build/utility/globals.js.map +1 -1
- package/build/utility/makeReq.js +159 -91
- package/build/utility/makeReq.js.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import makeRequest from "../../utility/makeReq.js";
|
|
11
|
+
import chalk from "chalk";
|
|
12
|
+
const next_bruteForceJsFiles = (urls) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
// just append .map to all of them and bruteforce for 200
|
|
14
|
+
console.log(chalk.cyan("[i] Bruteforcing .map files"));
|
|
15
|
+
const mapFiles = urls.map((url) => url + ".map");
|
|
16
|
+
let foundSourceMaps = [];
|
|
17
|
+
for (const mapFile of mapFiles) {
|
|
18
|
+
const req = yield makeRequest(mapFile);
|
|
19
|
+
const status = req.status;
|
|
20
|
+
if (status === 200) {
|
|
21
|
+
foundSourceMaps.push(mapFile);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (foundSourceMaps.length === 0) {
|
|
25
|
+
console.log(chalk.red("[!] No source maps found"));
|
|
26
|
+
return foundSourceMaps;
|
|
27
|
+
}
|
|
28
|
+
console.log(chalk.green(`[✓] Found ${foundSourceMaps.length} source maps`));
|
|
29
|
+
return foundSourceMaps;
|
|
30
|
+
});
|
|
31
|
+
export default next_bruteForceJsFiles;
|
|
32
|
+
//# sourceMappingURL=next_bruteForceJsFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next_bruteForceJsFiles.js","sourceRoot":"","sources":["../../../src/lazyLoad/next_js/next_bruteForceJsFiles.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,sBAAsB,GAAG,CAAO,IAAc,EAAE,EAAE;IACpD,yDAAyD;IACzD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC;IAEjD,IAAI,eAAe,GAAa,EAAE,CAAC;IAEnC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;QAEvC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QAE1B,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACjB,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACL,CAAC;IAED,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC,CAAC;QACnD,OAAO,eAAe,CAAC;IAC3B,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,eAAe,CAAC,MAAM,cAAc,CAAC,CAAC,CAAC;IAC5E,OAAO,eAAe,CAAC;AAC3B,CAAC,CAAA,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
|
@@ -10,9 +10,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { readdir, readFile } from "fs/promises";
|
|
11
11
|
import path from "path";
|
|
12
12
|
import * as next_globals from "./next_globals.js";
|
|
13
|
+
import chalk from "chalk";
|
|
13
14
|
export const next_buildId_RSC = (rsc_directory) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
15
|
const traverseDirectory = (directory) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
|
|
16
|
+
let dirents;
|
|
17
|
+
try {
|
|
18
|
+
dirents = yield readdir(directory, { withFileTypes: true });
|
|
19
|
+
}
|
|
20
|
+
catch (_a) {
|
|
21
|
+
console.log(chalk.red(`[!] Can't read subsequent requests directory. Skipping build ID extraction using this method...`));
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
16
24
|
for (const dirent of dirents) {
|
|
17
25
|
const fullPath = path.join(directory, dirent.name);
|
|
18
26
|
if (dirent.isDirectory()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next_buildId.js","sourceRoot":"","sources":["../../../src/lazyLoad/next_js/next_buildId.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAO,aAAqB,EAA0B,EAAE;IACpF,MAAM,iBAAiB,GAAG,CAAO,SAAiB,EAAoB,EAAE;QACpE,
|
|
1
|
+
{"version":3,"file":"next_buildId.js","sourceRoot":"","sources":["../../../src/lazyLoad/next_js/next_buildId.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAElD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAO,aAAqB,EAA0B,EAAE;IACpF,MAAM,iBAAiB,GAAG,CAAO,SAAiB,EAAoB,EAAE;QACpE,IAAI,OAAyB,CAAC;QAC9B,IAAI,CAAC;YACD,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,CAAC;QAAC,WAAM,CAAC;YACL,OAAO,CAAC,GAAG,CACP,KAAK,CAAC,GAAG,CACL,iGAAiG,CACpG,CACJ,CAAC;YACF,OAAO,KAAK,CAAC;QACjB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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import makeRequest from "../../utility/makeReq.js";
|
|
11
|
+
import parser from "@babel/parser";
|
|
12
|
+
import _traverse from "@babel/traverse";
|
|
13
|
+
import chalk from "chalk";
|
|
14
|
+
import next_getJSScript from "./next_GetJSScript.js";
|
|
15
|
+
const traverse = _traverse.default;
|
|
16
|
+
const next_parseLayoutJs = (baseUrl, urls) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
console.log(chalk.cyan("[i] Parsing layout.js files"));
|
|
18
|
+
let toReturn = [];
|
|
19
|
+
// iterate through all the URLs and find the layout.*.js files
|
|
20
|
+
for (const url of urls) {
|
|
21
|
+
if (url.includes("layout-")) {
|
|
22
|
+
// request the content, and parse it
|
|
23
|
+
const req = yield makeRequest(url);
|
|
24
|
+
const jsContent = yield req.text();
|
|
25
|
+
let ast;
|
|
26
|
+
try {
|
|
27
|
+
ast = parser.parse(jsContent, {
|
|
28
|
+
sourceType: "unambiguous",
|
|
29
|
+
plugins: ["jsx", "typescript"],
|
|
30
|
+
errorRecovery: true,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (_a) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
let hrefFinds = [];
|
|
37
|
+
const resolveString = (node) => {
|
|
38
|
+
if (!node)
|
|
39
|
+
return "";
|
|
40
|
+
if (node.type === "StringLiteral") {
|
|
41
|
+
return node.value;
|
|
42
|
+
}
|
|
43
|
+
if (node.type === "TemplateLiteral") {
|
|
44
|
+
let str = "";
|
|
45
|
+
node.quasis.forEach((q, i) => {
|
|
46
|
+
str += q.value.raw;
|
|
47
|
+
if (i < node.expressions.length) {
|
|
48
|
+
str += resolveString(node.expressions[i]);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return str;
|
|
52
|
+
}
|
|
53
|
+
if (node.type === "BinaryExpression" && node.operator === "+") {
|
|
54
|
+
return resolveString(node.left) + resolveString(node.right);
|
|
55
|
+
}
|
|
56
|
+
if (node.type === "CallExpression") {
|
|
57
|
+
if (node.callee.type === "MemberExpression" && node.callee.property.name === "concat") {
|
|
58
|
+
let base = resolveString(node.callee.object);
|
|
59
|
+
node.arguments.forEach((arg) => {
|
|
60
|
+
base += resolveString(arg);
|
|
61
|
+
});
|
|
62
|
+
return base;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// If it's an identifier or unknown, we return a placeholder to represent dynamic content
|
|
66
|
+
return Math.random()
|
|
67
|
+
.toString(36)
|
|
68
|
+
.substring(2, 2 + 64);
|
|
69
|
+
};
|
|
70
|
+
// traverse through the AST, and find all the hrefs
|
|
71
|
+
traverse(ast, {
|
|
72
|
+
ObjectProperty(path) {
|
|
73
|
+
const { key, value } = path.node;
|
|
74
|
+
// Check if key is 'href' (identifier) or "href" (literal)
|
|
75
|
+
if (key.name === "href") {
|
|
76
|
+
const resolved = resolveString(value);
|
|
77
|
+
if (resolved) {
|
|
78
|
+
hrefFinds.push(resolved);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
// iterate through each href, and try to send the server a request
|
|
84
|
+
// if the response code is 200, run all the methods again on that
|
|
85
|
+
for (const href of hrefFinds) {
|
|
86
|
+
const newUrl = new URL(href, new URL(url).origin).href;
|
|
87
|
+
if (newUrl.startsWith("mailto:"))
|
|
88
|
+
continue;
|
|
89
|
+
// also, check if the origin is same or not
|
|
90
|
+
if (new URL(baseUrl).origin !== new URL(newUrl).origin)
|
|
91
|
+
continue;
|
|
92
|
+
let req;
|
|
93
|
+
try {
|
|
94
|
+
req = yield makeRequest(newUrl);
|
|
95
|
+
}
|
|
96
|
+
catch (_b) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (req.status === 200) {
|
|
100
|
+
console.log(chalk.green("[✓] Found new client side URL: ", newUrl));
|
|
101
|
+
// parse the HTML for script tags
|
|
102
|
+
const jsFiles = yield next_getJSScript(newUrl);
|
|
103
|
+
toReturn.push(...jsFiles);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// dedupe
|
|
109
|
+
toReturn = [...new Set(toReturn)];
|
|
110
|
+
if (toReturn.length !== 0) {
|
|
111
|
+
console.log(chalk.green(`[✓] Found ${toReturn.length} JS files from the layout.js files`));
|
|
112
|
+
}
|
|
113
|
+
return toReturn;
|
|
114
|
+
});
|
|
115
|
+
export default next_parseLayoutJs;
|
|
116
|
+
//# sourceMappingURL=next_parseLayoutJs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next_parseLayoutJs.js","sourceRoot":"","sources":["../../../src/lazyLoad/next_js/next_parseLayoutJs.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AAErD,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;AAEnC,MAAM,kBAAkB,GAAG,CAAO,OAAe,EAAE,IAAc,EAAE,EAAE;IACjE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,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AAO,QAAQ,CAAC;AACpB,CAAC,CAAA,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import chalk from "chalk";
|
|
11
|
+
import makeRequest from "../../utility/makeReq.js";
|
|
12
|
+
import parser from "@babel/parser";
|
|
13
|
+
import _traverse from "@babel/traverse";
|
|
14
|
+
const traverse = _traverse.default;
|
|
15
|
+
const next_promiseResolve = (urls) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
console.log(chalk.cyan("[i] Check for Promise.all pattern"));
|
|
17
|
+
let toReturn = [];
|
|
18
|
+
// go through all the URLs, and find which which one has `static/chunks/` in it
|
|
19
|
+
let jsDirBase = null;
|
|
20
|
+
for (const url of urls) {
|
|
21
|
+
if (url.includes("static/chunks/")) {
|
|
22
|
+
jsDirBase = url.split("/").slice(0, -1).join("/");
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const url of urls) {
|
|
27
|
+
// get the contents of the file
|
|
28
|
+
const req = yield makeRequest(url);
|
|
29
|
+
if (!req || !req.ok)
|
|
30
|
+
continue;
|
|
31
|
+
const data = yield req.text();
|
|
32
|
+
try {
|
|
33
|
+
const ast = parser.parse(data, {
|
|
34
|
+
sourceType: "unambiguous",
|
|
35
|
+
plugins: ["jsx", "typescript"],
|
|
36
|
+
errorRecovery: true,
|
|
37
|
+
});
|
|
38
|
+
let matches = [];
|
|
39
|
+
traverse(ast, {
|
|
40
|
+
CallExpression(path) {
|
|
41
|
+
const { node } = path;
|
|
42
|
+
// Check for Promise.all([...].map(...)) pattern
|
|
43
|
+
if (node.callee.type === "MemberExpression" &&
|
|
44
|
+
node.callee.object.type === "Identifier" &&
|
|
45
|
+
node.callee.object.name === "Promise" &&
|
|
46
|
+
node.callee.property.type === "Identifier" &&
|
|
47
|
+
node.callee.property.name === "all") {
|
|
48
|
+
const arg = node.arguments[0];
|
|
49
|
+
if (arg &&
|
|
50
|
+
arg.type === "CallExpression" &&
|
|
51
|
+
arg.callee.type === "MemberExpression" &&
|
|
52
|
+
arg.callee.property.type === "Identifier" &&
|
|
53
|
+
arg.callee.property.name === "map" &&
|
|
54
|
+
arg.callee.object.type === "ArrayExpression") {
|
|
55
|
+
arg.callee.object.elements.forEach((element) => {
|
|
56
|
+
if (element && element.type === "StringLiteral") {
|
|
57
|
+
matches.push(element.value);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
// now that we got the match, we can use it to build the final URL
|
|
65
|
+
for (const match of matches) {
|
|
66
|
+
const jsFileName = match.replace("static/chunks/", "/");
|
|
67
|
+
const jsFileUrl = jsDirBase + jsFileName;
|
|
68
|
+
toReturn.push(jsFileUrl);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (e) { }
|
|
72
|
+
}
|
|
73
|
+
return toReturn;
|
|
74
|
+
});
|
|
75
|
+
export default next_promiseResolve;
|
|
76
|
+
//# sourceMappingURL=next_promiseResolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next_promiseResolve.js","sourceRoot":"","sources":["../../../src/lazyLoad/next_js/next_promiseResolve.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,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S,GAAG,SAAS,GAAG,UAAU,CAAC;gBAEzC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IAClB,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAA,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import chalk from "chalk";
|
|
11
|
+
import next_getJSScript from "./next_GetJSScript.js";
|
|
12
|
+
import fs from "fs";
|
|
13
|
+
const next_scriptTagsSubsequentRequests = (url, endpointsFile) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
console.log(chalk.cyan("[i] Getting JS files from subsequent requests (script tags)"));
|
|
15
|
+
let endpoints = JSON.parse(fs.readFileSync(endpointsFile, "utf8")).paths;
|
|
16
|
+
endpoints.push("/");
|
|
17
|
+
let jsUrls = [];
|
|
18
|
+
// TODO: when you get a page, you can also search for anchor tags. If you find any additional
|
|
19
|
+
// pages, you can go through them as well. this will give you a lot more JS files
|
|
20
|
+
// go through all endpoints, and parse them
|
|
21
|
+
for (const endpoint of endpoints) {
|
|
22
|
+
const reqUrl = new URL(endpoint, url).href;
|
|
23
|
+
const jsUrlsFromEndpoint = yield next_getJSScript(reqUrl);
|
|
24
|
+
jsUrls.push(...jsUrlsFromEndpoint);
|
|
25
|
+
}
|
|
26
|
+
// dedupe
|
|
27
|
+
jsUrls = [...new Set(jsUrls)];
|
|
28
|
+
if (jsUrls.length !== 0) {
|
|
29
|
+
console.log(chalk.green(`[✓] Found ${jsUrls.length} JS files from subsequent requests (script tags)`));
|
|
30
|
+
}
|
|
31
|
+
return jsUrls;
|
|
32
|
+
});
|
|
33
|
+
export default next_scriptTagsSubsequentRequests;
|
|
34
|
+
//# sourceMappingURL=next_scriptTagsSubsequentRequests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next_scriptTagsSubsequentRequests.js","sourceRoot":"","sources":["../../../src/lazyLoad/next_js/next_scriptTagsSubsequentRequests.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,iCAAiC,GAAG,CAAO,GAAW,EAAE,aAAqB,EAAE,EAAE;IACnF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAC,CAAC;IAEvF,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IAEzE,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEpB,IAAI,MAAM,GAAa,EAAE,CAAC;IAE1B,6FAA6F;IAC7F,iFAAiF;IAEjF,2CAA2C;IAC3C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;QAC3C,MAAM,kBAAkB,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAC1D,MAAM,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,CAAC;IACvC,CAAC;IAED,SAAS;IACT,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,MAAM,CAAC,MAAM,kDAAkD,CAAC,CAAC,CAAC;IAC3G,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC,CAAA,CAAC;AAEF,eAAe,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source Map Decoder
|
|
3
|
+
*
|
|
4
|
+
* Extracts original source code from minified JavaScript using source maps.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Extract original source files from a source map.
|
|
8
|
+
*
|
|
9
|
+
* @param sourceMap - The source map object or JSON string
|
|
10
|
+
* @param options - Optional configuration
|
|
11
|
+
* @returns Object containing extracted files and count of missing sources
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { extractSources } from './sourcemap';
|
|
16
|
+
*
|
|
17
|
+
* const sourceMap = {
|
|
18
|
+
* version: 3,
|
|
19
|
+
* sources: ['src/app.ts', 'src/utils.ts'],
|
|
20
|
+
* sourcesContent: ['const x = 1;', 'export const y = 2;'],
|
|
21
|
+
* mappings: '...',
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* const result = extractSources(sourceMap);
|
|
25
|
+
* for (const file of result.files) {
|
|
26
|
+
* console.log(`${file.path}:\n${file.content}`);
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function extractSources(sourceMap, options = {}) {
|
|
31
|
+
var _a;
|
|
32
|
+
const { cleanPaths = true, normalizePaths = true } = options;
|
|
33
|
+
// Parse JSON string if needed
|
|
34
|
+
const map = typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap;
|
|
35
|
+
// Validate source map
|
|
36
|
+
if (!map.sources || !Array.isArray(map.sources)) {
|
|
37
|
+
throw new Error('Invalid source map: missing "sources" array');
|
|
38
|
+
}
|
|
39
|
+
const files = [];
|
|
40
|
+
let missingCount = 0;
|
|
41
|
+
for (let i = 0; i < map.sources.length; i++) {
|
|
42
|
+
let path = map.sources[i];
|
|
43
|
+
const content = (_a = map.sourcesContent) === null || _a === void 0 ? void 0 : _a[i];
|
|
44
|
+
// Skip if no content
|
|
45
|
+
if (content === null || content === undefined) {
|
|
46
|
+
missingCount++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
// Clean up path
|
|
50
|
+
if (cleanPaths) {
|
|
51
|
+
path = cleanPath(path);
|
|
52
|
+
}
|
|
53
|
+
if (normalizePaths) {
|
|
54
|
+
path = normalizePath(path);
|
|
55
|
+
}
|
|
56
|
+
// Apply sourceRoot if present
|
|
57
|
+
if (map.sourceRoot && !path.startsWith("/")) {
|
|
58
|
+
const root = cleanPaths ? cleanPath(map.sourceRoot) : map.sourceRoot;
|
|
59
|
+
path = joinPaths(root, path);
|
|
60
|
+
}
|
|
61
|
+
files.push({ path, content });
|
|
62
|
+
}
|
|
63
|
+
return { files, missingCount };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Extract a single source file by index or path.
|
|
67
|
+
*
|
|
68
|
+
* @param sourceMap - The source map object or JSON string
|
|
69
|
+
* @param indexOrPath - Index into sources array or file path to find
|
|
70
|
+
* @returns The source file or null if not found
|
|
71
|
+
*/
|
|
72
|
+
export function extractSource(sourceMap, indexOrPath) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const map = typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap;
|
|
75
|
+
if (typeof indexOrPath === "number") {
|
|
76
|
+
const index = indexOrPath;
|
|
77
|
+
if (index < 0 || index >= map.sources.length) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const content = (_a = map.sourcesContent) === null || _a === void 0 ? void 0 : _a[index];
|
|
81
|
+
if (content === null || content === undefined) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return { path: map.sources[index], content };
|
|
85
|
+
}
|
|
86
|
+
// Search by path
|
|
87
|
+
const searchPath = indexOrPath;
|
|
88
|
+
const index = map.sources.findIndex((s) => s === searchPath ||
|
|
89
|
+
s.endsWith(searchPath) ||
|
|
90
|
+
cleanPath(s) === searchPath ||
|
|
91
|
+
cleanPath(s).endsWith(searchPath));
|
|
92
|
+
if (index === -1) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const content = (_b = map.sourcesContent) === null || _b === void 0 ? void 0 : _b[index];
|
|
96
|
+
if (content === null || content === undefined) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return { path: map.sources[index], content };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get list of source file paths without extracting content.
|
|
103
|
+
*
|
|
104
|
+
* @param sourceMap - The source map object or JSON string
|
|
105
|
+
* @returns Array of source file paths
|
|
106
|
+
*/
|
|
107
|
+
export function listSources(sourceMap) {
|
|
108
|
+
const map = typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap;
|
|
109
|
+
return map.sources || [];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if a source map has embedded source content.
|
|
113
|
+
*
|
|
114
|
+
* @param sourceMap - The source map object or JSON string
|
|
115
|
+
* @returns true if sourcesContent is present and has at least one non-null entry
|
|
116
|
+
*/
|
|
117
|
+
export function hasSourceContent(sourceMap) {
|
|
118
|
+
const map = typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap;
|
|
119
|
+
return Array.isArray(map.sourcesContent) && map.sourcesContent.some((c) => c !== null && c !== undefined);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Remove protocol prefixes like webpack://, file://, etc.
|
|
123
|
+
*/
|
|
124
|
+
function cleanPath(path) {
|
|
125
|
+
return path
|
|
126
|
+
.replace(/^webpack:\/\/[^/]*\//, "") // webpack://package-name/
|
|
127
|
+
.replace(/^webpack:\/\//, "") // webpack://
|
|
128
|
+
.replace(/^file:\/\//, "") // file://
|
|
129
|
+
.replace(/^\.\//, ""); // ./
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Normalize path by resolving ../ sequences.
|
|
133
|
+
* SECURITY: Removes all leading ../ to prevent directory traversal attacks.
|
|
134
|
+
* Files will always stay within the intended output directory.
|
|
135
|
+
*/
|
|
136
|
+
function normalizePath(path) {
|
|
137
|
+
const parts = path.split("/");
|
|
138
|
+
const result = [];
|
|
139
|
+
for (const part of parts) {
|
|
140
|
+
if (part === "..") {
|
|
141
|
+
// Only allow going back within the path we've built
|
|
142
|
+
// Never allow escaping (result would go negative)
|
|
143
|
+
if (result.length > 0) {
|
|
144
|
+
result.pop();
|
|
145
|
+
}
|
|
146
|
+
// If result is empty, just skip the '..' entirely (prevents traversal)
|
|
147
|
+
}
|
|
148
|
+
else if (part !== "." && part !== "") {
|
|
149
|
+
result.push(part);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return result.join("/") || ".";
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Sanitize a path to ensure it cannot escape the output directory.
|
|
156
|
+
* This is a safety check that should be used before writing files.
|
|
157
|
+
*
|
|
158
|
+
* @param basePath - The base output directory (absolute path)
|
|
159
|
+
* @param filePath - The file path to sanitize
|
|
160
|
+
* @returns Safe path that is guaranteed to be under basePath
|
|
161
|
+
*/
|
|
162
|
+
export function safePath(basePath, filePath) {
|
|
163
|
+
// Clean and normalize the file path
|
|
164
|
+
let cleaned = cleanPath(filePath);
|
|
165
|
+
cleaned = normalizePath(cleaned);
|
|
166
|
+
// Remove any remaining ../ sequences (belt and suspenders)
|
|
167
|
+
cleaned = cleaned.replace(/\.\.\//g, "").replace(/^\.\.$/, "");
|
|
168
|
+
// Remove leading slashes to prevent absolute path injection
|
|
169
|
+
cleaned = cleaned.replace(/^\/+/, "");
|
|
170
|
+
// Join with base path
|
|
171
|
+
const joined = basePath.endsWith("/") ? basePath + cleaned : basePath + "/" + cleaned;
|
|
172
|
+
return joined;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Join two path segments
|
|
176
|
+
*/
|
|
177
|
+
function joinPaths(base, path) {
|
|
178
|
+
if (!base)
|
|
179
|
+
return path;
|
|
180
|
+
if (!path)
|
|
181
|
+
return base;
|
|
182
|
+
const baseClean = base.endsWith("/") ? base.slice(0, -1) : base;
|
|
183
|
+
const pathClean = path.startsWith("/") ? path.slice(1) : path;
|
|
184
|
+
return `${baseClean}/${pathClean}`;
|
|
185
|
+
}
|
|
186
|
+
// Default export for convenience
|
|
187
|
+
export default { extractSources, extractSource, listSources, hasSourceContent };
|
|
188
|
+
//# sourceMappingURL=sourcemap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourcemap.js","sourceRoot":"","sources":["../../src/lazyLoad/sourcemap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA6CH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,cAAc,CAAC,SAA6B,EAAE,UAA0B,EAAE;;IACtF,MAAM,EAAE,UAAU,GAAG,IAAI,EAAE,cAAc,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAE7D,8BAA8B;IAC9B,MAAM,GAAG,GAAc,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEzF,sBAAsB;IACtB,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACnE,CA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