Context
/api/github/route.ts proxies GitHub API responses and forces Content-Type: application/json on the response, regardless of what GitHub actually returns.
const body = await res.text();
return new NextResponse(body, {
status: res.status,
headers: { "Content-Type": "application/json", ... },
});
Risk: If GitHub returns an HTML error page (500, maintenance), the raw HTML is returned with a JSON content type. While modern browsers respect content-type, edge cases could lead to HTML being rendered.
Proposed approach
- Check GitHub response content-type before forwarding
- If response is not JSON, return a structured error instead of raw body
- Add response body validation (ensure it parses as JSON before forwarding)
Acceptance criteria
Context
/api/github/route.tsproxies GitHub API responses and forcesContent-Type: application/jsonon the response, regardless of what GitHub actually returns.Risk: If GitHub returns an HTML error page (500, maintenance), the raw HTML is returned with a JSON content type. While modern browsers respect content-type, edge cases could lead to HTML being rendered.
Proposed approach
Acceptance criteria