Repository navigation
fix(selfupdate): only the server's own page can start or check an update - #454
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Another page open in the same browser could start an update. With the defaults (CORS
*, self-updateauto, loopback, no auth)POST /api/updaterefused onlySec-Fetch-Site: cross-site. A page on another port of localhost (a dev server onhttp://localhost:5173) issame-site, so it passed. So did a browser withoutSec-Fetch-*. The*preflight answered 204, and the update and restart started.Now:
/api/update/checkand/api/updateaccept only the UI itself. That meansSec-Fetch-Site: same-originornone. WithoutSec-Fetch-Site, anOriginequal to the request Host passes, and so does noOriginat all (curl, scripts).same-site,cross-site, a foreignOriginandOrigin: nullget 403. The loopback Host guard (DNS rebinding) stays./api/update*, whatevercors.originssays. These paths get no CORS headers, and their preflight is not answered with 204./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 overfetchonly.Tests:
TestAPI_SameOrigincovers 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 andget:api/updateover the bridge get 403, and no update starts. Without the fix it fails: phasedownloading.TestCORS_UpdateIsSameOriginOnly: with*, the preflight for/api/eventsis 204;/api/updateand/api/update/checkget no CORS headers.go test ./internal/selfupdate ./internal/server/ws ./internal/server/http -run TestCORSandgo vet ./internal/selfupdate ./internal/server/...pass.Made with harnsy