From bf6e682315b859334baa2bf6f09a7296ab6ea561 Mon Sep 17 00:00:00 2001 From: Dixit Sabharwal Date: Sun, 1 Nov 2026 22:10:23 +0100 Subject: [PATCH] android: do not attach the auth token to presigned object-storage URLs The okhttp authInterceptor added Authorization: Bearer to every request, including the direct chunk PUT/GET to presigned S3 URLs for S3-style storage policies. Hetzner's Ceph (and AWS S3) reject a presigned request that also carries an Authorization header with 400 InvalidArgument, so every direct upload failed: the server opened the multipart upload, the phone PUT each part and got a 400, and zero parts ever landed. Browsers never hit this because a cross-origin fetch does not send the app's Authorization header. Scope the header to the API host only. Fixes direct uploads and downloads for S3/OSS/COS/OneDrive presigned-URL policies. --- .../src/main/java/org/cloudreve/android/api/ApiClient.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/org/cloudreve/android/api/ApiClient.kt b/android/app/src/main/java/org/cloudreve/android/api/ApiClient.kt index 93ce3129fe..dcb22c4e84 100644 --- a/android/app/src/main/java/org/cloudreve/android/api/ApiClient.kt +++ b/android/app/src/main/java/org/cloudreve/android/api/ApiClient.kt @@ -46,9 +46,16 @@ class ApiClient(private val session: SessionManager) { } private fun buildService(baseUrl: String): ApiService { + // Only our own API host may receive the Cloudreve bearer token. Chunk uploads and + // downloads for S3-style policies go to presigned object-storage URLs on a + // different host; S3/Ceph rejects a presigned request that also carries an + // Authorization header ("only one auth mechanism allowed", HTTP 400), so attaching + // the token there breaks every direct upload and download. + val apiHost = runCatching { java.net.URI(baseUrl).host }.getOrNull() val authInterceptor = Interceptor { chain -> val token = runBlocking { session.accessTokenNow() } - val request = if (token.isNotEmpty()) { + val sameHost = chain.request().url.host.equals(apiHost, ignoreCase = true) + val request = if (token.isNotEmpty() && sameHost) { chain.request().newBuilder() .header("Authorization", "Bearer $token") .build()