Skip to content

fix(frida): reject an unreadable script file before starting a session - #2211

Merged
morluto merged 3 commits into
mainfrom
fix/issue-2209
Oct 12, 2026
Merged

morluto merged 3 commits into
mainfrom
fix/issue-2209

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

FridaInstrumentationService.instrument, the shared CLI (instrument-with-frida) and MCP (instrument_with_frida) one-shot workflow, starts the Frida session before the provider reads a file script source. If the file is missing:

  • the session spawns the target paused (or attaches);
  • loadScript fails;
  • cleanup closes the session, and by design a paused spawn is resumed (REA never kills the target).

So the target program ran without instrumentation, and the caller got a bare invalid_request with no issue.

The workflow now checks that a file source is a readable regular file before #startSession:

  • a missing path or a non-file returns invalid_request with an invalid_value issue at ["path"] (Cannot read Frida script file <path>: no file exists there. / it is not a regular file.);
  • EACCES/EPERM returns access_denied.

Inline sources are unchanged. The provider still reads the file when loading, so a file that changes between the check and the load is handled as before.

Fixes #2209

Before / after (macOS, Frida via rea-agents; target is a compiled program that appends to a marker file when it runs)

$ rea instrument-with-frida spawn …/fr/target --script-file /nonexistent.js --duration-ms 300 --format json
before: {"code":"invalid_request", …}  — no issues;  marker file: "ran 96778" (target executed)
after:  {"code":"invalid_request","details":{"issues":[{"path":["path"],"reason":"invalid_value","message":"Cannot read Frida script file /nonexistent.js: no file exists there."}]}}  — marker file absent

Validation

  • New service tests (src/application/frida/FridaInstrumentationService.test.ts) cover a missing file and a directory. They assert the issue and that the provider's startSession is never called. They fail on main and pass with this change; all Frida tests pass (64 across the CLI, MCP, manager, service and contract suites).
  • npm run lint passes.
  • npm test: 9246 passed, 14 failed in 7 files. These are the same environmental files that fail on clean origin/main on this host: Hopper not installed, Command Line Tools only (ibtool), hdiutil, and inspector target-location cases.
  • Real-provider scope: Frida on this macOS host can spawn a self-built binary but generally cannot attach (Unable to access process … from the current user account). Instrumentation itself was not exercised here, only the pre-start rejection and the absence of the target run.

Remaining

The separate MCP load_frida_script operation still reports a file read failure as AnalysisInputError("load_frida_script") without an issue naming the path, from FridaInstrumentationManager.#loadScript. There the caller has already started the session explicitly, so no side effect is introduced by REA. I left it out to keep this change to the pre-start ordering.

🤖 Generated with Claude Code

The shared instrument_with_frida workflow started the Frida session, which
attaches or spawns the target, before the provider read a file script
source. A missing script file then failed loadScript with a bare
invalid_request, and session cleanup resumed the paused spawn, so the
target ran without instrumentation. Check that the selected file is a
readable regular file first and report the path, or access_denied for
EACCES/EPERM, before any device effect.

Fixes #2209

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T14:44:27.671813Z 6116a9d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0ed313d40

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

>
> {
// Reject an unreadable script file before any attach or spawn effect.
const unreadable = await unreadableScriptFile(input.source);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check cancellation before validating the script file

When instrument receives an already-aborted CLI/MCP signal together with a missing, unreadable, or non-regular file source, this preflight runs before #startSession's cancellation guard and returns an input/access-denied error rather than AnalysisCancelledError. It also makes cancellation wait for filesystem I/O. Check the signal before this preflight (and let cancellation win if it arrives during it) so file sources retain the existing cancellation semantics.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 4046536 (with a small extraction in 6116a9d). instrument now checks the signal before the script-file preflight and again after it, so an already-aborted request returns AnalysisCancelledError without touching the filesystem, and an abort that arrives during the check also wins over the input/access-denied error. New test reports cancellation before checking a file script source uses an aborted signal with a missing file and fails without the change.

kaoru0822-kitauji and others added 2 commits October 12, 2026 14:39
An already-aborted request with an unreadable file source returned the
input or access-denied error instead of AnalysisCancelledError. Check the
signal before the script file preflight and again after it, so file
sources keep the existing cancellation semantics.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto
morluto merged commit c9aecde into main Oct 12, 2026
30 checks passed
@morluto
morluto deleted the fix/issue-2209 branch October 12, 2026 15:10
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the provider: frida Analysis provider / engine: frida label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working provider: frida Analysis provider / engine: frida

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] instrument_with_frida spawns and runs the target before noticing a missing script file

2 participants