Skip to content

fix(githttp): refuse a ref at an object that no registered pack holds - #896

Open
ThomasK33 wants to merge 3 commits into
mainfrom
registry-checked-ref-targets
Open

ThomasK33 wants to merge 3 commits into
mainfrom
registry-checked-ref-targets

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Why

The node's cache repository can hold an object that no registered pack holds: a cache that was copied or edited out of band, or a registry that was rolled back. git reads such an object without complaint. Every other node, and this node after it loses its cache, hydrates from the registered packs alone and cannot write a ref at that object (update-ref ... trying to write ref ... with nonexistent object), so a ref at it wedges the repository: reads, clones and later writes answer 500.

A write-path audit of main found no product path that puts such an object into the cache (every writer registers its pack before the ref move), but three entry points trust the cache and not the registry, so one drifted cache is enough to store the wedging ref. I reproduced each on a live node and in tests by planting a loose commit in the cache directory:

  • POST /repos/branches/create resolves base_ref and preferred_base in the cache, and moves the ref without publishing a pack.
  • POST /repos/tags does the same for ref.
  • A push update with an empty pack that names the cache-only commit passes git's connectivity check, and the update hook moves the ref.

What changed

  • githttp.RegisteredPackView is a temporary object directory that links exactly the pack files that the registry lists (ListPacks) from the cache. A git child with GIT_OBJECT_DIRECTORY set to it, and no alternates, reads an object only when a registered pack holds it. A registered pack that the cache lacks (a fold replaced the packs since the cache was hydrated) is downloaded first. With no way to download it, the view refuses with ErrPackMissing and never reads "missing" for an object that a pack holds. gitread.RegisteredKinds asks the view for the type of each id.
  • POST /repos/branches/create (base_ref, base_branch, preferred_base) and POST /repos/tags accept the commit only when a registered pack holds it. A commit that only the cache holds answers 404 like one that does not exist, and a base that names no usable commit still falls back to preferred_base. docs/reference/http-api.md says so.
  • The push update hook refuses an update of a ref to an object that no registered pack holds (denyUnregisteredTarget), before the compare-and-swap, per ref, like a policy denial: update: <ref> is at <sha>, which no pack of this repository's registry holds. A push that carries its objects is unaffected, because pre-receive registers its pack before this hook runs and git has moved the pack into the cache. A delete has no new value and is not checked.
  • Tests: TestRefWritesRefuseACommitThatOnlyTheCacheHolds (5 request shapes, pg and sqlite: 404, no ref written, a fresh node still hydrates, and the same request at a registered commit still answers 200) and TestUpdateHookRefusesATargetThatNoRegisteredPackHolds (branch, tag and notes, with an empty pack, plus a registered commit) fail on main. TestRegisteredKindsReadsTheRegisteredPacksOnly covers the view, including a cache that lost its pack files.
  • The lane-schedule fingerprints are re-recorded, because updateHook is a covered function. The model does not describe the check. The S3-WAL push census budget for a steady push goes from 21 to 22 round trips: the check lists the registered packs once, one manifest read (I could not run that lane here: it needs docker, so CI confirms the exact count).
  • Two in-process hook tests that run the update hook on an invented object id replace the check through a test seam.

Limits

  • The check covers the object that the ref names. A commit that a push carries in its pack but whose parent only the cache holds (a closure variant) still passes: closing it needs a reachability walk over the registered packs for every push, which this PR does not take on.
  • Each branch or tag create, and each ref update of a push, now lists the packs (one registry read) and starts one git child. A push of N refs pays it N times, once in each update hook.

Verification

  • The new route and hook tests fail on main and pass here. The full internal/api race lane (sqlite subtests, 332 s) and the full internal/githttp race lane (local backend) pass, with the two hook tests fixed through the seam. gofmt, golangci-lint 2.15.0 (0 issues), the gitlimit lease audit, the darwin test build, the doc-link gate and both fingerprint gates pass. The PostgreSQL and S3-WAL lanes run in CI.

Generated with xum • Model: anthropic:claude-sonnet-5-5 • Thinking: xhigh

