Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(cli): refuse a JavaScript integrity policy the binary analyze lane cannot honor (#2808)
吴佳浩Alben641a8395ee6e
diff --git a/src/cli/coreBinaryCommands.ts b/src/cli/coreBinaryCommands.tsindex 8902cf4e9..ff8a86536 100644--- a/src/cli/coreBinaryCommands.ts+++ b/src/cli/coreBinaryCommands.ts@@ -45,6 +45,24 @@ const registerOverviewCommands = (.describe("Load and update a local analysis snapshot"),...nativeOpenOptionFields,});+ // `analyze` declares the JavaScript integrity policy for its JavaScript+ // lane. Preserve whether the caller supplied it until the target lane is+ // known, then apply the JavaScript default only in that lane. The owner+ // field fills an omission with that default, and an `.optional()` wrapper+ // keeps reporting it, so every binary target would look like an explicit+ // policy. Remove the owner's default before making the CLI option optional;+ // reapply its metadata so help and `--schema` keep describing the option.+ const ownerIntegrityPolicy =+ javascriptApplicationOptions.shape.integrityPolicy;+ const defaultIntegrityPolicy = ownerIntegrityPolicy.parse(undefined);+ const policyMetadata = ownerIntegrityPolicy.meta();+ const omittableIntegrityPolicy = ownerIntegrityPolicy+ .removeDefault()+ .optional();+ const laneIntegrityPolicy =+ policyMetadata === undefined+ ? omittableIntegrityPolicy+ : omittableIntegrityPolicy.meta(policyMetadata);cli.command(CLI_COMMANDS.analyze, {description: "Get an overview of an app",args: z.object({@@ -54,7 +72,7 @@ const registerOverviewCommands = (.describe("App, program, or analysis database path"),}),options: overviewOptions.extend({- integrityPolicy: javascriptApplicationOptions.shape.integrityPolicy,+ integrityPolicy: laneIntegrityPolicy,sourcePath: javascriptApplicationOptions.shape.sourcePath,}),run: async ({ args, options }) => {@@ -67,7 +85,8 @@ const registerOverviewCommands = (runCliJavaScriptApplicationAnalysis({input_path: resolve(args.path),- integrity_policy: options.integrityPolicy,+ integrity_policy:+ options.integrityPolicy ?? defaultIntegrityPolicy,...(options.sourcePath === undefined? {}: { source_paths: options.sourcePath }),@@ -90,6 +109,19 @@ const registerOverviewCommands = (},],);+ if (options.integrityPolicy !== undefined)+ throw new AnalysisInputError(+ "analyze_javascript_application",+ undefined,+ [+ {+ path: ["integrity_policy"],+ reason: "invalid_value",+ message:+ "An integrity policy requires the static JavaScript ASAR/directory analysis lane; binary_overview accepts no input.",+ },+ ],+ );return runDirectAnalysis(args.path,"binary_overview",diff --git a/tests/boundary/cli/javascriptIntegrityPolicyCli.test.ts b/tests/boundary/cli/javascriptIntegrityPolicyCli.test.tsindex 4883ac741..1a79942bd 100644--- a/tests/boundary/cli/javascriptIntegrityPolicyCli.test.ts+++ b/tests/boundary/cli/javascriptIntegrityPolicyCli.test.ts@@ -15,6 +15,19 @@ const run = async (arguments_: readonly string[]): Promise<unknown> => {return JSON.parse(stdout);};+const runFailure = async (arguments_: readonly string[]): Promise<unknown> => {+ try {+ await run(arguments_);+ } catch (cause: unknown) {+ if (typeof cause !== "object" || cause === null || !("stdout" in cause))+ throw cause;+ const stdout = cause.stdout;+ if (typeof stdout !== "string") throw cause;+ return JSON.parse(stdout);+ }+ throw new Error("Expected the CLI command to fail");+};+it.each(["analyze-javascript-application", "analyze"])("%s carries the integrity policy into shared JavaScript analysis",async (command) => {@@ -46,3 +59,48 @@ it("rejects the JavaScript integrity policy on binary-only inspection", async ()stdout: expect.stringContaining("Unknown flag: --integrityPolicy"),});});++it.each(["fail", "record-and-continue"] as const)(+ "rejects the explicitly selected %s integrity policy on a binary analyze target",+ async (policy) => {+ const failure = await runFailure([+ "analyze",+ "unused.bin",+ "--integrity-policy",+ policy,+ ]);+ expect(failure).toMatchObject({+ code: "invalid_request",+ details: {+ issues: [+ {+ path: ["integrity_policy"],+ reason: "invalid_value",+ message:+ "An integrity policy requires the static JavaScript ASAR/directory analysis lane; binary_overview accepts no input.",+ },+ ],+ },+ });+ },+);++it("still routes a binary analyze target without an integrity policy", async () => {+ await expect(run(["analyze", "unused.bin"])).rejects.toMatchObject({+ code: 1,+ stdout: expect.stringContaining("target does not exist"),+ });+});++it("advertises the optional integrity policy without an undefined union", async () => {+ const schema = (await run(["analyze", "--schema"])) as {+ options?: { properties?: { integrityPolicy?: unknown } };+ };+ const policy = schema.options?.properties?.integrityPolicy;+ expect(policy).toMatchObject({+ type: "string",+ enum: ["fail", "record-and-continue"],+ description: "Behavior when declared application integrity does not match",+ });+ expect(JSON.stringify(policy)).not.toContain("undefined");+});