fix(javascript): recover Electron API identity through aliases
Reuse semantic module provenance for aliases and keep property path segments intact through Electron matching. Reject shadowed names and nested or dotted lookalikes. Reassigned and conditionally initialized module origins remain ambiguous, with their source origins retained. Add a compiled CLI/stdio MCP regression for windows, preloads, context bridges, IPC operations, pairing, and source ranges. Validate 771 JavaScript domain tests, seven composition tests, the public acceptance workflow, build, and check:fast. Fixes #1656
This commit is contained in:
@@ -7,7 +7,7 @@ import type {
|
||||
} from "./electronStaticAnalysisTypes.js";
|
||||
import {
|
||||
boundedExpression,
|
||||
electronCalleeName,
|
||||
electronCalleePath,
|
||||
electronStaticValue,
|
||||
handlerKind,
|
||||
} from "./electronStaticAnalysisValues.js";
|
||||
@@ -37,8 +37,7 @@ const inspectIpcCall = (
|
||||
node: t.CallExpression,
|
||||
context: JavaScriptFindingContext,
|
||||
): void => {
|
||||
const name = electronCalleeName(node.callee, context);
|
||||
const descriptor = ipcDescriptor(name);
|
||||
const descriptor = ipcDescriptor(electronCalleePath(node.callee, context));
|
||||
if (descriptor === undefined) return;
|
||||
const channelNode = argumentNode(node.arguments[0]);
|
||||
const channelValue = electronStaticValue(context.source, channelNode);
|
||||
@@ -176,9 +175,13 @@ const addValidation = (
|
||||
});
|
||||
};
|
||||
|
||||
const ipcDescriptor = (name: string): ElectronIpcDescriptor | undefined => {
|
||||
const renderer = suffixOperation(name, "ipcRenderer");
|
||||
if (renderer !== undefined) {
|
||||
const ipcDescriptor = (
|
||||
path: readonly string[] | undefined,
|
||||
): ElectronIpcDescriptor | undefined => {
|
||||
if (path?.length !== 2) return undefined;
|
||||
const [object, operation] = path;
|
||||
if (object === "ipcRenderer" && operation !== undefined) {
|
||||
const renderer = operation;
|
||||
switch (renderer) {
|
||||
case "send":
|
||||
return { side: "renderer", operation: "send", mode: "send" };
|
||||
@@ -204,7 +207,7 @@ const ipcDescriptor = (name: string): ElectronIpcDescriptor | undefined => {
|
||||
return { side: "renderer", operation: "once", mode: "listen" };
|
||||
}
|
||||
}
|
||||
const main = suffixOperation(name, "ipcMain");
|
||||
const main = object === "ipcMain" ? operation : undefined;
|
||||
switch (main) {
|
||||
case "on":
|
||||
return { side: "main", operation: "on", mode: "listen" };
|
||||
@@ -219,19 +222,6 @@ const ipcDescriptor = (name: string): ElectronIpcDescriptor | undefined => {
|
||||
}
|
||||
};
|
||||
|
||||
const suffixOperation = (
|
||||
name: string,
|
||||
object: "ipcRenderer" | "ipcMain",
|
||||
): string | undefined => {
|
||||
const marker = `${object}.`;
|
||||
const index = name.lastIndexOf(marker);
|
||||
if (index < 0) return undefined;
|
||||
const prefix = name.slice(0, index);
|
||||
if (prefix !== "" && !prefix.endsWith(".")) return undefined;
|
||||
const operation = name.slice(index + marker.length);
|
||||
return operation.includes(".") ? undefined : operation;
|
||||
};
|
||||
|
||||
const senderSubject = (
|
||||
node: t.Node,
|
||||
): ElectronSenderValidationFinding["subject"] | undefined => {
|
||||
|
||||
Reference in New Issue
Block a user