Skip to content

Harden the API: re-login for hook commands, registry token, OAuth limit, 404 bodies, log streams - #139

Merged
tricknotes merged 5 commits into
mainfrom
api-hardening
Nov 23, 2026
Merged

tricknotes merged 5 commits into
mainfrom
api-hardening

Conversation

@tricknotes

Copy link
Copy Markdown
Owner

Summary

Five fixes in the HTTP API, one commit each.

  • Recent login for hook commands of a production app. Changing dump_hook_*, load_hook_* or post_load_* on a production app now needs a login within the last 10 minutes, like running a command there. The dump hook runs on every backup, so a stolen cookie could otherwise run commands in production containers without the re-login that 10.3 asks for.
  • A saved registry token stays with its registry. Changing the registry or the user name of an app's registry credential without entering a token kept the saved token, so it could be pointed at another host and sent there by Docker. The token is now required whenever either changes.
  • OAuth callback limit. The callback counted every request against its limit before looking at the state cookie, so an unauthenticated client could keep real logins failing. Requests without a matching state are refused without being counted. (The next pull request adds a limit per client address.)
  • One 404 for "no role" and "does not exist". A member could tell an app, deployment, task run or database copy they have no role on from one that does not exist, by the body of the 404. The bodies are now identical. copy_not_found becomes db_copy_not_found, the code ARCHITECTURE and API.md already used.
  • Open log streams end when access ends. A live log stream was authorized only when it was opened. It is now checked again every 15 seconds and closed when the session or token is no longer valid or the role is gone.

Screenshots

The registry credential form when the registry or user name is edited:

Token required, light
Token required, dark
Token missing, light
Token missing, dark
390px, light
390px, dark

Test plan

  • go vet ./..., go test ./..., go test -race on the stream, token and session tests
  • pnpm lint, pnpm test
  • New tests: TestProductionHookCommandsNeedRecentLogin, TestHiddenRecordsAnswerLikeMissingOnes (whole bodies, every route), internal/api/stream_access_test.go
  • Screenshots from the mock API, checked in light, dark and at 390px
  • The whole integration suite on the combined stack

🤖 Generated with Claude Code

tricknotes and others added 5 commits November 24, 2026 03:43
The dump hook, the load hook and the command after a load are settings
that hold a shell command koroku runs inside the app's containers. The
dump hook runs on every backup, so a session with the manage role could
save a command there and have it executed in a production app by the
nightly run or by POST /api/backups, without the recent login that
one-off commands and task changes of a production app already need.

PATCH /api/apps/{slug} now answers 403 reauth_required when it changes
any of the six fields on a production app. Unchanged values and staging
apps are not affected. The console already opens the re-login dialog
for this answer and keeps what was typed; a test pins that for the
backup settings form, and the mock API refuses the same change in its
stale-login scenario.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
PUT /api/apps/{slug}/registry-credential kept the saved token whenever
the request had none, also when it named another registry or username.
Docker sends the token to whatever host the credential names, so anyone
who may save the credential (a member with the manage role, a stolen
session within the re-login window) could point the token someone else
entered at a host of their own and read it there on the next pull.

A request that changes the registry or the username now has to bring
the token (422 validation_failed on token). The same registry and
username without a token still keep the saved one, so an unchanged form
can be saved.

The settings form makes the token field required and says why as soon
as the registry or the username differs from the saved credential, and
does not send such a save without a token. The mock API follows the
same rule, and the screenshot script has the new state.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
GET /auth/github/callback took one of the ten slots a minute before it
looked at the request, so a client that never started a login could
send ten bare requests a minute and make every real login in that
minute end in github_error.

The limit exists to bound the requests to GitHub that carry the client
secret, so it is now taken right before the code exchange. A request
without the state cookie, with a state that differs from the cookie, or
without a code is refused first and does not count.

A client that sends a state cookie and a matching state of its own
still counts, as the state is only compared within the browser; the
design document says so.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
A member without a role on an app got a 404 from authorize whose
message ("not found") differed from the one the handlers write for a
record that does not exist ("no such app", "no such deployment", ...),
and for database copies the code differed too (db_copy_not_found
against copy_not_found). Comparing the bodies told a member which slugs
and which sequential ids exist, which the design rules out: an app a
member has no role on does not exist for it.

authorize and the handlers now write the 404 of an app, a deployment, a
task run and a database copy through one helper, so both cases are the
same bytes. The database copy keeps one code, db_copy_not_found, the
one the design document and the error table of the API reference
already name; the console knows it as the 404 of a record, and the mock
API uses it.

A test walks every route of the table and compares the whole answer
for a hidden record with the one for a missing record.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The log streams were authorized once, when the connection was opened.
A member who was removed or lost its role on the app, a session that
was ended or had expired and an API token that was revoked or had
expired all kept receiving log lines for as long as the connection
stayed open, so revoking a stolen cookie or a leaked token did not stop
whoever was already reading.

The live log stream now asks again at every heartbeat (15 seconds), and
the job log streams (deployments, commands, database copies) at the
same interval: is the session or token still valid, may its user still
use the console, and does a member still hold the level the route needs
on the app. If not, the stream is closed without an end event, and the
client's reconnect gets the 401 or 404 of a new request. A failing
check closes the stream as well.

The checks are the ones a request passes. The session and token rules
moved into validSession and validToken, which lookupSession,
serveWithToken and the new stillAllowed share, and authorize remembers
the app and level it let a member in for.

logHeartbeatInterval is a variable so that tests can shorten it.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Base automatically changed from bound-log-volume to main November 23, 2026 19:24
@tricknotes
tricknotes merged commit 5166ae4 into main Nov 23, 2026
5 checks passed
@tricknotes
tricknotes deleted the api-hardening branch November 23, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant