Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
Anyone who is not the owner or a moderator gets 404 on GET and POST /admin, not 401/403 #175
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
/admin now answers 404 to anyone who is neither the owner nor a moderator. The admin tests pass (10 pass, 0 fail). I couldn't run bun x tsc --noEmit: it failed here with "bun is unable to write files to tempdir: ReadOnlyFileSystem", so the type check is unverified.
shipped merged
2 earlier comments · 1 event
/admin now answers 404 to anyone who is neither the owner nor a moderator. The admin tests pass (10 pass, 0 fail). I couldn't run bun x tsc --noEmit: it failed here with "bun is unable to write files to tempdir: ReadOnlyFileSystem", so the type check is unverified. I did not run the full bun --cwd Software/so101 test suite.
- Change:
serveAdminPageinsrc/admin-routes.tsnow refuses with 404 instead of 401/403. That covers GET and POST, for anonymous visitors and signed-in non-moderators, and for a guest who only types a moderator's name. - 404 body: the repo has no HTML not-found page. The body is the JSON
{"error":"no such route"}that the rest of the app returns for an unknown route, so/adminlooks like any other missing path. - Moderators: a moderator who POSTs a settings change still gets 403.
- Dead branch: the anonymous "Sign in" branch of
renderRefusalis now unreachable. I left it in place. - Tests: in
src/admin-relay.test.tsI changed four expectations from 403 to 404. They are the stranger and unverified-guest cases, and a user who was removed from the moderator list. The tests were wrong only in that they asserted the old behaviour. I added cases for an anonymous GET, an anonymous POST, and a signed-in non-moderator POST.
GET and POST /admin now answer 404 to anonymous visitors and to signed-in people who are neither the owner nor a moderator. A moderator who POSTs a settings change still gets 403.
The preview failure was a second test I had missed: /admin is the owner's… in src/lobby.test.ts still expected 401/403. I changed its anonymous GET, non-moderator GET and non-moderator POST to expect 404. I also dropped its check that the anonymous refusal page contains the sign-in link, because that page no longer exists. Those expectations were wrong for the new behaviour, so I changed the tests, not the code.
Locally, lobby.test.ts, lobby.security.test.ts and the admin suites pass (38 pass, 0 fail). I did not run the full suite. bun x tsc --noEmit couldn't run here ("bun is unable to write files to tempdir: ReadOnlyFileSystem"), so the type check is still unverified.
The change itself is in src/admin-routes.ts. The 404 body is the app's ordinary not-found response, {"error":"no such route"}, since the repo has no HTML not-found page. In src/admin-relay.test.ts I changed four 403 expectations to 404 and added anonymous GET, anonymous POST and non-moderator POST cases. The owner's cross-site POST still gets 403. That check is separate from the new 404.
Behaviour is right: on the preview, anonymous GET and POST /admin answer 404 with the same {"error":"no such route"} body as /nope, and the tests cover anonymous, non-moderator, guest-typing-a-moderator-name and removed-moderator cases. One miss against the Clean rule: dead code is left behind on purpose. The anonymous Sign in branch of renderRefusal in src/admin-page.ts (the : <p>Only the owner...<a href="/__forge/signin... arm) can no longer be reached, because renderRefusal is now only called for a signed-in moderator (the refuse path after a 403). Fix first: make renderRefusal take a Who (not Who|null), delete the sign-in arm and its ternary, and drop the who ? handling. Also tsc was never run by the builder; run bun x tsc --noEmit after the signature change. Nothing else to change.
renderRefusal in src/admin-page.ts now takes a Person, not Who. I deleted the anonymous "Sign in" arm and its ternary, so it only renders the signed-in moderator's refusal.
The admin and lobby tests pass (34 pass, 0 fail). bun x tsc --noEmit ran this time, after bun install with BUN_INSTALL_CACHE_DIR pointed at $TMPDIR so it could write. It reports errors only in src/ui/*.js. They look like missing DOM types (for example Cannot find name 'location'), and I didn't touch that code. There are no errors in the files I changed. I didn't check whether the same errors show up on main.
I made no other changes.
Preview checked: anonymous GET and POST /admin return 404 with the same JSON body, headers and security floor as an unknown path (/nope), so /admin does not reveal itself. The owner is unchanged, a moderator can view the page, and a moderator POST still gets 403. The cross-site owner POST also stays 403. The tests cover each case: anonymous GET and POST, non-moderator GET and POST, and a guest who types a moderator name. The dead Sign-in arm of renderRefusal is gone. Next: (1) run bun x tsc --noEmit on main to confirm the src/ui/*.js errors the builder saw are not new; (2) the 404 body is JSON, so a browser user sees raw JSON. If a not-found page is ever wanted, make it one shared page for every route, not an admin special case.
/adminnow answers 404 to anyone who is neither the owner nor a moderator. The admin tests pass (10 pass, 0 fail). I couldn't runbun x tsc --noEmit: it failed here with "bun is unable to write files to tempdir: ReadOnlyFileSystem", so the type check is unverified. I did not run the fullbun --cwd Software/so101 testsuite.serveAdminPageinsrc/admin-routes.tsnow refuses with 404 instead of 401/403. That covers GET and POST, for anonymous visitors and signed-in non-moderators, and for a guest who only types a moderator's name.{"error":"no such route"}that the rest of the app returns for an unknown route, so/adminlooks like any other missing path.renderRefusalis now unreachable. I left it in place.src/admin-relay.test.tsI changed four expectations from 403 to 404. They are the stranger and unverified-guest cases, and a user who was removed from the moderator list. The tests were wrong only in that they asserted the old behaviour. I added cases for an anonymous GET, an anonymous POST, and a signed-in non-moderator POST.Closes #137