Skip to content

fix: verify the bot cannot bypass the merge restriction - #795

Merged
max-sixty merged 4 commits into
mainfrom
ruleset-bypass-checks
Jul 27, 2026
Merged

max-sixty merged 4 commits into
mainfrom
ruleset-bypass-checks

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

tend check asserted its central claim — the bot cannot merge to the default branch — without reading the two fields that decide it. It passed whenever an update rule covered the branch, never looking at the ruleset's bypass_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 .permission field, 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 check verifies the bypass list. Each update rule is traced to its ruleset and every bypass actor must outrank write: roles are allowlisted ({maintain, admin} — unknown IDs fail closed), a User exemption is resolved against the bot's own id (naming the bot there is an explicit grant of the merge), and OrganizationAdmin/EnterpriseOwner pass. A team, app, or deploy key can't be resolved from the ruleset, and a bypass_actors list GitHub withholds (only ruleset admins see it) is unverifiable, not empty — both report as skips with instructions, never as passes.
  • tend check judges the bot by capabilities, not names. The permissions booleans replace string matching, so a custom role built on maintain or admin fails the same as the base role.
  • Preflight re-proves the restriction as the bot itself, every run. current_user_can_bypass on 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 answering never proves 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 .protected floor.

The docs feature the run-time self-test (README, site, security model, install recipe), and checks.py records 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 check against 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 via never, 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_actors withheld below ruleset-admin) were confirmed empirically, not just from docs.

🤖 Generated with Claude Code

This was written by Claude Code on behalf of max

max-sixty and others added 4 commits July 26, 2026 13:59
`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]>
@max-sixty
max-sixty merged commit 00bd755 into main Jul 27, 2026
7 checks passed
@max-sixty
max-sixty deleted the ruleset-bypass-checks branch July 27, 2026 03:24
@max-sixty max-sixty mentioned this pull request Aug 3, 2026
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_
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.

2 participants