Skip to content

Commit e4bf6fa

Browse files
birdbluesclaude
andcommitted
mobile: sandboxed HTML apps — app card, sandbox WebView, NIP-11 door discovery
- imeta `x` / `preview-light` / `preview-dark`; `MessageMediaKind.app` (= text/html + a lowercase 64-hex hash) - AppCard: theme-matched static preview, Run, Download, sender in the chrome; never in clamped previews - AppWebViewPage: CupertinoPageRoute, `loadRequest` with the Authorization header (never a URL token), navigation locked to the initial URL, no JavaScript channels, error + retry states - relay_info: NIP-11 `app_content_url` with the desktop's validation (bare origin, relay hostname, distinct origin), re-asked on every reconnect, remembered per relay; null = HTML stays a link - signAppContentAuth: blob-scoped kind-24242 token, 300 s, no `server` tag, minted fresh per Run - iOS: NSAllowsLocalNetworking (WKWebView obeys ATS); SandboxWebViewHardening swizzles WKWebView.load(_:) to register the document-start WebRTC/sendBeacon removal script for /app/<sha>.html requests — webview_flutter exposes no user-script API and WebKit ignores CSP `webrtc 'block'` - Pretendard 1.3.9 (OFL) bundled as a font family - dev_push_lease: widen the exact NIP-11 allowlist (app_content_url, admin_api, gif) — advertising the door made the push descriptor unparseable and silently disabled push discovery on mobile - docs: mobile section rewritten — code on the mac mini, build and verify on the Intel Mac + iPad Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01UAm5qbNPszvcwnMMbfGVGa Signed-off-by: dhseo <[email protected]>
1 parent 1ab6be3 commit e4bf6fa

29 files changed

Lines changed: 1625 additions & 56 deletions

‎docs/sandboxed-apps.md‎

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Three independent layers; any one failing leaves the other two:
1919
| Layer | Where | What it guarantees |
2020
|---|---|---|
2121
| Response CSP `sandbox allow-scripts; default-src 'none'; connect-src 'none'; webrtc 'block'; …` | relay app door **and** re-stamped by the desktop proxy | opaque origin, no fetch/XHR/WS/beacon, no forms, no plugins. **WebKit ignores `webrtc 'block'`** — see the subframe script below |
22-
| Subframe script | desktop `sandbox_frame_hardening.rs` (`initialization_script_for_all_frames`) | in every non-main frame, `RTCPeerConnection` & co. are undefined and `sendBeacon` returns false before app code runs; properties are non-configurable. Observed before the fix: ICE gathering reached a public STUN server from inside the sandbox |
22+
| Subframe script | desktop `sandbox_frame_hardening.rs` (`initialization_script_for_all_frames`); mobile `ios/Runner/SandboxWebViewHardening.swift` (document-start `WKUserScript`, all frames of the sandbox web view) | `RTCPeerConnection` & co. are undefined and `sendBeacon` returns false before app code runs; properties are non-configurable. Observed before the fix: ICE gathering reached a public STUN server from inside the sandbox |
2323
| Embedder sandbox | desktop `<iframe sandbox="allow-scripts">`; mobile `NavigationDelegate` | survives in-frame navigation; no top navigation, popups, downloads, forms |
2424
| Navigation lock | desktop `navigation_policy.rs` (`WebviewWindowBuilder::on_navigation`), parent CSP `frame-src buzz-media:`; mobile: every request after the first is `prevent` | a frame cannot carry data out by navigating itself to an external URL |
2525

@@ -107,55 +107,48 @@ Report back by cross-session message to the mac-mini session (it shows as
107107
"buzz 웹앱 구현" in your ListAgents) with one line per item 2–6 and the run id
108108
from item 5. Then continue with the mobile checklist below.
109109

