fix(javascript): trace nested Electron bridge members (#2745)
* fix(javascript): trace nested Electron bridge members * fix(javascript): preserve shallow Electron bridge paths * fix(javascript): preserve exact Electron bridge member paths * fix(javascript): preserve exact Electron bridge paths * fix(javascript): preserve bridge entry ownership * fix(javascript): preserve bridge path identity * fix(javascript): normalize typed feature seeds before tracing * test(javascript): normalize direct selector seed inputs * refactor(javascript): consume normalized feature seed defaults --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -44,6 +44,7 @@ const callLabel = (node: t.Node): string =>
|
||||
interface PathContext {
|
||||
readonly entryNode: t.Node;
|
||||
readonly entry: string;
|
||||
readonly entryPath?: readonly string[];
|
||||
readonly entryKind: ElectronCallPath["entry_kind"] | null;
|
||||
readonly channel: string | null;
|
||||
readonly steps: readonly ElectronCallPathStep[];
|
||||
@@ -122,6 +123,37 @@ export const collectElectronWrappedCallPaths = (
|
||||
};
|
||||
const hasConditions = (value: SymbolicValue): boolean =>
|
||||
symbolicVariants(value).some((variant) => variant.conditions?.length);
|
||||
function* bridgeMemberFunctions(
|
||||
value: SymbolicValue,
|
||||
segments: readonly string[] = [],
|
||||
active = new Set<SymbolicValue>(),
|
||||
): Generator<{
|
||||
readonly name: string;
|
||||
readonly path: readonly string[];
|
||||
readonly fn: SymbolicFunction;
|
||||
}> {
|
||||
if (active.has(value)) return;
|
||||
if (active.size >= 128) {
|
||||
accumulator.unknownFindings += 1;
|
||||
accumulator.electronCallPathLimitReached = true;
|
||||
return;
|
||||
}
|
||||
const nested = new Set(active);
|
||||
nested.add(value);
|
||||
for (const member of [...resolver.members(value)].sort()) {
|
||||
if (--remainingVisits < 0) return;
|
||||
const path = [...segments, member];
|
||||
const name = path.join(".");
|
||||
for (const variant of symbolicVariants(
|
||||
resolver.property(value, member),
|
||||
)) {
|
||||
if (variant.kind === "function") yield { name, path, fn: variant };
|
||||
else if (resolver.members(variant).length > 0)
|
||||
yield* bridgeMemberFunctions(variant, path, nested);
|
||||
}
|
||||
if (remainingVisits < 0) return;
|
||||
}
|
||||
}
|
||||
const isolatedBridgeCall = (
|
||||
node: t.CallExpression | t.OptionalCallExpression,
|
||||
):
|
||||
@@ -167,6 +199,10 @@ export const collectElectronWrappedCallPaths = (
|
||||
const path: ElectronCallPath = {
|
||||
entry_kind: context.entryKind,
|
||||
entry: context.entry,
|
||||
...(context.entryKind !== "bridge-member" ||
|
||||
context.entryPath === undefined
|
||||
? {}
|
||||
: { entry_path: context.entryPath }),
|
||||
channel,
|
||||
terminal,
|
||||
resolution: "candidate",
|
||||
@@ -405,27 +441,25 @@ export const collectElectronWrappedCallPaths = (
|
||||
offset: node.start ?? -1,
|
||||
value: finding,
|
||||
});
|
||||
for (const name of members) {
|
||||
const value = resolver.property(object, name);
|
||||
for (const fn of symbolicVariants(value))
|
||||
if (fn.kind === "function") {
|
||||
const memberContext = metadataContext(keyContext, fn);
|
||||
if (!memberContext) continue;
|
||||
functionBody(
|
||||
fn,
|
||||
fn.node.params.map(() => symbolicUnknown("public API argument")),
|
||||
{
|
||||
...memberContext,
|
||||
entryNode: node,
|
||||
entryKind: "bridge-member",
|
||||
entry: `${key.value}.${name}`,
|
||||
channel: null,
|
||||
steps: [step(node, "exposure", `${key.value}.${name}`)],
|
||||
active: new Set(),
|
||||
},
|
||||
node,
|
||||
);
|
||||
}
|
||||
for (const { name, path, fn } of bridgeMemberFunctions(object)) {
|
||||
const memberContext = metadataContext(keyContext, fn);
|
||||
if (!memberContext) continue;
|
||||
const entry = `${key.value}.${name}`;
|
||||
functionBody(
|
||||
fn,
|
||||
fn.node.params.map(() => symbolicUnknown("public API argument")),
|
||||
{
|
||||
...memberContext,
|
||||
entryNode: node,
|
||||
entryKind: "bridge-member",
|
||||
entry,
|
||||
entryPath: [key.value, ...path],
|
||||
channel: null,
|
||||
steps: [step(node, "exposure", entry)],
|
||||
active: new Set(),
|
||||
},
|
||||
node,
|
||||
);
|
||||
}
|
||||
};
|
||||
const call = (
|
||||
|
||||
Reference in New Issue
Block a user