[GH-ISSUE #2209] [Bug] instrument_with_frida spawns and runs the target before noticing a missing script file #736

Closed
opened 2026-10-15 18:27:50 +00:00 by bsakaguchi · 0 comments
Owner

Originally created by @kaoru0822-kitauji on GitHub (Oct 12, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/2209

Observed behavior

instrument-with-frida spawn <program> --script-file <path> (and MCP instrument_with_frida with source_kind: "file") starts the Frida session before reading the caller-selected script file. If the file does not exist:

  1. REA spawns the target paused;
  2. loadScript fails to read the file;
  3. the cleanup path resumes the paused spawn (by design, REA never kills the target), so the target program runs without any instrumentation;
  4. the caller gets a bare invalid_request with no issue naming the script path.
$ rea instrument-with-frida spawn /tmp/fr/target --script-file /nonexistent.js --duration-ms 300 --format json
{"code":"invalid_request","message":"Analysis input is invalid. Check the arguments and try again.", …}    # no details.issues
$ cat /tmp/fr/ran.txt
ran 96778          # the target executed

With a valid inline script, the same target is not run on this host: Frida cannot attach to it here, and the paused spawn is cleaned up without the target writing its marker. In attach mode the session is also attached before the missing file is noticed.

Reproduction (macOS, Frida 17 via rea-agents on main 4a4ae9b2b)

// t.c — writes a marker file when it runs
#include <stdio.h>
#include <unistd.h>
int main(void){ FILE *f=fopen("/tmp/fr/ran.txt","a"); if(f){fprintf(f,"ran %d\n",getpid()); fclose(f);} sleep(2); return 0; }
cc -o /tmp/fr/target t.c
rea instrument-with-frida spawn /tmp/fr/target --script-file /nonexistent.js --duration-ms 300 --format json
cat /tmp/fr/ran.txt

Expected behavior

An unreadable script file is a caller input error that can be detected before any device, attach or spawn effect. The one-shot workflow should reject it before starting the session, with an issue naming the script path (or access_denied for EACCES/EPERM), and leave the target untouched.

Cause

FridaInstrumentationService.instrument (src/application/frida/FridaInstrumentationService.ts), the shared CLI/MCP one-shot workflow, calls #startSession and only then provider.loadScript. FridaInstrumentationManager.#loadScript reads the file and returns new AnalysisInputError("load_frida_script", { cause }) with no issues. The workflow then closes the session, and close resumes a paused spawn.

Originally created by @kaoru0822-kitauji on GitHub (Oct 12, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/2209 ### Observed behavior `instrument-with-frida spawn <program> --script-file <path>` (and MCP `instrument_with_frida` with `source_kind: "file"`) starts the Frida session before reading the caller-selected script file. If the file does not exist: 1. REA spawns the target paused; 2. `loadScript` fails to read the file; 3. the cleanup path resumes the paused spawn (by design, REA never kills the target), so **the target program runs without any instrumentation**; 4. the caller gets a bare `invalid_request` with no issue naming the script path. ```text $ rea instrument-with-frida spawn /tmp/fr/target --script-file /nonexistent.js --duration-ms 300 --format json {"code":"invalid_request","message":"Analysis input is invalid. Check the arguments and try again.", …} # no details.issues $ cat /tmp/fr/ran.txt ran 96778 # the target executed ``` With a valid inline script, the same target is not run on this host: Frida cannot attach to it here, and the paused spawn is cleaned up without the target writing its marker. In attach mode the session is also attached before the missing file is noticed. ### Reproduction (macOS, Frida 17 via rea-agents on main 4a4ae9b2b) ```c // t.c — writes a marker file when it runs #include <stdio.h> #include <unistd.h> int main(void){ FILE *f=fopen("/tmp/fr/ran.txt","a"); if(f){fprintf(f,"ran %d\n",getpid()); fclose(f);} sleep(2); return 0; } ``` ```sh cc -o /tmp/fr/target t.c rea instrument-with-frida spawn /tmp/fr/target --script-file /nonexistent.js --duration-ms 300 --format json cat /tmp/fr/ran.txt ``` ### Expected behavior An unreadable script file is a caller input error that can be detected before any device, attach or spawn effect. The one-shot workflow should reject it before starting the session, with an issue naming the script path (or `access_denied` for EACCES/EPERM), and leave the target untouched. ### Cause `FridaInstrumentationService.instrument` (`src/application/frida/FridaInstrumentationService.ts`), the shared CLI/MCP one-shot workflow, calls `#startSession` and only then `provider.loadScript`. `FridaInstrumentationManager.#loadScript` reads the file and returns `new AnalysisInputError("load_frida_script", { cause })` with no issues. The workflow then closes the session, and close resumes a paused spawn.
bsakaguchi 2026-10-15 18:27:50 +00:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#736
No description provided.