Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(javascript): retain guards without duplicating observed IPC calls

morluto42b0ed126df7
diff --git a/src/domain/javascript/electronWrappedCallPaths.test.ts b/src/domain/javascript/electronWrappedCallPaths.test.ts
index 13c0c21af..a0f19a160 100644
--- a/src/domain/javascript/electronWrappedCallPaths.test.ts
+++ b/src/domain/javascript/electronWrappedCallPaths.test.ts
@@ -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");
diff --git a/src/domain/javascript/electronWrappedCallPaths.ts b/src/domain/javascript/electronWrappedCallPaths.ts
index b74747273..554fe24a7 100644
--- a/src/domain/javascript/electronWrappedCallPaths.ts
+++ b/src/domain/javascript/electronWrappedCallPaths.ts
@@ -240,16 +240,21 @@ export const collectElectronWrappedCallPaths = (
handler_location: null,
...findingContext,
};
+ // A fully observed transmission stays one source fact when its callback is
+ // traced. Registrations retain invocation identity because handlers compete.
const duplicate = accumulator.ipc.some(
({ value }) =>
value.side === finding.side &&
value.operation === finding.operation &&
value.channel === channel &&
JSON.stringify(value.location) === JSON.stringify(location) &&
- JSON.stringify(value.invocation_location) ===
- JSON.stringify(invocationLocation),
+ ((value.resolution_basis === undefined &&
+ (value.mode === "send" || value.mode === "invoke")) ||
+ JSON.stringify(value.invocation_location) ===
+ JSON.stringify(invocationLocation)),
);
- const findingGuarded = hasConditions(first) || guardedDispatch;
+ const findingGuarded =
+ context.conditions.length > 0 || hasConditions(first) || guardedDispatch;
if (!duplicate && !findingGuarded) {
accumulator.ipc.push({
offset: node.start ?? -1,
@@ -315,7 +320,11 @@ export const collectElectronWrappedCallPaths = (
// cannot be recorded as an unconditional exposure fact.
const guardedKey = hasConditions(key);
const guardedObject = hasConditions(object);
- const guarded = guardedKey || guardedObject || guardedDispatch;
+ const guarded =
+ context.conditions.length > 0 ||
+ guardedKey ||
+ guardedObject ||
+ guardedDispatch;
if (guarded) accumulator.unknownFindings += 1;
// Existing entries are raw syntax observations and remain valid even when
// symbolic substitution can only describe this call under a predicate.
diff --git a/tests/boundary/cli/electronWrappedCallPaths.test.ts b/tests/boundary/cli/electronWrappedCallPaths.test.ts
index 9eb45649c..af61f0885 100644
--- a/tests/boundary/cli/electronWrappedCallPaths.test.ts
+++ b/tests/boundary/cli/electronWrappedCallPaths.test.ts
@@ -139,6 +139,7 @@ for (const surface of ["CLI", "stdio MCP"] as const) {
choose:choose(),
ambiguous:()=>e.ipcRenderer.send("test:ambiguous"),
competing:()=>e.ipcRenderer.send("test:competing"),
+ conditional:()=>e.ipcRenderer.send("test:conditional"),
fallback:()=>e.ipcRenderer.send("test:fallback"),
});`,
"main.js": `const e=require("electron");
@@ -148,6 +149,7 @@ for (const surface of ["CLI", "stdio MCP"] as const) {
register("test:ambiguous",flag?copy:cut);
register("test:competing",copy);
register("test:competing",flag?copy:unknownHandler);
+ if(flag) register("test:conditional",copy);
register("test:fallback",event=>{false ?? event.sender.copy()});`,
});
const { graph } = await analyzeJavaScriptDirectory(surface, cli, root);