Skip to content

fix(selfupdate): only the server's own page can start or check an update - #454

Merged
butschster merged 2 commits into
masterfrom
fix/update-same-origin
Nov 17, 2026
Merged

butschster merged 2 commits into
masterfrom
fix/update-same-origin

Conversation

@butschster

@butschster butschster commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Another page open in the same browser could start an update. With the defaults (CORS *, self-update auto, loopback, no auth) POST /api/update refused only Sec-Fetch-Site: cross-site. A page on another port of localhost (a dev server on http://localhost:5173) is same-site, so it passed. So did a browser without Sec-Fetch-*. The * preflight answered 204, and the update and restart started.

Now:

  • /api/update/check and /api/update accept only the UI itself. That means Sec-Fetch-Site: same-origin or none. Without Sec-Fetch-Site, an Origin equal to the request Host passes, and so does no Origin at all (curl, scripts). same-site, cross-site, a foreign Origin and Origin: null get 403. The loopback Host guard (DNS rebinding) stays.
  • CORS never covers /api/update*, whatever cors.origins says. These paths get no CORS headers, and their preflight is not answered with 204.
  • The WebSocket RPC bridge refuses /api/update* with 403. Any page can open the WebSocket, and the bridged request carries no Origin, so it looked like curl. The path is checked decoded and cleaned, as the mux routes it. The UI calls the update API over fetch only.

Tests:

  • TestAPI_SameOrigin covers each case for both endpoints: UI same-origin, curl, none, Origin of this host, another port (same-site), cross-site, no Sec-Fetch with another port, a foreign Origin, null.
  • TestAPI_RPCBridgeRefused: post:api/update/check, post:api/update, %75pdate, a query string and get:api/update over the bridge get 403, and no update starts. Without the fix it fails: phase downloading.
  • TestCORS_UpdateIsSameOriginOnly: with *, the preflight for /api/events is 204; /api/update and /api/update/check get no CORS headers.

go test ./internal/selfupdate ./internal/server/ws ./internal/server/http -run TestCORS and go vet ./internal/selfupdate ./internal/server/... pass.

Made with harnsy

@butschster
butschster merged commit 6b1786e into master Nov 17, 2026
1 check passed
@butschster
butschster deleted the fix/update-same-origin branch November 17, 2026 17:50
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