rea-agents 1.6.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -66
- package/bridge/ghidra/ReaGhidraBridge.java +2075 -0
- package/bridge/hopper_bridge.py +13 -3
- package/dist/application/AbortablePromise.js +25 -0
- package/dist/application/AnalysisProvider.js +3 -0
- package/dist/application/AnalysisProviderEvaluation.js +60 -0
- package/dist/application/AnalysisProviderRegistry.js +228 -0
- package/dist/application/AnalysisSnapshotCache.js +41 -21
- package/dist/application/AnalysisSnapshotFiles.js +5 -6
- package/dist/application/BinarySession.js +218 -101
- package/dist/application/CapabilityInventory.js +18 -0
- package/dist/application/CompositeProvider.js +20 -8
- package/dist/application/CrossVersionInvestigation.js +10 -6
- package/dist/application/DirectAnalysis.js +49 -35
- package/dist/application/Doctor.js +110 -8
- package/dist/application/ElectronBoundaryAnalysis.js +96 -0
- package/dist/application/ElectronBoundaryGraph.js +9 -0
- package/dist/application/ElectronBoundaryGraphContext.js +62 -0
- package/dist/application/ElectronBoundaryGraphIpc.js +242 -0
- package/dist/application/ElectronBoundaryGraphNative.js +86 -0
- package/dist/application/ElectronBoundaryGraphWindows.js +199 -0
- package/dist/application/EnhancedTools.js +39 -14
- package/dist/application/InvestigationProviders.js +41 -0
- package/dist/application/JavaScriptApplicationEvidence.js +26 -0
- package/dist/application/JavaScriptApplicationEvidenceGraph.js +89 -0
- package/dist/application/JavaScriptApplicationService.js +74 -0
- package/dist/application/JavaScriptApplicationWorkflowEvidence.js +29 -0
- package/dist/application/JavaScriptApplicationWorkflowService.js +90 -0
- package/dist/application/JavaScriptArtifactAnalysis.js +305 -0
- package/dist/application/JavaScriptArtifactAnalysisTypes.js +1 -0
- package/dist/application/JavaScriptArtifactFiles.js +231 -0
- package/dist/application/JavaScriptArtifactGraphAccumulator.js +54 -0
- package/dist/application/JavaScriptArtifactGraphBuilder.js +144 -0
- package/dist/application/JavaScriptArtifactGraphContext.js +205 -0
- package/dist/application/JavaScriptArtifactGraphDocuments.js +108 -0
- package/dist/application/JavaScriptArtifactGraphEvidence.js +99 -0
- package/dist/application/JavaScriptArtifactGraphFindings.js +271 -0
- package/dist/application/JavaScriptArtifactGraphStructure.js +409 -0
- package/dist/application/JavaScriptArtifactReconstruction.js +77 -0
- package/dist/application/JavaScriptArtifactReconstructionInput.js +18 -0
- package/dist/application/JavaScriptReplayPlanning.js +201 -0
- package/dist/application/JavaScriptReplayService.js +266 -0
- package/dist/application/JavaScriptRuntimeReconciliationEvidence.js +25 -0
- package/dist/application/JavaScriptRuntimeReconciliationService.js +27 -0
- package/dist/application/MacHopper.js +20 -4
- package/dist/application/ManagedApplicationGraphService.js +55 -0
- package/dist/application/ManagedMemberComparisonService.js +122 -0
- package/dist/application/ManagedNativeVerificationService.js +39 -0
- package/dist/application/ManagedReconstructionService.js +58 -0
- package/dist/application/ManagedRuntimeCorrelationService.js +103 -0
- package/dist/application/PermissionAuthority.js +1 -1
- package/dist/application/ProcessCaptureLifecycle.js +1 -1
- package/dist/application/ProcessHarness.js +1 -1
- package/dist/application/ProcessSampling.js +16 -12
- package/dist/application/ProjectPermissionStore.js +1 -0
- package/dist/application/SessionProviderRouter.js +219 -0
- package/dist/application/Setup.js +84 -60
- package/dist/application/SetupClients.js +1 -1
- package/dist/application/SetupPlan.js +9 -2
- package/dist/application/SupportedClients.js +40 -16
- package/dist/application/Upgrade.js +1 -1
- package/dist/application/runtime.js +11 -6
- package/dist/artifacts/AsarArtifactReader.js +23 -3
- package/dist/browser/CdpBrowserProvider.js +4 -2
- package/dist/browser/CdpCaptureEvents.js +49 -0
- package/dist/browser/CdpElectronInspection.js +106 -162
- package/dist/browser/CdpElectronProvider.js +9 -3
- package/dist/browser/CdpElectronScriptEvents.js +69 -0
- package/dist/browser/CdpElectronScripts.js +94 -0
- package/dist/browser/CdpElectronWorkers.js +56 -0
- package/dist/browser/CdpEndpoint.js +14 -1
- package/dist/browser/CdpPageCapture.js +8 -4
- package/dist/catalogIdentity.js +6 -42
- package/dist/cli.js +446 -34
- package/dist/cliApplicationCommands.js +62 -0
- package/dist/cliBrowserAdvancedCommands.js +5 -4
- package/dist/cliBrowserCommands.js +5 -4
- package/dist/cliCommandNames.js +56 -0
- package/dist/cliElectronCommands.js +106 -3
- package/dist/cliEvidenceCommands.js +4 -3
- package/dist/cliInvestigationCommands.js +2 -1
- package/dist/cliJsonInput.js +54 -0
- package/dist/cliPolicyCommands.js +2 -1
- package/dist/cliProcessCommands.js +3 -2
- package/dist/config.js +101 -2
- package/dist/contracts/applicationToolContracts.js +91 -0
- package/dist/contracts/artifactToolContracts.js +5 -9
- package/dist/contracts/browserToolContracts.js +14 -62
- package/dist/contracts/electronToolContracts.js +45 -19
- package/dist/contracts/enhancedInputs.js +2 -2
- package/dist/contracts/errorSchemas.js +1 -0
- package/dist/contracts/investigationExamples.js +0 -6
- package/dist/contracts/javascriptApplicationWorkflowExamples.js +46 -0
- package/dist/contracts/javascriptRuntimeReconciliationExample.js +208 -0
- package/dist/contracts/managedToolContracts.js +153 -0
- package/dist/contracts/managedWorkflowExamples.js +346 -0
- package/dist/contracts/managedWorkflowToolContracts.js +203 -0
- package/dist/contracts/nativeToolContracts.js +2 -6
- package/dist/contracts/promptContracts.js +18 -2
- package/dist/contracts/providerSelection.js +28 -0
- package/dist/contracts/sessionLifecycleInputs.js +2 -0
- package/dist/contracts/toolContractExamples.js +10 -25
- package/dist/contracts/toolContracts.js +69 -65
- package/dist/contracts/toolEffects.js +160 -0
- package/dist/contracts/toolOutputSchemas.js +152 -42
- package/dist/doctorRuntime.js +47 -0
- package/dist/domain/analysisProfile.js +78 -0
- package/dist/domain/analysisSnapshot.js +92 -46
- package/dist/domain/artifactComparison.js +3 -4
- package/dist/domain/artifactGraph.js +1 -0
- package/dist/domain/binaryTarget.js +4 -29
- package/dist/domain/browserObservation.js +3 -0
- package/dist/domain/bundleComparison.js +4 -4
- package/dist/domain/electronObservation.js +13 -0
- package/dist/domain/electronStaticAnalysis.js +9 -0
- package/dist/domain/electronStaticAnalysisBrowser.js +194 -0
- package/dist/domain/electronStaticAnalysisIpc.js +171 -0
- package/dist/domain/electronStaticAnalysisNative.js +164 -0
- package/dist/domain/electronStaticAnalysisTypes.js +1 -0
- package/dist/domain/electronStaticAnalysisValues.js +103 -0
- package/dist/domain/errors.js +148 -7
- package/dist/domain/evidence.js +44 -5
- package/dist/domain/evidenceBundle.js +9 -7
- package/dist/domain/functionComparison.js +9 -3
- package/dist/domain/functionComparisonNormalization.js +37 -0
- package/dist/domain/functionComparisonSchemas.js +3 -8
- package/dist/domain/functionDossierEvidence.js +4 -1
- package/dist/domain/hopperValues.js +66 -9
- package/dist/domain/inputIssueProjection.js +52 -0
- package/dist/domain/investigationWorkspace.js +2 -1
- package/dist/domain/javascriptApplicationAnalysis.js +155 -0
- package/dist/domain/javascriptApplicationChangeGraph.js +231 -0
- package/dist/domain/javascriptApplicationEvidenceSchemas.js +379 -0
- package/dist/domain/javascriptApplicationGraph.js +282 -0
- package/dist/domain/javascriptApplicationGraphSchemas.js +139 -0
- package/dist/domain/javascriptApplicationVersionComparison.js +116 -0
- package/dist/domain/javascriptApplicationVersionComparisonSchemas.js +139 -0
- package/dist/domain/javascriptApplicationVersionItems.js +221 -0
- package/dist/domain/javascriptApplicationVersionKeys.js +170 -0
- package/dist/domain/javascriptAstFingerprint.js +143 -0
- package/dist/domain/javascriptFeatureSeed.js +140 -0
- package/dist/domain/javascriptFeatureTrace.js +232 -0
- package/dist/domain/javascriptFeatureTraceSchemas.js +136 -0
- package/dist/domain/javascriptFeatureTraversal.js +88 -0
- package/dist/domain/javascriptNativeHandoff.js +85 -0
- package/dist/domain/javascriptReplay.js +361 -0
- package/dist/domain/javascriptRuntimeLoadState.js +106 -0
- package/dist/domain/javascriptRuntimeReconciliation.js +42 -0
- package/dist/domain/javascriptRuntimeReconciliationGraph.js +169 -0
- package/dist/domain/javascriptRuntimeReconciliationMatching.js +247 -0
- package/dist/domain/javascriptRuntimeReconciliationParsing.js +160 -0
- package/dist/domain/javascriptRuntimeReconciliationResult.js +119 -0
- package/dist/domain/javascriptRuntimeReconciliationRuntime.js +316 -0
- package/dist/domain/javascriptRuntimeReconciliationSchemas.js +245 -0
- package/dist/domain/javascriptRuntimeStaticCandidates.js +191 -0
- package/dist/domain/javascriptStaticAnalysis.js +346 -0
- package/dist/domain/javascriptStaticAnalysisFindings.js +39 -0
- package/dist/domain/javascriptStaticAnalysisHelpers.js +274 -0
- package/dist/domain/javascriptStaticAnalysisState.js +23 -0
- package/dist/domain/javascriptStaticAnalysisTypes.js +1 -0
- package/dist/domain/managedApplicationGraph.js +556 -0
- package/dist/domain/managedArtifact.js +444 -0
- package/dist/domain/managedMemberComparison.js +565 -0
- package/dist/domain/managedNativeVerification.js +408 -0
- package/dist/domain/managedReconstruction.js +183 -0
- package/dist/domain/managedRuntimeCorrelation.js +175 -0
- package/dist/domain/reconstructionVerificationSchemas.js +1 -3
- package/dist/dotnet/ManagedArtifactInspector.js +318 -0
- package/dist/dotnet/ManagedMemberInspector.js +887 -0
- package/dist/dotnet/ManagedMetadataHeaps.js +131 -0
- package/dist/dotnet/ManagedMetadataInventory.js +368 -0
- package/dist/dotnet/ManagedMetadataLayout.js +322 -0
- package/dist/dotnet/ManagedNativeBoundaryInspector.js +391 -0
- package/dist/dotnet/ManagedPeReader.js +157 -0
- package/dist/dotnet/ManagedReaderFailure.js +10 -0
- package/dist/dotnet/ManagedStaticProvider.js +203 -0
- package/dist/generatedPackageMetadata.js +2 -2
- package/dist/ghidra/GhidraAnalysisProfile.js +37 -0
- package/dist/ghidra/GhidraClient.js +400 -0
- package/dist/ghidra/GhidraClientTypes.js +1 -0
- package/dist/ghidra/GhidraDefaults.js +20 -0
- package/dist/ghidra/GhidraDiagnostics.js +43 -0
- package/dist/ghidra/GhidraDoctor.js +59 -0
- package/dist/ghidra/GhidraFunctionValues.js +264 -0
- package/dist/ghidra/GhidraInstallation.js +239 -0
- package/dist/ghidra/GhidraInventoryValues.js +217 -0
- package/dist/ghidra/GhidraLauncher.js +139 -0
- package/dist/ghidra/GhidraProvider.js +366 -0
- package/dist/ghidra/GhidraRequestQueue.js +98 -0
- package/dist/ghidra/GhidraResponseBuffer.js +31 -0
- package/dist/ghidra/GhidraResponseRouter.js +24 -0
- package/dist/ghidra/GhidraSessionError.js +39 -0
- package/dist/ghidra/GhidraSessionValues.js +62 -0
- package/dist/ghidra/GhidraSocketConnection.js +46 -0
- package/dist/ghidra/protocol.js +69 -0
- package/dist/hopper/BridgeLauncher.js +19 -54
- package/dist/hopper/HopperAnalysisProfile.js +106 -0
- package/dist/hopper/HopperClient.js +154 -162
- package/dist/hopper/HopperProvider.js +99 -7
- package/dist/hopper/HopperSessionValues.js +27 -0
- package/dist/hopper/HopperSocketConnection.js +31 -0
- package/dist/main.js +14 -0
- package/dist/native/NativeMacOSProvider.js +3 -1
- package/dist/process/PendingOperations.js +59 -0
- package/dist/process/PrivateRuntimeRoot.js +33 -0
- package/dist/process/ProviderDeadline.js +95 -0
- package/dist/process/ProviderProcess.js +275 -0
- package/dist/replay/JavaScriptReplayWorker.js +286 -0
- package/dist/replay/LinuxJavaScriptReplayRunner.js +434 -0
- package/dist/replay/LinuxRuntimeClosure.js +46 -0
- package/dist/replay/LinuxSeccompPolicy.js +40 -0
- package/dist/replay/ReplayWorkerProtocol.js +55 -0
- package/dist/replay/SystemJavaScriptReplayHost.js +182 -0
- package/dist/server/createServer.js +53 -0
- package/dist/server/promptCompletion.js +9 -3
- package/dist/server/registerApplicationTools.js +115 -0
- package/dist/server/registerArtifactComparisonTool.js +16 -9
- package/dist/server/registerBrowserTools.js +33 -8
- package/dist/server/registerBundleComparisonTool.js +17 -20
- package/dist/server/registerElectronTools.js +45 -3
- package/dist/server/registerEnhancedTools.js +67 -19
- package/dist/server/registerEvidenceTools.js +5 -1
- package/dist/server/registerFunctionComparisonTool.js +14 -7
- package/dist/server/registerInvestigationTools.js +21 -17
- package/dist/server/registerManagedTools.js +6 -0
- package/dist/server/registerManagedWorkflowTools.js +277 -0
- package/dist/server/registerOfficialTools.js +11 -8
- package/dist/server/registerProcessComparisonTool.js +25 -47
- package/dist/server/registerSessionStatusTool.js +7 -7
- package/dist/server/registerSessionTools.js +57 -87
- package/dist/server/sessionEvidence.js +14 -19
- package/dist/server/toolInputValidation.js +77 -0
- package/dist/server/toolRegistrationOptions.js +79 -2
- package/dist/server/toolResult.js +25 -17
- package/package.json +17 -7
- package/scripts/rea.mjs +36 -2
- package/skills/rea-analysis/SKILL.md +59 -3
- /package/dist/{application → process}/ProcessOwnership.js +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as t from "@babel/types";
|
|
2
|
+
import { boundedExpression, electronStaticValue, handlerKind, } from "./electronStaticAnalysisValues.js";
|
|
3
|
+
import { addLocatedFinding } from "./javascriptStaticAnalysisFindings.js";
|
|
4
|
+
import { argumentNode, calleeName, propertyName, range, } from "./javascriptStaticAnalysisHelpers.js";
|
|
5
|
+
/** Inspect Electron IPC operations and validation candidates. */
|
|
6
|
+
export const inspectElectronIpcNode = (node, context) => {
|
|
7
|
+
if (t.isCallExpression(node)) {
|
|
8
|
+
inspectIpcCall(node, context);
|
|
9
|
+
inspectValidationCall(node, context);
|
|
10
|
+
}
|
|
11
|
+
if (t.isBinaryExpression(node))
|
|
12
|
+
inspectValidationComparison(node, context);
|
|
13
|
+
};
|
|
14
|
+
const inspectIpcCall = (node, context) => {
|
|
15
|
+
const name = calleeName(node.callee);
|
|
16
|
+
const descriptor = ipcDescriptor(name);
|
|
17
|
+
if (descriptor === undefined)
|
|
18
|
+
return;
|
|
19
|
+
const channelNode = argumentNode(node.arguments[0]);
|
|
20
|
+
const channelValue = electronStaticValue(context.source, channelNode);
|
|
21
|
+
const channel = channelValue.status === "literal" && typeof channelValue.value === "string"
|
|
22
|
+
? channelValue.value
|
|
23
|
+
: null;
|
|
24
|
+
const channelExpression = channel === null
|
|
25
|
+
? channelValue.status === "dynamic"
|
|
26
|
+
? channelValue.expression
|
|
27
|
+
: boundedExpression(context.source, channelNode)
|
|
28
|
+
: null;
|
|
29
|
+
const hasHandler = descriptor.mode === "listen" || descriptor.mode === "handle";
|
|
30
|
+
const handlerNode = hasHandler ? argumentNode(node.arguments[1]) : undefined;
|
|
31
|
+
if (channel === null)
|
|
32
|
+
context.accumulator.unknownFindings += 1;
|
|
33
|
+
if (hasHandler && handlerNode === undefined)
|
|
34
|
+
context.accumulator.unknownFindings += 1;
|
|
35
|
+
const finding = {
|
|
36
|
+
...descriptor,
|
|
37
|
+
channel,
|
|
38
|
+
channel_expression: channelExpression,
|
|
39
|
+
handler_kind: hasHandler ? handlerKind(handlerNode) : null,
|
|
40
|
+
handler_location: handlerNode === undefined ? null : range(handlerNode),
|
|
41
|
+
module_key: null,
|
|
42
|
+
location: range(node),
|
|
43
|
+
};
|
|
44
|
+
addLocatedFinding(context, {
|
|
45
|
+
collection: context.accumulator.ipc,
|
|
46
|
+
key: `electron-ipc\0${descriptor.side}\0${descriptor.operation}\0${channel ?? channelExpression ?? "[missing]"}`,
|
|
47
|
+
node,
|
|
48
|
+
value: finding,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const inspectValidationComparison = (node, context) => {
|
|
52
|
+
if (!["==", "===", "!=", "!==", "in"].includes(node.operator))
|
|
53
|
+
return;
|
|
54
|
+
const left = senderSubject(node.left);
|
|
55
|
+
const right = senderSubject(node.right);
|
|
56
|
+
if (left === undefined && right === undefined)
|
|
57
|
+
return;
|
|
58
|
+
const expected = left === undefined ? node.left : node.right;
|
|
59
|
+
addValidation(context, node, {
|
|
60
|
+
subject: left ?? right ?? "sender-frame",
|
|
61
|
+
mechanism: `comparison:${node.operator}`,
|
|
62
|
+
expected: electronStaticValue(context.source, expected),
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const inspectValidationCall = (node, context) => {
|
|
66
|
+
if (!t.isMemberExpression(node.callee) &&
|
|
67
|
+
!t.isOptionalMemberExpression(node.callee))
|
|
68
|
+
return;
|
|
69
|
+
const method = propertyName(node.callee.property);
|
|
70
|
+
if (!["startsWith", "endsWith", "includes"].includes(method))
|
|
71
|
+
return;
|
|
72
|
+
const subject = t.isNode(node.callee.object)
|
|
73
|
+
? senderSubject(node.callee.object)
|
|
74
|
+
: undefined;
|
|
75
|
+
if (subject === undefined)
|
|
76
|
+
return;
|
|
77
|
+
addValidation(context, node, {
|
|
78
|
+
subject,
|
|
79
|
+
mechanism: `call:${method}`,
|
|
80
|
+
expected: electronStaticValue(context.source, argumentNode(node.arguments[0])),
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const addValidation = (context, node, input) => {
|
|
84
|
+
if (input.expected.status === "dynamic")
|
|
85
|
+
context.accumulator.unknownFindings += 1;
|
|
86
|
+
const finding = {
|
|
87
|
+
...input,
|
|
88
|
+
enforcement: "unknown",
|
|
89
|
+
module_key: null,
|
|
90
|
+
location: range(node),
|
|
91
|
+
};
|
|
92
|
+
addLocatedFinding(context, {
|
|
93
|
+
collection: context.accumulator.senderValidations,
|
|
94
|
+
key: `electron-validation\0${input.subject}\0${input.mechanism}\0${input.expected.status === "literal" ? String(input.expected.value) : input.expected.expression}`,
|
|
95
|
+
node,
|
|
96
|
+
value: finding,
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const ipcDescriptor = (name) => {
|
|
100
|
+
const renderer = suffixOperation(name, "ipcRenderer");
|
|
101
|
+
if (renderer !== undefined) {
|
|
102
|
+
switch (renderer) {
|
|
103
|
+
case "send":
|
|
104
|
+
return { side: "renderer", operation: "send", mode: "send" };
|
|
105
|
+
case "sendSync":
|
|
106
|
+
return { side: "renderer", operation: "send-sync", mode: "send" };
|
|
107
|
+
case "invoke":
|
|
108
|
+
return { side: "renderer", operation: "invoke", mode: "invoke" };
|
|
109
|
+
case "postMessage":
|
|
110
|
+
return {
|
|
111
|
+
side: "renderer",
|
|
112
|
+
operation: "post-message",
|
|
113
|
+
mode: "send",
|
|
114
|
+
};
|
|
115
|
+
case "sendToHost":
|
|
116
|
+
return {
|
|
117
|
+
side: "renderer",
|
|
118
|
+
operation: "send-to-host",
|
|
119
|
+
mode: "send",
|
|
120
|
+
};
|
|
121
|
+
case "on":
|
|
122
|
+
return { side: "renderer", operation: "on", mode: "listen" };
|
|
123
|
+
case "once":
|
|
124
|
+
return { side: "renderer", operation: "once", mode: "listen" };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const main = suffixOperation(name, "ipcMain");
|
|
128
|
+
switch (main) {
|
|
129
|
+
case "on":
|
|
130
|
+
return { side: "main", operation: "on", mode: "listen" };
|
|
131
|
+
case "once":
|
|
132
|
+
return { side: "main", operation: "once", mode: "listen" };
|
|
133
|
+
case "handle":
|
|
134
|
+
return { side: "main", operation: "handle", mode: "handle" };
|
|
135
|
+
case "handleOnce":
|
|
136
|
+
return { side: "main", operation: "handle-once", mode: "handle" };
|
|
137
|
+
default:
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const suffixOperation = (name, object) => {
|
|
142
|
+
const marker = `${object}.`;
|
|
143
|
+
const index = name.lastIndexOf(marker);
|
|
144
|
+
if (index < 0)
|
|
145
|
+
return undefined;
|
|
146
|
+
const prefix = name.slice(0, index);
|
|
147
|
+
if (prefix !== "" && !prefix.endsWith("."))
|
|
148
|
+
return undefined;
|
|
149
|
+
const operation = name.slice(index + marker.length);
|
|
150
|
+
return operation.includes(".") ? undefined : operation;
|
|
151
|
+
};
|
|
152
|
+
const senderSubject = (node) => {
|
|
153
|
+
const name = t.isCallExpression(node)
|
|
154
|
+
? calleeName(node.callee)
|
|
155
|
+
: calleeName(node);
|
|
156
|
+
if (/(?:^|\.)sender\.getURL$/u.test(name))
|
|
157
|
+
return "sender-url";
|
|
158
|
+
if (/(?:^|\.)senderFrame\.origin$/u.test(name))
|
|
159
|
+
return "sender-origin";
|
|
160
|
+
if (/(?:^|\.)senderFrame\.url$/u.test(name))
|
|
161
|
+
return "sender-url";
|
|
162
|
+
if (/(?:^|\.)senderFrame$/u.test(name))
|
|
163
|
+
return "sender-frame";
|
|
164
|
+
if (/(?:^|\.)sender\.id$/u.test(name))
|
|
165
|
+
return "sender-id";
|
|
166
|
+
if (/(?:^|\.)frameId$/u.test(name))
|
|
167
|
+
return "frame-id";
|
|
168
|
+
if (/(?:^|\.)processId$/u.test(name))
|
|
169
|
+
return "process-id";
|
|
170
|
+
return undefined;
|
|
171
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import * as t from "@babel/types";
|
|
2
|
+
import { addLocatedFinding } from "./javascriptStaticAnalysisFindings.js";
|
|
3
|
+
import { argumentNode, calleeName, compareCodePoints, propertyName, range, stringValue, } from "./javascriptStaticAnalysisHelpers.js";
|
|
4
|
+
const MAX_NATIVE_MEMBERS = 64;
|
|
5
|
+
/** Inspect JavaScript-side imports and re-exports of native .node addons. */
|
|
6
|
+
export const inspectElectronNativeNode = (node, context) => {
|
|
7
|
+
if (t.isImportDeclaration(node))
|
|
8
|
+
inspectImport(node, context);
|
|
9
|
+
else if (t.isExportNamedDeclaration(node))
|
|
10
|
+
inspectNamedExport(node, context);
|
|
11
|
+
else if (t.isExportAllDeclaration(node))
|
|
12
|
+
inspectExportAll(node, context);
|
|
13
|
+
else if (t.isVariableDeclarator(node))
|
|
14
|
+
inspectRequireBinding(node, context);
|
|
15
|
+
else if (t.isAssignmentExpression(node))
|
|
16
|
+
inspectReExport(node, context);
|
|
17
|
+
};
|
|
18
|
+
const inspectImport = (node, context) => {
|
|
19
|
+
if (!isNativeSpecifier(node.source.value))
|
|
20
|
+
return;
|
|
21
|
+
const members = node.specifiers.map((specifier) => {
|
|
22
|
+
if (t.isImportDefaultSpecifier(specifier))
|
|
23
|
+
return "default";
|
|
24
|
+
if (t.isImportNamespaceSpecifier(specifier))
|
|
25
|
+
return "*";
|
|
26
|
+
return propertyName(specifier.imported) || "[dynamic-import]";
|
|
27
|
+
});
|
|
28
|
+
addBinding({
|
|
29
|
+
context,
|
|
30
|
+
node,
|
|
31
|
+
specifier: node.source.value,
|
|
32
|
+
kind: "import",
|
|
33
|
+
members,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const inspectNamedExport = (node, context) => {
|
|
37
|
+
if (node.source === null ||
|
|
38
|
+
node.source === undefined ||
|
|
39
|
+
!isNativeSpecifier(node.source.value))
|
|
40
|
+
return;
|
|
41
|
+
const members = node.specifiers.map((specifier) => {
|
|
42
|
+
if (t.isExportSpecifier(specifier))
|
|
43
|
+
return propertyName(specifier.local);
|
|
44
|
+
return "*";
|
|
45
|
+
});
|
|
46
|
+
addBinding({
|
|
47
|
+
context,
|
|
48
|
+
node,
|
|
49
|
+
specifier: node.source.value,
|
|
50
|
+
kind: "re-export",
|
|
51
|
+
members,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
const inspectExportAll = (node, context) => {
|
|
55
|
+
if (node.source === undefined || !isNativeSpecifier(node.source.value))
|
|
56
|
+
return;
|
|
57
|
+
addBinding({
|
|
58
|
+
context,
|
|
59
|
+
node,
|
|
60
|
+
specifier: node.source.value,
|
|
61
|
+
kind: "re-export",
|
|
62
|
+
members: ["*"],
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const inspectRequireBinding = (node, context) => {
|
|
66
|
+
const required = nativeRequire(node.init);
|
|
67
|
+
if (required === undefined)
|
|
68
|
+
return;
|
|
69
|
+
addBinding({
|
|
70
|
+
context,
|
|
71
|
+
node,
|
|
72
|
+
specifier: required.specifier,
|
|
73
|
+
kind: "require",
|
|
74
|
+
members: required.member === null ? bindingMembers(node.id) : [required.member],
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const inspectReExport = (node, context) => {
|
|
78
|
+
const required = nativeRequire(node.right);
|
|
79
|
+
if (required === undefined || !isModuleExport(node.left))
|
|
80
|
+
return;
|
|
81
|
+
addBinding({
|
|
82
|
+
context,
|
|
83
|
+
node,
|
|
84
|
+
specifier: required.specifier,
|
|
85
|
+
kind: "re-export",
|
|
86
|
+
members: [required.member ?? exportedMember(node.left) ?? "*"],
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const addBinding = (input) => {
|
|
90
|
+
const { context, node, specifier, kind } = input;
|
|
91
|
+
const unique = [
|
|
92
|
+
...new Set(input.members.filter((member) => member !== "")),
|
|
93
|
+
].sort(compareCodePoints);
|
|
94
|
+
const members = (unique.length === 0 ? ["*"] : unique).slice(0, MAX_NATIVE_MEMBERS);
|
|
95
|
+
const omitted = Math.max(0, unique.length - MAX_NATIVE_MEMBERS);
|
|
96
|
+
if (omitted > 0) {
|
|
97
|
+
context.accumulator.structuralTruncation = true;
|
|
98
|
+
context.accumulator.droppedFindings += omitted;
|
|
99
|
+
}
|
|
100
|
+
addLocatedFinding(context, {
|
|
101
|
+
collection: context.accumulator.nativeAddonBindings,
|
|
102
|
+
key: `native-addon-binding\0${kind}\0${specifier}\0${members.join("\0")}`,
|
|
103
|
+
node,
|
|
104
|
+
value: {
|
|
105
|
+
specifier,
|
|
106
|
+
binding_kind: kind,
|
|
107
|
+
members,
|
|
108
|
+
members_truncated: omitted > 0,
|
|
109
|
+
module_key: null,
|
|
110
|
+
location: range(node),
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const nativeRequire = (node) => {
|
|
115
|
+
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
|
116
|
+
const nested = t.isNode(node.object)
|
|
117
|
+
? nativeRequire(node.object)
|
|
118
|
+
: undefined;
|
|
119
|
+
if (nested === undefined)
|
|
120
|
+
return undefined;
|
|
121
|
+
const member = propertyName(node.property);
|
|
122
|
+
return { ...nested, member: member === "" ? nested.member : member };
|
|
123
|
+
}
|
|
124
|
+
if (!t.isCallExpression(node))
|
|
125
|
+
return undefined;
|
|
126
|
+
const name = calleeName(node.callee);
|
|
127
|
+
if (name !== "require" &&
|
|
128
|
+
!name.endsWith(".require") &&
|
|
129
|
+
!name.includes("__webpack_require__"))
|
|
130
|
+
return undefined;
|
|
131
|
+
const specifier = stringValue(argumentNode(node.arguments[0]));
|
|
132
|
+
return specifier !== undefined && isNativeSpecifier(specifier)
|
|
133
|
+
? { specifier, member: null }
|
|
134
|
+
: undefined;
|
|
135
|
+
};
|
|
136
|
+
const bindingMembers = (pattern) => {
|
|
137
|
+
if (t.isIdentifier(pattern))
|
|
138
|
+
return ["*"];
|
|
139
|
+
if (!t.isObjectPattern(pattern))
|
|
140
|
+
return ["*"];
|
|
141
|
+
return pattern.properties.map((property) => {
|
|
142
|
+
if (t.isRestElement(property))
|
|
143
|
+
return "*";
|
|
144
|
+
return propertyName(property.key) || "[dynamic-import]";
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
const isModuleExport = (node) => {
|
|
148
|
+
const name = calleeName(node);
|
|
149
|
+
return (name === "module.exports" ||
|
|
150
|
+
name.startsWith("module.exports.") ||
|
|
151
|
+
name.startsWith("exports."));
|
|
152
|
+
};
|
|
153
|
+
const exportedMember = (node) => {
|
|
154
|
+
const name = calleeName(node);
|
|
155
|
+
if (name.startsWith("module.exports."))
|
|
156
|
+
return name.slice("module.exports.".length);
|
|
157
|
+
if (name.startsWith("exports."))
|
|
158
|
+
return name.slice("exports.".length);
|
|
159
|
+
return undefined;
|
|
160
|
+
};
|
|
161
|
+
const isNativeSpecifier = (specifier) => {
|
|
162
|
+
const path = specifier.split("#", 1)[0]?.split("?", 1)[0] ?? "";
|
|
163
|
+
return path.toLowerCase().endsWith(".node");
|
|
164
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as t from "@babel/types";
|
|
2
|
+
import { compareCodePoints, propertyName, sourceSlice, } from "./javascriptStaticAnalysisHelpers.js";
|
|
3
|
+
const MAX_EXPRESSION_CHARACTERS = 4_096;
|
|
4
|
+
/** Preserve one literal value or the exact bounded inert expression. */
|
|
5
|
+
export const electronStaticValue = (source, node) => {
|
|
6
|
+
const literal = literalValue(node);
|
|
7
|
+
return literal.found
|
|
8
|
+
? { status: "literal", value: literal.value, expression: null }
|
|
9
|
+
: {
|
|
10
|
+
status: "dynamic",
|
|
11
|
+
value: null,
|
|
12
|
+
expression: boundedExpression(source, node),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/** Return an actionable bounded expression without evaluating it. */
|
|
16
|
+
export const boundedExpression = (source, node) => {
|
|
17
|
+
if (node === null || node === undefined)
|
|
18
|
+
return "[missing-expression]";
|
|
19
|
+
const expression = sourceSlice(source, node).trim();
|
|
20
|
+
return (expression === "" ? `[${node.type}]` : expression).slice(0, MAX_EXPRESSION_CHARACTERS);
|
|
21
|
+
};
|
|
22
|
+
/** Read one named object property without following spreads or bindings. */
|
|
23
|
+
export const objectProperty = (object, name) => object.properties.find((property) => t.isObjectProperty(property) && propertyName(property.key) === name);
|
|
24
|
+
/** Classify a handler argument while retaining its exact source range. */
|
|
25
|
+
export const handlerKind = (node) => {
|
|
26
|
+
if (node === null || node === undefined)
|
|
27
|
+
return "missing";
|
|
28
|
+
if (t.isArrowFunctionExpression(node) ||
|
|
29
|
+
t.isFunctionExpression(node) ||
|
|
30
|
+
t.isFunctionDeclaration(node))
|
|
31
|
+
return "inline-function";
|
|
32
|
+
if (t.isIdentifier(node))
|
|
33
|
+
return "identifier";
|
|
34
|
+
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node))
|
|
35
|
+
return "member-expression";
|
|
36
|
+
return "dynamic-expression";
|
|
37
|
+
};
|
|
38
|
+
/** Collect bounded dotted keys from one literal contextBridge API object. */
|
|
39
|
+
export const collectContextBridgeMembers = (node, maximum = 128) => {
|
|
40
|
+
if (node === null || node === undefined)
|
|
41
|
+
return {
|
|
42
|
+
status: "missing",
|
|
43
|
+
members: [],
|
|
44
|
+
unknown: 0,
|
|
45
|
+
omitted: 0,
|
|
46
|
+
};
|
|
47
|
+
if (!t.isObjectExpression(node))
|
|
48
|
+
return {
|
|
49
|
+
status: "dynamic",
|
|
50
|
+
members: [],
|
|
51
|
+
unknown: 1,
|
|
52
|
+
omitted: 0,
|
|
53
|
+
};
|
|
54
|
+
const state = { members: [], unknown: 0 };
|
|
55
|
+
collectMembersAt(node, "", 0, state);
|
|
56
|
+
const members = [...new Set(state.members)].sort(compareCodePoints);
|
|
57
|
+
return {
|
|
58
|
+
status: "object-literal",
|
|
59
|
+
members: members.slice(0, maximum),
|
|
60
|
+
unknown: state.unknown,
|
|
61
|
+
omitted: Math.max(0, members.length - maximum),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const collectMembersAt = (object, prefix, depth, state) => {
|
|
65
|
+
if (depth >= 8) {
|
|
66
|
+
state.unknown += 1;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const property of object.properties) {
|
|
70
|
+
if (t.isSpreadElement(property)) {
|
|
71
|
+
state.unknown += 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const name = propertyName(property.key);
|
|
75
|
+
if (name === "" || property.computed) {
|
|
76
|
+
state.unknown += 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const path = (prefix === "" ? name : `${prefix}.${name}`).slice(0, MAX_EXPRESSION_CHARACTERS);
|
|
80
|
+
state.members.push(path);
|
|
81
|
+
if (t.isObjectProperty(property) && t.isObjectExpression(property.value))
|
|
82
|
+
collectMembersAt(property.value, path, depth + 1, state);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const literalValue = (node) => {
|
|
86
|
+
if (t.isStringLiteral(node) || t.isNumericLiteral(node))
|
|
87
|
+
return { found: true, value: node.value };
|
|
88
|
+
if (t.isBooleanLiteral(node))
|
|
89
|
+
return { found: true, value: node.value };
|
|
90
|
+
if (t.isNullLiteral(node))
|
|
91
|
+
return { found: true, value: null };
|
|
92
|
+
if (t.isTemplateLiteral(node) && node.expressions.length === 0)
|
|
93
|
+
return {
|
|
94
|
+
found: true,
|
|
95
|
+
value: (node.quasis[0]?.value.cooked ??
|
|
96
|
+
node.quasis[0]?.value.raw ??
|
|
97
|
+
"").slice(0, MAX_EXPRESSION_CHARACTERS),
|
|
98
|
+
};
|
|
99
|
+
if (t.isUnaryExpression(node, { operator: "-" }) &&
|
|
100
|
+
t.isNumericLiteral(node.argument))
|
|
101
|
+
return { found: true, value: -node.argument.value };
|
|
102
|
+
return { found: false };
|
|
103
|
+
};
|