Skip to content

Detect native apps via zerogapp.json manifests - #6

Open
SPhillips1337 wants to merge 1 commit into
mainfrom
feat/zerogapp-manifest
Open

SPhillips1337 wants to merge 1 commit into
mainfrom
feat/zerogapp-manifest

Conversation

@SPhillips1337

Copy link
Copy Markdown
Contributor

Teaches app detection to read zerogapp.json for native (Rust) projects alongside Electron build.fileAssociations.

  • zerogAppManifest() validates name/version/extensions/launch; args default to {file}; unsafe args filtered
  • Relative launch.command resolves against the project dir; missing exe → skipped
  • package.json associations keep priority when both exist
  • Enables ZeroG Edit / ZeroG Play to appear in Settings → File apps automatically

Verification: npm run ci green — 225 tests (8 new), typecheck + build pass.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>

Projects without Electron build.fileAssociations can ship a zerogapp.json
(name, version, extensions, launch) to appear in Settings > File apps.
Relative commands resolve against the project dir; missing executables
are skipped; package.json associations keep priority. Enables ZeroG Edit
and ZeroG Play detection. 8 new tests (225 total).

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This PR adds zerogapp.json manifest detection for native (Rust) apps alongside the existing Electron build.fileAssociations path. The overall structure — validation in the shared zerogAppManifest() function, resolution and existence-check in app-detect.ts, priority of package.json over the manifest — is sound, and the test coverage is good.

Two blocking issues need to be addressed:

  1. Logic error in app-detect.ts: The catch block wrapping the package.json path also covers the launchForProject async call. Any I/O error inside launchForProject will be silently swallowed and the project treated as if it had no package.json, leading to incorrect manifest-path fallback for valid Electron projects. The error boundary should be tightened to only guard the readFile/JSON.parse.

  2. Path traversal in file-apps.ts zerogAppManifest(): The cwd field from the manifest is accepted verbatim with no path validation, while command is properly resolved and existence-checked. A crafted zerogapp.json with a relative cwd (e.g., ../../../etc) can direct the spawned process into an arbitrary directory. cwd must be validated as an absolute path (or resolved against projectDir and constrained to it).


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread src/main/app-detect.ts
Comment on lines +91 to +93
} catch {
/* no package.json — try a native manifest below */
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Logic Error: The catch block at line 91 swallows all exceptions from the entire try block, including errors thrown by launchForProject (which performs async file I/O). If launchForProject throws — for example, due to a filesystem permission error — the exception is treated as "no package.json", detected stays false, and the code then tries to read zerogapp.json for a project that actually has a valid package.json. This silently drops legitimate Electron projects from detection results. The catch block should only guard the readFile/JSON.parse for package.json, not the launch resolution logic.

Comment thread src/shared/file-apps.ts
.filter((arg): arg is string => typeof arg === 'string' && arg.length <= 2048 && !/[\0\r\n]/.test(arg))
.slice(0, 32)
: [];
const cwd = typeof launchSource.cwd === 'string' && launchSource.cwd.trim() ? launchSource.cwd.trim() : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Security Vulnerability: The cwd value from the manifest is accepted and stored without validation. Unlike command, which is resolved against projectDir and checked for existence with existsSync, cwd is passed through verbatim (after a trim()). A malicious zerogapp.json could supply a cwd like ../../../sensitive/dir, causing the spawned process to run in an arbitrary directory outside the project. At minimum, cwd should be validated as an absolute path; if it must support relative paths, it should be resolved against projectDir and kept within it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant