Skip to content

Deploy only commits that a branch or tag of the repository reaches - #141

Merged
tricknotes merged 3 commits into
mainfrom
deploy-reachable-commits
Nov 23, 2026
Merged

tricknotes merged 3 commits into
mainfrom
deploy-reachable-commits

Conversation

@tricknotes

Copy link
Copy Markdown
Owner

Summary

A deployment's sha was only checked for its form. GitHub serves any commit that some ref of the repository reaches, and that includes refs/pull/N/head of 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.

Deployment Checked against
Manual, with ref that branch or tag
Manual, sha only the branch the app follows (auto_deploy_branch when automatic deploys are on, else default_branch)
Automatic deploys the pushed branch
Review apps the pull request's head branch
Promotions the ref of the deployment being promoted
  • The check is in the engine's fetch step, so every path goes through it, for GitHub App repositories and apps with a repo_url alike: git ls-remote for 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).
  • A commit that fails is not checked out, built or started.
  • Rollbacks to a kept release do not fetch and are not affected.
  • A commit removed from its branch by a force-push can no longer be deployed by SHA, redeployed or promoted. A release deployed to staging from a branch that was deleted after merging cannot be promoted; deploy the merged branch to staging first.

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

Light
Dark
390px light
390px dark

Test plan

  • go vet ./..., go vet -tags integration ./..., go test ./...
  • pnpm lint, pnpm test
  • Integration: TestDeployOnlyTakesCommitsTheRefReaches (a commit only refs/pull/1/head reaches 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 as ref)
  • Against a public repository on GitHub, anonymously: the head of a fork pull request is refused, the tip and an older commit are fetched
  • The whole integration suite on the combined stack
  • A private repository with an installation token (covered by tests with a fake only)

🤖 Generated with Claude Code

tricknotes and others added 3 commits November 24, 2026 04:02
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>
Base automatically changed from domain-and-backup-hardening to main November 23, 2026 19:24
@tricknotes
tricknotes merged commit 215a505 into main Nov 23, 2026
8 of 9 checks passed
@tricknotes
tricknotes deleted the deploy-reachable-commits 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