110-
## Mobile — checklist for the Intel-Mac session (real iPad)
111-
112-
Do not build or run the Flutter app on the M-series dev Mac; verify on a
113-
physical iPad from the Intel Mac session.
114-
115-
**Assignment (2026-09-05):** items 1–8 below are the Intel-Mac session's work
116-
— `mobile/` has no changes on this branch yet, so implementation comes first.
117-
Test fixtures are already in `#test`: an archify sequence app with light/dark
118-
previews, `sandbox-probe.html`, and a listener-targeted `sandbox-net-probe.html`.
119-
Relay: `ws://192.168.1.99:3000`, app door `http://192.168.1.99:3001`.
120-
121-
1. `pubspec.yaml`: add `webview_flutter`. `ios/Runner/Info.plist`: add
122-
`NSAppTransportSecurity` → `NSAllowsLocalNetworking = true` (WKWebView
123-
obeys ATS; the Dart `http` client does not).
124-
2. `lib/features/channels/message_media.dart`: parse imeta `x`,
125-
`preview-light`, `preview-dark`; add `MessageMediaKind.app` for
126-
`m == text/html && x`.
127-
3. `lib/features/channels/message_content.dart` `_buildLink`: when the link's
128-
imeta resolves to an app → `AppCard` (preview chosen by
129-
`Theme.of(context).brightness`, Run, Download). Widget test.
130-
4. `lib/shared/relay/relay_info.dart`: read NIP-11 `app_content_url`, same
131-
validation as desktop (bare origin, relay hostname, distinct port).
132-
5. `lib/shared/relay/media_auth.dart`: `signAppContentAuth(sha256)` — `t=get`,
133-
`x`, `expiration = now + 300 s`, **no `server` tag**. Leave the existing
134-
server-scoped signer untouched. The relay caps `expiration` at `now + 600`
135-
with **no clock-skew tolerance**, so minting the full 600 s returns 401
136-
whenever the device clock is a second ahead of the relay (seen on a second
137-
Mac); 300 s leaves ±300 s headroom.
138-
6. `AppWebViewPage` (pushed with `CupertinoPageRoute` — slides in from the
139-
right): `loadRequest(uri, headers: {'Authorization': …})`,
140-
`javaScriptMode: unrestricted`, **no JavaScript channels**,
141-
`NavigationDelegate.onNavigationRequest` returns `prevent` for anything
142-
but the initial URL, top bar with sender + "sandbox" + close.
143-
7. Bundle Pretendard (same release as the desktop/skill assets) as a Flutter
144-
font family for future SVG previews.
145-
7b. **WebKit ignores the CSP `webrtc 'block'` directive** — on the desktop
146-
the probe reached a public STUN server over UDP from inside the sandbox
147-
until a user script removed WebRTC. Add a document-start `WKUserScript`
148-
(webview_flutter: `runJavaScript` is too late; use the platform
149-
`WKUserScript` injection) that defines `RTCPeerConnection`,
150-
`webkitRTCPeerConnection`, `RTCDataChannel` & co. as non-configurable
151-
`undefined` and makes `navigator.sendBeacon` return `false`. Mirror
152-
`desktop/src-tauri/src/sandbox_frame_hardening.rs`; the mobile page is the
153-
top frame, so apply it unconditionally (no `window.top === window` guard).
154-
Probe row 9 (`RTCPeerConnection + ICE gather`) is the check.
155-
8. On the iPad: (a) an archify app renders and is interactive; (b) the probe
156-
page below shows every escape as blocked; (c) link taps, `window.open`,
157-
form submits do nothing; (d) no ATS error/blank page over
158-
`http://<lan-ip>:3001`; (e) reopening after 10 minutes mints a fresh token.
110+
## Mobile — code on the mac mini, build and verify on the Intel Mac (real iPad)
111+
112+
The M-series dev Mac has no Flutter toolchain or pub cache, so the mobile
113+
code is written there and **analyzed, built, installed and verified from the
114+
Intel-Mac session** on a physical iPad. Test fixtures are in `#test`: an
115+
archify sequence app with light/dark previews, `sandbox-probe.html`, and a
116+
listener-targeted `sandbox-net-probe.html`. Relay: `ws://192.168.1.99:3000`,
117+
app door `http://192.168.1.99:3001`.
118+
119+
### Implementation (2026-09-05)
120+
121+
| Piece | Where |
122+
|---|---|
123+
| imeta `x`, `preview-light`, `preview-dark`; `MessageMediaKind.app` (= `text/html` + a lowercase 64-hex `x`) | `mobile/lib/features/channels/message_media.dart` |
124+
| App card: theme-matched preview (`Theme.of(context).brightness`), Run, Download, sender in the chrome. Never in clamped previews (`maxLines`) | `mobile/lib/features/channels/message_content/app_card.dart`, wired from `message_content.dart` (`_buildAppCard`, for both `[…]()` and `![…]()` syntax) |
125+
| NIP-11 `app_content_url` discovery with the desktop's validation (bare origin, relay hostname, distinct origin); re-asked on every reconnect; remembered per relay so a community switch cannot reuse another relay's door | `mobile/lib/shared/relay/relay_info.dart` — `appContentUrlProvider`, null = HTML stays a link |
126+
| Blob-scoped token: `t=get`, `x`, `expiration = now + 300 s`, **no `server` tag**, minted fresh on every Run (never memoized) | `mobile/lib/shared/relay/media_auth.dart` `signAppContentAuth` |
127+
| Sandbox page: `CupertinoPageRoute` (slides in from the right, like the desktop drawer; stacks inside the pane in the wide shell), `loadRequest(uri, headers: {Authorization})`, JS unrestricted, **no JavaScript channels**, `onNavigationRequest` allows the initial URL only, error + retry states | `mobile/lib/features/channels/app_webview_page.dart` |
128+
| ATS: `NSAppTransportSecurity → NSAllowsLocalNetworking = true` (WKWebView obeys ATS; the Dart client does not) | `mobile/ios/Runner/Info.plist` |
129+
| WebRTC + `sendBeacon` removal. `webview_flutter` has no user-script API, so `WKWebView.load(_:)` is swizzled: a request for `/app/<sha256>.html` registers the document-start script (all frames) on that web view before the navigation starts. The script itself no-ops for a top-level document outside that path | `mobile/ios/Runner/SandboxWebViewHardening.swift`, installed from `AppDelegate` |
130+
| Pretendard 1.3.9 (OFL) as a Flutter font family | `mobile/pubspec.yaml`, `mobile/assets/fonts/Pretendard-*.otf` |
131+
| NIP-11 allowlist widened with `app_content_url`, `admin_api`, `gif`. The push descriptor parser rejects any unknown top-level NIP-11 field, so advertising the door would otherwise have silently disabled push on mobile | `mobile/lib/shared/push/dev_push_lease.dart` |
132+
133+
### Intel-Mac session: build and verify
134+
135+
1. `flutter pub get` → `flutter analyze` → `dart format --set-exit-if-changed` →
136+
`flutter test`. Send the `pubspec.lock` / `Podfile.lock` hunks back to the
137+
mac-mini session (or commit them) — it cannot resolve packages.
138+
2. Release build → `xcrun devicectl device install app` (`Buzz.app`) → launch
139+
`dev.birdblues.buzz.mobile`.
140+
3. Confirm the built `Info.plist` carries
141+
`NSAppTransportSecurity/NSAllowsLocalNetworking`. If the WebView still
142+
refuses `http://<lan-ip>:3001` (blank page, ATS error in the console), that
143+
iOS does not treat a raw private IP as local networking — add an
144+
`NSExceptionDomains` entry for the relay host instead.
145+
4. On the iPad: (a) an archify app renders and is interactive; (b) the probe
146+
page below shows every escape as blocked — row 9 (`RTCPeerConnection`) is
147+
the native script; (c) link taps, `window.open`, form submits do nothing;
148+
(d) no ATS error/blank page over `http://<lan-ip>:3001`; (e) reopening
149+
after 10 minutes mints a fresh token; (f) the listener-targeted net probe
150+
with the `3999`/`3478` listeners up on the mac mini reports zero hits
151+
(send the run id and time); (g) light/dark preview follows the app theme.
159152

