security(web): move the web app to its own origin, app.mostro.network, with a gradual migration

Aperta
#958 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
flutter

Direzione di ricerca

Start by reading .github/workflows/web-build.yml, CLAUDE.md § Web, and the referenced migration entry points: account_screen.dart, backup_ritual_screen.dart, and IdentityService. Map the work across hosting, deployment, migration screens, translations, announcements, and the rescue page; verify each phase against its exit criteria. Done means both origins work through the published transition, users can migrate safely, and old links continue to reach the new app.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: identity infra priority: high web

Problem

The web app is served at https://mostro.network/app/. For the browser, the security boundary is the origin (scheme + host + port), not the path. So the app shares its origin, https://mostro.network, with every other site the org publishes under that domain. Today (gh api repos/MostroP2P/<repo>/pages) that is 10 repositories:

Repo Path Build
MostroP2P.github.io / (the root) workflow
protocol /protocol/ workflow
docs-english /docs-english/ workflow
docs-spanish /docs-spanish/ workflow
mostro-cli-book /mostro-cli-book/ workflow
golazo /golazo/ workflow
blog /blog/ legacy Jekyll
mostro /mostro/ legacy Jekyll
mostrix /mostrix/ legacy Jekyll
app /app/ workflow

Any JavaScript that runs on any of those pages runs as the app, as far as the browser is concerned. It could come from a malicious PR, a compromised npm dependency or Jekyll theme in a docs build, or an XSS in a blog post. Such a script can:

  • Read the user's seed. The 12 words are stored with flutter_secure_storage (lib/core/services/identity_service.dart). On web, flutter_secure_storage_web 2.1.1 encrypts them with AES-GCM, but it stores the raw AES key in the same localStorage, next to the ciphertext. We pass no wrapKey, so the key is not wrapped. A script on mostro.network/blog/ can read both entries, decrypt the seed and send it out. The seed gives the identity and every trade key.
  • Read all the app's data in IndexedDB: trades, chat history, bond payout claims.
  • Open /app/ in an iframe or a window and drive it: read its DOM, call into it, act as the user.
  • Take over the app persistently. The root repo can do this directly. Any other repo can do it too by unregistering the app's service worker, since getRegistrations() returns every registration of the origin. A service worker scoped to / can intercept and replace main.dart.js and the wasm, and it stays installed after the malicious code is removed.

Encrypting harder inside the same origin does not fix this: any key the app can use, a same-origin script can use too. Even a non-extractable WebCrypto key can still be asked to decrypt. The only fix is to give the app its own origin.

Proposal

Serve the web app from https://app.mostro.network/.

  • A different origin. localStorage, IndexedDB, service workers and window access are isolated from the other nine sites. It stays same-site with mostro.network, but that only matters for cookies, and the app uses none.
  • One repository to trust instead of ten.
  • #951 gets simpler. Android App Links and iOS Universal Links need /.well-known/assetlinks.json and /.well-known/apple-app-site-association at the root of the host. On mostro.network that root belongs to another repo (MostroP2P.github.io). On app.mostro.network this repo publishes them itself.
  • No sub-path. --base-href becomes /, which removes a whole class of "blank page" mistakes (CLAUDE.md § Web). manifest.json and the FCM worker registration are already relative, so they follow.

The rest of this issue is about doing it without trauma: both URLs work at the same time while users move, nobody loses funds or access, and the links already shared keep working.

