fix: scope the auth header to the Gitea server; README trust note

- review.yml and git.push set http.<GITHUB_SERVER_URL>/.extraHeader, so the bot token
  is sent only to the Gitea server; git.push falls back to the unscoped key when no
  server is known.
- README: a same-repository PR runs the caller workflow from its head, so the
  safeguards bound PR content, not edits to the caller; drafter: local fails the job.
- Tests: the source-grep fetch test is replaced by a behavioral one over a resumed run
  (fetch ends options, push uses the scoped key); the no-op summary test is dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-12 15:06:30 -05:00
1 parent 7783b6e78f
commit 70c762bf8a
7 files changed
+64 -23

No files matched your search

+14 -5
View File
@@ -126,17 +126,26 @@ def commit(paths: list[str], message: str, author: tuple[str, str], cwd: Path) -
)
def push(branch: str, cwd: Path, token: str | None) -> None:
def header_key(server: str | None) -> str:
"""The config key for the auth header: scoped to the Gitea server when it is known,
so the header is never sent to any other host."""
if server:
return f"http.{server.rstrip('/')}/.extraHeader"
return "http.extraHeader"
def push(branch: str, cwd: Path, token: str | None, server: str | None = None) -> None:
"""Push branch to origin under an explicit refspec, never forced.
The token travels as an http.extraHeader set through GIT_CONFIG_* variables on this
call only, so it never reaches argv or .git/config. A branch starting with + or -
could force the push or read as an option, so it is refused."""
The token travels as an extraHeader set through GIT_CONFIG_* variables on this call
only, so it never reaches argv or .git/config; with server (GITHUB_SERVER_URL) the
header is scoped to that URL. A branch starting with + or - could force the push or
read as an option, so it is refused."""
if not branch or branch.startswith(("+", "-")):
raise GitError(f"refusing to push branch {branch!r}")
extra = None
if token:
extra = {"GIT_CONFIG_COUNT": "1", "GIT_CONFIG_KEY_0": "http.extraHeader",
extra = {"GIT_CONFIG_COUNT": "1", "GIT_CONFIG_KEY_0": header_key(server),
"GIT_CONFIG_VALUE_0": f"Authorization: token {token}"}
ref = f"refs/heads/{branch}"
run(["push", "origin", f"{ref}:{ref}"], cwd, extra_env=extra)