fix(graphs): separate source identities from display representations
Validation: integrated changes passed formatting, typecheck, lint, resolved module-boundary verification and git diff --check. Tests and real-provider workflows were not run.
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
|||||||
} from "./JavaScriptArtifactGraphContext.js";
|
} from "./JavaScriptArtifactGraphContext.js";
|
||||||
import { astObservationEvidence } from "./JavaScriptArtifactGraphEvidence.js";
|
import { astObservationEvidence } from "./JavaScriptArtifactGraphEvidence.js";
|
||||||
import { compositeKey } from "../../domain/unicodeCodePointOrder.js";
|
import { compositeKey } from "../../domain/unicodeCodePointOrder.js";
|
||||||
|
import { javascriptDisplayText } from "../../domain/javascript/javascriptAstValues.js";
|
||||||
import {
|
import {
|
||||||
addElectronInferenceEdge,
|
addElectronInferenceEdge,
|
||||||
electronFindingSourceNode,
|
electronFindingSourceNode,
|
||||||
@@ -51,17 +52,27 @@ const addNativeBinding = (input: NativeBindingInput): void => {
|
|||||||
identity: electronObservationIdentity(
|
identity: electronObservationIdentity(
|
||||||
context,
|
context,
|
||||||
"javascript-requested-native-export",
|
"javascript-requested-native-export",
|
||||||
// Members are a variable-length source-derived list: compositeKey keeps
|
compositeKey([
|
||||||
// ["a\0b"] distinct from ["a", "b"] inside the digested identity.
|
file.path,
|
||||||
`${file.path}:${value.specifier}:${value.binding_kind}:${compositeKey(value.members)}:${electronRangeKey(value.location)}`,
|
value.specifier,
|
||||||
|
value.binding_kind,
|
||||||
|
value.members,
|
||||||
|
value.namespace_access ?? null,
|
||||||
|
value.dynamic_member_access ?? null,
|
||||||
|
electronRangeKey(value.location),
|
||||||
|
]),
|
||||||
),
|
),
|
||||||
observations: [
|
observations: [
|
||||||
{
|
{
|
||||||
label: value.members.join(", "),
|
label:
|
||||||
|
value.members.map(javascriptDisplayText).join(", ") ||
|
||||||
|
value.specifier,
|
||||||
properties: {
|
properties: {
|
||||||
specifier: value.specifier,
|
specifier: value.specifier,
|
||||||
binding_kind: value.binding_kind,
|
binding_kind: value.binding_kind,
|
||||||
requested_members: value.members,
|
requested_members: value.members,
|
||||||
|
namespace_access: value.namespace_access ?? null,
|
||||||
|
dynamic_member_access: value.dynamic_member_access ?? null,
|
||||||
resolved_path: resolved,
|
resolved_path: resolved,
|
||||||
native_export_verification: "not-performed",
|
native_export_verification: "not-performed",
|
||||||
},
|
},
|
||||||
@@ -90,6 +101,8 @@ const addNativeBinding = (input: NativeBindingInput): void => {
|
|||||||
specifier: value.specifier,
|
specifier: value.specifier,
|
||||||
binding_kind: value.binding_kind,
|
binding_kind: value.binding_kind,
|
||||||
requested_members: value.members,
|
requested_members: value.members,
|
||||||
|
namespace_access: value.namespace_access ?? null,
|
||||||
|
dynamic_member_access: value.dynamic_member_access ?? null,
|
||||||
},
|
},
|
||||||
limitations: [
|
limitations: [
|
||||||
"Requested JavaScript members are not verified native exports.",
|
"Requested JavaScript members are not verified native exports.",
|
||||||
@@ -107,6 +120,8 @@ const addNativeBinding = (input: NativeBindingInput): void => {
|
|||||||
properties: {
|
properties: {
|
||||||
resolved_path: resolved,
|
resolved_path: resolved,
|
||||||
requested_members: value.members,
|
requested_members: value.members,
|
||||||
|
namespace_access: value.namespace_access ?? null,
|
||||||
|
dynamic_member_access: value.dynamic_member_access ?? null,
|
||||||
verified: false,
|
verified: false,
|
||||||
},
|
},
|
||||||
confidence: "medium",
|
confidence: "medium",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { ApplicationNode } from "../../domain/javascript/javascriptApplicationGraphSchemas.js";
|
import type { ApplicationNode } from "../../domain/javascript/javascriptApplicationGraphSchemas.js";
|
||||||
import type { JavaScriptBundlerRegistration } from "../../domain/javascript/javascriptStaticAnalysisTypes.js";
|
import type { JavaScriptBundlerRegistration } from "../../domain/javascript/javascriptStaticAnalysisTypes.js";
|
||||||
import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js";
|
import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js";
|
||||||
|
import { compositeKey } from "../../domain/unicodeCodePointOrder.js";
|
||||||
import {
|
import {
|
||||||
addAstContainsEdge,
|
addAstContainsEdge,
|
||||||
artifactLocalIdentity,
|
artifactLocalIdentity,
|
||||||
@@ -80,7 +81,11 @@ const createBundlerChunkNode = (
|
|||||||
const chunkKey = `${registration.runtime}:${registration.chunk_keys.join(",")}`;
|
const chunkKey = `${registration.runtime}:${registration.chunk_keys.join(",")}`;
|
||||||
return context.accumulator.addNode({
|
return context.accumulator.addNode({
|
||||||
kind: "javascript-chunk",
|
kind: "javascript-chunk",
|
||||||
identity: artifactLocalIdentity(file.sha256, "bundler-chunk", chunkKey),
|
identity: artifactLocalIdentity(
|
||||||
|
file.sha256,
|
||||||
|
"bundler-chunk",
|
||||||
|
compositeKey([registration.runtime, registration.chunk_keys]),
|
||||||
|
),
|
||||||
observations: [
|
observations: [
|
||||||
{
|
{
|
||||||
label: chunkKey,
|
label: chunkKey,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { ArtifactInventorySnapshot } from "../../domain/artifactInventorySnapshot.js";
|
import type { ArtifactInventorySnapshot } from "../../domain/artifactInventorySnapshot.js";
|
||||||
|
import { compositeKey } from "../../domain/unicodeCodePointOrder.js";
|
||||||
import {
|
import {
|
||||||
completeApplicationCoverage,
|
completeApplicationCoverage,
|
||||||
partialApplicationCoverage,
|
partialApplicationCoverage,
|
||||||
@@ -330,7 +331,7 @@ export const chunkLookupKey = (
|
|||||||
path: string,
|
path: string,
|
||||||
runtime: string,
|
runtime: string,
|
||||||
chunkKey: string,
|
chunkKey: string,
|
||||||
): string => `${path}\0${runtime}\0${chunkKey}`;
|
): string => compositeKey([path, runtime, chunkKey]);
|
||||||
|
|
||||||
/** Resolve a relative static specifier without escaping the artifact root. */
|
/** Resolve a relative static specifier without escaping the artifact root. */
|
||||||
export const resolveArtifactPath = (
|
export const resolveArtifactPath = (
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { posix } from "node:path";
|
import { posix } from "node:path";
|
||||||
|
|
||||||
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
import {
|
||||||
|
compareUnicodeCodePoints,
|
||||||
|
compositeKey,
|
||||||
|
} from "../../domain/unicodeCodePointOrder.js";
|
||||||
import type { ApplicationNode } from "../../domain/javascript/javascriptApplicationGraphSchemas.js";
|
import type { ApplicationNode } from "../../domain/javascript/javascriptApplicationGraphSchemas.js";
|
||||||
import {
|
import {
|
||||||
completeApplicationCoverage,
|
completeApplicationCoverage,
|
||||||
@@ -177,7 +180,7 @@ const addExportRelationship = (
|
|||||||
identity: artifactLocalIdentity(
|
identity: artifactLocalIdentity(
|
||||||
file.sha256,
|
file.sha256,
|
||||||
"module-export",
|
"module-export",
|
||||||
`${file.container_sha256}:${file.path}:${link.exportedName}`,
|
compositeKey([file.container_sha256, file.path, link.exportedName]),
|
||||||
),
|
),
|
||||||
observations: [
|
observations: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
let omittedHierarchyReferences = 0;
|
let omittedHierarchyReferences = 0;
|
||||||
for (const document of input.documents.slice(0, input.limits.max_documents)) {
|
for (const document of input.documents.slice(0, input.limits.max_documents)) {
|
||||||
const parsed = parseInterfaceBuilderRecords(document.raw);
|
const parsed = parseInterfaceBuilderRecords(document.raw);
|
||||||
const prefix = `ib:${document.relativePath}:`;
|
const prefix = `ib:${JSON.stringify(document.relativePath)}:`;
|
||||||
|
const graphId = (kind: string, parts: readonly unknown[] = []): string =>
|
||||||
|
`${prefix}${kind}:${JSON.stringify(parts)}`;
|
||||||
const rootId = `${prefix}root`;
|
const rootId = `${prefix}root`;
|
||||||
const objectIds = new Set(parsed.objects.map(({ id }) => id));
|
const objectIds = new Set(parsed.objects.map(({ id }) => id));
|
||||||
const evidenceFor = (description: string) => [
|
const evidenceFor = (description: string) => [
|
||||||
@@ -104,7 +106,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
addNode(rootNode);
|
addNode(rootNode);
|
||||||
let documentObjectCount = 0;
|
let documentObjectCount = 0;
|
||||||
for (const object of parsed.objects.slice(0, input.limits.max_objects)) {
|
for (const object of parsed.objects.slice(0, input.limits.max_objects)) {
|
||||||
const id = `${prefix}object:${object.id}`;
|
const id = graphId("object", [object.id]);
|
||||||
const kind = object.kind === "other" ? "unknown" : object.kind;
|
const kind = object.kind === "other" ? "unknown" : object.kind;
|
||||||
if (
|
if (
|
||||||
!addNode({
|
!addNode({
|
||||||
@@ -129,7 +131,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
let documentOmittedConnections = 0;
|
let documentOmittedConnections = 0;
|
||||||
let documentOmittedHierarchyEdges = 0;
|
let documentOmittedHierarchyEdges = 0;
|
||||||
const objectNodeId = (objectId: string): string =>
|
const objectNodeId = (objectId: string): string =>
|
||||||
`${prefix}object:${objectId}`;
|
graphId("object", [objectId]);
|
||||||
const addEdge = (
|
const addEdge = (
|
||||||
edge: (typeof edges)[number],
|
edge: (typeof edges)[number],
|
||||||
isHierarchy: boolean,
|
isHierarchy: boolean,
|
||||||
@@ -238,7 +240,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
const known = objectIds.has(objectId);
|
const known = objectIds.has(objectId);
|
||||||
const childId = known
|
const childId = known
|
||||||
? objectNodeId(objectId)
|
? objectNodeId(objectId)
|
||||||
: `${prefix}unknown:${objectId}`;
|
: graphId("unknown", [objectId]);
|
||||||
if (
|
if (
|
||||||
!known &&
|
!known &&
|
||||||
!addNode({
|
!addNode({
|
||||||
@@ -252,7 +254,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
)
|
)
|
||||||
hierarchyTruncated = true;
|
hierarchyTruncated = true;
|
||||||
connect(
|
connect(
|
||||||
`${prefix}hierarchy:${parentId}:${childId}`,
|
graphId("hierarchy", [parentId, childId]),
|
||||||
parentId,
|
parentId,
|
||||||
childId,
|
childId,
|
||||||
"contains",
|
"contains",
|
||||||
@@ -281,11 +283,11 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
const destinationId =
|
const destinationId =
|
||||||
item.destination_id === null ? null : objectNodeId(item.destination_id);
|
item.destination_id === null ? null : objectNodeId(item.destination_id);
|
||||||
if (item.kind === "action") {
|
if (item.kind === "action") {
|
||||||
const actionId = `${prefix}action:${item.id}`;
|
const actionId = graphId("action", [item.id]);
|
||||||
const selectorId =
|
const selectorId =
|
||||||
item.label === null
|
item.label === null
|
||||||
? null
|
? null
|
||||||
: `${prefix}selector:${item.destination_id ?? "unknown"}:${item.label}`;
|
: graphId("selector", [item.destination_id, item.label]);
|
||||||
addNode({
|
addNode({
|
||||||
id: actionId,
|
id: actionId,
|
||||||
kind: "action",
|
kind: "action",
|
||||||
@@ -299,7 +301,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
evidence: evidenceFor(`action ${item.id}`),
|
evidence: evidenceFor(`action ${item.id}`),
|
||||||
});
|
});
|
||||||
connect(
|
connect(
|
||||||
`${actionId}:source`,
|
graphId("action-edge", [item.id, "source"]),
|
||||||
sourceId,
|
sourceId,
|
||||||
actionId,
|
actionId,
|
||||||
"target_action",
|
"target_action",
|
||||||
@@ -315,7 +317,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
evidence: evidenceFor(`selector ${item.label}`),
|
evidence: evidenceFor(`selector ${item.label}`),
|
||||||
});
|
});
|
||||||
connect(
|
connect(
|
||||||
`${actionId}:selector`,
|
graphId("action-edge", [item.id, "selector"]),
|
||||||
actionId,
|
actionId,
|
||||||
selectorId,
|
selectorId,
|
||||||
"target_action",
|
"target_action",
|
||||||
@@ -324,7 +326,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
}
|
}
|
||||||
if (destinationId === null || !nodes.has(destinationId))
|
if (destinationId === null || !nodes.has(destinationId))
|
||||||
connect(
|
connect(
|
||||||
`${actionId}:destination`,
|
graphId("action-edge", [item.id, "destination"]),
|
||||||
actionId,
|
actionId,
|
||||||
null,
|
null,
|
||||||
"target_action",
|
"target_action",
|
||||||
@@ -333,14 +335,14 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
);
|
);
|
||||||
else
|
else
|
||||||
connect(
|
connect(
|
||||||
`${actionId}:destination`,
|
graphId("action-edge", [item.id, "destination"]),
|
||||||
actionId,
|
actionId,
|
||||||
destinationId,
|
destinationId,
|
||||||
"target_action",
|
"target_action",
|
||||||
`action destination ${item.destination_id}`,
|
`action destination ${item.destination_id}`,
|
||||||
);
|
);
|
||||||
} else if (item.kind === "outlet") {
|
} else if (item.kind === "outlet") {
|
||||||
const outletId = `${prefix}outlet:${item.id}`;
|
const outletId = graphId("outlet", [item.id]);
|
||||||
addNode({
|
addNode({
|
||||||
id: outletId,
|
id: outletId,
|
||||||
kind: "outlet",
|
kind: "outlet",
|
||||||
@@ -350,7 +352,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
evidence: evidenceFor(`outlet ${item.id}`),
|
evidence: evidenceFor(`outlet ${item.id}`),
|
||||||
});
|
});
|
||||||
connect(
|
connect(
|
||||||
`${outletId}:source`,
|
graphId("outlet-edge", [item.id, "source"]),
|
||||||
sourceId,
|
sourceId,
|
||||||
outletId,
|
outletId,
|
||||||
"contains",
|
"contains",
|
||||||
@@ -358,7 +360,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
);
|
);
|
||||||
if (destinationId === null || !nodes.has(destinationId))
|
if (destinationId === null || !nodes.has(destinationId))
|
||||||
connect(
|
connect(
|
||||||
`${outletId}:destination`,
|
graphId("outlet-edge", [item.id, "destination"]),
|
||||||
outletId,
|
outletId,
|
||||||
null,
|
null,
|
||||||
"outlet_to",
|
"outlet_to",
|
||||||
@@ -367,7 +369,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
);
|
);
|
||||||
else
|
else
|
||||||
connect(
|
connect(
|
||||||
`${outletId}:destination`,
|
graphId("outlet-edge", [item.id, "destination"]),
|
||||||
outletId,
|
outletId,
|
||||||
destinationId,
|
destinationId,
|
||||||
"outlet_to",
|
"outlet_to",
|
||||||
@@ -376,7 +378,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
} else if (item.kind === "segue") {
|
} else if (item.kind === "segue") {
|
||||||
if (destinationId === null || !nodes.has(destinationId))
|
if (destinationId === null || !nodes.has(destinationId))
|
||||||
connect(
|
connect(
|
||||||
`${prefix}segue:${index}`,
|
graphId("segue", [index]),
|
||||||
sourceId,
|
sourceId,
|
||||||
null,
|
null,
|
||||||
"segue_to",
|
"segue_to",
|
||||||
@@ -385,7 +387,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
);
|
);
|
||||||
else
|
else
|
||||||
connect(
|
connect(
|
||||||
`${prefix}segue:${index}`,
|
graphId("segue", [index]),
|
||||||
sourceId,
|
sourceId,
|
||||||
destinationId,
|
destinationId,
|
||||||
"segue_to",
|
"segue_to",
|
||||||
@@ -393,7 +395,7 @@ export const buildInterfaceBuilderAnalysis = (input: {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
connect(
|
connect(
|
||||||
`${prefix}unknown-connection:${index}`,
|
graphId("unknown-connection", [index]),
|
||||||
sourceId,
|
sourceId,
|
||||||
null,
|
null,
|
||||||
"contains",
|
"contains",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from "./javascriptStaticAnalysisHelpers.js";
|
} from "./javascriptStaticAnalysisHelpers.js";
|
||||||
import {
|
import {
|
||||||
propertyName,
|
propertyName,
|
||||||
semanticStaticPropertyName,
|
semanticStaticPropertyKey,
|
||||||
} from "./javascriptAstValues.js";
|
} from "./javascriptAstValues.js";
|
||||||
import type { JavaScriptFindingContext } from "./javascriptStaticAnalysisState.js";
|
import type { JavaScriptFindingContext } from "./javascriptStaticAnalysisState.js";
|
||||||
|
|
||||||
@@ -26,6 +26,8 @@ interface NativeBindingInput {
|
|||||||
readonly kind: ElectronNativeAddonBindingFinding["binding_kind"];
|
readonly kind: ElectronNativeAddonBindingFinding["binding_kind"];
|
||||||
readonly moduleKind: ElectronNativeAddonBindingFinding["module_kind"];
|
readonly moduleKind: ElectronNativeAddonBindingFinding["module_kind"];
|
||||||
readonly members: readonly string[];
|
readonly members: readonly string[];
|
||||||
|
readonly namespaceAccess: boolean;
|
||||||
|
readonly dynamicMemberAccess: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inspect JavaScript-side imports and re-exports of native .node addons. */
|
/** Inspect JavaScript-side imports and re-exports of native .node addons. */
|
||||||
@@ -45,10 +47,10 @@ const inspectImport = (
|
|||||||
context: JavaScriptFindingContext,
|
context: JavaScriptFindingContext,
|
||||||
): void => {
|
): void => {
|
||||||
if (!isNativeSpecifier(node.source.value, "import")) return;
|
if (!isNativeSpecifier(node.source.value, "import")) return;
|
||||||
const members = node.specifiers.map((specifier) => {
|
const members = node.specifiers.flatMap((specifier) => {
|
||||||
if (t.isImportDefaultSpecifier(specifier)) return "default";
|
if (t.isImportDefaultSpecifier(specifier)) return ["default"];
|
||||||
if (t.isImportNamespaceSpecifier(specifier)) return "*";
|
if (t.isImportNamespaceSpecifier(specifier)) return [];
|
||||||
return propertyName(specifier.imported) || "[dynamic-import]";
|
return [propertyName(specifier.imported)];
|
||||||
});
|
});
|
||||||
addBinding({
|
addBinding({
|
||||||
context,
|
context,
|
||||||
@@ -57,6 +59,10 @@ const inspectImport = (
|
|||||||
kind: "import",
|
kind: "import",
|
||||||
moduleKind: "import",
|
moduleKind: "import",
|
||||||
members,
|
members,
|
||||||
|
namespaceAccess: node.specifiers.some((value) =>
|
||||||
|
t.isImportNamespaceSpecifier(value),
|
||||||
|
),
|
||||||
|
dynamicMemberAccess: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,9 +76,10 @@ const inspectNamedExport = (
|
|||||||
!isNativeSpecifier(node.source.value, "import")
|
!isNativeSpecifier(node.source.value, "import")
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
const members = node.specifiers.map((specifier) => {
|
const members = node.specifiers.flatMap((specifier) => {
|
||||||
if (t.isExportSpecifier(specifier)) return propertyName(specifier.local);
|
if (t.isExportSpecifier(specifier)) return [propertyName(specifier.local)];
|
||||||
return "*";
|
if (t.isExportDefaultSpecifier(specifier)) return ["default"];
|
||||||
|
return [];
|
||||||
});
|
});
|
||||||
addBinding({
|
addBinding({
|
||||||
context,
|
context,
|
||||||
@@ -81,6 +88,10 @@ const inspectNamedExport = (
|
|||||||
kind: "re-export",
|
kind: "re-export",
|
||||||
moduleKind: "import",
|
moduleKind: "import",
|
||||||
members,
|
members,
|
||||||
|
namespaceAccess: node.specifiers.some((value) =>
|
||||||
|
t.isExportNamespaceSpecifier(value),
|
||||||
|
),
|
||||||
|
dynamicMemberAccess: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -99,7 +110,9 @@ const inspectExportAll = (
|
|||||||
specifier: node.source.value,
|
specifier: node.source.value,
|
||||||
kind: "re-export",
|
kind: "re-export",
|
||||||
moduleKind: "import",
|
moduleKind: "import",
|
||||||
members: ["*"],
|
members: [],
|
||||||
|
namespaceAccess: true,
|
||||||
|
dynamicMemberAccess: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -115,8 +128,7 @@ const inspectRequireBinding = (
|
|||||||
specifier: required.specifier,
|
specifier: required.specifier,
|
||||||
kind: "require",
|
kind: "require",
|
||||||
moduleKind: "require",
|
moduleKind: "require",
|
||||||
members:
|
...(required.hasMemberAccess ? required.access : bindingMembers(node.id)),
|
||||||
required.member === null ? bindingMembers(node.id) : [required.member],
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -132,27 +144,33 @@ const inspectReExport = (
|
|||||||
specifier: required.specifier,
|
specifier: required.specifier,
|
||||||
kind: "re-export",
|
kind: "re-export",
|
||||||
moduleKind: "require",
|
moduleKind: "require",
|
||||||
members: [required.member ?? exportedMember(node.left) ?? "*"],
|
...required.access,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const addBinding = (input: NativeBindingInput): void => {
|
const addBinding = (input: NativeBindingInput): void => {
|
||||||
const { context, node, specifier, kind } = input;
|
const { context, node, specifier, kind } = input;
|
||||||
const unique = [
|
const members = [...new Set(input.members)].sort(compareUnicodeCodePoints);
|
||||||
...new Set(input.members.filter((member) => member !== "")),
|
|
||||||
].sort(compareUnicodeCodePoints);
|
|
||||||
const members = unique.length === 0 ? ["*"] : unique;
|
|
||||||
addLocatedFinding(context, {
|
addLocatedFinding(context, {
|
||||||
collection: context.accumulator.nativeAddonBindings,
|
collection: context.accumulator.nativeAddonBindings,
|
||||||
// Members are a variable-length source-derived list: compositeKey keeps
|
// Members are a variable-length source-derived list: compositeKey keeps
|
||||||
// ["a\0b"] distinct from ["a", "b"] instead of collapsing one binding.
|
// ["a\0b"] distinct from ["a", "b"] instead of collapsing one binding.
|
||||||
key: compositeKey(["native-addon-binding", kind, specifier, members]),
|
key: compositeKey([
|
||||||
|
"native-addon-binding",
|
||||||
|
kind,
|
||||||
|
specifier,
|
||||||
|
members,
|
||||||
|
input.namespaceAccess,
|
||||||
|
input.dynamicMemberAccess,
|
||||||
|
]),
|
||||||
node,
|
node,
|
||||||
value: {
|
value: {
|
||||||
specifier,
|
specifier,
|
||||||
binding_kind: kind,
|
binding_kind: kind,
|
||||||
module_kind: input.moduleKind,
|
module_kind: input.moduleKind,
|
||||||
members,
|
members,
|
||||||
|
namespace_access: input.namespaceAccess,
|
||||||
|
dynamic_member_access: input.dynamicMemberAccess,
|
||||||
module_key: null,
|
module_key: null,
|
||||||
location: range(node),
|
location: range(node),
|
||||||
},
|
},
|
||||||
@@ -162,13 +180,20 @@ const addBinding = (input: NativeBindingInput): void => {
|
|||||||
const nativeRequire = (
|
const nativeRequire = (
|
||||||
node: t.Node | null | undefined,
|
node: t.Node | null | undefined,
|
||||||
):
|
):
|
||||||
| { readonly specifier: string; readonly member: string | null }
|
| {
|
||||||
|
readonly specifier: string;
|
||||||
|
readonly hasMemberAccess: boolean;
|
||||||
|
readonly access: NativeMemberAccess;
|
||||||
|
}
|
||||||
| undefined => {
|
| undefined => {
|
||||||
let member: string | null = null;
|
let member: string | null = null;
|
||||||
|
let hasMemberAccess = false;
|
||||||
while (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
while (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
||||||
if (!t.isNode(node.object)) return undefined;
|
if (!t.isNode(node.object)) return undefined;
|
||||||
const property = semanticStaticPropertyName(node.property, node.computed);
|
const property = semanticStaticPropertyKey(node.property, node.computed);
|
||||||
if (member === null && property !== "") member = property;
|
// Walking inward leaves the first member consumed from the addon itself.
|
||||||
|
member = property;
|
||||||
|
hasMemberAccess = true;
|
||||||
node = node.object;
|
node = node.object;
|
||||||
}
|
}
|
||||||
if (!t.isCallExpression(node)) return undefined;
|
if (!t.isCallExpression(node)) return undefined;
|
||||||
@@ -181,34 +206,52 @@ const nativeRequire = (
|
|||||||
return undefined;
|
return undefined;
|
||||||
const specifier = stringValue(argumentNode(node.arguments[0]));
|
const specifier = stringValue(argumentNode(node.arguments[0]));
|
||||||
return specifier !== undefined && isNativeSpecifier(specifier, "require")
|
return specifier !== undefined && isNativeSpecifier(specifier, "require")
|
||||||
? { specifier, member }
|
? {
|
||||||
|
specifier,
|
||||||
|
hasMemberAccess,
|
||||||
|
access: {
|
||||||
|
members: member === null ? [] : [member],
|
||||||
|
namespaceAccess: !hasMemberAccess,
|
||||||
|
dynamicMemberAccess: hasMemberAccess && member === null,
|
||||||
|
},
|
||||||
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const bindingMembers = (pattern: t.Node): string[] => {
|
interface NativeMemberAccess {
|
||||||
if (t.isIdentifier(pattern)) return ["*"];
|
readonly members: readonly string[];
|
||||||
if (!t.isObjectPattern(pattern)) return ["*"];
|
readonly namespaceAccess: boolean;
|
||||||
return pattern.properties.map((property) => {
|
readonly dynamicMemberAccess: boolean;
|
||||||
if (t.isRestElement(property)) return "*";
|
}
|
||||||
return propertyName(property.key) || "[dynamic-import]";
|
|
||||||
});
|
const bindingMembers = (pattern: t.Node): NativeMemberAccess => {
|
||||||
|
if (!t.isObjectPattern(pattern))
|
||||||
|
return { members: [], namespaceAccess: true, dynamicMemberAccess: false };
|
||||||
|
const members: string[] = [];
|
||||||
|
let namespaceAccess = false;
|
||||||
|
let dynamicMemberAccess = false;
|
||||||
|
for (const property of pattern.properties) {
|
||||||
|
if (t.isRestElement(property)) {
|
||||||
|
namespaceAccess = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const key = semanticStaticPropertyKey(property.key, property.computed);
|
||||||
|
if (key === null) dynamicMemberAccess = true;
|
||||||
|
else members.push(key);
|
||||||
|
}
|
||||||
|
return { members, namespaceAccess, dynamicMemberAccess };
|
||||||
};
|
};
|
||||||
|
|
||||||
const isModuleExport = (node: t.Node): boolean => {
|
const isModuleExport = (node: t.Node): boolean => {
|
||||||
const name = calleeName(node);
|
const keys: (string | null)[] = [];
|
||||||
return (
|
while (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
||||||
name === "module.exports" ||
|
keys.unshift(semanticStaticPropertyKey(node.property, node.computed));
|
||||||
name.startsWith("module.exports.") ||
|
node = node.object;
|
||||||
name.startsWith("exports.")
|
}
|
||||||
);
|
if (!t.isIdentifier(node)) return false;
|
||||||
};
|
return node.name === "exports"
|
||||||
|
? keys.length > 0
|
||||||
const exportedMember = (node: t.Node): string | undefined => {
|
: node.name === "module" && keys[0] === "exports";
|
||||||
const name = calleeName(node);
|
|
||||||
if (name.startsWith("module.exports."))
|
|
||||||
return name.slice("module.exports.".length);
|
|
||||||
if (name.startsWith("exports.")) return name.slice("exports.".length);
|
|
||||||
return undefined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const isNativeSpecifier = (
|
const isNativeSpecifier = (
|
||||||
|
|||||||
@@ -163,7 +163,11 @@ export interface ElectronNativeAddonBindingFinding {
|
|||||||
readonly specifier: string;
|
readonly specifier: string;
|
||||||
readonly binding_kind: "import" | "require" | "re-export";
|
readonly binding_kind: "import" | "require" | "re-export";
|
||||||
readonly module_kind: "import" | "require";
|
readonly module_kind: "import" | "require";
|
||||||
|
/** Exact requested addon member keys; namespace and dynamic access are separate. */
|
||||||
readonly members: readonly string[];
|
readonly members: readonly string[];
|
||||||
|
/** Omitted in legacy findings; omission means unknown, not false. */
|
||||||
|
readonly namespace_access?: boolean;
|
||||||
|
readonly dynamic_member_access?: boolean;
|
||||||
readonly module_key: string | null;
|
readonly module_key: string | null;
|
||||||
readonly location: JavaScriptSourceRange;
|
readonly location: JavaScriptSourceRange;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,7 +257,15 @@ const semanticValue = (
|
|||||||
return (
|
return (
|
||||||
joined(
|
joined(
|
||||||
properties.specifier,
|
properties.specifier,
|
||||||
stringList(properties.requested_members).join(","),
|
compositeKey([
|
||||||
|
stringList(properties.requested_members),
|
||||||
|
typeof properties.namespace_access === "boolean"
|
||||||
|
? properties.namespace_access
|
||||||
|
: null,
|
||||||
|
typeof properties.dynamic_member_access === "boolean"
|
||||||
|
? properties.dynamic_member_access
|
||||||
|
: null,
|
||||||
|
]),
|
||||||
) ?? firstLabel(node)
|
) ?? firstLabel(node)
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -103,7 +103,12 @@ const nativeExportNodes = (
|
|||||||
const requestedExports = (nodes: readonly ApplicationNode[]): string[] => {
|
const requestedExports = (nodes: readonly ApplicationNode[]): string[] => {
|
||||||
const values = nodes.flatMap((node) =>
|
const values = nodes.flatMap((node) =>
|
||||||
node.observations.flatMap((observation) => [
|
node.observations.flatMap((observation) => [
|
||||||
...(observation.label === null ? [] : [observation.label]),
|
// Display labels can summarize several names or namespace access.
|
||||||
|
// Only legacy observations without structured member facts need them.
|
||||||
|
...(observation.label === null ||
|
||||||
|
Array.isArray(observation.properties.requested_members)
|
||||||
|
? []
|
||||||
|
: [observation.label]),
|
||||||
...stringArray(observation.properties.requested_members),
|
...stringArray(observation.properties.requested_members),
|
||||||
...stringArray(observation.properties.members),
|
...stringArray(observation.properties.members),
|
||||||
]),
|
]),
|
||||||
|
|||||||
Reference in New Issue
Block a user