fix(frida): reject an unreadable script file before starting a session (#2211)
* fix(frida): reject an unreadable script file before starting a session 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 <noreply@anthropic.com> * fix(frida): let cancellation win over the script file check 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 <noreply@anthropic.com> * refactor(frida): keep the pre-start checks out of instrument Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ae412654d5
commit
c9aecde580
@@ -1,3 +1,6 @@
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import type { FridaInstrumentationPort } from "./FridaInstrumentationPort.js";
|
||||
@@ -102,6 +105,66 @@ it.each(["startSession", "instrument"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
[join(tmpdir(), "rea-missing-frida-script.js"), "no file exists there"],
|
||||
[tmpdir(), "it is not a regular file"],
|
||||
])(
|
||||
"rejects the unreadable script file %s before starting Frida",
|
||||
async (path, reason) => {
|
||||
let starts = 0;
|
||||
const provider = createProvider({
|
||||
async startSession() {
|
||||
starts += 1;
|
||||
return { ok: true, value: createSession() };
|
||||
},
|
||||
});
|
||||
const service = new FridaInstrumentationService(provider);
|
||||
|
||||
const result = await service.instrument({
|
||||
mode: "spawn",
|
||||
deviceId: "local",
|
||||
program: "/tmp/fixture",
|
||||
source: { sourceKind: "file", path },
|
||||
durationMs: 1,
|
||||
});
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) return;
|
||||
expect(result.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect((result.error as AnalysisInputError).issues).toEqual([
|
||||
{
|
||||
path: ["path"],
|
||||
reason: "invalid_value",
|
||||
message: `Cannot read Frida script file ${path}: ${reason}.`,
|
||||
},
|
||||
]);
|
||||
expect(starts).toBe(0);
|
||||
},
|
||||
);
|
||||
|
||||
it("reports cancellation before checking a file script source", async () => {
|
||||
const service = new FridaInstrumentationService(createProvider());
|
||||
const controller = new AbortController();
|
||||
controller.abort(new Error("cancelled before call"));
|
||||
|
||||
const result = await service.instrument(
|
||||
{
|
||||
mode: "spawn",
|
||||
deviceId: "local",
|
||||
program: "/tmp/fixture",
|
||||
source: {
|
||||
sourceKind: "file",
|
||||
path: join(tmpdir(), "rea-missing-frida-script.js"),
|
||||
},
|
||||
durationMs: 1,
|
||||
},
|
||||
controller.signal,
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) expect(result.error._tag).toBe("AnalysisCancelledError");
|
||||
});
|
||||
|
||||
it("does not resume a spawned target when cancellation arrives during script loading", async () => {
|
||||
const controller = new AbortController();
|
||||
let resumes = 0;
|
||||
|
||||
Reference in New Issue
Block a user