fix(javascript): retain guards without duplicating observed IPC calls
Include enclosing control-flow predicates when deciding whether symbolic wrapper facts can be reported without guards. Preserve the guarded paths and unresolved coverage instead of inventing unconditional exposures or channel pairing candidates. Keep fully observed renderer transmissions singular when tracing an exposed callback. Distinct wrapper registrations still retain invocation identities. This fixes the Electron package baseline's doubled transmission count. Validation: check; 43 exact source and public CLI/MCP tests; existing artifact, extraction, Electron analysis and routed-analysis verifier against the built CLI. Installed-package platform coverage remains with CI.
This commit is contained in:
@@ -257,6 +257,21 @@ it("retains distinct wrapper invocation ranges for one IPC API source", () => {
|
||||
findings[1]?.invocation_location,
|
||||
);
|
||||
});
|
||||
it("keeps a directly observed renderer operation singular when tracing its exposed callback", () => {
|
||||
const result = analyzeJavaScriptStaticSource(`
|
||||
const {contextBridge,ipcRenderer}=require("electron");
|
||||
contextBridge.exposeInMainWorld("desktop",{ping:()=>ipcRenderer.invoke("ping")});
|
||||
`);
|
||||
expect(result.electron.ipc).toHaveLength(1);
|
||||
expect(result.electron.ipc[0]).toMatchObject({
|
||||
channel: "ping",
|
||||
operation: "invoke",
|
||||
});
|
||||
expect(result.electron.ipc[0]).not.toHaveProperty("resolution_basis");
|
||||
expect(result.electron.call_paths).toContainEqual(
|
||||
expect.objectContaining({ entry: "desktop.ping", channel: "ping" }),
|
||||
);
|
||||
});
|
||||
it("does not identify overwritten Electron namespaces or shadowed require", () => {
|
||||
for (const source of [
|
||||
`const e=require("electron");e.ipcMain={on(){}};e.ipcMain.on("bad",event=>event.sender.copy());`,
|
||||
@@ -327,6 +342,37 @@ it("keeps conditional IPC channels unknown instead of reporting them uncondition
|
||||
expect(result.electron.call_paths ?? []).toEqual([]);
|
||||
expect(result.parse_status).toBe("partial");
|
||||
});
|
||||
it("retains enclosing branch predicates without emitting unconditional wrapper findings", () => {
|
||||
const result = analyzeJavaScriptStaticSource(`
|
||||
const e=require("electron");
|
||||
function expose(key,api){e.contextBridge.exposeInMainWorld(key,api);}
|
||||
function register(channel,handler){e.ipcMain.on(channel,handler);}
|
||||
if(flag){
|
||||
expose("conditional",{copy:()=>navigator.clipboard.writeText("copy")});
|
||||
register("only:flag",event=>event.sender.copy());
|
||||
}
|
||||
`);
|
||||
expect(result.electron.context_bridge_apis).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
api_key: "conditional",
|
||||
resolution_basis: "wrapper-substitution",
|
||||
}),
|
||||
);
|
||||
expect(result.electron.ipc).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
channel: "only:flag",
|
||||
resolution_basis: "wrapper-substitution",
|
||||
}),
|
||||
);
|
||||
for (const entry of ["conditional.copy", "only:flag"])
|
||||
expect(result.electron.call_paths).toContainEqual(
|
||||
expect.objectContaining({
|
||||
entry,
|
||||
conditions: [expect.objectContaining({ expression: "flag" })],
|
||||
}),
|
||||
);
|
||||
expect(result.parse_status).toBe("partial");
|
||||
});
|
||||
it("preserves the raw bridge observation for a guarded object value", () => {
|
||||
const result = analyzeJavaScriptStaticSource(`
|
||||
const e=require("electron");
|
||||
|
||||
Reference in New Issue
Block a user