160153
## Sandbox probe
161154

@@ -171,4 +164,4 @@ Pretendard (OFL) is the one fixed face:
171164
- archify skill `scripts/embed-fonts.mjs`: subsets the woff2 to the
172165
characters used and inlines it into the HTML (the sandbox blocks font
173166
downloads).
174-
- Mobile: bundle the same release.
167+
- Mobile: bundled as the `Pretendard` font family (same 1.3.9 release).
1.5 MB
Binary file not shown.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Copyright (c) 2021, Kil Hyung-jin (https://github.com/orioncactus/pretendard),
2+
with Reserved Font Name Pretendard.
3+
4+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
5+
This license is copied below, and is also available with a FAQ at:
6+
https://scripts.sil.org/OFL
7+
8+
9+
-----------------------------------------------------------
10+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
11+
-----------------------------------------------------------
12+
13+
PREAMBLE
14+
The goals of the Open Font License (OFL) are to stimulate worldwide
15+
development of collaborative font projects, to support the font creation
16+
efforts of academic and linguistic communities, and to provide a free and
17+
open framework in which fonts may be shared and improved in partnership
18+
with others.
19+
20+
The OFL allows the licensed fonts to be used, studied, modified and
21+
redistributed freely as long as they are not sold by themselves. The
22+
fonts, including any derivative works, can be bundled, embedded,
23+
redistributed and/or sold with any software provided that any reserved
24+
names are not used by derivative works. The fonts and derivatives,
25+
however, cannot be released under any other type of license. The
26+
requirement for fonts to remain under this license does not apply
27+
to any document created using the fonts or their derivatives.
28+
29+
DEFINITIONS
30+
"Font Software" refers to the set of files released by the Copyright
31+
Holder(s) under this license and clearly marked as such. This may
32+
include source files, build scripts and documentation.
33+
34+
"Reserved Font Name" refers to any names specified as such after the
35+
copyright statement(s).
36+
37+
"Original Version" refers to the collection of Font Software components as
38+
distributed by the Copyright Holder(s).
39+
40+
"Modified Version" refers to any derivative made by adding to, deleting,
41+
or substituting -- in part or in whole -- any of the components of the
42+
Original Version, by changing formats or by porting the Font Software to a
43+
new environment.
44+
45+
"Author" refers to any designer, engineer, programmer, technical
46+
writer or other person who contributed to the Font Software.
47+
48+
PERMISSION & CONDITIONS
49+
Permission is hereby granted, free of charge, to any person obtaining
50+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
51+
redistribute, and sell modified and unmodified copies of the Font
52+
Software, subject to the following conditions:
53+
54+
1) Neither the Font Software nor any of its individual components,
55+
in Original or Modified Versions, may be sold by itself.
56+
57+
2) Original or Modified Versions of the Font Software may be bundled,
58+
redistributed and/or sold with any software, provided that each copy
59+
contains the above copyright notice and this license. These can be
60+
included either as stand-alone text files, human-readable headers or
61+
in the appropriate machine-readable metadata fields within text or
62+
binary files as long as those fields can be easily viewed by the user.
63+
64+
3) No Modified Version of the Font Software may use the Reserved Font
65+
Name(s) unless explicit written permission is granted by the corresponding
66+
Copyright Holder. This restriction only applies to the primary font name as
67+
presented to the users.
68+
69+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
70+
Software shall not be used to promote, endorse or advertise any
71+
Modified Version, except to acknowledge the contribution(s) of the
72+
Copyright Holder(s) and the Author(s) or with their explicit written
73+
permission.
74+
75+
5) The Font Software, modified or unmodified, in part or in whole,
76+
must be distributed entirely under this license, and must not be
77+
distributed under any other license. The requirement for fonts to
78+
remain under this license does not apply to any document created
79+
using the Font Software.
80+
81+
TERMINATION
82+
This license becomes null and void if any of the above conditions are
83+
not met.
84+
85+
DISCLAIMER
86+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
94+
OTHER DEALINGS IN THE FONT SOFTWARE.
1.51 MB
Binary file not shown.
1.5 MB
Binary file not shown.
1.51 MB
Binary file not shown.

