fix(github): scope auth headers to API URLs#9271
Conversation
Greptile SummaryThis PR fixes a token-leaking regression by scoping GitHub Confidence Score: 5/5Safe to merge; no P0/P1 issues found and all prior review concerns are resolved. All previously flagged concerns (GHE.com No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Outbound HTTP request] --> B{is_github_api_url?}
B -- yes --> C[github::get_headers]
C --> D{resolve_token host}
D --> E[Add Authorization + X-GitHub-Api-Version]
E --> F{path contains /releases/assets/}
F -- yes --> G[Add Accept: application/octet-stream]
F -- no --> H[Return headers]
G --> H
B -- no --> I{is_gitlab_host?}
I -- yes --> J[gitlab::get_headers]
I -- no --> K{is_forgejo_host?}
K -- yes --> L[forgejo::get_headers]
K -- no --> M[Empty HeaderMap]
subgraph is_github_api_url logic
N[host == api.github.com] --> O[true]
P[is_ghe_com_api_host: api.*.ghe.com] --> O
Q[host != github.com AND not .githubusercontent.com AND not .ghe.com AND is_ghes_api_path /api/v3] --> O
end
Reviews (3): Last reviewed commit: "fix(github): scope auth headers to API U..." | Re-trigger Greptile |
There was a problem hiding this comment.
Code Review
This pull request refines the identification of GitHub API URLs and improves token resolution logic, notably adding support for ghe.com hosts and ensuring authentication headers are only sent to REST API endpoints. Key changes include the introduction of is_github_api_url and a multi-host lookup strategy in resolve_token. Feedback suggests extending the is_ghcom exclusion to ghe.com hosts to prevent unintended enterprise token usage and removing a redundant check in src/http.rs.
4d782c8 to
fdf976f
Compare
fdf976f to
b50f55e
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
### 🚀 Features - **(backend)** support aqua vars templates by @risu729 in [#9110](#9110) - add gsudo (Sudo for Windows) to registry by @matracey in [#9281](#9281) ### 🐛 Bug Fixes - **(cli)** retrieve token from github helper for `self-update` command by @sushichan044 in [#9259](#9259) - **(github)** scope auth headers to API URLs by @risu729 in [#9271](#9271) - **(vfox)** use github token for lua http requests by @jdx in [#9257](#9257) ### 📚 Documentation - add aube hero banner by @jdx in [#9265](#9265) - add en.dev footer by @jdx in [#9267](#9267) - implement landing page design by @jdx in [#9266](#9266) ### 📦️ Dependency Updates - lock file maintenance by @renovate[bot] in [#9268](#9268) ### 📦 Registry - add llama.cpp ([github:ggml-org/llama.cpp](https://github.com/ggml-org/llama.cpp)) by @igor-makarov in [#9282](#9282) - add kiro-cli by @shalk in [#9274](#9274) - add flux-operator & flux-operator-mcp by @monotek in [#8852](#8852) ### Chore - **(release)** add en.dev sponsor blurb to release notes by @jdx in [#9272](#9272) - bump communique to 1.0.1 by @jdx in [#9264](#9264) ### New Contributors - @monotek made their first contribution in [#8852](#8852) - @igor-makarov made their first contribution in [#9282](#9282) ## 📦 Aqua Registry Updates #### New Packages (2) - [`controlplaneio-fluxcd/flux-operator/flux-operator-mcp`](https://github.com/controlplaneio-fluxcd/flux-operator/flux-operator-mcp) - [`endevco/aube`](https://github.com/endevco/aube) #### Updated Packages (1) - [`graelo/pumas`](https://github.com/graelo/pumas)
Summary
AuthorizationandX-GitHub-Api-Versionheaders to non-API GitHub URLs, includinggithub.comrelease browser downloads and*.githubusercontent.comcontent/CDN hosts.api.github.com, GHES-styleHOSTNAME/api/v3, and GHE.com data-residencyapi.SUBDOMAIN.ghe.com.is_gh_hostHTTP routing branch so GitHub header generation is reached only for URLs classified as GitHub REST API URLs.Accept: application/octet-streamon/releases/assets/API URLs only.Root Cause
The token/header policy added for GitHub-related hosts was too broad. Public release browser URLs on
github.comcan reject requests when a GitHub token is attached, which forces mise to fall back to the API asset URL. That fallback still works, but it loses the clearer browser download URL/filename path and increases API usage, which earlier work tried to avoid.GHE Notes
https://HOSTNAME/api/v3/..., so this keeps auth on non-github.com/api/v3URLs.SUBDOMAIN.ghe.comfor the web host andapi.SUBDOMAIN.ghe.comfor REST API. Token lookup triesSUBDOMAIN.ghe.combeforeapi.SUBDOMAIN.ghe.com, matching the platform hostname users authenticate with, while still not sending headers to the web/download host./api/v3path matcher; onlyapi.SUBDOMAIN.ghe.comis treated as a GHE.com REST API host.Review Follow-up
is_gh_hostbranch fromsrc/http.rsnow thatgithub::get_headersandis_github_api_urlenforce API-only header behavior..ghe.comweb hosts from the GHES/api/v3path arm.MISE_GITHUB_ENTERPRISE_TOKENprecedence unchanged for non-github.comAPI hosts, includingapi.SUBDOMAIN.ghe.com, because this PR is scoped to header destination safety and the existing token precedence treats non-github.comGitHub Enterprise hosts as enterprise hosts.References
Tests
cargo fmt --allcargo test --all-features github::testsgit diff --checkcurl -sSILon the reportedgithub.com/cuotos/ecs-exec-pfasset URL returns200and redirects torelease-assets.githubusercontent.comwithout auth headers.Notes:
mise run formatdid not discover tasks in this checkout, so I rancargo fmt --alldirectly. Broadcargo clippy --all-features -- -Dwarningsandcargo clippy -p mise --all-features --no-deps -- -Dwarningscurrently fail on unrelated pre-existing clippy warnings outside this change.This PR description was AI-generated.