Repository navigation
Deploy only commits that a branch or tag of the repository reaches - #141
Merged
Merged
Conversation
POST /api/apps/{slug}/deployments checked only the form of "sha", and
the fetch step ran `git fetch --depth 1 <url> <sha>`. A hosting service
hands out every commit that any of its refs reaches, and on GitHub that
includes refs/pull/N/head of pull requests from forks, closed and
unmerged ones too. A member with only the deploy role on an app, who
need not be able to push to its repository, could therefore run code
that a stranger put into a fork pull request, wired to the app's
environment variables, volumes and database. That contradicts the line
drawn in ARCHITECTURE 10.7 (who can write to the repository and who may
run code on the host are not the same people) and the reason review apps
refuse fork pull requests (9.9).
A deployment now has to name the branch or tag its commit comes from,
and the fetch step refuses a commit that is neither the tip of that ref
nor one of its ancestors, before anything of it is fetched:
- gitrepo.Fetcher.Checkout takes the ref. It reads the tip with
ls-remote (the usual deployment of a branch head ends there), and for
an older commit fetches the commits of the ref without trees and blobs
(--filter=tree:0) and looks for the SHA in `git rev-list`. Only
refs/heads/<ref> and refs/tags/<ref> are read, so "pull/1/head" or
"refs/pull/1/head" as ref do not get around it. The commit is not
passed to `git merge-base --is-ancestor`: in a partial clone git
fetches a missing commit on demand when it is named. The repository
of the check is thrown away (git records the URL as a promisor remote
in its config) and the checkout runs in a fresh one, as before. The
token still travels only through the environment. The check is cut
off after five minutes.
- The engine records the ref when the deployment is queued. A request
with only a SHA is checked against the branch the app follows (the
branch of automatic deployments when they are on, otherwise the
default branch); pushes and review apps already pass their branch; a
promotion takes the ref of the promoted release, because it fetches
the commit again. Rollbacks to a kept release do not fetch and are
not affected.
- A full SHA sent as "ref" is taken as the commit, so that such a
request is checked against the app's branch instead of failing for a
branch of that name.
The check lives in the fetch step, not in the API handler, because
every path that deploys goes through it and it works the same for
GitHub App repositories and for plain repository URLs.
A commit that a force-push removed from its branch cannot be deployed
by SHA any more; the failure says to deploy from a branch or tag that
contains it. ARCHITECTURE 7 describes the rule, API.md the request and
the recorded ref, and the deploy-status and prepare-app Skills the new
cause of a failed fetch (plugin 0.26.1).
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The fetch step refuses a commit that the deployment's branch or tag does not reach. The console showed that like any other failure: an English sentence under "デプロイに失敗しました". It is a failure the reader has to act on, so the history row and the detail now say it in Japanese (which commit, from which ref, and to deploy from a branch or tag that contains it) and keep the reason koroku wrote below, as the failure for want of memory does. "このコミットを再デプロイ" on a rollback record sent the record's ref, the marker "rollback", as the branch. That would now fail for a branch of that name, so the button sends the ref of the deployment whose release the rollback started, or none when that row is not loaded, which leaves the branch to the server. The mock gets a scenario for the refused commit, and its deploy log the line the fetch step writes for the check. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The engine fills in the ref when it queues a deployment, so its tests never reached the fallback in the fetch step for a row that has none. Such rows exist: a deployment queued by a binary that did not record the branch, picked up by this one after an upgrade. The test queues one straight in the store and expects the commit to be checked against the branch the app follows. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2 of 3 tasks
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
A deployment's
shawas only checked for its form. GitHub serves any commit that some ref of the repository reaches, and that includesrefs/pull/N/headof pull requests from forks, even closed ones. So a member with only the deploy role, who need not be able to push, could deploy code that a stranger put into a fork pull request, connected to the app's variables and data.A deployment now only takes a commit that is the tip of its
ref(a branch or tag) or one of its ancestors.refshaonlyauto_deploy_branchwhen automatic deploys are on, elsedefault_branch)refof the deployment being promotedrepo_urlalike:git ls-remotefor the tip (0.5–0.9 s), and only for an older commit a fetch of the branch's history without file contents (4–5 s for a repository with 90,000 commits).The console shows the reason in Japanese with the original message; "redeploy this commit" on a rollback's row sends the ref of the deployment it went back to.
Screenshots
Test plan
go vet ./...,go vet -tags integration ./...,go test ./...pnpm lint,pnpm testTestDeployOnlyTakesCommitsTheRefReaches(a commit onlyrefs/pull/1/headreaches is refused however it is named, and nothing starts; an older commit of the branch deploys; a commit of another branch deploys only with that branch asref)🤖 Generated with Claude Code