Constraints that shape the plan

  1. The new origin starts empty. The browser will not share the old origin's storage with the new one. Each user moves their identity by backing up the seed on the old site and importing it on the new one. Then:
    • the trade history comes back through the restore (#813);
    • bond payout claims do not: per CLAUDE.md they live in their own bond_claims store and "no restore brings back" them. Users must settle open claims (and ideally open trades) before moving.
  2. No automatic transfer of the seed between origins. A postMessage/iframe handoff is technically possible. But it is exactly the kind of code that, if wrong, hands the seed to the wrong origin, and the old origin is the one this issue says cannot be trusted. Manual backup → import is simpler. It is also honest: the seed was exposed to the whole origin, and users should know it. Never put the seed in a URL either: fragments end up in history and sync.
  3. One GitHub Pages site per repo, one custom domain per site. The old path mostro.network/app/ exists only because the repo is named app and inherits the org's domain. As soon as the app repo gets a custom domain, GitHub redirects mostro.network/app/* to it (to verify against the current Pages docs before relying on it). So one repo cannot serve both URLs at the same time. During the transition a second repo has to serve one of them.
  4. The first run has no import. Today a seed is imported only from Account (account_screen.dart → IdentityService), after the first run created a fresh identity. A migrating user should be steered to import, not left with a new empty identity.
  5. The base path is derived from the repo name in .github/workflows/web-build.yml (--base-href "/${GITHUB_REPOSITORY#*/}/", and BASE_PATH for every smoke run). It needs to become an input.

Phases

Phase 0: preparation (no user-visible change)
  • Verify mostro.network for the org (Organization settings → Pages → Verified domains). Otherwise any GitHub user could claim a dangling *.mostro.network Pages domain (subdomain takeover). status.mostro.network and store.mostro.network already show subdomains are used, so this protects them too.
  • DNS: app.mostro.network CNAME mostrop2p.github.io. (whoever manages the zone).
  • Create the subdomain's repo, e.g. MostroP2P/app-web. It holds no app code, only a deploy workflow and the Pages setting (custom domain app.mostro.network, Enforce HTTPS).
  • Make the base path an input of web-build.yml (base-href, default /${repo}/), passed to flutter build web, pages_bundle_test.dart and every BASE_PATH=… node smoke.mjs. CI runs the smoke test for both /app/ and /, so the root build is proven before anyone uses it.
  • Check that actions/upload-pages-artifact keeps dot-folders, so .well-known/ survives for #951. If it drops them, find the switch or the workaround now.
Phase 1: both sites serve the same app (silent)
  • On every merge to main, the same commit is built twice:
    • app repo → mostro.network/app/ (unchanged, --base-href /app/);
    • app-web repo → app.mostro.network/ (--base-href /).
  • How app-web deploys: its own workflow, triggered by a repository_dispatch that deploy-pages.yml sends after a successful deploy (fine-grained token, contents: read on app-web only, as a secret). It calls the reusable MostroP2P/app/.github/workflows/web-build.yml@<sha> with base-href: /, then actions/deploy-pages. The build stays defined in one place (the CLAUDE.md rule for web-build.yml), and both sites ship the same commit.
  • Nothing tells users yet. The team uses app.mostro.network for a while and runs the smoke checks against it:
    • cross-origin isolation through the coi shim;
    • the Rust bridge answering;
    • the IndexedDB stores;
    • a Blossom upload from the new origin (CORS);
    • installability (SMOKE_INSTALLABLE).
  • Exit criterion: a full trade, chat with an attachment, a dispute chat and a restore work on app.mostro.network.
Phase 2: the app learns to migrate (one release, both sites)

The code behaves differently by origin, which it reads at runtime (Uri.base), so one bundle serves both.

On the old origin (mostro.network):

  • A banner on Book, dismissible but returning: "Mostro has a new address: app.mostro.network. Move your account." It is dismissible so trading is never blocked.
  • A "Move to the new address" screen (Settings and banner), a guided checklist:
    1. Open trades: lists trades not finished yet, using the existing in-progress lookup, and advises finishing them first. It does not block: they can be restored on the new site.
    2. Open bond payout claims: blocks until settled or explicitly acknowledged. They are lost otherwise.
    3. Back up the 12 words (the existing backup ritual, backup_ritual_screen.dart), unless already confirmed.
    4. "Open app.mostro.network": opens https://app.mostro.network/#/migrate in a new tab, with no seed or data in the URL.
  • Optionally, once the user confirms they finished on the new site, "Forget this browser's account here": the existing delete_identity wipe on the old origin. Then a leak of the old origin no longer holds their seed.

On the new origin (app.mostro.network):

  • #/migrate (first run or not): explains the move, then imports the 12 words, with the same validation as Account (validate_mnemonic). The restore (#813) brings back the trades.
    • On the first run: the walkthrough is skipped or shortened, and the node choice is replaced by the node the restore finds, or the default. No throwaway identity is created first.
    • Not on the first run: the import goes through the existing identity replacement.
  • A first run without #/migrate offers "I already use Mostro: import my words" next to starting fresh. Users who type the new address by hand reach the import too.

Translations: all 7 locales, as usual.

Phase 3: announce (time-boxed transition)
  • An announcement (kind 38387, docs/ANNOUNCEMENTS.md) in all seven locales, plus the project's social channels: the new address, why, and the steps.
  • Docs and links point to app.mostro.network: README, docs/DEEP_LINKS.md, node links (#950), the PWA instructions.
  • The transition window is set and published, e.g. 3 months. During it both sites run the same code. The old one keeps its banner, and its messages grow more insistent as the date nears.
  • Installed PWAs (#658): the old installed app keeps working on the old origin. The migration screen tells users to install the new one and remove the old one, since a manifest cannot move across origins.
Phase 4: the old address becomes a rescue page, then a redirect

At the end of the window, mostro.network/app/ stops serving the app. It serves a small static page instead (no Flutter, no Rust):

  1. If this browser still holds an account on the old origin, the page offers to show the 12 words, one deliberate click, so nobody who missed the window loses their identity. It reads them the same way the app did: the flutter_secure_storage_web entries in localStorage, decrypted with the key stored next to them. Same exposure as today, for the last time, and only on request. Then it offers to wipe them.
  2. Otherwise, it redirects to the new address keeping the fragment: location.replace('https://app.mostro.network/' + location.hash). GitHub Pages has no per-path server redirects, so it is done in JS, and every …/app/#/node?mostro=… link already shared keeps working.
  3. The page has no other script, no third-party asset, and a strict CSP in a <meta> tag.

This page stays until traffic to it is negligible, e.g. 6–12 more months.

Phase 5 (optional): simplify the hosting

When the rescue page is retired, the app repo can take the custom domain app.mostro.network itself. GitHub's own redirect then sends mostro.network/app/* to it, and app-web is archived. Alternatively, keep app-web as the permanent host and leave the app repo's Pages off. Either way only one repo serves the app again.

Effect on other work

  • #950 (node links): merge it as planned. Its links still use mostro.network/app/#/node?… until Phase 3, and they keep working through the Phase 4 redirect. From Phase 3 on, docs show app.mostro.network/#/node?….
  • #951 (App Links / Universal Links): should target app.mostro.network from the start. assetlinks.json goes in this repo's web/.well-known/, served at the subdomain's root, and the intent filter matches https://app.mostro.network/. Building it on mostro.network would put the domain files in another repo and the trust in ten.
  • Web push (PUSH_WEB_ENABLED, docs/PUSH_NOTIFICATIONS.md T4.5): still off, so nothing to migrate. When it ships, it ships on the new origin only.

Acceptance

  • https://app.mostro.network/ serves the app, cross-origin isolated, with the same smoke checks CI runs for /app/ today.
  • During Phases 1–3 both addresses serve the same commit, built once per base path from web-build.yml.
  • On the old origin a user can follow the guided move:
    • open bond claims block it;
    • the seed backup is part of it;
    • the new site opens with no secret in the URL.
  • On the new origin #/migrate, and the first run, import an existing seed without creating a throwaway identity first, and the restore brings back the trades.
  • At the end the old address serves the rescue page:
    • it shows the old account's words on request;
    • otherwise it redirects to the new address keeping the fragment.
  • mostro.network is a verified domain of the org.
  • CLAUDE.md (§ Web), docs/DEEP_LINKS.md and the README describe the new address.

Open questions

  1. Name of the subdomain's repo (app-web? webapp?) and who manages the mostro.network DNS zone.
  2. Length of the transition window (Phase 3) and of the rescue page (Phase 4).
  3. Should Phase 2's old-origin wipe ("forget this browser's account") be offered right after the import, or only once the new site has finished a restore?
  4. Do we want the rescue page to show the words at all, or only point to "open the old app version" for a while longer?

Related

  • #950, #951: node links and App Links. #951 should target the new host.
  • #658: installable web app.
  • #813: restore after a node switch, the mechanism that brings trades back on the new site.
  • docs/ANNOUNCEMENTS.md: the channel for the announcement.
Lingua principale
Dart
Stelle
11
Fork
9
Merge medio
2g 1h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MostroP2P/app

Tutte le issue di MostroP2P/app

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.