Repository navigation
fix(electron): support packaged app.asar pages and rewritten unpacked companions - #1400
Merged
morluto merged 4 commits intoOct 10, 2026
Merged
Conversation
Packaged Electron applications load their renderer pages from file URLs inside app.asar. The host filesystem cannot stat those paths, so list_electron_targets excluded every such page as unsupported_url and inspect_electron_page could not select it. Resolve these URLs the way Electron's file protocol does: the first .asar path component that is a regular file is the archive, and the remainder must name a regular file in its header. Directories, links, and missing members stay rejected. Parsed headers are cached by archive identity.
Packaging tools commonly sign or strip .asar.unpacked native binaries after writing the archive header, so their declared hashes no longer match. analyze_javascript_application already accepts integrity_policy, but extract_artifact did not, and inspect_artifact and extract_artifact still told callers to "get a fresh copy", which cannot help for a shipped app. - Accept integrity_policy on extract_artifact (MCP and CLI). The default still fails closed; record-and-continue writes the observed bytes and returns the extracted files' integrity_contradictions records. - Name the unpacked entry and the post-packaging cause in integrity failures, and point every operation that accepts integrity_policy at record-and-continue. - Report an active unpacked entry whose companion file is absent as unavailable with its logical path instead of a format failure. - Share one integrity_policy schema across the inventory, extraction, and JavaScript application inputs.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
# Conflicts: # src/domain/analysisErrorPresentation.ts
Owner
|
Thanks @suninrain086 for improving packaged Electron support, including app.asar pages and rewritten unpacked companions! Squash merged with the review fixes. Welcome to REA, and thank you for your first PR to the repo. |
2 tasks done
Contributor
Author
|
Thank you @morluto , REA is a very powerful tool, and I hope to continue contributing more PRs. |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Using REA on a shipped macOS Electron application (Neat Reader 9.0.10, Electron 13.6.9) exposed two gaps in the packaged-app workflow:
file:///…/app.asar/…URLs.authorizedElectronFilestats the URL path on the host filesystem, which cannot resolve paths inside an archive. Solist_electron_targetsreportedtargets: []withexcluded.unsupported_url: 1, andinspect_electron_pagecould not select the page at all..asar.unpackedcompanion blocked extraction and gave the wrong advice. The app shipsnode_modules/font-list/libs/darwin/fontlistas an unpacked Mach-O that was code-signed after the ASAR header was written, so its declared SHA-256 no longer matches. 7915ee5 (feat(javascript): record Electron integrity mismatches) already letsanalyze_javascript_applicationcontinue past this.extract_artifactstill had nointegrity_policy, though, andinspect_artifact/extract_artifactstill said "Artifact is invalid or has changed. Get a fresh copy and try again." A fresh copy of a signed app has the same mismatch. Separately, extracting an archive whose unpacked companion file is missing was reported as aformatfailure ("not an extractable regular child file").No issue is linked: I hit both problems while reverse-engineering a real application and am reporting them here with the fix.
Problem and expected behavior
Packaged pages
file:///Applications/App.app/Contents/Resources/app.asar/build-app/index.html?x=0#/library.unsupported_url, and so were every script, frame, and resource loaded from the archive..asarpath component that is a regular file is the archive, and the remainder must name a regular file in its header (packed or unpacked). The reported path is the canonical archive path joined with that member.Rewritten unpacked companions
createPackageWithOptions(src, "app.asar", { unpack: "**/*.node" }), then rewrite the unpacked.nodefile (as macOS signing or distro stripping does) and runextract_artifact.record-and-continueexactly as forinspect_artifactandanalyze_javascript_application.unavailable, with its logical path.Change and scope
Two commits:
fix(electron): resolve pages served from inside app.asarsrc/browser/ElectronFileScope.ts: if the URL path is not a regular host file, walk its components to the first.asarcomponent that is a regular file. Then look the remainder up in the archive header through@electron/asar'sgetRawHeader.linkentries, missing members, and empty/./..segments are rejected.dev,ino,size,mtimeMs), with at most 8 entries, because one inspection authorizes every frame, script, and resource URL.list_electron_targets,inspect_electron_pageframes/scripts/resources/DOM, Electron workers, V8 Inspector runtime locations) goes through the same function, so all of them pick this up without further changes.fix(artifacts): extract and explain rewritten ASAR unpacked companionsextract_artifactacceptsintegrity_policy(MCP input andrea extract-artifact --integrity-policy). Withrecord-and-continueit writes the observed bytes. It returns the extracted files' canonicalintegrity_contradictionsrecords (the same schema the JavaScript application result uses), plus one summary limitation.analysisErrorPresentation: this generalizes the JavaScript-only message added in 7915ee5 to every operation that acceptsintegrity_policy(inventory_artifact/inspect_artifact,extract_artifact,analyze_javascript_application), naming the operation to rerun.analyze_javascript_applicationis unchanged.artifact_id: null,hash_status: "unavailable") now fails asunavailablewithartifactDetails(logical_path,unpacked: true) instead offormat. The message tells the caller to keep the.unpackeddirectory beside the archive.src/domain/artifactIntegrityPolicy.ts: one sharedintegrity_policyschema now replaces the three duplicated inline enums, and the new extraction input uses it too.Intentionally not included:
AsarArtifactReaderdocuments thatunpackedis not an integrity exemption, and existing tests rely on the fail-closed default. The caller still choosesrecord-and-continue.analyze_javascript_applicationoutput is not addressed. For this app it was about 830 MB of JSON; that deserves its own issue.Contract and boundary impact
ElectronFileScope(URL authorization, before any Electron observation);ArtifactExtraction(inventory selection and result);analysisErrorPresentation(error projection).extract_artifactgains the optional inputintegrity_policy(defaultfail) and the result fieldintegrity_contradictions(an empty array when there is no contradiction).rea extract-artifactgains--integrity-policy. Theextract_artifactdescription is updated. Existing calls are unchanged.file://URLs inside regular.asarfiles on all hosts. Paths are built with the hostpathmodule, andfileURLToPathstill owns URL→path conversion.integrity_contradictionsschema (trust: "observed-untrusted") and are scoped to the extracted occurrences.file_pathvalues for packaged pages are<realpath(archive)>/<member>. They identify the member and are never opened as host files..asarfile. It still rejects remote hosts, credentials, encoded separators, archive directories and links, and unknown members. Extraction containment and cleanup are unchanged. A failed extraction still leaves no output root (covered by the existing completeness test).npm run docs:checkpasses against the changed contracts.Evidence and regression coverage
Tests added or updated:
tests/boundary/filesystem/electronFileScope.test.ts: packed, nested, query/hash-bearing, and unpacked ASAR members resolve. Archive directories, missing members, and a non-ASAR file used as a parent are rejected.tests/boundary/browser/cdpElectronProvider.test.ts:listTargetsandinspectPageagainst a fake CDP endpoint whose page and script live inside a realapp.asar.tests/boundary/mcp/asarUnpackedExtractionMcp.test.ts(MCP, reusescreateStrippedAsarAddon):extract_artifact.record-and-continueextracts the observed bytes and returnsintegrity_contradictionsplus the summary limitation.unavailablewith the logical path.tests/boundary/mcp/artifactMcp.test.ts: the embedded/unpackedinspect_artifactintegrity messages are updated.tests/boundary/providers/native/artifactProvider.extractionCompleteness.test.ts: the active-member refusal is now asserted asunavailablewithlogical_path/unpackedinstead offormat. Refusal and no output root are still asserted. The directmaterializeArtifactInventorycall passesintegrityPolicy: "fail".Base reproduction:
src/reverted toorigin/main, both new extraction MCP tests fail.ElectronFileScope.tsreverted to the base, the new ASAR file-scope test fails.list-electron-targetsreturned"targets": [],"excluded": {"unsupported_url": 1, "non_page": 0}.User-visible CLI/MCP output (paths shortened):
Remaining proof gaps:
Debugger.scriptParsedevents that all were Node/Electron internals or anonymous scripts. Everyapp.asarscript (11) was included.data:images and 1https:avatar.For evidence-bearing changes:
Validation performed
npm run check:changed— typecheck and lint passed; 98 test files / 973 tests passed (6 skipped).npm run docs:check— 6/6 tasks passed.npx vitest runover the touched boundary suites (tests/boundary/mcp/{asarUnpackedExtractionMcp,artifactMcp,electronMcp}.test.ts,tests/boundary/filesystem/electronFileScope.test.ts,tests/boundary/browser/cdpElectronProvider.test.ts,tests/boundary/providers/native) — all passed exceptnativeSignatureTargetBinding.test.ts › keeps real codesign bound to registered bytes during an ancestor directory swap, which also fails on unmodifiedorigin/mainon this host.rea extract-artifact,rea inspect-artifact, andrea analyze-javascript-applicationonapp.asar(default policy) each return the unpacked-entry message naming their own operation.rea extract-artifact --integrity-policy record-and-continueextracted 5321 files with oneobserved-untrustedcontradiction.--remote-debugging-port,rea list-electron-targets,rea inspect-electron-page, and the MCP toolslist_electron_targets/inspect_electron_pageall list and inspect theapp.asarpage, with identical results between CLI and MCP.Compatibility, safety, and release
unavailablewithlogical_path/unpackeddetails instead ofartifact_operation_faileddetails{operation, reason: "format", detail}. The error code (artifact_operation_failed) and the refusal itself are unchanged.inspect_artifact/extract_artifactchanged from the generic "get a fresh copy" text..asarfile reached through a hostlessfile://URL. It reads only the archive header and never executes or extracts archive content. Header reads are bounded by the existing@electron/asarparser and cached per file identity.Review checklist
type(scope): outcome.