Skip to content

fix(guard-public-text): let gh api reads through, and close the gaps around writes - #80

Merged
gutyoh merged 3 commits into
mainfrom
fix/guard-gh-api-reads
Nov 6, 2026
Merged

gutyoh merged 3 commits into
mainfrom
fix/guard-gh-api-reads

Conversation

@gutyoh

@gutyoh gutyoh commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Why

guard-public-text.sh classed every gh api call as publishing and scanned the whole command, endpoint included. So a plain read like gh api repos/<owner>/<name>/rulesets was blocked whenever the owner matched a scanner needle. That made read-only checks impossible without routing around the guard, which a guard must never encourage.

Fixing that exposed some writes the guard missed. They are fixed here too.

What changes

Case Before After
gh api GET/HEAD with no body, or a graphql query blocked when the endpoint names a needle passes unscanned (a read publishes nothing)
gh api with a field, --input, a non-GET method, or a graphql mutation scanned still scanned
a read chained to a write (gh api … && git commit -m …) scanned still scanned: each verb is detected on its own
gh api repos/<o>/<n>/… write repository unknown, so checked as public the repository comes from the endpoint, so its visibility decides
the endpoint or -R value scanned as if published left out: an address is not published text
two repositories in one command the first one's visibility unknown, so checked as public
git push <remote> origin only the named remote; an unresolvable word is checked
git push origin other-branch HEAD's messages only every local branch the remote lacks
git push --tags / --follow-tags tag messages not checked annotated tag messages checked
git -c k=v commit, git --no-pager commit missed checked
gh pr/issue close --comment, gh pr merge --subject/--body, gh repo/label create/edit, gh gist edit, gh workflow run missed checked

gh's own manual backs the read rule: the default method is GET, and adding fields switches it to POST; -X GET sends the fields as a query string instead.

Tests

  • 13 new bats tests, one per row above. The 22 existing guard tests pass unchanged (35/35).
  • shellcheck (-s bash -S warning) and shfmt (-i 4 -ci -bn) are clean.
  • The hook stays bash 3.2 safe: tr, not ${x^^}.
  • Locally, the full suite had 3 failures, none in the guard:
    • setup.sh --minimal completes under stock macOS bash 3.2 fails on unmodified main too.
    • Two "< 500 ms" timing tests failed under machine load and pass on main.

🤖 Generated with Claude Code

…around writes

The guard blocked every `gh api` read whose endpoint named an owner the
scanner flags: it classed any `gh api` as publishing and scanned the
endpoint itself. A GET of repos/<owner>/<name>/rulesets publishes nothing.

Reads:
- A `gh api` call with no field, no --input, and a GET or HEAD method
  passes unscanned. So does a graphql query; a mutation is still scanned.
  This follows gh's own rule: fields switch the default method to POST.
- Each publishing verb is detected on its own, so a read chained to a
  write (`gh api ... && git commit -m ...`) still has the write checked.

Addresses are not text:
- A `gh api` write takes its repository from a repos/<owner>/<name>
  endpoint, so the repository's visibility decides, as it does for -R.
- The endpoint and the -R value are left out of the scan. The body,
  fields and files are still scanned.
- A command naming two different repositories is checked as unknown
  visibility, so one private repository cannot clear a public one.

Gaps closed around writes:
- `git push <remote>` checks the remote it names, not only origin: a
  repository whose origin is elsewhere can push to a GitHub mirror. A word
  that is neither a remote nor a URL is checked, not waved through.
- A push checks every local branch the pushed-to remote lacks, not only
  HEAD. It also checks annotated tag messages when tags are sent
  (--tags, --follow-tags, refs/tags/, push.followTags).
- git's global options before the subcommand (`git -c k=v commit`,
  `git --no-pager commit`) no longer hide a commit or push.
- Also checked now:
  - gh pr/issue close --comment;
  - gh pr merge --subject/--body;
  - gh repo/label create/edit --description;
  - gh gist edit;
  - gh workflow run fields.

Stays bash 3.2 safe: no ${x^^}. 13 new bats tests; the 22 existing ones
pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gutyoh
gutyoh marked this pull request as draft November 2, 2026 21:48
gutyoh and others added 2 commits November 6, 2026 21:38
-ftitle=x and -XPOST are valid gh flags; the read check only knew the
spaced forms, so such a write passed unscanned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gutyoh
gutyoh marked this pull request as ready for review November 6, 2026 22:36
@gutyoh
gutyoh merged commit bd63335 into main Nov 6, 2026
16 of 18 checks passed
@gutyoh
gutyoh deleted the fix/guard-gh-api-reads branch November 6, 2026 22:36
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