The node's cache repository can hold an object that no registered pack
holds (a cache that was copied or edited out of band, or a registry that
was rolled back). git reads such an object, so three entry points stored
a ref at it: POST branches/create and POST tags resolved the base or the
target in the cache, and a push update with an empty pack passed git's
connectivity check. Every other node hydrates from the registered packs
alone, so each such ref wedged the repository. The two REST routes now
answer 404 for a commit that no registered pack holds, and the update hook
refuses the update, both by object state against a view of the cache that
links only the packs that the registry lists.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
<!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->

Change-Id: Ia072c3e1bd28cbd9b2a4441250dae1d810a2d150
…arget check

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
<!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->

Change-Id: I89f3a475d656e81fd175b9b8f2c4c980c2409bfd
Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
<!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->

Change-Id: I868869117ec8447c2206cf6ffea5cfc051631500
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T17:45:51.565794Z 3c8007f Manual request
🔒 Security Review ✅ Completed 2026-11-16T17:48:14.520456Z 3c8007f Manual request

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c8007fd81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/githttp/hook.go
Comment on lines +1853 to +1855
if new != ref.ZeroSHA {
if err := unregisteredTargetCheck(ctx, st, repo, refName, new); err != nil {
return err

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject unregistered targets before atomic update hooks

For a multi-ref --atomic push where an earlier command targets a registered object and a later command targets a cache-only object, the earlier update hook commits its authority CAS before this later per-ref check rejects. Git then aborts the local atomic ref transaction and reports the entire push as failed, while the earlier authority update remains committed. The registered-target check needs a whole-push pre-receive gate for atomic pushes, before any update hook can run.

Useful? React with 👍 / 👎.

Comment thread internal/githttp/hook.go
Comment on lines +2970 to +2975
kinds, err := ParseObjectKinds([]string{new}, out.String())
if err != nil {
return fmt.Errorf("update: %w", err)
}
if kinds[new] == "missing" {
return refusef("update: %s is at %s, which no pack of this repository's registry holds", refName, new)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Validate the registered object closure, not only the tip

When a crafted incoming pack contains the new commit or tag object but omits a referenced tree, parent, or tag target that exists only in this node's cache, receive-pack's connectivity check succeeds and the pack is registered. Since kinds[new] is then non-missing, this check accepts the ref even though a fresh node hydrating only registered packs cannot traverse it. Validate connectivity using the registered-pack-only view rather than checking only the direct object's type.

Useful? React with 👍 / 👎.

Comment on lines +58 to +63
if heal == nil || attempt > 0 {
return nil, fmt.Errorf("%w: the cache of %s lacks the registered pack %s", ErrPackMissing, repo, missing)
}
if err := heal(ctx); err != nil {
return nil, fmt.Errorf("fetch the registered packs of %s: %w", repo, err)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retry healing when the refreshed listing adds packs

On a fleet node whose cache is missing a listed pack, heal can download the snapshot returned by its own ListPacks while another node concurrently registers another pack. The subsequent outer listing then sees that new healthy pack missing locally, but attempt > 0 returns ErrPackMissing instead of healing again, so an otherwise valid branch/tag creation or push is transiently rejected during normal concurrent writes. Retry this list-and-heal cycle with a bounded race budget, as HydratePacks does.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 3c8007fd81

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread internal/githttp/hook.go
Comment on lines +1853 to +1856
if new != ref.ZeroSHA {
if err := unregisteredTargetCheck(ctx, st, repo, refName, new); err != nil {
return err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review

P2 Badge Security: Batch registered-target checks across push refs

With a git:write token and default-off rate limiting, an attacker can send one allowed no-pack push containing very many refs at an already registered commit. Git runs update once per ref, and this new call rebuilds a registered-pack view, calls ListPacks, creates two symlinks per pack, and launches git cat-file each time. The repository has no command-count cap, and receive-pack has no work slot or server deadline, so an N-ref push buys N backend reads, temp views, and Git children. Concurrent pushes can exhaust a node or shared store. Batch the SHAs in pre-receive or impose a strict command/work budget.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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