Repository navigation
Harden the API: re-login for hook commands, registry token, OAuth limit, 404 bodies, log streams - #139
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Five fixes in the HTTP API, one commit each.
dump_hook_*,load_hook_*orpost_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.copy_not_foundbecomesdb_copy_not_found, the code ARCHITECTURE and API.md already used.Screenshots
The registry credential form when the registry or user name is edited:
Test plan
go vet ./...,go test ./...,go test -raceon the stream, token and session testspnpm lint,pnpm testTestProductionHookCommandsNeedRecentLogin,TestHiddenRecordsAnswerLikeMissingOnes(whole bodies, every route),internal/api/stream_access_test.go🤖 Generated with Claude Code