@inspecto-dev/plugin 0.3.3 → 0.3.5
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.cjs +180 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +179 -44
- package/dist/index.js.map +1 -1
- package/dist/legacy/rspack/index.cjs +109 -19
- package/dist/legacy/rspack/index.cjs.map +1 -1
- package/dist/legacy/rspack/index.js +109 -19
- package/dist/legacy/rspack/index.js.map +1 -1
- package/dist/legacy/rspack/loader.cjs +49 -4
- package/dist/legacy/rspack/loader.cjs.map +1 -1
- package/dist/legacy/rspack/loader.js +49 -4
- package/dist/legacy/rspack/loader.js.map +1 -1
- package/dist/legacy/webpack4/index.cjs +121 -21
- package/dist/legacy/webpack4/index.cjs.map +1 -1
- package/dist/legacy/webpack4/index.d.cts +2 -0
- package/dist/legacy/webpack4/index.d.ts +2 -0
- package/dist/legacy/webpack4/index.js +121 -21
- package/dist/legacy/webpack4/index.js.map +1 -1
- package/dist/legacy/webpack4/loader.cjs +49 -4
- package/dist/legacy/webpack4/loader.cjs.map +1 -1
- package/dist/legacy/webpack4/loader.js +49 -4
- package/dist/legacy/webpack4/loader.js.map +1 -1
- package/dist/rollup.cjs +180 -45
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.js +179 -44
- package/dist/rollup.js.map +1 -1
- package/dist/rspack.cjs +180 -45
- package/dist/rspack.cjs.map +1 -1
- package/dist/rspack.js +179 -44
- package/dist/rspack.js.map +1 -1
- package/dist/vite.cjs +180 -45
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +179 -44
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +180 -45
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.js +179 -44
- package/dist/webpack.js.map +1 -1
- package/package.json +6 -6
|
@@ -36,13 +36,13 @@ __export(rspack_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(rspack_exports);
|
|
38
38
|
|
|
39
|
-
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.
|
|
39
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.9_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/cjs_shims.js
|
|
40
40
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
41
41
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
42
42
|
|
|
43
43
|
// src/server/index.ts
|
|
44
44
|
var import_node_http = __toESM(require("http"), 1);
|
|
45
|
-
var
|
|
45
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
46
46
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
47
47
|
var import_node_os2 = __toESM(require("os"), 1);
|
|
48
48
|
var import_node_crypto2 = __toESM(require("crypto"), 1);
|
|
@@ -562,6 +562,7 @@ function hasOverrides(overrides) {
|
|
|
562
562
|
|
|
563
563
|
// src/server/path-guards.ts
|
|
564
564
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
565
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
565
566
|
function isWindowsAbsolutePath(file) {
|
|
566
567
|
return /^[a-zA-Z]:[\\/]/.test(file) || /^\\\\[^\\]+\\[^\\]+/.test(file);
|
|
567
568
|
}
|
|
@@ -572,9 +573,94 @@ function resolveWorkspacePath(file, cwd) {
|
|
|
572
573
|
return import_node_path2.default.isAbsolute(file) ? import_node_path2.default.resolve(file) : import_node_path2.default.resolve(cwd, file);
|
|
573
574
|
}
|
|
574
575
|
function assertPathWithinProject(file, projectRoot) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
576
|
+
let realFile = file;
|
|
577
|
+
let realProjectRoot = projectRoot;
|
|
578
|
+
try {
|
|
579
|
+
if (import_node_fs2.default.existsSync(file)) {
|
|
580
|
+
realFile = import_node_fs2.default.realpathSync(file);
|
|
581
|
+
}
|
|
582
|
+
} catch {
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
if (import_node_fs2.default.existsSync(projectRoot)) {
|
|
586
|
+
realProjectRoot = import_node_fs2.default.realpathSync(projectRoot);
|
|
587
|
+
}
|
|
588
|
+
} catch {
|
|
589
|
+
}
|
|
590
|
+
if (isWithinPath(file, projectRoot) || isWithinPath(realFile, realProjectRoot)) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
throw new Error(
|
|
594
|
+
`Access denied: File ${normalizeForComparison(realFile)} is outside of project workspace ${normalizeForComparison(realProjectRoot)}`
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
function tryReadPackageName(packageRoot) {
|
|
598
|
+
try {
|
|
599
|
+
const packageJsonPath = import_node_path2.default.join(packageRoot, "package.json");
|
|
600
|
+
if (!import_node_fs2.default.existsSync(packageJsonPath)) return void 0;
|
|
601
|
+
const packageJson = JSON.parse(import_node_fs2.default.readFileSync(packageJsonPath, "utf8"));
|
|
602
|
+
return typeof packageJson.name === "string" ? packageJson.name : void 0;
|
|
603
|
+
} catch {
|
|
604
|
+
return void 0;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function findNearestPackageRoot(file) {
|
|
608
|
+
let current = import_node_path2.default.dirname(file);
|
|
609
|
+
while (true) {
|
|
610
|
+
if (import_node_fs2.default.existsSync(import_node_path2.default.join(current, "package.json"))) {
|
|
611
|
+
return current;
|
|
612
|
+
}
|
|
613
|
+
const parent = import_node_path2.default.dirname(current);
|
|
614
|
+
if (parent === current) {
|
|
615
|
+
return void 0;
|
|
616
|
+
}
|
|
617
|
+
current = parent;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
function normalizeForComparison(file) {
|
|
621
|
+
return isWindowsAbsolutePath(file) ? import_node_path2.default.win32.normalize(file) : import_node_path2.default.normalize(file);
|
|
622
|
+
}
|
|
623
|
+
function pathSeparatorFor(file) {
|
|
624
|
+
return isWindowsAbsolutePath(file) ? import_node_path2.default.win32.sep : import_node_path2.default.sep;
|
|
625
|
+
}
|
|
626
|
+
function isWithinPath(file, root) {
|
|
627
|
+
const normalizedFile = normalizeForComparison(file);
|
|
628
|
+
const normalizedRoot = normalizeForComparison(root);
|
|
629
|
+
const separator = pathSeparatorFor(normalizedRoot);
|
|
630
|
+
const rootWithSep = normalizedRoot.endsWith(separator) ? normalizedRoot : normalizedRoot + separator;
|
|
631
|
+
return normalizedFile === normalizedRoot || normalizedFile.startsWith(rootWithSep);
|
|
632
|
+
}
|
|
633
|
+
function resolveLinkedDependencyEntry(projectRoot, packageName) {
|
|
634
|
+
const packageSegments = packageName.split("/");
|
|
635
|
+
const dependencyPath = import_node_path2.default.join(projectRoot, "node_modules", ...packageSegments);
|
|
636
|
+
if (!import_node_fs2.default.existsSync(dependencyPath)) return void 0;
|
|
637
|
+
try {
|
|
638
|
+
return import_node_fs2.default.realpathSync(dependencyPath);
|
|
639
|
+
} catch {
|
|
640
|
+
return dependencyPath;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
function isLinkedDependencyPath(file, projectRoot, packageName) {
|
|
644
|
+
const linkedDependencyRoot = resolveLinkedDependencyEntry(projectRoot, packageName);
|
|
645
|
+
if (!linkedDependencyRoot) return false;
|
|
646
|
+
return isWithinPath(file, linkedDependencyRoot);
|
|
647
|
+
}
|
|
648
|
+
function isLinkedDependencySourcePath(file, projectRoot) {
|
|
649
|
+
const packageRoot = findNearestPackageRoot(file);
|
|
650
|
+
if (!packageRoot) return false;
|
|
651
|
+
const packageName = tryReadPackageName(packageRoot);
|
|
652
|
+
if (!packageName) return false;
|
|
653
|
+
return isLinkedDependencyPath(file, projectRoot, packageName);
|
|
654
|
+
}
|
|
655
|
+
function assertPathWithinIdeOpenScope(file, projectRoot) {
|
|
656
|
+
try {
|
|
657
|
+
assertPathWithinProject(file, projectRoot);
|
|
658
|
+
return;
|
|
659
|
+
} catch {
|
|
660
|
+
if (isLinkedDependencySourcePath(file, projectRoot)) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
throw new Error(`Access denied: File is outside of project workspace`);
|
|
578
664
|
}
|
|
579
665
|
}
|
|
580
666
|
|
|
@@ -779,7 +865,7 @@ var VSCODE_FAMILY_SCHEMES = [
|
|
|
779
865
|
];
|
|
780
866
|
function handleOpenFileRequest(body, serverState3) {
|
|
781
867
|
const absolutePath = resolveWorkspacePath(body.file, serverState3.cwd);
|
|
782
|
-
|
|
868
|
+
assertPathWithinIdeOpenScope(absolutePath, serverState3.projectRoot);
|
|
783
869
|
const userConfig = loadUserConfigSync(false, serverState3.cwd, serverState3.configRoot);
|
|
784
870
|
const configuredIde = userConfig.ide;
|
|
785
871
|
const activeIde = serverState3.ideInfo?.ide;
|
|
@@ -837,7 +923,7 @@ function handleOpenFileRequest(body, serverState3) {
|
|
|
837
923
|
}
|
|
838
924
|
|
|
839
925
|
// src/server/project-root.ts
|
|
840
|
-
var
|
|
926
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
841
927
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
842
928
|
var import_node_child_process3 = require("child_process");
|
|
843
929
|
var serverLogger3 = createLogger("inspecto:server", { logLevel: getGlobalLogLevel() });
|
|
@@ -855,7 +941,7 @@ function resolveProjectRoot() {
|
|
|
855
941
|
let current = start;
|
|
856
942
|
while (!visited.has(current)) {
|
|
857
943
|
visited.add(current);
|
|
858
|
-
if (
|
|
944
|
+
if (import_node_fs3.default.existsSync(import_node_path3.default.join(current, ".inspecto"))) return current;
|
|
859
945
|
if (current === stop) break;
|
|
860
946
|
const parent = import_node_path3.default.dirname(current);
|
|
861
947
|
if (parent === current) break;
|
|
@@ -927,28 +1013,28 @@ async function startServer() {
|
|
|
927
1013
|
const portFile = import_node_path4.default.join(import_node_os2.default.tmpdir(), "inspecto.port.json");
|
|
928
1014
|
try {
|
|
929
1015
|
let portData = {};
|
|
930
|
-
if (
|
|
1016
|
+
if (import_node_fs4.default.existsSync(portFile)) {
|
|
931
1017
|
try {
|
|
932
|
-
portData = JSON.parse(
|
|
1018
|
+
portData = JSON.parse(import_node_fs4.default.readFileSync(portFile, "utf-8"));
|
|
933
1019
|
} catch (e) {
|
|
934
1020
|
}
|
|
935
1021
|
}
|
|
936
1022
|
const rootHash = import_node_crypto2.default.createHash("md5").update(serverState.projectRoot).digest("hex");
|
|
937
1023
|
portData[rootHash] = port;
|
|
938
|
-
|
|
1024
|
+
import_node_fs4.default.writeFileSync(portFile, JSON.stringify(portData, null, 2), "utf-8");
|
|
939
1025
|
} catch (e) {
|
|
940
1026
|
serverLogger4.warn("Failed to write port file:", e);
|
|
941
1027
|
}
|
|
942
1028
|
process.once("exit", () => {
|
|
943
1029
|
try {
|
|
944
|
-
if (
|
|
945
|
-
const portData = JSON.parse(
|
|
1030
|
+
if (import_node_fs4.default.existsSync(portFile)) {
|
|
1031
|
+
const portData = JSON.parse(import_node_fs4.default.readFileSync(portFile, "utf-8"));
|
|
946
1032
|
const rootHash = import_node_crypto2.default.createHash("md5").update(serverState.projectRoot).digest("hex");
|
|
947
1033
|
delete portData[rootHash];
|
|
948
1034
|
if (Object.keys(portData).length === 0) {
|
|
949
|
-
|
|
1035
|
+
import_node_fs4.default.unlinkSync(portFile);
|
|
950
1036
|
} else {
|
|
951
|
-
|
|
1037
|
+
import_node_fs4.default.writeFileSync(portFile, JSON.stringify(portData, null, 2), "utf-8");
|
|
952
1038
|
}
|
|
953
1039
|
}
|
|
954
1040
|
} catch {
|
|
@@ -1017,8 +1103,10 @@ async function handleRequest(url, req, res) {
|
|
|
1017
1103
|
}
|
|
1018
1104
|
try {
|
|
1019
1105
|
handleOpenFileRequest(body, serverState);
|
|
1020
|
-
} catch {
|
|
1021
|
-
serverLogger4.warn(
|
|
1106
|
+
} catch (err) {
|
|
1107
|
+
serverLogger4.warn(
|
|
1108
|
+
`Security: Blocked path traversal attempt in IDE_OPEN: ${body.file}. Reason: ${err.message}`
|
|
1109
|
+
);
|
|
1022
1110
|
res.writeHead(403, { "Content-Type": "application/json" });
|
|
1023
1111
|
res.end(JSON.stringify({ error: "Access denied: File is outside of project workspace" }));
|
|
1024
1112
|
return;
|
|
@@ -1036,8 +1124,10 @@ async function handleRequest(url, req, res) {
|
|
|
1036
1124
|
const absolutePath = resolveWorkspacePath(file, serverState.cwd);
|
|
1037
1125
|
try {
|
|
1038
1126
|
assertPathWithinProject(absolutePath, serverState.projectRoot);
|
|
1039
|
-
} catch {
|
|
1040
|
-
serverLogger4.warn(
|
|
1127
|
+
} catch (err) {
|
|
1128
|
+
serverLogger4.warn(
|
|
1129
|
+
`Security: Blocked path traversal attempt in PROJECT_SNIPPET: ${file}. Reason: ${err.message}`
|
|
1130
|
+
);
|
|
1041
1131
|
res.writeHead(403, { "Content-Type": "application/json" });
|
|
1042
1132
|
res.end(
|
|
1043
1133
|
JSON.stringify({
|