Repository navigation
Android: don't attach the auth token to presigned object-storage URLs - #413
Merged
Merged
Conversation
The okhttp authInterceptor added Authorization: Bearer <token> 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.
Mira PR WalkthroughThis PR fixes a critical Android upload/download issue where the okhttp auth interceptor was incorrectly attaching Authorization headers to presigned object-storage URLs (S3, OSS, COS, OneDrive, etc.). Since presigned URLs already contain authentication via query parameters, the extra Authorization header causes 400 InvalidArgument errors. The fix scopes the bearer token to only the API host, skipping it for off-host presigned URLs. 1 file reviewed
|
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The okhttp
authInterceptorinApiClient.ktattachesAuthorization: Bearer <token>to every request made on the client, including the direct chunkPUT/GETto the presigned object-storage URLs returned for S3-style storage policies (S3, OSS, COS, OneDrive, …).S3-compatible stores reject a presigned request that also carries an
Authorizationheader — the presigned query parameters are already a complete auth mechanism. The result is400 InvalidArgument("only one auth mechanism allowed") on every part upload:PUTs each part to object storage and gets a400,Direct downloads/original previews hit the same wall for the same reason.
Web clients are unaffected, because a browser's cross-origin
fetchnever sends the app'sAuthorizationheader — which is exactly why this reproduces only on Android.Reproduction
Against Hetzner Object Storage (Ceph RGW), an identical presigned
UploadPartPUT:Authorizationheader →200, ETag returned;Authorization: Bearer <token>added →400 InvalidArgument.Fix
Scope the bearer token to the API host only; never attach it to off-host (presigned) URLs. This fixes direct uploads and downloads for every presigned-URL policy and is a no-op for same-origin API calls.