Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(apktool): retain advisory facts from the version observation

morluto63696d277328
diff --git a/docs/apktool-resource-analysis.md b/docs/apktool-resource-analysis.md
index 484dafcf0..5b8967c4a 100644
--- a/docs/apktool-resource-analysis.md
+++ b/docs/apktool-resource-analysis.md
@@ -24,6 +24,15 @@ missing launcher reports `capability_unavailable` with the
`binary_session` uses the same host probe for tool availability; it does not
validate a particular APK or guarantee that the selected input can be decoded.
+Client inspection and decode results disclose CVE-2024-21633 when the
+reported version predates its upstream 2.9.2 fix. This advisory-specific
+limitation preserves older supported distribution builds. A launcher version
+does not prove the decoder's contents, downstream backports, or overall safety;
+verify the selected decoder's patches before decoding untrusted APKs. See the
+[upstream advisories](https://github.com/iBotPeaches/Apktool/security/advisories),
+including the Windows follow-up and later regression; the compatibility floor
+above is not a security recommendation.
+
On Windows, a `.bat` or `.cmd` launcher (such as Chocolatey's `apktool.bat`)
runs through an explicit `cmd.exe /d /s /c` call. That call has no AutoRun,
no delayed expansion, and quotes every argument. A launcher path that
diff --git a/src/apktool/ApktoolConfiguration.test.ts b/src/apktool/ApktoolConfiguration.test.ts
index df7dccd6e..07b70b7f4 100644
--- a/src/apktool/ApktoolConfiguration.test.ts
+++ b/src/apktool/ApktoolConfiguration.test.ts
@@ -53,7 +53,7 @@ describe("resolveApktoolCommand", () => {
describe("parseApktoolVersionOutput", () => {
it("reads the version from real apktool output", () => {
- expect(parseApktoolVersionOutput("2.7.0-dirty\n")).toEqual({
+ expect(parseApktoolVersionOutput("2.7.0-dirty\n")).toMatchObject({
version: "2.7.0-dirty",
});
});
@@ -72,18 +72,83 @@ describe("parseApktoolVersionOutput", () => {
});
it("parses semantic prerelease versions without claiming they meet the minimum", () => {
- expect(parseApktoolVersionOutput("2.7.0-beta.1\n")).toEqual({
+ expect(parseApktoolVersionOutput("2.7.0-beta.1\n")).toMatchObject({
version: "2.7.0-beta.1",
});
});
it("validates normalized semantic versions while preserving caller spelling", () => {
- expect(parseApktoolVersionOutput("v2.7.0\n")).toEqual({
+ expect(parseApktoolVersionOutput("v2.7.0\n")).toMatchObject({
version: "v2.7.0",
});
});
});
+describe("reported Apktool version policy", () => {
+ it.each([
+ "2.7.0-dirty",
+ "2.9.1",
+ "v1.5.2",
+ "2.9.2-rc.1",
+ "2.9.2-rc-dirty",
+ "2.9.1+patched",
+ ])(
+ "discloses the upstream advisory for %s without claiming engine patch identity",
+ (version) => {
+ const identity = parseApktoolVersionOutput(version);
+ if (identity.version === null) throw new Error("Expected parsed version");
+ expect(identity.version).toBe(version);
+ const warnings = identity.limitations.filter((limitation) =>
+ limitation.includes("CVE-2024-21633"),
+ );
+ expect(warnings).toHaveLength(1);
+ expect(warnings[0]).toContain(
+ "does not establish engine contents or downstream backports",
+ );
+ },
+ );
+ it.each([
+ "2.9.2",
+ "2.9.2-dirty",
+ "v2.9.2",
+ "2.9.2+downstream",
+ "2.10.0-dirty",
+ "3.0.1",
+ ])(
+ "does not attach CVE-2024-21633 to a reported version at or beyond its fix: %s",
+ (version) => {
+ const identity = parseApktoolVersionOutput(version);
+ if (identity.version === null) throw new Error("Expected parsed version");
+ expect(identity).toMatchObject({
+ version,
+ supportsDocumentedVersion: true,
+ });
+ expect(
+ identity.limitations.filter((limitation) =>
+ limitation.includes("CVE-2024-21633"),
+ ),
+ ).toEqual([]);
+ },
+ );
+ it.each([
+ ["2.7.0", true],
+ ["2.7.0-dirty", true],
+ ["v2.7.0-dirty", true],
+ ["2.7.0-beta.1", false],
+ ["2.7.0-rc-dirty", false],
+ ["2.7.0-dirty+patched", false],
+ ["2.6.9", false],
+ ] as const)(
+ "preserves the documented release floor for %s",
+ (version, supported) => {
+ expect(parseApktoolVersionOutput(version)).toMatchObject({
+ version,
+ supportsDocumentedVersion: supported,
+ });
+ },
+ );
+});
+
describe("apktoolInvocation", () => {
const windows = { SystemRoot: "C:\\Windows" };
diff --git a/src/apktool/ApktoolConfiguration.ts b/src/apktool/ApktoolConfiguration.ts
index a8f3e03df..ff5841eac 100644
--- a/src/apktool/ApktoolConfiguration.ts
+++ b/src/apktool/ApktoolConfiguration.ts
@@ -24,7 +24,7 @@ import {
import type { ProviderAvailability } from "../application/AnalysisProvider.js";
import type { ProviderRejectionCode } from "../contracts/providerSelection.js";
import type { JsonValue } from "../domain/jsonValue.js";
-import { gte, valid } from "semver";
+import { parse } from "semver";
import {
isWindowsBatchFile,
windowsBatchCommand,
@@ -176,9 +176,11 @@ export class ApktoolConfigurationFailure extends Error {
}
}
-export type ApktoolClientIdentity =
- | { readonly version: string; readonly reportedVersion?: never }
- | { readonly version: null; readonly reportedVersion: string | null };
+export interface ApktoolClientIdentity {
+ readonly version: string;
+ readonly supportsDocumentedVersion: boolean;
+ readonly limitations: readonly string[];
+}
/** Process creation for one apktool run on the selected host. */
export interface ApktoolInvocation {
@@ -217,22 +219,35 @@ export const apktoolInvocation = (
/** Read the version from Apktool's single-line `--version` response. */
export const parseApktoolVersionOutput = (
stdout: string,
-): ApktoolClientIdentity => {
+):
+ | ApktoolClientIdentity
+ | { readonly version: null; readonly reportedVersion: string | null } => {
const line = stdout
.split(/\r?\n/u)
.map((entry) => entry.trim())
.find((entry) => entry !== "");
- if (line === undefined || valid(line) === null)
+ const parsed = line === undefined ? null : parse(line);
+ if (line === undefined || parsed === null)
return { version: null, reportedVersion: line ?? null };
- return { version: line };
-};
-
-const supportsDocumentedApktoolVersion = (version: string): boolean => {
- // Debian's verified 2.7.0-dirty build is a downstream build marker, not a
- // prerelease. Treat only that known marker as build metadata for the floor.
- const comparisonVersion = version.replace(/-dirty$/u, "+dirty");
- const parsedVersion = valid(comparisonVersion);
- return parsedVersion !== null && gte(parsedVersion, "2.7.0");
+ // Debian's exact -dirty marker denotes a downstream release build. Preserve
+ // the reported spelling; other prereleases remain earlier than their release.
+ const downstreamRelease =
+ parsed.prerelease.length === 1 &&
+ parsed.prerelease[0] === "dirty" &&
+ parsed.build.length === 0;
+ const atLeast = (release: string): boolean =>
+ (downstreamRelease
+ ? parsed.compareMain(release)
+ : parsed.compare(release)) >= 0;
+ return {
+ version: line,
+ supportsDocumentedVersion: atLeast("2.7.0"),
+ limitations: atLeast("2.9.2")
+ ? []
+ : [
+ `Reported apktool version ${JSON.stringify(line)} predates the upstream 2.9.2 fix for CVE-2024-21633 (decoded resource paths could escape the output directory). Verify the selected decoder's patches before decoding untrusted APKs; launcher version alone does not establish engine contents or downstream backports. https://github.com/iBotPeaches/Apktool/security/advisories/GHSA-2hqv-2xv4-5h5w`,
+ ],
+ };
};
/** Probe within the caller-admitted command scope; decodes nothing. */
@@ -377,7 +392,7 @@ const interpretApktoolVersion = (
stderr,
},
);
- if (!supportsDocumentedApktoolVersion(identity.version))
+ if (!identity.supportsDocumentedVersion)
throw new ApktoolConfigurationFailure(
"unsupported_version",
`The selected Apktool version ${identity.version} is older than the supported minimum 2.7.0`,
@@ -434,7 +449,9 @@ const versionProbeFailure = (
return new AnalysisCancelledError("inspect_apktool_client", {
cause: cause.cancellation?.reason,
...(output === undefined ? {} : { capturedOutput: output }),
- ...(observed === undefined ? {} : { diagnostics: { client: observed } }),
+ ...(observed === undefined
+ ? {}
+ : { diagnostics: { client: { version: observed.version } } }),
});
if (preparation !== undefined)
return new ProviderAdapterError("apktool", "inspect_apktool_client", {
@@ -480,7 +497,9 @@ const versionProbeFailure = (
"The selected apktool launcher did not report a usable version",
{
selected_command: selection.command,
- ...(observed === undefined ? {} : { client: observed }),
+ ...(observed === undefined
+ ? {}
+ : { client: { version: observed.version } }),
...(snapshot === null
? {}
: {
diff --git a/src/apktool/ApktoolProvider.test.ts b/src/apktool/ApktoolProvider.test.ts
index 7532e87dd..bff476f10 100644
--- a/src/apktool/ApktoolProvider.test.ts
+++ b/src/apktool/ApktoolProvider.test.ts
@@ -719,6 +719,9 @@ it.each([false, true])(
expect(result.error.partialObservation).toMatchObject({
operation: "decode_android_resources",
normalized_result: { target: { sha256: apk.sha256 } },
+ limitations: expect.arrayContaining([
+ expect.stringContaining("CVE-2024-21633"),
+ ]),
});
denied = false;
await provider.close();
@@ -999,3 +1002,45 @@ it("discloses qualified and unfamiliar strings tables while preserving exact loc
await provider.close();
}
});
+
+it.each(["2.7.0-dirty", "2.9.1", "2.9.2-rc.1", "2.9.2", "2.9.2-dirty"])(
+ "retains reported-version limitations for both operations without refusing %s (#3438)",
+ async (version) => {
+ const { command, root } = await writeApktoolStub((root) =>
+ decodeStub()(root).replace(VERSION_BLOCK, `printf '%s\\n' '${version}'`),
+ );
+ const apk = await apkFixture(root);
+ const provider = providerOver(command);
+ try {
+ const inspect = await provider.execute({
+ operation: "inspect_apktool_client",
+ input: {},
+ });
+ const decode = await provider.execute({
+ operation: "decode_android_resources",
+ input: { path: apk.path, include_strings: true },
+ });
+ if (!inspect.ok) throw inspect.error;
+ if (!decode.ok) throw decode.error;
+ const warnings = inspect.value.limitations.filter((limitation) =>
+ limitation.includes("CVE-2024-21633"),
+ );
+ expect(warnings.length).toBe(
+ ["2.9.2", "2.9.2-dirty"].includes(version) ? 0 : 1,
+ );
+ if (warnings.length > 0) expect(warnings[0]).toContain("CVE-2024-21633");
+ for (const warning of inspect.value.limitations)
+ expect(decode.value.limitations).toContain(warning);
+ expect(inspect.value.result).toMatchObject({
+ client: { apktool_version: version },
+ });
+ expect(decode.value.result).toMatchObject({
+ client: { apktool_version: version },
+ target: { sha256: apk.sha256 },
+ coverage: "complete",
+ });
+ } finally {
+ await provider.close();
+ }
+ },
+);
diff --git a/src/apktool/ApktoolProvider.ts b/src/apktool/ApktoolProvider.ts
index 51a8eb557..7681774ac 100644
--- a/src/apktool/ApktoolProvider.ts
+++ b/src/apktool/ApktoolProvider.ts
@@ -441,7 +441,11 @@ export class ApktoolProvider {
version: identity.version,
};
if (request.operation === "inspect_apktool_client")
- return ok(createAnalysisExecution({ client }, provider));
+ return ok(
+ createAnalysisExecution({ client }, provider, {
+ limitations: identity.limitations,
+ }),
+ );
return this.decodeResources(
request.operation,
selection,
@@ -449,6 +453,7 @@ export class ApktoolProvider {
client,
provider,
request.input,
+ identity.limitations,
signal,
);
}
@@ -506,6 +511,7 @@ export class ApktoolProvider {
readonly include_strings: boolean;
readonly locale?: string | undefined;
},
+ clientLimitations: readonly string[],
signal: AbortSignal | undefined,
): Promise<Result<AnalysisExecution, AnalysisError>> {
const runtime = await PrivateRuntimeRoot.create({ prefix: "rea-apktool-" });
@@ -636,6 +642,7 @@ export class ApktoolProvider {
{
subject: { path: input.path, sha256, format: "apk" },
limitations: [
+ ...clientLimitations,
"Decoding skips smali (--no-src); Java-source recovery belongs to the JADX family",
...(input.locale !== undefined &&
stringsRead.text === null &&
diff --git a/src/apktool/ApktoolVersionProbe.test.ts b/src/apktool/ApktoolVersionProbe.test.ts
index f2f9b4291..1e40e4cee 100644
--- a/src/apktool/ApktoolVersionProbe.test.ts
+++ b/src/apktool/ApktoolVersionProbe.test.ts
@@ -47,7 +47,11 @@ it("runs the version probe as an owned interpreter-script process group", async
environment: {},
platform: "linux",
}),
- ).resolves.toEqual({ version: "2.9.3" });
+ ).resolves.toEqual({
+ version: "2.9.3",
+ supportsDocumentedVersion: true,
+ limitations: [],
+ });
expect(vi.mocked(runOwnedCommand).mock.lastCall?.[0]).toMatchObject({
command: "/opt/apktool/apktool",
arguments: ["--version"],