Public: anyone can read this; the crew can change it.

Access 3, web pages: every page that gates on isAdmin or sign-in also asks may(), counted beside the old check #18400

opened this

Merged 2h 34m ago, live in production

Web pages now ask may() in shadow next to their old sign-in and admin checks. The old check still decides, so nobody's access changes. This covers the two common gate shapes.

Notes

opened this

Web pages now ask may() in shadow next to their old sign-in and admin checks. The old check still decides, so nobody's access changes. This covers the two common gate shapes. About 48 admin gates written other ways are not done yet: they are in follow-up issue #18401.

What changed

  • src/http/may_beside.ts: one function, mayBeside(ctx, door, action, old). It asks may for the request's credential and writes one access_disagreement row when the answer differs from old, using the existing noteDisagreement. mayToolWrite (src/http/mcp/tool_may.ts) now calls it too, so the MCP door and the web pages use the same code; the gate had flagged the two as near-duplicates.
  • src/http/page_may.ts:
    • adminPage(ctx, page, old) asks forge.administer.
    • signedInPage(ctx, page) asks forge.write, which every account has and anonymous does not. It also narrows ctx.auth.user to defined for the code after it.
    • Both return the old answer, not may's.
  • src/web/pages: in 77 pages, every if (!ctx.auth.user) return … and if (!ctx.auth.user.isAdmin) return … now goes through these helpers. Each records under the door web <module>, e.g. web maintenance or web account. That names the page's file, not its URL path, because some URL paths contain repository names. No account, token or repository is recorded.
  • docs/features/may.md: new paragraph, "The web pages ask it".

Not done, in #18401

  • Admin gates of other shapes are untouched: if (!user?.isAdmin), isAdmin !== true || kind === "agent", isAdminPerson, and the gates in everyday.ts. Wrapping them the same mechanical way would break TypeScript's narrowing, so each needs a hand edit.
  • No inline check was deleted, as the issue asked.

Tests

  • test/web-pages-may.test.ts, one case per kind of page:
    • Admin-only: the admin's session agrees and writes no row. The admin's ro token parts on forge.administer and writes one row, but is still let in.
    • Signed-in: a session and an rw token agree. An ro token parts on forge.write and writes one row.
    • Anonymous: both answers turn it away, with no row. An old gate deliberately set to let it in writes one row.
  • bun x tsc --noEmit, bun scripts/gate.ts --explain (0 fail), bun scripts/design-lint.ts, and 61 test files pass (383 tests, 0 fail). Those files include mcp-size, mcp-tools-may, repo-routes-may, unused-exports, dup-imports, doorless, page-budget*, route-marks*, and the account, people, backups and maintenance pages. scripts/fast.ts named 2,943 files for this diff, too many to run here; the forge runs the full check on push.

Try it: on the preview, open /maintenance as the admin and /account signed in. Both answer as before, and SELECT * FROM access_disagreement WHERE door LIKE 'web %' stays empty for a browser session.

[{"go":"/maintenance","look":"the page as the admin","expect":"renders as before"},{"go":"/account","look":"signed out","expect":"sends you to sign in, as before"}]

🤖 Generated with Claude Code

Closes #18395

3 earlier comments
commented

Web pages now ask may() in shadow next to their old sign-in and admin checks. The old check still decides, so nobody's access changes. This covers the two common gate shapes. About 48 admin gates written other ways are not done yet: they are in follow-up issue #18401.

What changed

  • src/http/may_beside.ts: one function, mayBeside(ctx, door, action, old). It asks may for the request's credential and writes one access_disagreement row when the answer differs from old, using the existing noteDisagreement. mayToolWrite (src/http/mcp/tool_may.ts) now calls it too, so the MCP door and the web pages use the same code; the gate had flagged the two as near-duplicates.
  • src/http/page_may.ts:
    • adminPage(ctx, page, old) asks forge.administer.
    • signedInPage(ctx, page) asks forge.write, which every account has and anonymous does not. It also narrows ctx.auth.user to defined for the code after it.
    • Both return the old answer, not may's.
  • src/web/pages: in 77 pages, every if (!ctx.auth.user) return … and if (!ctx.auth.user.isAdmin) return … now goes through these helpers. Each records under the door web <module>, e.g. web maintenance or web account. That names the page's file, not its URL path, because some URL paths contain repository names. No account, token or repository is recorded.
  • docs/features/may.md: new paragraph, "The web pages ask it".

Not done, in #18401

  • Admin gates of other shapes are untouched: if (!user?.isAdmin), isAdmin !== true || kind === "agent", isAdminPerson, and the gates in everyday.ts. Wrapping them the same mechanical way would break TypeScript's narrowing, so each needs a hand edit.
  • No inline check was deleted, as the issue asked.

Tests

  • test/web-pages-may.test.ts, one case per kind of page:
    • Admin-only: the admin's session agrees and writes no row. The admin's ro token parts on forge.administer and writes one row, but is still let in.
    • Signed-in: a session and an rw token agree. An ro token parts on forge.write and writes one row.
    • Anonymous: both answers turn it away, with no row. An old gate deliberately set to let it in writes one row.
  • bun x tsc --noEmit, bun scripts/gate.ts --explain (0 fail), bun scripts/design-lint.ts, and 61 test files pass (383 tests, 0 fail). Those files include mcp-size, mcp-tools-may, repo-routes-may, unused-exports, dup-imports, doorless, page-budget*, route-marks*, and the account, people, backups and maintenance pages. scripts/fast.ts named 2,943 files for this diff, too many to run here; the forge runs the full check on push.

