Repository navigation
fix: verify the bot cannot bypass the merge restriction - #795
Merged
Merged
Conversation
`tend check` reported a repo protected whenever an `update` rule applied to the branch, without reading the ruleset's bypass list. A bypass actor at write — exactly what the bot holds — defeats that rule, so the check could pass a repo the bot could merge to. It also read the bot's role from the legacy `.permission` field, which reports a maintain-role collaborator as "write", and maintain bypasses too. Each update rule is now followed back to its ruleset (under `/orgs` when the ruleset is org-level) and its bypass actors checked: only maintain and admin outrank the bot. A `User` actor is resolved against the bot's own id, since naming the bot there is an explicit grant of the merge the restriction exists to deny. Actors that can't be resolved — a team, app, or deploy key — report as unverified rather than passing silently. The role IDs are worth stating plainly: maintain is 2, write 4, admin 5. They aren't ordered by privilege, so the plausible guess for maintain is in fact write, and granting it hands the bot the merge. The REST API reports only the number; GraphQL names it, so the comment carries the query that reads a live ruleset back. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Matching `role_name` against {maintain, admin} narrowed the old check: the
legacy `.permission` field collapses a custom admin-derived role to "admin",
so the old code caught it, while a name match passes any custom role
whatever it grants. The `permissions` booleans in the same response report
effective capabilities, covering base and custom roles uniformly — they are
also what exposes a maintain collaborator that `.permission` reports as
"write".
Also resolves the bot's user id once per ruleset rather than per User
bypass actor, and updates the all-pass test fakes to serve the ruleset and
permission endpoints with real shapes — they previously passed through the
degraded not-a-dict path instead of the path the tests name.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The local `tend check` reconstructs "can the bot bypass?" from the ruleset's bypass actors, which leaves genuinely undecidable cases: a team's membership isn't visible from the ruleset, and GitHub withholds `bypass_actors` from callers below ruleset-admin. The CI preflight has what the local check lacks — the bot's own credentials — and `current_user_can_bypass` on a ruleset is GitHub's evaluation of exactly the caller's standing, teams, custom roles, and org/enterprise-sourced rulesets included. The preflight now asks that question directly: one applying update rule whose ruleset answers `never` proves the bot cannot update the branch; if update rules exist but the bot can bypass every one, the merge restriction provably does not restrict the bot and the run aborts. Repos protected by required reviews alone have no update rule and keep the `.protected` floor. Verified live: an admin identity aborts (it can bypass), a non-collaborator passes via `never` on vercel/next.js, and a reviews-only repo falls through to the floor. Also fixes the local check reading a withheld `bypass_actors` as an empty list — "nobody bypasses" — a false pass for exactly the caller who can't see the danger; it now reports unverifiable. The repo-scoped ruleset endpoint turns out to serve org- and enterprise-sourced rulesets too (verified against live repos), so the per-source endpoint routing is gone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The README security section, the site's security blurb, and the shipped security-model reference now lead the merge-restriction story with the property that carries it: the bot proves against itself, on every run, that its own credentials cannot bypass the ruleset, with GitHub doing the evaluation. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
tend-agent
approved these changes
Jul 27, 2026
Merged
max-sixty
added a commit
that referenced
this pull request
Aug 3, 2026
Bumps the generator to 0.1.13, syncs the lockfile, and adds the CHANGELOG section the release workflow publishes verbatim as the GitHub Release notes. 13 commits since 0.1.12. The release's substance is the security work: the operational secrets move into a gated `tend` deployment environment, with a secretless review-event relay in `tend-mention` and two new `tend check` checks ([#810](#810)), and `tend check` now verifies the bot cannot bypass the merge restriction ([#795](#795)). Alongside those: the `claude-interactive` harness is removed ([#804](#804)), `tend-review` runs the adopter's `setup:` on the base tree rather than the PR's ([#806](#806)), tend's uv is pinned and isolated from the adopter's ([#807](#807)), and the proxy readiness check waits for the port instead of trusting the CA file ([#811](#811)). Adopters have manual work after this ships: the environment gate is inert until each repo's regenerated workflows name the environment and its secrets are re-minted into it. `TODO.md` carries the per-repo recipe. Once this merges: tag `0.1.13`, which publishes to PyPI and creates the GitHub Release, then regenerate tend's own workflows against the published version. > _This was written by Claude Code on behalf of max-sixty_
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.
tend checkasserted its central claim — the bot cannot merge to the default branch — without reading the two fields that decide it. It passed whenever anupdaterule covered the branch, never looking at the ruleset'sbypass_actors: a bypass entry at Write (exactly what the bot holds) defeated the rule while the check reported the repo protected. And it read the bot's role from the legacy.permissionfield, which reports a maintain-role collaborator as"write"— maintain bypasses too. Found on a live repo where widening merge access nearly granted the bot the merge: the base role IDs run maintain 2, write 4, admin 5 — not ordered by privilege — so the plausible guess for "maintain" is in fact write.Three layers land here, strongest last:
tend checkverifies the bypass list. Eachupdaterule is traced to its ruleset and every bypass actor must outrank write: roles are allowlisted ({maintain, admin} — unknown IDs fail closed), aUserexemption is resolved against the bot's own id (naming the bot there is an explicit grant of the merge), andOrganizationAdmin/EnterpriseOwnerpass. A team, app, or deploy key can't be resolved from the ruleset, and abypass_actorslist GitHub withholds (only ruleset admins see it) is unverifiable, not empty — both report as skips with instructions, never as passes.tend checkjudges the bot by capabilities, not names. Thepermissionsbooleans replace string matching, so a custom role built on maintain or admin fails the same as the base role.current_user_can_bypasson each applying ruleset is GitHub's own evaluation of the caller's standing — teams, custom roles, and org/enterprise-sourced rulesets included, none of which the local check can resolve. One update rule answeringneverproves the bot cannot update the branch; if the bot can bypass every one, the run aborts. Repos protected by required reviews alone have no update rule and keep the.protectedfloor.The docs feature the run-time self-test (README, site, security model, install recipe), and
checks.pyrecords the verified role-ID mapping with the GraphQL query that reads names back, since REST returns only the numbers.Testing: 291 generator tests (+15) cover the bypass matrix — write/maintain/admin/OrgAdmin/Team/User bypasses, withheld lists, org/enterprise sources, untraceable rules. Verified live:
tend checkagainst a real repo passes through the new paths (API calls traced); the preflight's three verdicts each exercised against real repos — an identity that can bypass aborts, a non-collaborator passes vianever, a reviews-only repo falls through to the floor. Endpoint behaviors the code relies on (org/enterprise rulesets served by the repo-scoped endpoint;bypass_actorswithheld below ruleset-admin) were confirmed empirically, not just from docs.🤖 Generated with Claude Code