Skip to content

feat: run commands from the page, gated by trusted origins - #22

Merged
KoSHeroff merged 1 commit into
mainfrom
feat/page-commands
Jul 25, 2026
Merged

feat: run commands from the page, gated by trusted origins#22
KoSHeroff merged 1 commit into
mainfrom
feat/page-commands

Conversation

@KoSHeroff

Copy link
Copy Markdown
Member

What

A page rendered in the webview can now run a Minecraft command, executed as the player — exactly as if they typed it in chat. No privilege escalation.

Trust model

Commands are accepted only from the main frame of an origin the server declares trusted, via trustedCommandOrigins in config/webgui/server.json:

{ "trustedCommandOrigins": ["https://ui.myserver.example", "http://localhost:3000"] }
  • The list is sent to the client on join and cleared on disconnect, so trust never carries across servers.
  • Requests from any other origin (after a redirect, or from an <iframe>) are dropped.

Changes

  • WebGUITrustedOrigins — client-side registry of trusted origins (normalization, session-scoped).
  • WebviewTrustedOriginsS2CPayload — sent on join, received on client (all targets).
  • trustedCommandOrigins in server.json.
  • command channel in WebviewPageToClientBridge: main-frame + origin check → run as player (sendChatCommand / connection.sendCommand).
  • Reset trusted origins on disconnect.
  • Bump to 1.6.0.

Pairs with the @webgui/react PR adding runCommand / useRunCommand.

Verification

  • Compiles on all targets: fabric 1.20.1/1.21.1/1.21.11, neoforge 1.21.1/1.21.11/26.1.2/26.2.
  • Full jar build of the active target succeeds.

A page can run a Minecraft command that executes as the player (client-side,
via the new "command" bridge channel) — as if typed in chat, no privilege
escalation.

Commands are only accepted from the main frame of an origin the server declares
trusted via trustedCommandOrigins in server.json; requests from any other origin
(redirect, iframe) are dropped. The list is sent on join and cleared on
disconnect, so trust never carries across servers.

- add WebGUITrustedOrigins (client-side origin registry, normalization)
- add WebviewTrustedOriginsS2CPayload + send on join + receive on client
- add trustedCommandOrigins to server.json
- handle the "command" channel in WebviewPageToClientBridge with frame/origin checks
- bump to 1.6.0
@KoSHeroff
KoSHeroff merged commit 42a9e6b into main Jul 25, 2026
8 checks passed
@KoSHeroff
KoSHeroff deleted the feat/page-commands branch August 3, 2026 10:12
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