fix(inspector): preserve lossy Node discovery locations (#542)
Keep explicitly selected Node Inspector targets observable when discovery cannot verify their file location. Resolve literal POSIX discovery paths without URI decoding, and retain lossy Windows or underscore paths as unresolved metadata. Validate scriptParsed file URLs independently. Preserve unknown target identity through runtime reconciliation, regenerate contracts, and verify real CLI/MCP behavior on Linux and Windows. Closes #530 Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
import {
|
||||
browserOriginSchema,
|
||||
sanitizeBrowserUrl,
|
||||
} from "../domain/browserObservation.js";
|
||||
import type { JavaScriptRuntimeLocation } from "../domain/javascriptRuntimeObservation.js";
|
||||
import type {
|
||||
JavaScriptRuntimeLocation,
|
||||
JavaScriptRuntimeTargetLocation,
|
||||
} from "../domain/javascriptRuntimeObservation.js";
|
||||
import { authorizedElectronFile } from "./ElectronFileScope.js";
|
||||
|
||||
export type RuntimeLocationDecision =
|
||||
@@ -48,7 +53,43 @@ export const authorizeRuntimeLocation = async (
|
||||
};
|
||||
};
|
||||
|
||||
/** Authorize a target whose Node Inspector URL omits its main entry path. */
|
||||
/** Interpret Node's lossy discovery metadata separately from scriptParsed URLs. */
|
||||
export const authorizeRuntimeTargetLocation = async (
|
||||
value: string,
|
||||
): Promise<RuntimeLocationDecision> => authorizeRuntimeLocation(value);
|
||||
context: { readonly type: string; readonly product: string },
|
||||
): Promise<
|
||||
| {
|
||||
readonly allowed: true;
|
||||
readonly location: JavaScriptRuntimeTargetLocation;
|
||||
}
|
||||
| { readonly allowed: false; readonly reason: "unsupported_location" }
|
||||
> => {
|
||||
if (
|
||||
context.type !== "node" ||
|
||||
!/^node\.js\/v/iu.test(context.product) ||
|
||||
!value.startsWith("file://")
|
||||
)
|
||||
return authorizeRuntimeLocation(value);
|
||||
const reportedPath = value.slice("file://".length);
|
||||
if (!reportedPath.startsWith("/") && !/^[a-z]:[/\\_]/iu.test(reportedPath))
|
||||
return authorizeRuntimeLocation(value);
|
||||
|
||||
// Node concatenates the pathname, then replaces quotes and backslashes with
|
||||
// underscores. A remaining underscore cannot prove which pathname was used.
|
||||
if (process.platform !== "win32" && !/[_"\\]/u.test(reportedPath)) {
|
||||
if (reportedPath.startsWith("/")) {
|
||||
const decision = await authorizeRuntimeLocation(
|
||||
pathToFileURL(reportedPath).href,
|
||||
);
|
||||
if (decision.allowed) return decision;
|
||||
}
|
||||
}
|
||||
return {
|
||||
allowed: true,
|
||||
location: {
|
||||
kind: "unresolved",
|
||||
reported_url: value,
|
||||
reason: "unverifiable-file-location",
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user