commit fd8e9e9dfe2b4fdc427f0b3b571ec6acac1b6c5f
parent ed839b4eabdf973313ece40229452fbb63fd0d2f
Author: anon <anon@example.com>
Date: Thu, 5 Nov 2026 08:47:49 +0000
Restrict browser profile uploads to administrators
Diffstat:
7 files changed, 93 insertions(+), 14 deletions(-)
diff --git a/DEVELOPERS.md b/DEVELOPERS.md
@@ -24,8 +24,9 @@ By default, the terminal and log file contain startup/shutdown, player connectio
with peer IP and port, and errors. Browser connections retain the HTTP peer address;
when proxied, this is the proxy address. Pass `-trace` when debugging to also write
packet, movement and HTTP request traces to `logs/server.log`.
-Browser profiling is also off by default; open the game with `?profile=1` to
-collect and upload a diagnostic profile.
+Browser profiling is also off by default; sign in to `/admin` in the same
+browser, then open the game with `?profile=1` to collect and upload a diagnostic
+profile. Uploads require an administrator session.
Back up `data/` when moving servers. Paths are relative to the working directory.
The SQLite database contains character identity and credentials, stats, poses,
diff --git a/TODO.md b/TODO.md
@@ -109,15 +109,18 @@ research separately. More screenshots and test cases do not count as new gamepla
unimplemented mission token/completion-XP rewards must not be promised.
Keep a compact matrix of passed paths and specific remaining failures.
-- [ ] **A8: Isolate administration before public hosting.** The current HTTP
+- [x] **A8: Isolate administration before public hosting.** The current HTTP
and HTTPS listeners share a handler. Administration now requires separate
admin credentials under `/admin`, with first-admin setup, expiring sessions
- and cross-origin write protection. Remaining release check: decide access to
- the public browser-profile upload endpoint and verify deployment provisioning.
- Completion: a public client cannot
- read or mutate administrative state through those routes, while the intended
- local administration path still works. Verify the actual launch configuration
- and keep any test/debug endpoints out of the public server.
+ and cross-origin write protection. Profile uploads now use the same protected
+ boundary at `/admin/browser-profile/{session}`. November 5 checks passed for
+ anonymous/player-only refusal, cross-origin rejection and a real browser
+ administrator upload under a URL prefix. The rebuilt development server was
+ restarted with its existing database and default launch configuration; both
+ HTTP 8080 and HTTPS 8443 reject public administrative writes, the old upload
+ route and tested debug paths are absent, and one administrator is provisioned.
+ See [administration](docs/admin.md). Provision the first administrator before
+ exposing any new installation.
Finish A1 first, then A2-A5 in order, with independent work on A8 before public
exposure. Address demonstrated A6 corruption immediately when found. Complete
@@ -127,6 +130,12 @@ rewriting this document does not close them.
## P1: bounded follow-up work
+- [ ] **Repair the admin browser scenario's adopted-player fixture.**
+ `TestAdminBrowser` currently stops at its player Change password link because
+ its fixture is an unadopted visitor. Prepare an adopted player through the
+ current account flow and retain the password-change assertion. Completion:
+ the existing scenario reaches its final checks. This is P1 test maintenance;
+ the visitor restriction itself is intentional and must remain unchanged.
- [ ] **Use external assets by default; make single-executable bundling opt-in.**
The assets directory currently occupies about 1.2 GB and is unconditionally
embedded into the server/test build. Default development builds should read
diff --git a/client/browser/profile-worker.js b/client/browser/profile-worker.js
@@ -62,7 +62,7 @@ async function upload() {
events = []; frames = []; metrics = {}; dropped = 0; started = ended;
uploading = true;
try {
- const response = await fetch(new URL(`../browser-profile/${configuration.session}`, location.href), {
+ const response = await fetch(new URL(`../admin/browser-profile/${configuration.session}`, location.href), {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify(batch), signal: AbortSignal.timeout(10000)
});
diff --git a/client/tests/browser_profile.mjs b/client/tests/browser_profile.mjs
@@ -17,7 +17,7 @@ function fixture(detailed, status = 204) {
assert.equal(url.href, 'https://example.test/wasm/build.json');
return {ok: true, json: async () => ({source_commit: 'build-test'})};
}
- assert.equal(url.href, 'https://example.test/browser-profile/test');
+ assert.equal(url.href, 'https://example.test/admin/browser-profile/test');
uploads.push(JSON.parse(options.body));
if (rejectUpload) throw new Error('offline');
if (pendingUpload) await pendingUpload;
diff --git a/docs/admin.md b/docs/admin.md
@@ -14,8 +14,20 @@ logout. Cookies are HttpOnly, SameSite=Strict, scoped to the mounted admin path,
and Secure on HTTPS. All admin pages, actions, map feeds and assets pass through
the same authentication boundary on both listeners. Cross-origin writes are
rejected. `/control` and its descendants no longer exist. Use HTTPS for remote
-administration. The browser profile upload endpoint is outside this change and
-still needs a public-release policy under TODO A8.
+administration. Browser profile uploads use `/admin/browser-profile/{session}`
+and require the same administrator session and cross-origin write protection.
+Sign in to `/admin` in the same browser before opening the game with `?profile=1`.
+Anonymous players cannot upload profiles; failed uploads leave gameplay running.
+
+The November 5 deployment check used the normal launch configuration and the
+existing provisioned administrator after a graceful server restart. HTTP 8080
+and HTTPS 8443 both returned 401 for unauthenticated administrative/profile
+writes, 403 for cross-origin profile writes, and 404 for the removed public
+upload route and tested debug paths. The real browser worker rejected a
+player-only session and uploaded successfully after administrator login under
+`/share/test/`. Evidence is retained in `local/admin-profile/`. The broader
+admin browser scenario currently needs an adopted-player fixture repair;
+that separate failure occurs before its profiling check.
General shows player, connection, instance, NPC and database-size counts, game
time and weather. Query rate samples driver executions over two seconds,
diff --git a/server/browser_profile_test.go b/server/browser_profile_test.go
@@ -8,6 +8,63 @@ import (
"testing"
)
+func TestBrowserProfileAdministratorBoundary(t *testing.T) {
+ for _, baseURL := range []string{"/", "/share/demo/"} {
+ t.Run(baseURL, func(t *testing.T) {
+ world := newAdminTestServer(t)
+ world.baseURL = baseURL
+ handler := world.httpHandler()
+ login := adminRequest(handler, "POST", baseURL+"admin/login", "username=Operator&password=", nil)
+ if login.Code != http.StatusSeeOther {
+ t.Fatal(login.Code, login.Body)
+ }
+ cookie := login.Result().Cookies()[0]
+ path := baseURL + "admin/browser-profile/12345678-1234-1234-1234-123456789abc"
+
+ for _, scenario := range []struct {
+ name, path, origin string
+ cookie *http.Cookie
+ status int
+ }{
+ {"anonymous", path, "", nil, http.StatusUnauthorized},
+ {"player cookie", path, "", &http.Cookie{Name: "ao_client", Value: cookie.Value}, http.StatusUnauthorized},
+ {"cross origin", path, "https://attacker.test", cookie, http.StatusForbidden},
+ {"removed public route", baseURL + "browser-profile/12345678-1234-1234-1234-123456789abc", "", nil, http.StatusNotFound},
+ } {
+ t.Run(scenario.name, func(t *testing.T) {
+ request := httptest.NewRequest("POST", "https://example.test"+scenario.path, strings.NewReader(`{"sequence":0}`))
+ request.Header.Set("Content-Type", "application/json")
+ if scenario.origin != "" {
+ request.Header.Set("Origin", scenario.origin)
+ }
+ if scenario.cookie != nil {
+ request.AddCookie(scenario.cookie)
+ }
+ response := httptest.NewRecorder()
+ handler.ServeHTTP(response, request)
+
+ if response.Code != scenario.status {
+ t.Fatal(response.Code, response.Body)
+ }
+ if _, err := os.Stat("logs/profiles"); !os.IsNotExist(err) {
+ t.Fatal("rejected upload created profile storage", err)
+ }
+ })
+ }
+
+ accepted := adminRequest(handler, "POST", path, `{"sequence":1}`, cookie)
+
+ if accepted.Code != http.StatusNoContent {
+ t.Fatal(accepted.Code, accepted.Body)
+ }
+ contents, err := os.ReadFile("logs/profiles/12345678-1234-1234-1234-123456789abc.ndjson")
+ if err != nil || string(contents) != "{\"sequence\":1}\n" {
+ t.Fatal("administrator upload", string(contents), err)
+ }
+ })
+ }
+}
+
func TestBrowserProfileAppendsJSONLines(t *testing.T) {
t.Chdir(t.TempDir())
mux := http.NewServeMux()
diff --git a/server/http.go b/server/http.go
@@ -27,7 +27,6 @@ func (server *server) httpHandler() http.Handler {
mux.HandleFunc("GET /browser-chat", server.browserChat)
mux.HandleFunc("GET /browser-manifest", browserManifest)
mux.HandleFunc("GET /browser-resource-index", browserResourceIndex)
- mux.HandleFunc("POST /browser-profile/{session}", browserProfile)
mux.HandleFunc("GET /wasm/", server.browserClient)
mux.HandleFunc("GET /{$}", server.browserClient)
protectedAdmin := http.NewCrossOriginProtection().Handler(server.adminAuth(server.adminHandler()))
@@ -54,6 +53,7 @@ func (server *server) httpHandler() http.Handler {
func (server *server) adminHandler() http.Handler {
admin := http.NewServeMux()
+ admin.HandleFunc("POST /admin/browser-profile/{session}", browserProfile)
admin.HandleFunc("GET /admin", server.controlPage)
admin.HandleFunc("GET /admin/{$}", server.controlPage)
admin.HandleFunc("GET /admin/players", server.usersPage)