rea-agents 1.7.0 → 2.1.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 +112 -59
- package/bridge/ghidra/ReaGhidraBridge.java +96 -11
- package/dist/application/ArtifactExtraction.js +1 -1
- package/dist/application/ArtifactInventory/classify.js +42 -0
- package/dist/application/ArtifactInventory/hash.js +43 -0
- package/dist/application/ArtifactInventory/reader.js +41 -0
- package/dist/application/ArtifactInventory/scanCanonical.js +155 -0
- package/dist/application/ArtifactInventory/scanReader.js +124 -0
- package/dist/application/ArtifactInventory/types.js +10 -0
- package/dist/application/ArtifactInventory.js +9 -351
- package/dist/application/AuthorizedArtifactInventory.js +2 -2
- package/dist/application/BinarySession.js +47 -270
- package/dist/application/BinarySessionExecution.js +28 -0
- package/dist/application/BinarySessionOpen.js +39 -0
- package/dist/application/BinarySessionRecords.js +149 -0
- package/dist/application/BinarySessionStatus.js +75 -0
- package/dist/application/CapabilityInventory.js +42 -2
- package/dist/application/ClientRegistrationStatus.js +1 -1
- package/dist/application/CrossVersionInventory.js +8 -2
- package/dist/application/CrossVersionInvestigation.js +11 -29
- package/dist/application/CrossVersionInvestigationCollections.js +23 -0
- package/dist/application/DirectAnalysis.js +47 -44
- package/dist/application/Doctor.js +165 -197
- package/dist/application/DoctorDiagnostics.js +180 -0
- package/dist/application/ElectronBoundaryAnalysis.js +112 -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 +223 -0
- package/dist/application/EnhancedToolPagination.js +22 -0
- package/dist/application/EnhancedToolTypes.js +4 -0
- package/dist/application/EnhancedTools.js +58 -50
- package/dist/application/InstrumentedJavaScriptReplayHost.js +36 -0
- package/dist/application/InvestigationProviders.js +30 -0
- package/dist/application/InvestigationWorkspaceStore.js +24 -10
- 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 +52 -7
- package/dist/application/JavaScriptArtifactFiles.js +6 -2
- package/dist/application/JavaScriptArtifactGraphBuilder.js +82 -17
- package/dist/application/JavaScriptArtifactGraphBundlers.js +225 -0
- package/dist/application/JavaScriptArtifactGraphContext.js +37 -36
- package/dist/application/JavaScriptArtifactGraphDocuments.js +27 -4
- package/dist/application/JavaScriptArtifactGraphEvidence.js +24 -14
- package/dist/application/JavaScriptArtifactGraphFindings.js +54 -8
- package/dist/application/JavaScriptArtifactGraphStructure.js +29 -101
- package/dist/application/JavaScriptArtifactPathResolution.js +269 -0
- package/dist/application/JavaScriptArtifactReconstruction.js +4 -1
- package/dist/application/JavaScriptArtifactReconstructionInput.js +2 -83
- package/dist/application/JavaScriptJsonModules.js +39 -0
- package/dist/application/JavaScriptModuleRelationships.js +262 -0
- package/dist/application/JavaScriptReplayPermission.js +16 -0
- package/dist/application/JavaScriptReplayPlanning.js +201 -0
- package/dist/application/JavaScriptReplayService.js +292 -0
- package/dist/application/JavaScriptRuntimeReconciliationEvidence.js +25 -0
- package/dist/application/JavaScriptRuntimeReconciliationService.js +27 -0
- package/dist/application/LinuxHopper.js +10 -0
- package/dist/application/MacHopper.js +22 -11
- 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/NodeRuntimeCharacterizationService.js +196 -0
- package/dist/application/PermissionAuthority.js +106 -63
- package/dist/application/ProcessCaptureCapability.js +1 -1
- package/dist/application/ProcessCapturePermission.js +13 -0
- package/dist/application/ProcessCli.js +2 -12
- package/dist/application/ProcessHarness.js +1 -1
- package/dist/application/ProcessSampling.js +15 -11
- package/dist/application/ProjectPermissionStore.js +49 -9
- package/dist/application/RealHopperAssertions.js +76 -0
- package/dist/application/ReconstructionCoverageService.js +69 -0
- package/dist/application/ReconstructionCoverageWorkspaceStore.js +31 -0
- package/dist/application/RuntimeExecutableDiagnostics.js +172 -0
- package/dist/application/Setup.js +147 -259
- package/dist/application/SetupClientConfiguration.js +220 -0
- package/dist/application/SetupClients.js +24 -2
- package/dist/application/SetupPlan.js +123 -12
- package/dist/application/SetupSkill.js +26 -12
- package/dist/application/SupportedClients.js +1 -0
- package/dist/application/Uninstall.js +6 -3
- package/dist/application/WindowsCapabilities.js +86 -0
- package/dist/application/runtime.js +2 -0
- package/dist/artifacts/AsarArtifactReader.js +11 -0
- package/dist/browser/BrowserProcessStartup.js +88 -0
- package/dist/browser/CdpCaptureDocuments.js +12 -8
- package/dist/browser/CdpCaptureEventBodyShapes.js +75 -0
- package/dist/browser/CdpCaptureEventHandlers.js +336 -0
- package/dist/browser/CdpCaptureEventHelpers.js +71 -0
- package/dist/browser/CdpCaptureEventState.js +1 -0
- package/dist/browser/CdpCaptureEventTypes.js +1 -0
- package/dist/browser/CdpCaptureEvents.js +46 -464
- package/dist/browser/CdpElectronInspection.js +106 -162
- package/dist/browser/CdpElectronProvider.js +5 -1
- package/dist/browser/CdpElectronScriptEvents.js +69 -0
- package/dist/browser/CdpElectronScripts.js +94 -0
- package/dist/browser/CdpElectronWorkers.js +56 -0
- package/dist/browser/CdpObservationSession.js +51 -8
- package/dist/browser/CdpPageCapture.js +12 -129
- package/dist/browser/CdpPageCaptureScripts.js +97 -0
- package/dist/browser/CdpPageCaptureWorkers.js +46 -0
- package/dist/browser/CdpWebMcpDiscovery.js +38 -14
- package/dist/browser/PngVisualDiff.js +9 -2
- package/dist/catalogIdentity.js +8 -1
- package/dist/cli/artifactCommands.js +82 -0
- package/dist/cli/coreAnalysisCommands.js +232 -0
- package/dist/cli/managedCommands.js +397 -0
- package/dist/cli/managedProjectGraphCommand.js +24 -0
- package/dist/cli/options.js +9 -0
- package/dist/cli/setupCommands.js +108 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/utilityCommands.js +122 -0
- package/dist/cli.js +13 -383
- package/dist/cliApplicationCommands.js +176 -0
- package/dist/cliBrowserAdvancedCommands.js +73 -16
- package/dist/cliBrowserCommands.js +39 -115
- package/dist/cliCommandNames.js +17 -0
- package/dist/cliElectronCommands.js +100 -27
- package/dist/cliEvidenceCommands.js +13 -2
- package/dist/cliInvestigationCommands.js +53 -10
- package/dist/cliJsonInput.js +54 -0
- package/dist/cliObservationOptions.js +137 -0
- package/dist/cliPolicyCommands.js +80 -46
- package/dist/cliSetup.js +289 -0
- package/dist/config/environment.js +107 -0
- package/dist/config/parseConfig.js +228 -0
- package/dist/config/parsers.js +68 -0
- package/dist/config/permissions.js +30 -0
- package/dist/config/types.js +1 -0
- package/dist/config.js +1 -292
- package/dist/contracts/applicationToolContracts.js +225 -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/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 +2 -0
- package/dist/contracts/toolContractExamples.js +10 -25
- package/dist/contracts/toolContracts.js +49 -47
- package/dist/contracts/toolEffects.js +174 -0
- package/dist/contracts/toolOutputSchemaGroups.js +232 -0
- package/dist/contracts/toolOutputSchemaPrimitives.js +327 -0
- package/dist/contracts/toolOutputSchemas.js +2 -535
- package/dist/doctorRuntime.js +42 -1
- package/dist/domain/analysisErrorPresentation.js +234 -0
- package/dist/domain/analysisErrorProjection.js +284 -0
- package/dist/domain/artifactComparison.js +37 -19
- package/dist/domain/binaryTarget.js +87 -37
- package/dist/domain/browserObservation.js +1 -282
- package/dist/domain/browserObservationSchemas.js +286 -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 +206 -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 +32 -448
- package/dist/domain/functionComparison.js +4 -165
- package/dist/domain/functionComparisonDimensions.js +164 -0
- package/dist/domain/functionComparisonSchemas.js +3 -8
- package/dist/domain/inputIssueProjection.js +52 -0
- package/dist/domain/javascriptApplicationAnalysis.js +155 -0
- package/dist/domain/javascriptApplicationChangeGraph.js +231 -0
- package/dist/domain/javascriptApplicationEvidenceSchemas.js +18 -0
- package/dist/domain/javascriptApplicationGraph.js +2 -1
- package/dist/domain/javascriptApplicationGraphSchemas.js +7 -0
- package/dist/domain/javascriptApplicationVersionComparison.js +116 -0
- package/dist/domain/javascriptApplicationVersionComparisonSchemas.js +139 -0
- package/dist/domain/javascriptApplicationVersionItems.js +233 -0
- package/dist/domain/javascriptApplicationVersionKeys.js +170 -0
- package/dist/domain/javascriptExportInstrumentation.js +97 -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 +100 -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 +193 -0
- package/dist/domain/javascriptSemanticAnalysis.js +386 -0
- package/dist/domain/javascriptSemanticIr.js +30 -0
- package/dist/domain/javascriptSemanticProjection.js +366 -0
- package/dist/domain/javascriptSemanticState.js +40 -0
- package/dist/domain/javascriptSemanticTraversal.js +22 -0
- package/dist/domain/javascriptSemanticValues.js +352 -0
- package/dist/domain/javascriptStaticAnalysis.js +26 -254
- package/dist/domain/javascriptStaticAnalysisBundler.js +209 -0
- package/dist/domain/javascriptStaticAnalysisCalls.js +180 -0
- package/dist/domain/javascriptStaticAnalysisFindings.js +39 -0
- package/dist/domain/javascriptStaticAnalysisHelpers.js +81 -2
- package/dist/domain/javascriptStaticAnalysisState.js +6 -0
- package/dist/domain/knownPageCoverage.js +21 -0
- package/dist/domain/managedApplicationGraph.js +206 -0
- package/dist/domain/managedApplicationGraphCoverage.js +170 -0
- package/dist/domain/managedApplicationGraphNodeCoverage.js +6 -0
- package/dist/domain/managedApplicationGraphNodes.js +336 -0
- package/dist/domain/managedArtifact.js +452 -0
- package/dist/domain/managedMemberComparison.js +211 -0
- package/dist/domain/managedMemberComparisonCoverage.js +72 -0
- package/dist/domain/managedMemberComparisonMatch.js +356 -0
- package/dist/domain/managedNativeVerification.js +46 -0
- package/dist/domain/managedNativeVerificationMatch.js +272 -0
- package/dist/domain/managedNativeVerificationSchemas.js +141 -0
- package/dist/domain/managedReconstruction.js +196 -0
- package/dist/domain/managedRuntimeCorrelation.js +184 -0
- package/dist/domain/nodeRuntimeCharacterization.js +66 -0
- package/dist/domain/permissionPolicy.js +2 -0
- package/dist/domain/reconstructionCoverage.js +387 -0
- package/dist/domain/reconstructionCoverageEvaluation.js +212 -0
- package/dist/domain/reconstructionVerificationSchemas.js +9 -3
- package/dist/domain/runtimeCharacterization.js +85 -0
- package/dist/domain/webBundleAnalyzer.js +3 -409
- package/dist/domain/webBundleAnalyzerAst.js +77 -0
- package/dist/domain/webBundleAnalyzerInspection.js +307 -0
- package/dist/domain/webBundleAnalyzerResult.js +120 -0
- package/dist/dotnet/ManagedArtifactInspector.js +339 -0
- package/dist/dotnet/ManagedMemberInspector.js +153 -0
- package/dist/dotnet/ManagedMemberInspectorCore.js +297 -0
- package/dist/dotnet/ManagedMemberInstructionDecoder.js +427 -0
- package/dist/dotnet/ManagedMemberRows.js +120 -0
- package/dist/dotnet/ManagedMetadataHeaps.js +131 -0
- package/dist/dotnet/ManagedMetadataInventory.js +104 -0
- package/dist/dotnet/ManagedMetadataInventoryRows.js +292 -0
- package/dist/dotnet/ManagedMetadataLayout.js +259 -0
- package/dist/dotnet/ManagedMetadataRowSizes.js +54 -0
- package/dist/dotnet/ManagedMethodBodyReader.js +143 -0
- package/dist/dotnet/ManagedNativeBoundaryHelpers.js +311 -0
- package/dist/dotnet/ManagedNativeBoundaryInspector.js +143 -0
- package/dist/dotnet/ManagedPeReader.js +188 -0
- package/dist/dotnet/ManagedReaderFailure.js +10 -0
- package/dist/dotnet/ManagedStaticProvider.js +203 -0
- package/dist/generatedPackageMetadata.js +2 -2
- package/dist/ghidra/GhidraClient.js +76 -91
- package/dist/ghidra/GhidraClientStartup.js +29 -0
- package/dist/ghidra/GhidraClientWire.js +34 -0
- package/dist/ghidra/GhidraDefaults.js +1 -1
- package/dist/ghidra/GhidraDiagnostics.js +6 -1
- package/dist/ghidra/GhidraInstallation.js +20 -15
- package/dist/ghidra/GhidraLauncher.js +93 -29
- package/dist/ghidra/GhidraProvider.js +67 -161
- package/dist/ghidra/GhidraProviderCapabilities.js +173 -0
- package/dist/ghidra/GhidraSessionValues.js +2 -0
- package/dist/ghidra/GhidraSocketConnection.js +44 -7
- package/dist/ghidra/GhidraTargetSnapshot.js +30 -0
- package/dist/ghidra/GhidraTransport.js +71 -0
- package/dist/identity.js +3 -2
- package/dist/main/messages.js +5 -0
- package/dist/main/reload.js +49 -0
- package/dist/main/shutdown.js +25 -0
- package/dist/main/startup.js +14 -0
- package/dist/main/state.js +26 -0
- package/dist/main/transport.js +61 -0
- package/dist/main/types.js +1 -0
- package/dist/main.js +35 -132
- package/dist/process/PrivateRuntimeRoot.js +3 -2
- package/dist/process/ProcessOwnership.js +35 -0
- package/dist/process/ProviderProcess.js +2 -0
- package/dist/replay/JavaScriptReplayWorker.js +300 -0
- package/dist/replay/LinuxJavaScriptReplayRunner.js +217 -0
- package/dist/replay/LinuxJavaScriptReplaySandbox.js +140 -0
- package/dist/replay/LinuxRuntimeClosure.js +46 -0
- package/dist/replay/LinuxSeccompPolicy.js +40 -0
- package/dist/replay/ReplayOutcome.js +95 -0
- package/dist/replay/ReplayProcessLifecycle.js +71 -0
- package/dist/replay/ReplayWorkerProtocol.js +55 -0
- package/dist/replay/SystemJavaScriptReplayHost.js +182 -0
- package/dist/server/ProcessCaptureElicitation.js +157 -0
- package/dist/server/createServer.js +158 -41
- package/dist/server/registerApplicationTools/characterization.js +57 -0
- package/dist/server/registerApplicationTools/compareVersions.js +34 -0
- package/dist/server/registerApplicationTools/controlledReplay.js +38 -0
- package/dist/server/registerApplicationTools/coverage.js +84 -0
- package/dist/server/registerApplicationTools/helpers.js +42 -0
- package/dist/server/registerApplicationTools/traceFeature.js +26 -0
- package/dist/server/registerApplicationTools/types.js +1 -0
- package/dist/server/registerApplicationTools.js +13 -0
- package/dist/server/registerArtifactComparisonTool.js +16 -9
- package/dist/server/registerBrowserTools.js +61 -60
- package/dist/server/registerBundleComparisonTool.js +17 -20
- package/dist/server/registerElectronTools.js +39 -12
- package/dist/server/registerEnhancedTools.js +52 -15
- package/dist/server/registerEvidenceResources.js +54 -0
- package/dist/server/registerEvidenceTools.js +5 -1
- package/dist/server/registerFunctionComparisonTool.js +14 -7
- package/dist/server/registerInvestigationTools/helpers.js +74 -0
- package/dist/server/registerInvestigationTools/types.js +1 -0
- package/dist/server/registerInvestigationTools.js +103 -132
- package/dist/server/registerManagedTools.js +6 -0
- package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +65 -0
- package/dist/server/registerManagedWorkflowTools/contract.js +8 -0
- package/dist/server/registerManagedWorkflowTools/evidence.js +43 -0
- package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +39 -0
- package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +39 -0
- package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +52 -0
- package/dist/server/registerManagedWorkflowTools/types.js +1 -0
- package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +75 -0
- package/dist/server/registerManagedWorkflowTools.js +13 -0
- package/dist/server/registerOfficialTools.js +81 -67
- package/dist/server/registerProcessComparisonTool.js +25 -47
- package/dist/server/registerSessionRecordTools.js +137 -0
- package/dist/server/registerSessionStatusTool.js +9 -8
- package/dist/server/registerSessionTools.js +77 -216
- package/dist/server/sessionAvailabilityPolicy.js +10 -0
- package/dist/server/sessionEvidence.js +14 -19
- package/dist/server/toolInputValidation.js +77 -0
- package/dist/server/toolRegistrationOptions.js +177 -2
- package/dist/server/toolResult.js +30 -17
- package/package.json +21 -14
- package/scripts/rea.mjs +1 -1
- package/skills/{rea-analysis → reverse-engineer-anything}/SKILL.md +75 -6
- package/scripts/prepare-node-pty.mjs +0 -35
- package/scripts/rebuild-native.mjs +0 -22
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import { addAstContainsEdge, artifactLocalIdentity, } from "./JavaScriptArtifactGraphContext.js";
|
|
3
|
+
import { astObservationEvidence, completeReconstructionCoverage, partialReconstructionCoverage, staticInferenceEvidence, } from "./JavaScriptArtifactGraphEvidence.js";
|
|
4
|
+
import { resolveArtifactPathByContext } from "./JavaScriptArtifactPathResolution.js";
|
|
5
|
+
/** Create one path-scoped source-module identity for every analyzed source file. */
|
|
6
|
+
export const addJavaScriptSourceModules = (context) => {
|
|
7
|
+
for (const analyzed of context.analysis.files) {
|
|
8
|
+
const { file, semantic } = analyzed;
|
|
9
|
+
const asset = context.assetNodes.get(file.path);
|
|
10
|
+
const program = semantic?.ir.scopes.find(({ kind }) => kind === "program");
|
|
11
|
+
if (asset === undefined || semantic === null || program === undefined)
|
|
12
|
+
continue;
|
|
13
|
+
const exports = semantic.ir.moduleLinks
|
|
14
|
+
.flatMap(({ exportedName }) => exportedName === null ? [] : [exportedName])
|
|
15
|
+
.sort(compareCodePoints);
|
|
16
|
+
const retainedExports = [...new Set(exports)].slice(0, 128);
|
|
17
|
+
const source = context.accumulator.addNode({
|
|
18
|
+
kind: "javascript-module",
|
|
19
|
+
identity: artifactLocalIdentity(file.sha256, "source-module", `${file.container_sha256}:${file.path}`),
|
|
20
|
+
observations: [
|
|
21
|
+
{
|
|
22
|
+
label: file.path,
|
|
23
|
+
properties: {
|
|
24
|
+
semantic_role: "source-module",
|
|
25
|
+
path: file.path,
|
|
26
|
+
container_sha256: file.container_sha256,
|
|
27
|
+
logical_module_key: file.path,
|
|
28
|
+
module_format: moduleFormat(file.path, semantic.ir),
|
|
29
|
+
import_relationships: semantic.ir.moduleLinks.filter(({ kind }) => kind === "import" || kind === "require").length,
|
|
30
|
+
export_relationships: exports.length,
|
|
31
|
+
export_names: retainedExports,
|
|
32
|
+
omitted_export_names: Math.max(0, exports.length - retainedExports.length),
|
|
33
|
+
},
|
|
34
|
+
evidence: astObservationEvidence({
|
|
35
|
+
sha256: file.sha256,
|
|
36
|
+
path: file.path,
|
|
37
|
+
range: program.location,
|
|
38
|
+
operation: "recover-source-module",
|
|
39
|
+
coverage: semanticCoverage(semantic),
|
|
40
|
+
limitations: semantic.ir.limitations,
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
context.sourceModuleNodes.set(file.path, source);
|
|
46
|
+
addAstContainsEdge(context, {
|
|
47
|
+
source: asset,
|
|
48
|
+
target: source,
|
|
49
|
+
file,
|
|
50
|
+
range: program.location,
|
|
51
|
+
coverage: semanticCoverage(semantic),
|
|
52
|
+
properties: { logical_module_key: file.path },
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/** Compose bounded CommonJS and ESM binding relationships across artifact files. */
|
|
57
|
+
export const addJavaScriptModuleRelationships = (context) => {
|
|
58
|
+
for (const analyzed of context.analysis.files) {
|
|
59
|
+
const { file, semantic } = analyzed;
|
|
60
|
+
const source = context.sourceModuleNodes.get(file.path);
|
|
61
|
+
if (semantic === null || source === undefined)
|
|
62
|
+
continue;
|
|
63
|
+
for (const link of semantic.ir.moduleLinks) {
|
|
64
|
+
const input = { context, file, semantic, source, link };
|
|
65
|
+
if (isExportLink(link))
|
|
66
|
+
addExportRelationship(input);
|
|
67
|
+
else if (link.specifier !== null)
|
|
68
|
+
addImportRelationship(input, source, {
|
|
69
|
+
specifier: link.specifier,
|
|
70
|
+
importedPath: link.importedName === null ? [] : [link.importedName],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const addExportRelationship = (input) => {
|
|
76
|
+
const { context, file, semantic, source, link } = input;
|
|
77
|
+
if (link.exportedName === null)
|
|
78
|
+
return;
|
|
79
|
+
const exported = context.accumulator.addNode({
|
|
80
|
+
kind: "javascript-module",
|
|
81
|
+
identity: artifactLocalIdentity(file.sha256, "module-export", `${file.container_sha256}:${file.path}:${link.exportedName}`),
|
|
82
|
+
observations: [
|
|
83
|
+
{
|
|
84
|
+
label: `${file.path}:${link.exportedName}`,
|
|
85
|
+
properties: {
|
|
86
|
+
semantic_role: "export-binding",
|
|
87
|
+
module_path: file.path,
|
|
88
|
+
relationship_kind: link.kind,
|
|
89
|
+
exported_name: link.exportedName,
|
|
90
|
+
local_name: link.localName,
|
|
91
|
+
imported_name: link.importedName,
|
|
92
|
+
declared_specifier: link.specifier,
|
|
93
|
+
},
|
|
94
|
+
evidence: astObservationEvidence({
|
|
95
|
+
sha256: file.sha256,
|
|
96
|
+
path: file.path,
|
|
97
|
+
range: link.location,
|
|
98
|
+
operation: "recover-module-export",
|
|
99
|
+
coverage: semanticCoverage(semantic),
|
|
100
|
+
limitations: semantic.ir.limitations,
|
|
101
|
+
}),
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
context.accumulator.addEdge({
|
|
106
|
+
source_node_id: source.node_id,
|
|
107
|
+
target_node_id: exported.node_id,
|
|
108
|
+
relation: "exposes",
|
|
109
|
+
properties: relationshipProperties(link, null),
|
|
110
|
+
evidence: relationshipEvidence(input, "expose-module-export", []),
|
|
111
|
+
});
|
|
112
|
+
const origin = moduleOriginForExport(semantic.ir, link);
|
|
113
|
+
if (origin !== null)
|
|
114
|
+
addImportRelationship(input, exported, origin);
|
|
115
|
+
};
|
|
116
|
+
const addImportRelationship = (input, source, origin) => {
|
|
117
|
+
const target = resolveModuleTarget(input, origin.specifier);
|
|
118
|
+
input.context.accumulator.addEdge({
|
|
119
|
+
source_node_id: source.node_id,
|
|
120
|
+
target_node_id: target.node.node_id,
|
|
121
|
+
relation: "imports",
|
|
122
|
+
properties: relationshipProperties(input.link, target, origin),
|
|
123
|
+
evidence: relationshipEvidence(input, "resolve-semantic-module-relationship", target.limitations, target.status === "resolved"
|
|
124
|
+
? "high"
|
|
125
|
+
: target.status === "external"
|
|
126
|
+
? "medium"
|
|
127
|
+
: "low"),
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const resolveModuleTarget = (input, specifier) => {
|
|
131
|
+
const resolution = resolveArtifactPathByContext({
|
|
132
|
+
declaredPath: specifier,
|
|
133
|
+
sourcePath: input.file.path,
|
|
134
|
+
context: "module-specifier",
|
|
135
|
+
files: input.context.filesByPath,
|
|
136
|
+
moduleKind: input.link.kind === "require" || input.link.kind === "commonjs-export"
|
|
137
|
+
? "require"
|
|
138
|
+
: "import",
|
|
139
|
+
});
|
|
140
|
+
const path = resolution.resolved_path;
|
|
141
|
+
const file = path === null ? undefined : input.context.filesByPath.get(path);
|
|
142
|
+
const node = path === null
|
|
143
|
+
? undefined
|
|
144
|
+
: (input.context.sourceModuleNodes.get(path) ??
|
|
145
|
+
input.context.fileNodes.get(path));
|
|
146
|
+
if (path !== null && file !== undefined && node !== undefined)
|
|
147
|
+
return {
|
|
148
|
+
node,
|
|
149
|
+
path,
|
|
150
|
+
file,
|
|
151
|
+
status: "resolved",
|
|
152
|
+
limitations: resolution.limitations,
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
node: unresolvedModuleNode(input, specifier, resolution.resolution_status),
|
|
156
|
+
path: null,
|
|
157
|
+
file: null,
|
|
158
|
+
status: resolution.resolution_status,
|
|
159
|
+
limitations: resolution.limitations,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const unresolvedModuleNode = (input, specifier, status) => input.context.accumulator.addNode({
|
|
163
|
+
kind: "javascript-module",
|
|
164
|
+
identity: artifactLocalIdentity(input.file.sha256, "unresolved-semantic-module", `${status}:${specifier}`),
|
|
165
|
+
observations: [
|
|
166
|
+
{
|
|
167
|
+
label: specifier,
|
|
168
|
+
properties: {
|
|
169
|
+
semantic_role: "module-reference",
|
|
170
|
+
declared_specifier: specifier,
|
|
171
|
+
resolution_status: status,
|
|
172
|
+
},
|
|
173
|
+
evidence: staticInferenceEvidence({
|
|
174
|
+
sha256: input.file.sha256,
|
|
175
|
+
path: input.file.path,
|
|
176
|
+
range: input.link.location,
|
|
177
|
+
operation: "retain-unresolved-semantic-module",
|
|
178
|
+
coverage: semanticCoverage(input.semantic),
|
|
179
|
+
confidence: "low",
|
|
180
|
+
limitations: input.semantic.ir.limitations,
|
|
181
|
+
}),
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
const moduleOriginForExport = (ir, link) => {
|
|
186
|
+
if (link.specifier !== null)
|
|
187
|
+
return {
|
|
188
|
+
specifier: link.specifier,
|
|
189
|
+
importedPath: link.importedName === null ? [] : [link.importedName],
|
|
190
|
+
};
|
|
191
|
+
if (link.localName === null)
|
|
192
|
+
return null;
|
|
193
|
+
const program = ir.scopes.find(({ kind }) => kind === "program");
|
|
194
|
+
const binding = ir.bindings.find(({ name, scopeId }) => name === link.localName && scopeId === program?.scopeId);
|
|
195
|
+
return binding?.provenance.status === "module" &&
|
|
196
|
+
binding.provenance.origins.length === 1
|
|
197
|
+
? (binding.provenance.origins[0] ?? null)
|
|
198
|
+
: null;
|
|
199
|
+
};
|
|
200
|
+
const relationshipProperties = (link, target, origin) => ({
|
|
201
|
+
module_link_kind: link.kind,
|
|
202
|
+
specifier: origin?.specifier ?? link.specifier,
|
|
203
|
+
imported_name: origin?.importedPath.at(-1) ?? link.importedName,
|
|
204
|
+
imported_path: origin?.importedPath ?? [],
|
|
205
|
+
local_name: link.localName,
|
|
206
|
+
exported_name: link.exportedName,
|
|
207
|
+
resolved_path: target?.path ?? null,
|
|
208
|
+
resolution_status: target?.status ?? null,
|
|
209
|
+
target_file_kind: target?.file?.kind ?? null,
|
|
210
|
+
target_json_status: target?.file?.kind === "json" ? jsonStatus(target.file) : null,
|
|
211
|
+
});
|
|
212
|
+
const relationshipEvidence = (input, operation, limitations, confidence = "high") => staticInferenceEvidence({
|
|
213
|
+
sha256: input.file.sha256,
|
|
214
|
+
path: input.file.path,
|
|
215
|
+
range: input.link.location,
|
|
216
|
+
operation,
|
|
217
|
+
coverage: semanticCoverage(input.semantic),
|
|
218
|
+
confidence,
|
|
219
|
+
limitations: [...input.semantic.ir.limitations, ...limitations],
|
|
220
|
+
});
|
|
221
|
+
const semanticCoverage = (semantic) => {
|
|
222
|
+
const limits = Object.entries(semantic.limits).map(([name, value]) => ({
|
|
223
|
+
name: `semantic-${camelToKebab(name)}`,
|
|
224
|
+
value,
|
|
225
|
+
unit: "items",
|
|
226
|
+
}));
|
|
227
|
+
if (semantic.ir.coverage.status === "complete")
|
|
228
|
+
return completeReconstructionCoverage(limits);
|
|
229
|
+
return partialReconstructionCoverage(limits, semantic.ir.coverage.omittedCount, semantic.ir.coverage.status === "truncated");
|
|
230
|
+
};
|
|
231
|
+
const moduleFormat = (path, ir) => {
|
|
232
|
+
const extension = posix.extname(path).toLowerCase();
|
|
233
|
+
if (extension === ".mjs")
|
|
234
|
+
return "esm";
|
|
235
|
+
if (extension === ".cjs")
|
|
236
|
+
return "commonjs";
|
|
237
|
+
const esm = ir.moduleLinks.some(({ kind }) => ["import", "export", "re-export"].includes(kind));
|
|
238
|
+
const commonJs = ir.moduleLinks.some(({ kind }) => ["require", "commonjs-export"].includes(kind));
|
|
239
|
+
return esm && commonJs
|
|
240
|
+
? "mixed"
|
|
241
|
+
: esm
|
|
242
|
+
? "esm"
|
|
243
|
+
: commonJs
|
|
244
|
+
? "commonjs"
|
|
245
|
+
: "unknown";
|
|
246
|
+
};
|
|
247
|
+
const jsonStatus = (file) => {
|
|
248
|
+
if (!file.text.included)
|
|
249
|
+
return "unavailable";
|
|
250
|
+
try {
|
|
251
|
+
JSON.parse(file.text.value);
|
|
252
|
+
return "included";
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return "invalid";
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
const isExportLink = (link) => link.kind === "export" ||
|
|
259
|
+
link.kind === "re-export" ||
|
|
260
|
+
link.kind === "commonjs-export";
|
|
261
|
+
const camelToKebab = (value) => value.replaceAll(/([a-z])([A-Z])/gu, "$1-$2").toLowerCase();
|
|
262
|
+
const compareCodePoints = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Build the exact permission request for one controlled replay operation. */
|
|
2
|
+
export const replayPermissionRequest = (input, policy) => ({
|
|
3
|
+
capability: "javascript_replay",
|
|
4
|
+
roots: [...input.left.modules, ...(input.right?.modules ?? [])].map(({ path }) => path),
|
|
5
|
+
executables: [
|
|
6
|
+
policy.nodePath,
|
|
7
|
+
policy.bubblewrapPath,
|
|
8
|
+
policy.systemdRunPath,
|
|
9
|
+
policy.systemctlPath,
|
|
10
|
+
policy.shellPath,
|
|
11
|
+
],
|
|
12
|
+
environment_names: [],
|
|
13
|
+
network: "none",
|
|
14
|
+
mount: true,
|
|
15
|
+
operation_identity: `run_controlled_replay:${input.plan_digest ?? "plan"}`,
|
|
16
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import canonicalize from "canonicalize";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
const REPLAY_POLICY_VERSION = "linux-bwrap-systemd-v1";
|
|
4
|
+
const REPLAY_POLICY_DOCUMENT = Object.freeze({
|
|
5
|
+
version: REPLAY_POLICY_VERSION,
|
|
6
|
+
namespaces: ["user", "pid", "network", "ipc", "uts", "cgroup"],
|
|
7
|
+
capabilities: "drop-all",
|
|
8
|
+
network: "none",
|
|
9
|
+
filesystem: "minimal-read-only-runtime-plus-private-tmpfs",
|
|
10
|
+
seccomp: "rea-linux-x86_64-v1",
|
|
11
|
+
resource_manager: "systemd-user-cgroup-v2",
|
|
12
|
+
nested_user_namespaces: false,
|
|
13
|
+
});
|
|
14
|
+
/** Read, normalize, and content-address every input to one replay experiment. */
|
|
15
|
+
export const prepareReplayPlan = async (input, policy, host) => {
|
|
16
|
+
const cases = replayCases(input).map((item) => ({
|
|
17
|
+
...item,
|
|
18
|
+
sha256: digestJson(item.arguments),
|
|
19
|
+
}));
|
|
20
|
+
if (new TextEncoder().encode(JSON.stringify(cases.map(({ arguments: args }) => args))).byteLength > input.limits.input_bytes)
|
|
21
|
+
throw new RangeError("Replay case inputs exceed the aggregate byte limit");
|
|
22
|
+
await host.probe(policy);
|
|
23
|
+
const [runtime, bubblewrap, systemdRun, systemctl, shell, worker, runtimeFiles, left, right,] = await Promise.all([
|
|
24
|
+
host.identifyExecutable(policy.nodePath, ["--version"]),
|
|
25
|
+
host.identifyExecutable(policy.bubblewrapPath, ["--version"]),
|
|
26
|
+
host.identifyExecutable(policy.systemdRunPath, ["--version"]),
|
|
27
|
+
host.identifyExecutable(policy.systemctlPath, ["--version"]),
|
|
28
|
+
host.identifyExecutable(policy.shellPath, ["--version"]),
|
|
29
|
+
host.identifyWorker(),
|
|
30
|
+
host.identifyRuntimeClosure(policy.nodePath),
|
|
31
|
+
prepareSide(input.left, input.limits.module_bytes, host),
|
|
32
|
+
input.right === undefined
|
|
33
|
+
? Promise.resolve(undefined)
|
|
34
|
+
: prepareSide(input.right, input.limits.module_bytes, host),
|
|
35
|
+
]);
|
|
36
|
+
const withoutDigest = {
|
|
37
|
+
schema_version: 1,
|
|
38
|
+
policy_version: REPLAY_POLICY_VERSION,
|
|
39
|
+
policy_sha256: digestJson(REPLAY_POLICY_DOCUMENT),
|
|
40
|
+
network: "none",
|
|
41
|
+
filesystem: {
|
|
42
|
+
host_writes: false,
|
|
43
|
+
private_tmpfs_bytes: input.limits.tmpfs_bytes,
|
|
44
|
+
},
|
|
45
|
+
runtime: {
|
|
46
|
+
executable: runtime,
|
|
47
|
+
worker,
|
|
48
|
+
read_only_files: runtimeFiles.map((item) => ({
|
|
49
|
+
source_path: item.sourcePath,
|
|
50
|
+
destination_path: item.destinationPath,
|
|
51
|
+
sha256: item.sha256,
|
|
52
|
+
})),
|
|
53
|
+
},
|
|
54
|
+
sandbox: {
|
|
55
|
+
bubblewrap,
|
|
56
|
+
systemd_run: systemdRun,
|
|
57
|
+
systemctl,
|
|
58
|
+
shell,
|
|
59
|
+
seccomp_sha256: host.seccompDigest(),
|
|
60
|
+
},
|
|
61
|
+
left: left.commitment,
|
|
62
|
+
...(right === undefined ? {} : { right: right.commitment }),
|
|
63
|
+
cases,
|
|
64
|
+
determinism: input.determinism,
|
|
65
|
+
limits: input.limits,
|
|
66
|
+
effects: [
|
|
67
|
+
"Execute selected extracted modules in a disposable Linux OS sandbox",
|
|
68
|
+
"Create and remove one private cgroup and mount namespace",
|
|
69
|
+
"Retain bounded return, exception, termination, and diagnostic evidence",
|
|
70
|
+
"Perform no host filesystem writes and expose no host or external network",
|
|
71
|
+
...(input.reproducer_export === undefined
|
|
72
|
+
? []
|
|
73
|
+
: ["Write one separately approved reproducer after sandbox cleanup"]),
|
|
74
|
+
],
|
|
75
|
+
reproducer_export: input.reproducer_export === undefined
|
|
76
|
+
? null
|
|
77
|
+
: {
|
|
78
|
+
path: input.reproducer_export.path,
|
|
79
|
+
include_sources: input.reproducer_export.include_sources,
|
|
80
|
+
authority: "evidence_write",
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const publicPlan = {
|
|
84
|
+
...withoutDigest,
|
|
85
|
+
plan_digest: digestJson(withoutDigest),
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
publicPlan,
|
|
89
|
+
leftSources: left.sources,
|
|
90
|
+
...(right === undefined ? {} : { rightSources: right.sources }),
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const prepareSide = async (side, maximumBytes, host) => {
|
|
94
|
+
const aliases = new Set(side.modules.map(({ alias }) => alias));
|
|
95
|
+
if (aliases.size !== side.modules.length || !aliases.has(side.entry_alias))
|
|
96
|
+
throw new TypeError("Replay manifest aliases or entry alias are invalid");
|
|
97
|
+
for (const module of side.modules)
|
|
98
|
+
for (const dependency of Object.values(module.dependencies))
|
|
99
|
+
if (!aliases.has(dependency))
|
|
100
|
+
throw new TypeError(`Undeclared replay dependency alias: ${dependency}`);
|
|
101
|
+
const loaded = [];
|
|
102
|
+
let totalBytes = 0;
|
|
103
|
+
for (const module of side.modules) {
|
|
104
|
+
const remaining = maximumBytes - totalBytes;
|
|
105
|
+
if (remaining <= 0)
|
|
106
|
+
throw new RangeError("Replay module bytes exceed the aggregate limit");
|
|
107
|
+
const source = await host.readSource(module.path, remaining);
|
|
108
|
+
totalBytes += source.bytes.byteLength;
|
|
109
|
+
loaded.push({ module, source });
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
commitment: {
|
|
113
|
+
modules: loaded.map(({ module, source }) => ({
|
|
114
|
+
alias: module.alias,
|
|
115
|
+
canonical_path: source.canonicalPath,
|
|
116
|
+
format: module.format,
|
|
117
|
+
role: module.role,
|
|
118
|
+
byte_count: source.bytes.byteLength,
|
|
119
|
+
sha256: digestBytes(source.bytes),
|
|
120
|
+
dependencies: module.dependencies,
|
|
121
|
+
})),
|
|
122
|
+
entry_alias: side.entry_alias,
|
|
123
|
+
entry_export: side.entry_export,
|
|
124
|
+
},
|
|
125
|
+
sources: Object.fromEntries(loaded.map(({ module, source }) => [
|
|
126
|
+
module.alias,
|
|
127
|
+
new TextDecoder("utf-8", { fatal: true }).decode(source.bytes),
|
|
128
|
+
])),
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
const replayCases = (input) => {
|
|
132
|
+
const explicit = input.cases.map((item) => ({
|
|
133
|
+
case_id: item.case_id,
|
|
134
|
+
arguments: item.arguments,
|
|
135
|
+
}));
|
|
136
|
+
if (input.generator === undefined)
|
|
137
|
+
return uniqueCases(explicit);
|
|
138
|
+
let state = input.generator.seed || 0x9e37_79b9;
|
|
139
|
+
const next = () => {
|
|
140
|
+
state ^= state << 13;
|
|
141
|
+
state ^= state >>> 17;
|
|
142
|
+
state ^= state << 5;
|
|
143
|
+
return state >>> 0;
|
|
144
|
+
};
|
|
145
|
+
const corpus = boundaryCorpus(input.generator.preset);
|
|
146
|
+
const generated = Array.from({ length: input.generator.count }, (_, index) => ({
|
|
147
|
+
case_id: `generated-${input.generator?.preset ?? "boundary"}-${String(index)}`,
|
|
148
|
+
arguments: [corpus[next() % corpus.length] ?? ""],
|
|
149
|
+
}));
|
|
150
|
+
return uniqueCases([...explicit, ...generated]);
|
|
151
|
+
};
|
|
152
|
+
const uniqueCases = (cases) => {
|
|
153
|
+
const ids = new Set();
|
|
154
|
+
for (const item of cases) {
|
|
155
|
+
if (ids.has(item.case_id))
|
|
156
|
+
throw new TypeError(`Duplicate replay case ID: ${item.case_id}`);
|
|
157
|
+
ids.add(item.case_id);
|
|
158
|
+
}
|
|
159
|
+
return cases;
|
|
160
|
+
};
|
|
161
|
+
const boundaryCorpus = (preset) => {
|
|
162
|
+
if (preset === "sanitizer-boundaries")
|
|
163
|
+
return [
|
|
164
|
+
"",
|
|
165
|
+
"<script>alert(1)</script>",
|
|
166
|
+
"<img src=x onerror=alert(1)>",
|
|
167
|
+
"javascript:alert(1)",
|
|
168
|
+
"<b>ok</b>",
|
|
169
|
+
"\u0000",
|
|
170
|
+
];
|
|
171
|
+
if (preset === "clipboard-boundaries")
|
|
172
|
+
return [
|
|
173
|
+
"",
|
|
174
|
+
"plain",
|
|
175
|
+
"a\r\nb",
|
|
176
|
+
"a\nb",
|
|
177
|
+
"\t",
|
|
178
|
+
"😀",
|
|
179
|
+
"text/html",
|
|
180
|
+
"text/plain",
|
|
181
|
+
];
|
|
182
|
+
return [
|
|
183
|
+
"",
|
|
184
|
+
" ",
|
|
185
|
+
"\n",
|
|
186
|
+
"# heading",
|
|
187
|
+
"**bold**",
|
|
188
|
+
"[x](javascript:y)",
|
|
189
|
+
"`code`",
|
|
190
|
+
"😀",
|
|
191
|
+
"\u0000",
|
|
192
|
+
"a".repeat(1024),
|
|
193
|
+
];
|
|
194
|
+
};
|
|
195
|
+
export const digestBytes = (value) => createHash("sha256").update(value).digest("hex");
|
|
196
|
+
export const digestJson = (value) => {
|
|
197
|
+
const encoded = canonicalize(value);
|
|
198
|
+
if (encoded === undefined)
|
|
199
|
+
throw new TypeError("Replay commitment is not canonical JSON");
|
|
200
|
+
return createHash("sha256").update(encoded).digest("hex");
|
|
201
|
+
};
|