Repository navigation
Custom HTTP headers in the iOS/Android apps (Cloudflare Access, auth proxies) #3212
Replies: 3 comments
|
This is absolutely a must. I am in the same situation, using Pangolin. |
|
Thanks for the kind words and the detailed write-up, and great to hear the trip went well! We've looked into custom headers closely and won't add them, mainly for a technical reason: the app shows TREK in the system web view, and on iOS that web view can't attach extra headers to the requests a page makes (API calls, images, the WebSocket), only to the very first page load. On Android it only works partly. So a header option would look like it works and then fail halfway through a session. What the app does instead, and what should cover most setups:
If it still happens, could you tell us which page comes back (the Access sign-in or a Cloudflare "verify you are human" page), on iOS or Android, and whether it shows up right after starting the app without network or after an app update? There's one case on iOS we want to check there. |
|
Thanks @mauriceboe, the explanation about the web view limits makes sense, and your mTLS suggestion ended up being a better solution than what I asked for. To answer your questions: it was the Cloudflare "Verify you are human" page (a WAF Managed Challenge), not Access. I'm on iOS. It came back whenever the What fixed it for me, without blocking anyone who doesn't have a certificate:
iOS tip: AirDrop treats a Now the app opens straight in, with no challenges. One certificate per device, so each can be revoked on its own. @fravel77 since you're on Pangolin: the same idea should work wherever your proxy can make a valid client certificate an exception rather than a requirement. |
Uh oh!
There was an error while loading. Please reload this page.
Hey all!
First of all, thank you for this awesome project. I'd been following TREK for a while, and last weekend I finally used it on a real trip: everything worked flawlessly. Congrats on the iOS and Android launch, too!
The request
Let us add custom HTTP headers to the server connection in the mobile apps: a list of name/value pairs that the app sends with every request to my TREK server.
Why
My instance is on a public hostname, protected by Cloudflare Zero Trust: I want TREK reachable from anywhere, but with an extra layer of authentication in front of it. Today the app shows Cloudflare's challenge page, and once I pass it TREK loads and works, but shortly after the challenge comes back and I have to go through it again. It works, but the experience is rough, especially on a phone during a trip.
In a mobile app this is easy to solve for good, with custom headers. Cloudflare Access has service tokens for exactly this case (
CF-Access-Client-IdandCF-Access-Client-Secret), and a WAF rule can skip the challenge for requests that carry a secret header. The same goes for a reverse proxy (nginx, Caddy, Traefik) that only lets through requests with a shared-secret header. In every case TREK's own login stays the same; the header only gets the app past the layer in front of it, without the user ever seeing it.This is common in self-hosted mobile apps. Immich, for example, has it in the advanced settings of its login screen: immich-app/immich#1604
Suggestion
Related: #836 fixed Zero Trust redirects for the PWA; this would be the native-app side of the same problem.
Thanks again!
All reactions