← Back to Pull requests

fix: authenticate the GitHub repo-size preflight and log its outcome #124

Closed
unknown closed this pull request without merging on Oct 21, 2026 15:59 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 15:39 UTC
Author

Problem

When bootstrapping from a github.com source without --target-max-pack-bytes, git-sync asks the GitHub REST API (GET /repos/{owner}/{repo}) for the repository size. It switches to 512 MiB batches when the size is 1.5 GiB or more. That lookup sent no credentials. For a private repository GitHub answers 404 to an anonymous caller, so every private repository bootstrapped as a single pack, whatever its size.

Nothing reported this:

  • Every failure (non-200, transport error, parse error) returned silently.

  • The "selected batched mode" message only showed with verbose logging.
  • Public repositories were exposed too: anonymous calls share GitHub's 60 requests/hour limit per egress IP.

    Changes

    Authenticated lookup

  • The size request now carries the source connection's credentials (basic or bearer): an explicit token, a user:token@ in the source URL, or credentials the git credential helper supplied when the git server asked for them. A public repository never asks, so with only a helper its lookup stays anonymous. A URL username without a password is not sent: it may be an account name.

  • If the API refuses the token with 401 or 403 (for example an SSO-unauthorized PAT), the lookup retries once anonymously. A public repository is never worse off than before. If the retry fails too, the refusal is reported rather than hidden behind the retry's 404.

  • The new HTTPConn.CredentialsFor(dest) decides which credentials may go to the API, checking the real destination. Each credential is measured from the URL it is bound to (the endpoint for explicit and URL credentials, the looked-up host for helper ones), the destination must be same-site with it, and with TLS verification off nothing crosses to another host. So helper credentials looked up for a redirect host stay with that host, and an API base on another site gets nothing.

  • GitHubOwnerRepo now treats github.com as GitHub only on its scheme's default port. The connection's redirect guard still strips credentials from any hop that leaves the API's site, and the logged authenticated reflects the request that actually produced the answer.
  • Visible outcome

  • Every lookup that is attempted is logged through Options.BootstrapLogger. This does not need verbose mode.

  • Fields: repository, authenticated, http_status, refused_auth_status, refused_auth_error, size_kb or error, threshold_kb, mode, target_max_pack_bytes.

  • A failed lookup logs at WARN and also prints a notice that the bootstrap starts with a single pack, so CLI users see it without -v (it can still switch to batches if the target rejects the pack). The notice names the token refusal when there was one. Under -v the failure is printed once, and the verbose log and BootstrapLogger use the same record name.
  • Hardening

  • A reported size of 0 counts as unknown, like a missing or negative size: bootstrap only runs with source refs, so 0 means GitHub has not sized the repo yet. It warns and prints the notice.

  • A cancelled run reports nothing. Every error text (transport errors included) is cleaned before it is logged or printed.

  • A 401/403 counts as a refused token only when the request still carried it, so a redirect that stripped the credentials is neither retried nor blamed on the token.

  • Wiki sources (owner/repo.wiki) get no lookup: the API has nothing to size.

  • Each lookup request has its own 30s timeout, so a slow refusal does not starve the anonymous retry.

  • GitHub's error message is cleaned (control characters including C1, bidi formatting) and truncated before it is logged.
  • Docs

  • docs/usage.md documents the lookup and its credential scope.

  • Updated the BootstrapLogger doc comments and CHANGELOG.md.
  • Tests

    New file internal/strategy/bootstrap/github_preflight_test.go, written test-first. It covers:

  • a private repo: 404 without auth, 200 with auth, so batched (also end-to-end through Execute);

  • a bearer token, user:token@ URL credentials, and a bare URL username not being sent;

  • no credentials with TLS verification off, or to an API base on another site;

  • lookup failure: one-shot, a WARN record and a notice;

  • the anonymous retry on 401/403, the refusal reported when the retry fails too, and no retry on other failures;

  • a transport error, and unusable bodies (not JSON, no size, negative size);

  • sanitizing GitHub's error message;

  • a small repo staying one-shot without a warning, and one reporting size 0 warning as unknown;

  • a cancelled run, unclean transport errors, an unauthenticated 403 after a redirect, and the per-attempt timeout;

  • skipped lookups (caller already batching, non-default port, non-GitHub host);

  • a redirect that leaves the API's site dropping credentials (asserting the target was reached, and logged as unauthenticated);

  • CredentialsFor in internal/gitproto/smarthttp_test.go: explicit, helper and URL credentials, helper credentials bound to a redirect host, and TLS verification off.
  • The preflight tests reach a local TLS server as https://api.github.com, so the destination check runs as in production.

    The new tests fail against the previous implementation. go test ./..., go test -race on the affected packages and golangci-lint run (v2.11.4) all pass.

    ---
    _Generated by Claude Code_

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Touches credential scoping for cross-host API calls and bootstrap batching decisions; mistakes could leak tokens or mis-size packs, but changes are heavily tested and fail closed on redirects/TLS-off.

    > Overview

    Fixes batched bootstrap for large private GitHub repos by sending source credentials on the GET /repos/{owner}/{repo} size preflight (scoped to api.github.com via new HTTPConn.CredentialsFor), with same-site/TLS rules aligned to redirect handling and helper creds bound to authOrigin.

    > The preflight moves into github_preflight.go with structured BootstrapLogger / PushLogger records, CLI notices on lookup failure, 401/403 → one anonymous retry, stricter GitHubOwnerRepo parsing, and sanitize.Line for API/error text in logs. Docs and changelog describe the behavior.

    > <sup>Reviewed by Cursor Bugbot for commit d0e7b7873bb287a3c90f5ed779923b16b26d5b15. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: pjbgf Review duration: 2900m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #124"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%