Skip to content

feat: open protected conversation files in the app (open-protected-file) - #67

Merged
TobiasDuelli merged 1 commit into
masterfrom
fix/protected-files-native
Nov 18, 2026
Merged

TobiasDuelli merged 1 commit into
masterfrom
fix/protected-files-native

Conversation

@TobiasDuelli

@TobiasDuelli TobiasDuelli commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Why

Projects with authenticated conversation files serve new files from https://files.gleap.io/af/<id> (files.us.gleap.ai in the US). Only the session's short-lived file session (X-File-Session) can read them. The SDK already holds and refreshes it (GleapFileAccess), but nothing in the app could open such a file:

  • the Messenger shows "Open this chat in a browser to download" for files in the apps;
  • open-url with an /af/ URL went to ACTION_VIEW → the browser → 403;
  • open-url with a blob: URL was handled as an app link and closed the widget.

What

  • session-update announces capabilities.openProtectedFile: true (next to adoptSession). The Messenger sends the new open-protected-file { url, name } only to SDKs that announce it, so older SDKs keep today's behaviour.
  • GleapProtectedFiles (new):
    • accepts only a protected file of the configured region (https, files.gleap.io or files.us.gleap.ai for the US API, no port/userinfo, /af/<id> or /files/af/<id>; or the local API's own origin in development). The file session is never sent anywhere else;
    • downloads on a thread of its own (a large file does not hold back the SDK's request thread). The only credential is X-File-Session; no redirect is followed and nothing is cached;
    • stores the file in cache/gleap-files/<uuid>/<name>. The name is the attachment's name, else Content-Disposition; the extension comes from the type when the name has none;
    • opens it with ACTION_VIEW through io.gleap.GleapFileProvider (authority ${applicationId}.gleap.files, read-only grant, its own subclass so it never clashes with an app's FileProvider). If no app views the type, it opens the ACTION_SEND share sheet instead (save to Files or Drive, send);
    • keeps only the latest file; clearIdentity deletes it and drops a download on its way;
    • without a valid file session (e.g. right after the app returns from the background), the file waits for the usual refresh and opens with the next session-update.
  • open-url and links tapped in the widget page that point to a protected file take the same path instead of the browser.
  • blob: is now a blocked scheme (GleapExternalLinks): never opened, never closes the widget.

Apps without protected files see no change: no /af/ URLs exist for them. The only addition they get is the new capability flag, which the Messenger ignores unless a file is protected.

Tests

  • ProtectedFilesTest (unit, 11 tests): region/host rules, the request headers (token only, no redirects), names and types, waiting for a file session, other URLs never get the token, a 403 shows nothing and keeps nothing, only the latest file is shown, logout drops files, the capability flag, blob: blocked.
  • ProtectedFilesE2ETest (emulator, Pixel 6 Pro API 34, fake server and widget page from the existing e2e harness):
    • the page's open-protected-file downloads with the file session and starts a VIEW intent whose content://<pkg>.gleap.files/... URI is readable, has the read grant and has the right type and name;
    • an open-url to the file does the same and never reaches the browser;
    • an open-url with blob: keeps the widget open.
  • ./gradlew :gleap:testDebugUnitTest :gleap:assembleRelease: 271 tests, all pass. connectedDebugAndroidTest (ProtectedFilesE2ETest + WidgetLifecycleE2ETest): 4 of 4 pass.

Not verified: a real third-party viewer app opening the file (the e2e test catches the intent instead of launching one), and the share-sheet fallback (no device without a viewer was tried).

Rollout

🤖 Generated with Claude Code

Projects with authenticated conversation files serve them from
files.gleap.io/af/<id> (files.us.gleap.ai in the US), readable only with the
session's file session. A browser does not have it, so a protected file could
not be opened or saved from the app.

- session-update announces capabilities.openProtectedFile; the Messenger sends
  open-protected-file {url, name} only to SDKs that announce it.
- GleapProtectedFiles downloads the file on a thread of its own with
  X-File-Session as the only credential (no redirect, no cache), only from the
  files host of the configured API region (or the local API's own origin),
  keeps it in cache/gleap-files and hands it to the app that views its type
  through io.gleap.GleapFileProvider (<applicationId>.gleap.files, read-only
  grant); the share sheet when no app views it. Only the latest file is kept;
  a logout deletes it and drops a download on its way.
- Without a valid file session the file waits for the renewal (the usual
  foreground refresh) and opens with the next session update.
- open-url and tapped links to a protected file go the same way instead of to
  the browser (403). blob: is a blocked scheme: as an app link it closed the
  widget.

Tests: ProtectedFilesTest (unit) and ProtectedFilesE2ETest (emulator, fake
server + widget page: the bridge message and the open-url link start a VIEW
intent with a readable content URI; a blob: link keeps the widget open).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TobiasDuelli
TobiasDuelli merged commit bc94d85 into master Nov 18, 2026
1 check passed
@TobiasDuelli
TobiasDuelli deleted the fix/protected-files-native branch November 18, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants