fix(api): send required User-Agent on GitHub release requests#2
Open
Jeccoman wants to merge 1 commit into
Open
fix(api): send required User-Agent on GitHub release requests#2Jeccoman wants to merge 1 commit into
Jeccoman wants to merge 1 commit into
Conversation
The `/api/releases` route fetched the CPU and GPU latest releases without a
`User-Agent` header. GitHub's REST API requires a User-Agent on every request
and rejects those without one with `403 Forbidden` — regardless of whether an
auth token is present. As a result these two lookups silently failed and the
downloads page fell back to `null` for the CPU/GPU miner releases whenever the
response wasn't served from an intermediate cache.
`lib/clientRelease.ts` already sent the header correctly, so the client-app
release kept working while the CPU/GPU releases did not — the two code paths
had drifted apart despite doing the same job.
Consolidate both into a single hardened helper (`lib/github.ts`) that:
- always sends the required `User-Agent` (plus Accept + API version),
- attaches the server token when present and transparently retries once
anonymously on 401/403 so a bad/expired token can't take down an
otherwise-public lookup,
- returns a structured result instead of throwing, and sets `cache: no-store`.
Both `pages/api/releases.ts` and `lib/clientRelease.ts` now use it, removing the
duplicated request logic that allowed the drift in the first place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
/api/releasesroute fetched the CPU and GPU latest releases from the GitHub REST API without aUser-Agentheader. GitHub requires aUser-Agenton every request and rejects requests that omit it with403 Forbidden— with or without an auth token. So these two lookups silently failed and the downloads page fell back tonullfor the CPU/GPU miner releases whenever the response wasn't served from an intermediate cache.lib/clientRelease.tsalready sent the header correctly, which is why the client-app release kept working while the CPU/GPU releases didn't — the two code paths had drifted despite doing the same job.What changed
lib/github.ts— a single hardened GitHub release client that:User-Agent(plusAccept+ API version),{ ok, status, data }result instead of throwing, withcache: 'no-store'.pages/api/releases.tsandlib/clientRelease.tsnow both use it, removing the duplicated request logic that allowed the drift.Why this way
The bug existed because the same request logic was implemented twice and one copy was missing a header. Fixing it in one place and routing both callers through it prevents the class of bug, not just this instance.
Testing
npx tsc --noEmit— no new type errors (pre-existing.svgmodule-resolution errors are unrelated).npx next linton changed files — clean.npm run build— succeeds;/api/releasescompiles.Risk
Low. No API surface or response-shape change (
{ cpu, gpu, client }unchanged). Behavior only improves on the previously-failing path. No new dependencies.