Try it: on the preview, open /maintenance as the admin and /account signed in. Both answer as before, and SELECT * FROM access_disagreement WHERE door LIKE 'web %' stays empty for a browser session.

[{"go":"/maintenance","look":"the page as the admin","expect":"renders as before"},{"go":"/account","look":"signed out","expect":"sends you to sign in, as before"}]

🤖 Generated with Claude Code

commented

Web pages now ask may() in shadow beside every check they gate on, whether that check is isAdmin or sign-in. The old check still decides, so nobody's access changes. Where the two answers differ, one row is counted in access_disagreement under web <page>. The row records the action and the kind of principal (session, ro token, anonymous and so on). It names no account, token or repository.

The sign-in check asks by what the request does (src/http/page_may.ts). GET and HEAD ask forge.read, and writes ask forge.write. An ro token reading its own page is no longer counted, and an ro token that posts still is. The test that expected a row for an ro read is now two tests, one for reads and one for writes.

Disagreement: an anonymous GET to a page that needs sign-in now records a difference on forge.read, because may lets anyone read and the page lets in only accounts. That difference is real: it shows forge.read is too wide for these pages. It costs one bounded row per page. I count it instead of skipping anonymous visitors. No current action means "any account, any token scope". Adding one changes the can lists in the API and the terminal, so it belongs in its own change.

The admin checks the first pass missed now ask forge.administer. These include:

  • features, subscriptions and packs-settings (each through its requireAdmin)
  • backupsDrill, backupsLive, forges, forge_machine, forge_upgrade and forge_move_in
  • billing, admin-limits, boards*, flows-all, packs, visitors, economics, flow, teams, data, runners, telemetry, trusted, advisories, org, app_templates, crew-settings, connections and client_cloud
  • the studio pages: home, home_archive, keeper_row, crew_key, crew_budgets and crew_fallback
  • settings/devices, settings/plans and requests_card

Where the user may be missing, the check tests for undefined first. may also refuses an anonymous visitor forge.administer, so no row is lost.

Deliberately left as they were:

  • everydayToAdmin: it checks another account (adminOf(daily)), not the person asking.
  • repo.ts isAdmin(ctx, repo): a repository's admin, which the repo routes already cover.
  • Checks that only change what a page shows (the admin links in changelog, pricing, account and so on): they turn nobody away.

Smaller fixes:

  • domainsCard in backups.ts is back to the plain ctx.auth.user check, with a test that it does not ask may again.
  • The commit carries No door:: this is shadow counting only, so the terminal has nothing new to show.
  • docs/features/may.md says which action each kind of request asks.

Checks: tsc, design-lint, bun scripts/gate.ts --explain and test/web-pages-may.test.ts pass. --fix had nothing to commit. scripts/fast.ts named 3,002 files, too many to run, so I ran 265 files covering the touched pages, may, and the duplicate-import, dead-code and first-view-budget rules. Three tests failed there:

  • test/attention-stamped.test.ts (the first-view budget for /changelog): failed under load and passed when run alone.
  • The data-browser masking test: it was already red on main (#18393/#18394).
  • The 200 MB child-process memory test: it is not touched by this change.
[{"go":"/settings/features","look":"the page as the admin","expect":"renders as before; no access change"},
 {"go":"/settings/backups","look":"the failure-domains card","expect":"shown as before for a signed-in admin"}]

🤖 Generated with Claude Code

commented

Web pages now check may() in shadow next to their old gates (#18395). Admin-only pages ask forge.administer. Pages that need an account ask by what the request does: a read (GET or HEAD) asks forge.read, anything else asks forge.write. The old gate still makes the decision. When may() gives a different answer, http/page_may.ts adds one row to access_disagreement under the door web <page>. The MCP write floor and the web pages share one helper for this (http/may_beside.ts). Nobody's access changes.

The last commit fixes the red check. Writing a disagreement row moved the forge's write clock (core/write_clock.ts), and the /explore.json etag is built from that clock. A GET to a gated page could therefore land between another page's GET and HEAD and change its etag. That is what the HEAD sweep caught. noteDisagreement now writes its count with quietly, the same way other usage counts are written, so it no longer moves the clock. A new test in test/web-pages-may.test.ts checks that counting a disagreement leaves the clock unchanged; it fails without the fix.

Worth a look:

  • src/core/access_disagreement.ts: the quiet write.
  • src/http/page_may.ts: the read/write split for pages that need an account.

Checked locally: the type check and the gate pass. test/head-options-sweep.test.ts, test/web-pages-may.test.ts and the tests that use the write clock or the disagreement table pass (87 tests). The full suite reaches about 3,000 files, which is too broad to run here, so it is left to the forge's check.

[{"go":"/maintenance","look":"the page as the admin","expect":"it renders as before; a non-admin is still turned away"},
 {"go":"/explore.json","look":"the ETag header on GET and on HEAD","expect":"the same tag, even after visiting a signed-in page while signed out in between"}]

🤖 Generated with Claude Code

commented

Left #18395 open: 1 unticked item remain (Each web page whose handler checks isAdmin, scopeAllows or !ctx.auth.user also computes may(principal, action, resource) and, where the two answers part, records one access_disagreement row (door web <route>, action, principal kind; no account, token or repository named). The old check still decides; no person's access changes.).

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs