Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: audit unprotected Play APK artifacts

tianma-ifef836cdbb493
diff --git a/.github/workflows/play-generated-apk-audit.yml b/.github/workflows/play-generated-apk-audit.yml
new file mode 100644
index 00000000..5bab6682
--- /dev/null
+++ b/.github/workflows/play-generated-apk-audit.yml
@@ -0,0 +1,33 @@
+name: Audit Play Generated APKs
+
+on:
+ workflow_dispatch:
+ inputs:
+ version_code:
+ description: "Google Play Android versionCode"
+ required: true
+ type: string
+
+permissions:
+ contents: read
+
+jobs:
+ audit:
+ if: github.repository == 'tianma-if/edgeever'
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v5
+
+ - name: Set up Bun
+ uses: oven-sh/setup-bun@v2
+ with:
+ bun-version: 1.3.14
+
+ - name: Install dependencies
+ run: bun install --frozen-lockfile
+
+ - name: Inspect generated APK types
+ env:
+ ANDROID_PLAY_APP_SIGNER_SHA256: ${{ secrets.ANDROID_PLAY_APP_SIGNER_SHA256 }}
+ GOOGLE_PLAY_SERVICE_ACCOUNT_JSON_BASE64: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON_BASE64 }}
+ run: node scripts/download-play-universal-apk.mjs "${{ inputs.version_code }}" --inspect
diff --git a/scripts/download-play-universal-apk.mjs b/scripts/download-play-universal-apk.mjs
index fa7f2068..8bcdf083 100644
--- a/scripts/download-play-universal-apk.mjs
+++ b/scripts/download-play-universal-apk.mjs
@@ -13,6 +13,26 @@ const DEFAULT_POLL_INTERVAL_MS = 10_000;
const DEFAULT_DOWNLOAD_TIMEOUT_MS = 10 * 60_000;
const LOOKUP_TIMEOUT_MS = 30_000;
+export const summarizePlayGeneratedApks = (response, expectedSignerSha256) => {
+ const expectedSigner = normalizePlayCertificateHash(expectedSignerSha256);
+ if (!expectedSigner) {
+ throw new Error("ANDROID_PLAY_APP_SIGNER_SHA256 must be a SHA-256 certificate fingerprint.");
+ }
+ const candidate = (response?.generatedApks ?? []).find((entry) =>
+ normalizePlayCertificateHash(entry.certificateSha256Hash) === expectedSigner
+ );
+ if (!candidate) {
+ throw new Error(`Google Play returned no generated APKs for signer ${expectedSigner}.`);
+ }
+ return {
+ protectedSplitCount: candidate.generatedSplitApks?.length ?? 0,
+ protectedStandaloneVariants: (candidate.generatedStandaloneApks ?? []).map(({ variantId }) => variantId),
+ protectedUniversal: Boolean(candidate.generatedUniversalApk?.downloadId),
+ unprotectedSplitCount: candidate.unprotectedGeneratedSplitApks?.length ?? 0,
+ unprotectedStandaloneVariants: (candidate.unprotectedGeneratedStandaloneApks ?? []).map(({ variantId }) => variantId),
+ };
+};
+
export const normalizePlayCertificateHash = (value) => {
const compact = String(value ?? "").trim();
const hex = compact.toLowerCase().replace(/[^0-9a-f]/g, "");
@@ -78,6 +98,31 @@ const requestHeaders = async () => {
return client.getRequestHeaders();
};
+const fetchGeneratedApks = async ({ headers, packageName, versionCode }) => {
+ const url = `https://androidpublisher.googleapis.com/androidpublisher/v3/applications/${encodeURIComponent(packageName)}/generatedApks/${versionCode}`;
+ const response = await fetch(url, {
+ headers,
+ signal: AbortSignal.timeout(LOOKUP_TIMEOUT_MS),
+ });
+ if (!response.ok) {
+ throw new Error(`Google Play generated APK lookup failed with HTTP ${response.status}: ${await response.text()}`);
+ }
+ return response.json();
+};
+
+export const inspectPlayGeneratedApks = async ({
+ expectedSignerSha256,
+ packageName = DEFAULT_PACKAGE_NAME,
+ versionCode,
+}) => {
+ if (!Number.isSafeInteger(versionCode) || versionCode <= 0) {
+ throw new Error("versionCode must be a positive integer.");
+ }
+ const headers = await requestHeaders();
+ const response = await fetchGeneratedApks({ headers, packageName, versionCode });
+ return summarizePlayGeneratedApks(response, expectedSignerSha256);
+};
+
const wait = (milliseconds) => new Promise((resolveWait) => setTimeout(resolveWait, milliseconds));
export const downloadPlayUniversalApk = async ({
@@ -145,6 +190,14 @@ export const downloadPlayUniversalApk = async ({
const run = async () => {
const [versionCodeValue, outputPath] = process.argv.slice(2);
const versionCode = Number(versionCodeValue);
+ if (outputPath === "--inspect") {
+ const summary = await inspectPlayGeneratedApks({
+ expectedSignerSha256: process.env.ANDROID_PLAY_APP_SIGNER_SHA256,
+ versionCode,
+ });
+ console.log(JSON.stringify(summary));
+ return;
+ }
if (!versionCodeValue || !outputPath) {
throw new Error("Usage: node scripts/download-play-universal-apk.mjs <version-code> <output-apk>");
}
diff --git a/scripts/download-play-universal-apk.test.mjs b/scripts/download-play-universal-apk.test.mjs
index e2f88b27..cc489118 100644
--- a/scripts/download-play-universal-apk.test.mjs
+++ b/scripts/download-play-universal-apk.test.mjs
@@ -3,6 +3,7 @@ import {
assertDownloadedApk,
normalizePlayCertificateHash,
selectPlayUniversalApk,
+ summarizePlayGeneratedApks,
} from "./download-play-universal-apk.mjs";
describe("Google Play universal APK selection", () => {
@@ -34,6 +35,26 @@ describe("Google Play universal APK selection", () => {
);
});
+ test("reports protected and unprotected generated APK variants", () => {
+ const signer = "ab".repeat(32);
+ expect(summarizePlayGeneratedApks({
+ generatedApks: [{
+ certificateSha256Hash: signer,
+ generatedSplitApks: [{ downloadId: "protected-split" }],
+ generatedStandaloneApks: [{ downloadId: "protected-standalone", variantId: 1 }],
+ generatedUniversalApk: { downloadId: "protected-universal" },
+ unprotectedGeneratedSplitApks: [{ downloadId: "plain-split" }],
+ unprotectedGeneratedStandaloneApks: [{ downloadId: "plain-standalone", variantId: 2 }],
+ }],
+ }, signer)).toEqual({
+ protectedSplitCount: 1,
+ protectedStandaloneVariants: [1],
+ protectedUniversal: true,
+ unprotectedSplitCount: 1,
+ unprotectedStandaloneVariants: [2],
+ });
+ });
+
test("rejects empty or non-APK download responses", () => {
expect(() => assertDownloadedApk(Buffer.alloc(0))).toThrow("empty or not a ZIP archive");
expect(() => assertDownloadedApk(Buffer.from("not an apk"))).toThrow("empty or not a ZIP archive");