Developer docs
Telvoro Mini Apps
On this page
Bots can ship HTML5 apps that open inside Televo. Mini app content is untrusted code. The rules marked MUST are security requirements for every client (official and third-party); the official clients have tests for each one.
1. Launch & authentication
- Client calls
WebAppsService/RequestWebView→WebView{url, origin, expires_at}. - Launch data travels in the URL fragment (
#tvWebAppData=...), never the query string. init_data= URL-encoded fieldsquery_id, user (JSON), chat_type, chat_instance, start_param, auth_date, expires_atplus two signatures:hash= hex HMAC-SHA256(key = HMAC-SHA256(“WebAppData”, bot_token), data_check_string) — Telegram-compatible algorithm, so existing validation libraries work;signature= Ed25519 by the Telvoro server key (public key published at/.well-known/televo-webapp-key), so third parties can verify without the bot token.
- Bots MUST verify a signature and reject
auth_dateolder than their own limit (recommended ≤ 1 h) — documented prominently, with copy-paste validators for Go/Python/Node. - The session token is never exposed to a mini app in any form.
1.1 Exact signing rules and test vector (normative)
dcs(excl): every field not inexcl, askey=valuewith the URL-decoded value, sorted by key (byte order), joined by\n.signature= base64url, no padding, of Ed25519(server_key,"<bot_id>:WebAppData\n" + dcs({hash, signature})). It is computed first.hash= lowercase hex of HMAC-SHA256(key = HMAC-SHA256(key="WebAppData", msg=bot_token), msg =dcs({hash})). It is computed second, sosignatureis covered by the HMAC, exactly like Telegram’s current scheme.kidnames the server key that producedsignature. It is an ordinary field, covered by both signatures./.well-known/televo-webapp-keyreturns:{"ed25519": "<active key, base64url>", "kid": "<active kid>", "keys": [{"kid", "alg": "Ed25519", "key": "<base64url>", "status": "active|retired", "expires_at": <ms>}]}.- Verify with the key whose
kidmatches. Retired keys stay listed for 24 h.
Test vector (Ed25519 seed = bytes 0x00…0x1f, bot_id 123456, bot_token 123456:AAH-televo-test-vector-token):
public key (base64url): A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg
init_data:
auth_date=1700000000&chat_instance=-555&chat_type=sender&expires_at=1700003600&hash=861c707013be8420c318137b465ff02cb41a2bc20e141d18417acf78f3ad690b&kid=k0&query_id=987654321&signature=amApX25QSlBLj0OxzC53GLcq1xbAr9kwKz37w4fYAsIiPfinGEzGo4T0tv180sOuhjRsV2tTtsKm-AFxvVjLBQ&start_param=ref_1&user=%7B%22id%22%3A42%2C%22first_name%22%3A%22Ann%22%2C%22username%22%3A%22ann%22%7D
hash: 861c707013be8420c318137b465ff02cb41a2bc20e141d18417acf78f3ad690b
signature: amApX25QSlBLj0OxzC53GLcq1xbAr9kwKz37w4fYAsIiPfinGEzGo4T0tv180sOuhjRsV2tTtsKm-AFxvVjLBQ
Server test: server/internal/webapp/vector_test.go. Client validators must reproduce both values (evaluate at a fixed “now” such as 1700000100, since this vector is already expired).
2. Isolation (MUST)
| Platform | Container | Settings |
|---|---|---|
| iOS / macOS | WKWebView, non-persistent or per-bot WKWebsiteDataStore | no allowFileAccessFromFileURLs, isInspectable = false in release, JS bridge via WKScriptMessageHandler on a dedicated content world |
| Android | WebView in its own activity/fragment | setAllowFileAccess(false), setAllowContentAccess(false), no addJavascriptInterface with reflection — single WebMessagePort channel, setWebContentsDebuggingEnabled(false) in release, Safe Browsing on |
| Windows | WebView2 with a dedicated user-data folder per bot | AreDevToolsEnabled=false release, IsWebMessageEnabled only |
| Linux | WebKitGTK, ephemeral WebKitWebsiteDataManager | dev tools off in release |
| Web client | cross-origin <iframe sandbox="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin"> where allow-same-origin refers to the app’s own origin, which MUST differ from the client origin; no allow-top-navigation* | client page served with strict CSP (script-src 'self', no inline, frame-src https:), Trusted Types, frame-ancestors 'none' |
- Navigation inside the view is restricted to
WebView.allowed_origins(https only); anything else is cancelled and offered as an external link (§3). - Each bot gets separate storage/cookies; clearing on “log out” and per-bot reset.
3. Bridge (MUST)
- One message channel; every inbound message is checked for source and origin
(
event.source === iframe.contentWindow && event.origin === WebView.origin; native: the frame’s security origin from the message handler, main frame only). - Messages are JSON
{ "method": string, "params": object }, ≤ 64 KiB, validated against a fixed schema per method; unknown methods/fields → ignored. No method executes code, builds HTML, or touches the client DOM. - Links:
openLink(url)acceptshttps:only (alsohttp:after an extra warning);javascript:,data:,file:,blob:,intent:, custom schemes → rejected. The URL is parsed with the platform URL parser and re-serialised before use; the confirmation sheet shows the punycode-decoded registrable domain. Opens in the external browser. openInternalLink(path)accepts onlytelevo://routes from an allow-list (user/chat/join/addstickers/app) and goes through the normal router + its confirmations.- Anything with side effects shows a client-drawn confirmation that the mini app cannot
draw over: send data / share message, request phone, request write access, location,
camera/mic (
getUserMediamapped to the permission model), add to home screen, file download. - Rate limits: popups/alerts ≤ 1 visible + 3/min, haptics ≤ 20/s,
sendDataonce per query. - Theme/viewport events flow client → app only.
4. Anti-phishing UI (MUST)
- The header with the bot’s name, avatar, verified badge and current domain is drawn by the client and always visible, also in fullscreen mode (collapsed pill). The app cannot set its own title.
- First launch of an unverified bot shows a one-time “this app is run by <bot>, not by Telvoro” notice. Never render mini app content in the chat timeline.
- Long-press/right-click the header: Reload, Open in browser, Report, Remove permissions.
5. Server-side controls
- Bot owners register app URLs; https only, public IPs only (same SSRF guard as webhooks for any server-side fetch), domain change re-requires confirmation.
AnswerWebAppQueryonly for a livequery_idof the same bot, single use, 15 min TTL.- Abuse: report flow, per-bot kill switch (server refuses RequestWebView with
403 WEBAPP_DISABLED).
6. Bridge protocol and SDKs
The wire protocol is specified normatively in WEBAPP_BRIDGE.md
(envelope, handshake + version negotiation, per-platform transports, channel token, every
method/event with its schema, error codes, limits). Content authors use the SDKs in
sdk/js: @televo/webapp (served by televod as /webapp/televo-web-app.js,
window.Televo.WebApp), @televo/card (inline it into cards), and
@televo/telegram-compat (/webapp/telegram-web-app.js, window.Telegram.WebApp;
unsupported Telegram APIs fail closed). Server-side validation of init_data:
@televo/validate (HMAC + Ed25519), Go/Python snippets in WEBAPP_BRIDGE.md §7.
7. Security test suite (required before release)
Malicious fixture app (app/test_fixtures/evil_webapp/) attempting: javascript:/data:/
intent: links; postMessage from a nested cross-origin iframe and from another window;
oversized/malformed messages; window.top.location navigation; popup flood; drawing a fake
“Telvoro login” page (header must still show bot + domain); reading client storage/cookies;
replaying an expired init_data against the sample bot validator; file:// navigation.
Every attempt must fail; the test runs on web + at least one native platform in CI.
8. Interactive HTML messages (Media.html / HtmlCard) — normative
HTML cards are mini documents with JavaScript inside a message bubble. They are more dangerous than mini apps (they appear unprompted in chats, in bulk), so they are tighter.
Who may send: bots only (SendMessage with InputMedia.html from a user session →
403 HTML_BOT_ONLY). Server limits: ≤ 64 KiB, height ≤ 640, edits via EditMessage
bump version. Channels may post cards only via an admin bot. Forwarding keeps the card
attributed to the original bot (“via @bot”).
Isolation (MUST):
- Each card runs in its own context with an opaque origin: web
iframe sandbox="allow-scripts"srcdoc(NOallow-same-origin, NOallow-popups, NOallow-top-navigation*, NOallow-forms, NOallow-modals); native: a fresh non-persistent WebView loaded vialoadHTMLStringwith a null/opaque base URL.
- The client injects, before the card’s own markup, a CSP the card cannot relax:
default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:; font-src data:; connect-src 'none'; frame-src 'none'; form-action 'none'; base-uri 'none'; navigate-to 'none'and, where the platform supports it, a network-level block too (WKContentRuleList blocking all loads, AndroidshouldInterceptRequest→ deny, WebView2WebResourceRequested→ deny). Result: a card cannot make any network request — no tracking pixels, no IP leak, no exfiltration, no fetching remote scripts. - No storage persistence (
localStorage/IndexedDB/cookies are ephemeral or unavailable). - Navigation of the card frame is always cancelled.
- No camera, mic, geolocation, clipboard-read, notifications, fullscreen, WebUSB/Bluetooth, etc.
Activation & resource limits (MUST):
- Default: render
preview(orfallback_text) only; JavaScript runs after the user taps “▶ Run” on that card.autostartis honoured only for verified bots and only while visible. - At most one live card at a time (activating another stops the previous); a card is torn down when scrolled off-screen or after 5 min without interaction.
- Hard caps: ≤ 640 px height, CPU watchdog (unresponsive > 2 s → kill, show “card stopped”),
memory per the platform’s process limits; reduce-motion disables
autostart.
Bridge (subset of §3, MUST): window.TelevoCard with only:
ready(), resize(height), callback(data ≤ 4 KiB) → bot receives a CallbackQuery
with from_html_card = true (rate limit 1/s, 30/min per card), openLink(url) (same rules
as §3, always confirmed), openMiniApp(short_name) (bot’s own apps only), haptic(kind),
and read-only theme / lang / platform. No user identity, chat id, message content,
or files are exposed to the card; data must come from the bot via callbacks and message edits.
Card content can’t draw outside its bubble; the bubble shows “via @bot” chrome the card can’t hide.
Server: validates size/UTF-8, stores encrypted like other content, never renders or
executes it. Push notifications and dialog-list previews use fallback_text only.
Tests: extend §7 with card fixtures attempting: fetch/XHR/WebSocket/<img src=https:>/
CSS url()/<link rel=prefetch>/<meta http-equiv=refresh>/DNS-prefetch exfiltration (all must
produce zero network requests — assert with a local sniffing server), window.top/parent
access, document.cookie/storage read of the client, infinite loop (watchdog), 10k-node DOM
bomb, window.open, form submit, javascript: link via bridge, bridge spam.
9. Platform notes and residual risks (measured by the §7/§8 suites)
| Platform (official client) | Mini apps | HTML cards | Navigation cancel | Notes |
|---|---|---|---|---|
| iOS / macOS | ✓ WKWebView via webview_flutter | ✓ televo_card_webview (own WKWebView) | ✓ before any request | cards: non-persistent data store, compiled WKContentRuleList blocking every load except about:/data:/blob:, exactly one navigation allowed (the loadHTMLString with nil base → about:blank, opaque origin), native handler in a dedicated WKContentWorld (page world only gets a frozen window.televo.postMessage relay), WebRTC off via the WebKit peerConnectionEnabled preference where present (SPI, guarded by respondsToSelector) plus a document-start script, media autoplay off, capture permissions denied, not inspectable in release. Needs iOS 14 / macOS 11 (older: card shows “crashed”). |
| Android | ✓ WebView via webview_flutter | ✓ televo_card_webview (own android.webkit.WebView) | ✓ | cards: base64 data: document (opaque origin), shouldInterceptRequest → empty 403 for everything but data:/blob:, setBlockNetworkLoads/Image(true), shouldOverrideUrlLoading → true, no file/content access, no DOM storage, no geolocation, permissions denied, Safe Browsing on, bridge = one WebMessagePort handed to the main frame with init, WebRTC removed by a DOCUMENT_START_SCRIPT in every frame. Mini apps: webview_flutter uses addJavascriptInterface (window.televo, visible to all frames) → channel token required. |
| Web client (iframe) | ✓ | ✓ | ✗ detected after the fact | a sandboxed frame can still navigate itself (location.href = …): the request is made, then the card is torn down / the mini app header switches to “unverified page” until the page re-authenticates over the bridge; card watchdog unavailable (relies on browser process isolation) |
| Windows | ✓ WebView2 via webview_windows | fallback text only (WebView2 card host written, untested, opt-in --dart-define=TELEVO_WIN_CARDS=true) | ✗ detected (mini apps) | card host: own environment + InPrivate controller, AddWebResourceRequestedFilter("*", ALL) → native 403, NavigationStarting cancelled after the first, FrameNavigationStarting always cancelled, NewWindowRequested handled, permissions denied, downloads cancelled, dev tools off. Compiled only in CI; hosted in a child HWND over the Flutter view (no platform views on Windows), so it is drawn above Flutter overlays. |
| Linux | external browser | fallback text only | — | no maintained WebKitGTK embedding for Flutter |
Card authors: links and forms never navigate a card (all anchor clicks and form submissions
are cancelled by the host’s hardening, because on the web srcdoc anchors resolve against
the client page URL); use TelevoCard.openLink(url).
Layers on native card hosts, outermost first: engine-level network block (above) → CSP meta → static tag stripping → runtime hardening script. The suites run the evil card markup raw (no CSP, no stripping, no hardening) in the card view to show the engine layer alone holds: 0 HTTP requests on macOS, iOS simulator and Android emulator; a plain WebView with the same markup reaches the sniffer (positive control).
Known residual risks:
- Web client: a malicious card can cause one request (its own navigation) before it is
stopped, leaking the viewer’s IP to the bot (cards run only after a tap unless the bot is
verified). WebRTC is disabled by constructor removal in the card realm and by stripping
frame creation; where Trusted Types is unsupported, an
about:blankframe created through an unpatched HTML sink could in theory expose a freshRTCPeerConnection— the suites found no working path on WebKit or Chromium. - Content blockers and
shouldInterceptRequestdo not cover WebRTC: on native, STUN is closed only by script-level constructor removal (+ the WebKit preference on Apple platforms). On Android a user script cannot reach the initialabout:blankdocument of a synchronously created iframe; the hardening layer blocks frame creation, and the raw-markup run measured 0 STUN datagrams, but there is no engine switch for WebRTC inandroid.webkit. - Android: the card WebView shares the app’s single WebView renderer process with mini apps,
so a card’s busy loop also stalls other web views until the watchdog tears the card down
(~2.5 s measured).
android:processcan’t be used: a platform view must live in the Flutter activity’s process, so per-process data directories don’t apply either. - iOS/macOS: the WebRTC preference is SPI; if a future WebKit drops it the document-start
script remains (capability reported by the plugin’s
capabilitiescall). - Windows card host has never run on a real machine; until it has passed this suite there, Windows cards stay off by default.
9.1 Why cards don’t use flutter_inappwebview
flutter_inappwebview 6.1.5 (last release Oct 2024) exposes most of the needed switches
(contentBlockers → WKContentRuleList, Android shouldInterceptRequest, WebView2
WebResourceRequested, incognito, isInspectable, permission callbacks), but for untrusted
card content it fails §2/§3/§8 in ways the released version can’t turn off:
- its JavaScript bridge (
window.flutter_inappwebview.callHandler) lives in the page world of every frame with no frame/secret check, and accepts the plugin’s internal handler names — e.g.callHandler('onPrintRequest')starts a native print job (iOS/macOS/Android), i.e. native UI a card could trigger; on Android the bridge is an unconditionaladdJavascriptInterface(§2 Android row); - it injects its own plugin scripts (console capture,
window.printoverride, ajax/fetch interception hooks) into the card document, which enlarges the untrusted surface; - Windows request interception round-trips to Dart per request and fails open (on a Dart error or missing handler the deferral completes without a response and the request goes to the network); a card’s block has to be decided natively;
- no dedicated
WKContentWorldfor the bridge, no WebRTC switch. Mini apps keep webview_flutter; cards use the smallapp/packages/televo_card_webviewplugin (≈ 440 lines Swift, 360 Kotlin, 550 C++, 270 Dart), whose job is the configuration above. Licenses of what it links are inapp/packages/televo_card_webview/NOTICE.
Generated from docs/MINIAPPS.md in the Telvoro repository. Wire names such as televo.v1 are unchanged.