Skip to content

Only let projects call allowlisted Rotur methods - #98

Merged
Mistium merged 1 commit into
developfrom
rotur-bridge-allowlist
Oct 2, 2026
Merged

Mistium merged 1 commit into
developfrom
rotur-bridge-allowlist

Conversation

@Mistium

@Mistium Mistium commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

The Rotur bridge on the community project page ran any method path a project sent it, on the viewer's own Rotur client. A custom extension running in the player could read the viewer's Rotur token, or send their credits without a confirmation. This replaces the open dispatch with an allowlist in the project page, the editor and packaged exports.

How custom extension code reaches the bridge

The project page embeds the player at /embed.html in an iframe sandboxed without allow-same-origin. It listens for {type: 'mw:rotur', kind: 'call', method, args, opts} messages whose source is that iframe's window, and passed method to callRotur. callRotur split the method on dots and walked the Rotur SDK client.

Any extension that runs unsandboxed inside the player runs in that window, so it can post the message. These extensions run unsandboxed in the player:

  • gallery extensions
  • extensions that MistWarp staff marked as trusted
  • any custom extension the viewer allows with "Run without sandbox" ticked in the load prompt. The tick becomes the default for the next prompt.

Extensions in TurboWarp's own iframe sandbox are a nested frame, so they fail the source check and could not use the bridge.

What such an extension could do

  • method: '_http.getToken' returned the raw token. In the SDK, _http.getToken is a closure, so the dotted walk found a function and called it. That token is the MistWarp sign-in token, which holds 31 permissions, including credits:transfer, credits:manage, account:settings, signing:private and validators:generate. Whoever holds it can spend the viewer's credits, sign in to MistWarp and other Rotur apps as them, change account settings and sign with their key. setToken, tokens.create and me.deleteAccount were reachable the same way.
  • kind: 'call' never checked the project's grant. The confirmation dialog only appeared if the frame set opts.sensitive, and the dialog showed the frame's own label. So me.transfer ran without asking, or behind a dialog that said something else.
  • kind: 'consent' with meta.authenticatedOnly: true granted any scope without asking and widened the shared token. meta.name chose which stored grant was used.
  • storage.* took the project id from the frame, so one project could read or write another project's storage.

Unsandboxed extensions in the editor and in packaged exports could do the same through vm.runtime.roturHost.call. In the editor they already share the origin with the token, so this is defence in depth there. #17 covers that case. In exports, the token is the export's own token and holds only the scopes the project asked for.

The fix

src/lib/rotur/project-methods.js is the single allowlist. It lists the 91 SDK methods the eight built-in Rotur extensions call. Each entry gives the scopes that cover the method, and spending or destructive methods also get a confirmation builder. All three hosts now:

  • reject any method outside the table, and resolve paths only from table keys
  • require a grant covering the method's scope before a non-confirmed scoped call runs
  • decide confirmations themselves. Payments, gifts, purchases, key and item transfers and post deletion always ask. The dialog text is built from the real arguments, such as "send 5000 credits to @thief".
  • accept consent requests only for scopes that some block uses. Requests such as tokens:manage or signing:private are rejected. Read-only scopes, and scopes whose methods always confirm, are granted without asking, as before. Everything else asks.
  • choose the grant key and storage id themselves. On the project page, both are the platform project id.

callRotur in extension-bridge.js dispatches through the same table, so nothing else in the GUI can walk arbitrary paths either.

Behaviour changes

  • Grants on the project page are now keyed by project id, so a project people already approved asks once more.
  • Confirmation dialogs for non-payment actions use the host's wording, such as "buy key abc", instead of the block's.
  • This doesn't change "Run without sandbox", which drops the iframe sandbox entirely. That mode still has full access, and the page already warns about it.

The scratch-vm fallback host gets the same treatment in MistWarp/scratch-vm#23.

Testing

  • test/unit/rotur-project-methods.test.js runs every block of every built-in Rotur extension from the pinned scratch-vm against a recording host. It checks that every method called is allowlisted with the block's scope, that every sensitive block is confirmed, and that the table has no extra entries. It also checks that private paths are rejected, that the token can't be reached through a real rotur-sdk client, that grants are enforced, that storage is pinned to the host's project id and that unknown scopes are rejected.
  • test/unit/community-project-rotur-bridge.test.jsx mounts the real project page and posts the messages a malicious extension would send from the player frame. All four tests fail on develop and pass here.
  • rotur-extension-host and packager-account tests cover the editor and export hosts.
  • jest --ci test/unit: 321 suites, 1874 tests pass. eslint is clean on the changed files.

The only visible change is the wording of the confirmation dialog for non-payment actions.

The community project page, the editor and packaged exports passed any
dotted method path from a project to the Rotur SDK, so a custom extension
next to the project could call _http.getToken and read the viewer's token,
or call me.transfer without a confirmation. Hosts now dispatch only the
methods the built-in Rotur blocks use, check the project's grant for each
call, and build confirmations, grant keys and storage ids themselves.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying scratch-gui with  Cloudflare Pages  Cloudflare Pages

Latest commit: 819114a
Status: ✅  Deploy successful!
Preview URL: https://9a6f2f09.scratch-gui.pages.dev
Branch Preview URL: https://rotur-bridge-allowlist.scratch-gui.pages.dev

View logs

@Mistium
Mistium merged commit 3fb85fd into develop Oct 2, 2026
2 checks passed
@Mistium
Mistium deleted the rotur-bridge-allowlist branch October 15, 2026 21:45
mc20000-01 pushed a commit to mc20000-01/scratch-gui that referenced this pull request Nov 7, 2026
Only let projects call allowlisted Rotur methods
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.

1 participant