From a3a019a1fd24b8f618eed1d70464f2bfe7411dcd Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Sun, 4 Jan 2026 01:42:08 -0500 Subject: [PATCH] Use blob URL instead of query string API key for APK download MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fetches APK using X-API-Key header and returns blob URL instead of exposing API key in the download URL query string. This is more secure as API keys are not logged or leaked via Referer headers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/lib/deploy/APKBuilderAdapter.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/lib/deploy/APKBuilderAdapter.ts b/src/lib/deploy/APKBuilderAdapter.ts index bca9c88a..2e559f88 100644 --- a/src/lib/deploy/APKBuilderAdapter.ts +++ b/src/lib/deploy/APKBuilderAdapter.ts @@ -108,10 +108,11 @@ export class APKBuilderAdapter implements DeployAdapter { } if (status.status === 'complete') { - const downloadUrl = `${this.buildServerUrl}/api/build/${buildId}/download?apiKey=${encodeURIComponent(this.apiKey)}`; + // Fetch APK with header auth and create blob URL + const apkBlobUrl = await this.downloadApk(buildId); return { - url: downloadUrl, + url: apkBlobUrl, metadata: { buildId, type: 'apk', @@ -137,6 +138,25 @@ export class APKBuilderAdapter implements DeployAdapter { throw new Error('APK build timed out after 10 minutes'); } + private async downloadApk(buildId: string): Promise { + const url = `${this.buildServerUrl}/api/build/${buildId}/download`; + const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url; + + const response = await fetch(targetUrl, { + method: 'GET', + headers: { + 'X-API-Key': this.apiKey, + }, + }); + + if (!response.ok) { + throw new Error(`Failed to download APK: ${response.status} ${response.statusText}`); + } + + const blob = await response.blob(); + return URL.createObjectURL(blob); + } + private async getStatus(buildId: string): Promise { const url = `${this.buildServerUrl}/api/build/${buildId}/status`; const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;