‎mobile/ios/Runner.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
42C129326CE4E1B8E617B9CD /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD6B899582D0416ADBD8A68F /* Pods_RunnerTests.framework */; };
4040
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
4141
BZZ00000000000000000023 /* PushNativeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = BZZ00000000000000000024 /* PushNativeState.swift */; };
42+
BZZ00000000000000000030 /* SandboxWebViewHardening.swift in Sources */ = {isa = PBXBuildFile; fileRef = BZZ00000000000000000031 /* SandboxWebViewHardening.swift */; };
4243
BZZ00000000000000000026 /* PushEndpointGrantStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BZZ00000000000000000027 /* PushEndpointGrantStore.swift */; };
4344
BZZ00000000000000000029 /* PushSnapshotBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = BZZ0000000000000000002A /* PushSnapshotBridge.swift */; };
4445
BZZ0000000000000000002B /* BuzzCommunicationNotificationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BZZ0000000000000000002C /* BuzzCommunicationNotificationTests.swift */; };
@@ -121,6 +122,7 @@
121122
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
122123
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
123124
BZZ00000000000000000024 /* PushNativeState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNativeState.swift; sourceTree = "<group>"; };
125+
BZZ00000000000000000031 /* SandboxWebViewHardening.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SandboxWebViewHardening.swift; sourceTree = "<group>"; };
124126
BZZ00000000000000000027 /* PushEndpointGrantStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushEndpointGrantStore.swift; sourceTree = "<group>"; };
125127
BZZ0000000000000000002A /* PushSnapshotBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushSnapshotBridge.swift; sourceTree = "<group>"; };
126128
BZZ0000000000000000002C /* BuzzCommunicationNotificationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuzzCommunicationNotificationTests.swift; sourceTree = "<group>"; };
@@ -247,6 +249,7 @@
247249
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
248250
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
249251
BZZ00000000000000000024 /* PushNativeState.swift */,
252+
BZZ00000000000000000031 /* SandboxWebViewHardening.swift */,
250253
BZZ00000000000000000027 /* PushEndpointGrantStore.swift */,
251254
BZZ0000000000000000002A /* PushSnapshotBridge.swift */,
252255
331C809A294A618700263BE5 /* MediaSanitizer.swift */,
@@ -574,6 +577,7 @@
574577
files = (
575578
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
576579
BZZ00000000000000000023 /* PushNativeState.swift in Sources */,
580+
BZZ00000000000000000030 /* SandboxWebViewHardening.swift in Sources */,
577581
BZZ00000000000000000026 /* PushEndpointGrantStore.swift in Sources */,
578582
BZZ00000000000000000029 /* PushSnapshotBridge.swift in Sources */,
579583
331C809B294A63AB00263BE5 /* MediaSanitizer.swift in Sources */,

‎mobile/ios/Runner/AppDelegate.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import os.log
4040
_ application: UIApplication,
4141
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
4242
) -> Bool {
43+
// Before Flutter creates any WKWebView: see SandboxWebViewHardening.swift.
44+
SandboxWebViewHardening.install()
4345
UNUserNotificationCenter.current().delegate = self
4446
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
4547
}

‎mobile/ios/Runner/Info.plist‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
<string>Buzz uses Face ID to confirm sensitive identity transfers.</string>
5252
<key>NSLocalNetworkUsageDescription</key>
5353
<string>Buzz uses your local network to connect to relays hosted on devices near you, such as during development. Remote messaging does not require this access.</string>
54+
<key>NSAppTransportSecurity</key>
55+
<dict>
56+
<!-- WKWebView obeys ATS (the Dart http client does not). Sandboxed apps
57+
are served over plain HTTP from the relay's LAN app door. -->
58+
<key>NSAllowsLocalNetworking</key>
59+
<true/>
60+
</dict>
5461
<key>NSCameraUsageDescription</key>
5562
<string>Buzz uses the camera to take profile photos and animated avatars, attach photos to messages, and scan QR codes for device pairing.</string>
5663
<key>NSMicrophoneUsageDescription</key>

0 commit comments

Comments
 (0)