Skip to content

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

Merged
TobiasDuelli merged 3 commits into
mainfrom
fix/protected-files-native
Nov 18, 2026
Merged

TobiasDuelli merged 3 commits into
mainfrom
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 renews it (GleapSessionHelper), 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 SFSafariViewController without the header → 403;
  • open-url with a blob: URL was handled as a deep link → [Gleap close] closed the Messenger.

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, internal), owned by the widget's GleapFrameManagerViewController:
    • 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 with X-File-Session as the only header; no cookies, no URL cache, no redirect followed;
    • moves the file to Caches/gleap-files/<uuid>/<name>. The name is the attachment's name, else the server's suggested name; the extension comes from the MIME type (UTType) when the name has none, so QuickLook knows the type;
    • presents QuickLook over the widget. Its share button saves the file (Files, AirDrop, …). Images, PDFs, video and Office documents preview; anything else shows its icon with the share button;
    • deletes the file when QuickLook closes, when the next file downloads and on clearIdentity. A download that finishes after a logout or a user change is dropped;
    • without a valid file session (e.g. right after the app returns from the background), the file waits for refreshFileAccessIfNeeded and opens with the next session-update.
  • open-url, tapped links, other main-frame navigations and window.open that point to a protected file take the same path instead of Safari.
  • open-url with blob: is ignored instead of closing the widget.
  • The SDK now links QuickLook and UniformTypeIdentifiers (Package.swift + podspec).

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 (iPhone 16 Pro simulator)

  • GleapProtectedFilesTests (11 tests): region/host rules, request headers (token only), file names, waiting for the renewed file session (real identify round trip with stubs), other URLs never get the token, a 403 shows nothing and keeps nothing, logout drops files, open-url routing (blob: ignored, /af/ opens in the app, other links still go to the app's openExternalLink:), a blob: link does not close the widget, the capability flag.
  • End to end on the simulator: a page on the Messenger origin, in a real WKWebView with the SDK's bridge, posts open-protected-file. The test checks that QuickLook appears over the widget in a window with the downloaded file (right name and bytes), and that closing it deletes the file.
  • Full suite: 177 tests, all pass. pod lib lint Gleap.podspec --allow-warnings passes.

Not verified: the live Messenger and the real files host (the tests use stubbed HTTP and a test page), and saving through the share sheet by hand. On-screen QuickLook can't be checked in unit tests either: the SwiftPM test host has no window scene, so UIKit accepts the presentation (that is what the end-to-end test checks) but never finishes its transition.

CI: the end-to-end test failed once in CI (run 44128972531). It had a single 30 s deadline, and WebKit's cold start on the CI simulator alone takes 30–40 s. It now waits for each step with its own deadline, and its teardown leaves nothing presented for the next test. Reproduced and verified on an erased iPhone 16e / iOS 26.2 simulator: the old test fails 1 of 177, the new one passes 177 of 177. .github/scripts/test.sh now writes build/TestResults.xcresult, and CI uploads it when the tests fail; before, -quiet showed only the failing test's name.

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. Safari 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 with X-File-Session as the only
  credential (no cookies, no cache, no redirect), only from the files host of
  the configured API region (or the local API's own origin), keeps it under
  Caches/gleap-files and shows it in QuickLook over the widget, whose share
  button saves it. The file is deleted when QuickLook closes, with the next
  download and on clearIdentity; a download on its way for another user is
  dropped.
- Without a valid file session the file waits for the renewal and opens with
  the next session update.
- open-url, tapped links and window.open to a protected file go the same way
  instead of to Safari (403). open-url with blob: is ignored: as an app link it
  closed the widget.
- Links QuickLook and UniformTypeIdentifiers (Package.swift, podspec).

Tests: GleapProtectedFilesTests, including a page in a real WKWebView posting
open-protected-file through the bridge and QuickLook appearing over the widget
in a window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TobiasDuelli and others added 2 commits November 18, 2026 09:30
xcodebuild -quiet prints only the names of failing tests, so a CI failure
showed no message, log or attachment. test.sh now writes a result bundle
(build/TestResults.xcresult, TEST_RESULT_BUNDLE to override) and CI uploads
it as an artifact when the tests fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
testTheMessengersMessageOpensTheFileInQuickLook failed in CI (run
44128972531, iPhone 16e / iOS 26.2): one 30 s deadline covered WebKit
starting its processes for the test page, the download and the presentation.
On a freshly erased iPhone 16e / iOS 26.2 simulator WebKit alone takes 30 to
40 s; the old test failed there the same way ("QuickLook is shown over the
widget", 176 of 177 passed) and the run then hung until xcodebuild collected
diagnostics, because the file presented after the test had ended.

- Step 1 waits for the file request (proves the page's message went through
  WebKit's bridge to the SDK), deadline 180 s.
- Step 2 waits for QuickLook to be the widget's presented view controller,
  deadline 30 s (about 1 s here). The SwiftPM test host connects no window
  scene, so UIKit never finishes a presentation's transition there; the test
  checks what UIKit takes, as before, and says so.
- Closing waits for the dismissal's completion, then checks the file is gone.
- Teardown removes the widget from the window, so a download still on its way
  presents nothing after the test.
- The link spy's openExternalLink takes a non-optional URL (Xcode 26 warned).

No production code changed. Locally: 177 of 177 on an erased iPhone 16e /
iOS 26.2 simulator (Xcode 27.1); the old test fails 1 of 177 there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TobiasDuelli
TobiasDuelli merged commit d3e0ed8 into main Nov 18, 2026
1 check passed
@TobiasDuelli
TobiasDuelli deleted the fix/protected-files-native branch November 18, 2026 20:40
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