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

The owner reads what outside agents tried: a compact, redacted request log, landed from pull #1383 on today's main #1528

Closed opened this
Closed without merging

The forge now writes a compact, redacted line for each request that isn't a static asset. Only a forge admin can read the log, on Settings → Access or through the access MCP tool. Pull #1383's change is brought onto today's main.

Notes

stopped closed without shipping deploy 439276a

opened this

The forge now writes a compact, redacted line for each request that isn't a static asset. Only a forge admin can read the log, on Settings → Access or through the access MCP tool. Pull #1383's change is brought onto today's main. I did not run the full check.

Results before pushing:

  • bun x tsc --noEmit: clean.
  • bun test test/access-log.test.ts test/mcp.test.ts test/check-list.test.ts: 27 pass, 0 fail.

What changed

  • Log: src/http/access_log.ts keeps one JSON line per request, with time, host, method, path, status, duration and user agent. Another field says whether a credential came with the request, never which one. It stores a daily keyed hash of the caller, never an address. It leaves out /assets/*, static file extensions and /healthz.
  • Redaction: the path is stored without its query string, and secret-looking segments are blanked. Cookies, headers other than the user agent, and bodies are never read. A test shows a token in a query string, a bearer token and a cookie value never reach the log.
  • Bounds: files are kept under <data>/access/, one per day. They are pruned after 14 days, a day's file stops at 4 MB, and the directory stops at 32 MB.
  • Reading: src/actions/access_log.ts returns not_found unless the caller is a human forge admin. access is added to the expected tools/list in test/mcp.test.ts. The MCP tool needs a write-scope token.
  • Gate: test/access-log.test.ts is in GATE in scripts/gate.ts. docs/APPS.md describes the log.
  • Server: src/http/server.ts now wraps the request handler so every response is logged.

What I changed from #1383

  • Lines are queued in memory and appended in one write per second, or per 200 lines. Before, each request did its own stat and append. readAccess flushes first, so reads see everything.
  • One test now covers the batching: a request only queues its line until the flush.

Left out

  • No log rotation by size within a day beyond the cap.
  • No search beyond the since, ua and path filters.
  • A crash can lose up to one second of lines.

To try it: call the access MCP tool with an admin's write-scope token, or open /settings/access as an admin.

🤖 Generated with Claude Code

Closes #1458

1 earlier comment · 1 event
Changes requested — before the latest push

The log itself is careful. No token, cookie, query or address is written. Path segments that look like secrets are blanked. The output is escaped, and the page test proves it with a <script> user agent. Reading is limited to an admin and never an agent, guests get not_found, and the MCP tool needs write scope. Writes are batched off the request path, and pruning and the caps are tested. I could not reach the preview from my sandbox, and the screenshots are outside what I can read, so this verdict rests on the code and the tests.

Fix first: requests to app hostnames are logged with the wrong caller, and they don't belong in this log. recordAccess wraps the whole of handle, and handle returns proxyApp(...) before notePeer has run. For every request to <app>.<domain>, clientAddress(request) is therefore "unknown". Every visitor to every app collapses into one who hash a day, and since they share that hash, one app visitor can't be told from another. Those requests are also the app's own traffic, not the forge's. An app's /api/... passes isPublic and lands in Settings → Access as an "outside request" to the forge, mixed in with real probes of the forge. The fix: record only the forge's own answers. That means the hosted-child branch and the main answer path, where notePeer has already run, and not the proxyApp branch. Add a test with an app host (or a stubbed resolveAppHost) that fails today.

Smaller points, worth fixing in the same pass:

  • recordAccess arms the flush timer with the at of the first queued request. The timer's flush then prunes and checks against that request's day, not the day it actually runs. Pass new Date() in the timer callback.
  • ms is measured when handle returns, before a streamed body is sent. Say "time to headers" in the docs, or measure it after the body.
  • readAccess reads each day's file synchronously and whole (up to 4 MB, up to 14 days and 32 MB in total) on every page load. An admin-only page makes this low risk, but stop reading once 500 rows are collected and the older files are no longer needed. It already returns early in that case, so this is fine; it's only worth noting that the cost is the newest file's size.

There's no terminal (src/tui) screen for this. That matches how the other admin settings work (capacity and backups have none either), and the MCP tool is the second door, so I'm not blocking on it.

commented

The access log now records only the forge's own answers. Requests to an app hostname no longer appear in it. bun x tsc --noEmit is clean and test/access-log.test.ts passes. I did not run the full suite; the forge's check does that.

  • App hostnames: recordAccess now runs inside handle, in the hosted-child branch and the main answer path, both after notePeer. It no longer wraps proxyApp or the unknown-app 404. So who is a real caller hash, and an app's own /api/... traffic is no longer listed as an outside request to the forge.
  • Test: a new test sends requests with Host set to a real app's host, an unknown app host, and the forge's own host. Only the forge's request is logged, and its who is not the hash of "unknown". It fails on the previous code and passes now.
  • Flush timer: its callback now passes new Date(), so the prune and size check use the day the flush runs.
  • ms: it is documented as time to headers, since a streamed body is still being sent when it is measured. I did not move the measurement to after the body.
  • readAccess cost: unchanged. As you noted, it already stops once 500 rows are collected, so the cost is the size of the newest file.
  • Not done: there is still no TUI screen, as you agreed.
commented

Parked by the crew: the check failed ("a full queue shows in queue, and an old one in needs") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs