fix(cache): stop forwarding the GitHub token when following redirects (closes #53) - #158
Conversation
|
Warning Review limit reached
Next review available in: 13 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
f45508d
into
harsharajkumar-273:main
Summary
_downloadAssetfollows redirects itself and was sendingAuthorization: token …on every hop. GitHub release assets redirect to pre-signed S3 URLs, so the token was
going to a host that has no business seeing it.
Worth stating the order of severity differently from the issue: the 400 from S3 is
the symptom, but the actual problem is that a GitHub credential was being handed to a
third party. S3 rejecting the request is arguably the lucky part — a host that
accepted it would have received a working token silently.
Fixed by only sending the header when the target is GitHub.
Related Issue
Closes #53
Type of Change
Changes Made
The host check is stricter than the one in the issue.
hostname.endsWith('github.com')also matches
evilgithub.com,notgithub.comandmygithub.com— anyone able to geta redirect pointed at a lookalike domain would still receive the token. So:
The dot is the whole point. Exported so the classification can be tested directly.
A second bug in the same function. A
Locationheader is allowed to be relative(RFC 9110), and the value was passed straight back into
follow(). There,url.startsWith('https')would be false for a bare path, so it would pick thehttpmodule and try to request a URL with no host. Redirects are now resolved against the
URL that produced them, and the target is parsed once through
new URL()— which alsomeans a malformed redirect rejects the promise instead of throwing out of the executor.
url.startsWith('https')was also replaced withtarget.protocol === 'https:', whichis what it was reaching for.
AI Usage
Used Claude for coding.
Testing
10 new tests in
backend/tests/githubCacheStore.test.js, all passing.The redirect tests run against two real local HTTP servers rather than mocks, so what
is asserted is the headers that actually went over a socket:
Covered:
github.comand its subdomains accepted;evilgithub.com,notgithub.comand
mygithub.comrejected;objects.githubusercontent.comandgithub-releases.s3.amazonaws.comrejected, since those are where a release assetactually lands;
github.com.evil.netrejected;User-AgentandAcceptstill sent;the body written from the redirect target rather than the redirect; a relative
Locationresolved correctly; a malformed URL rejected; and a redirect loop giving upwith
Too many redirects.Full backend suite: 69 tests, 65 pass, 4 fail — the four being
buildQueue,gitWorkspaceDraft,gitWorkspaceServiceandserver.routes, which fail identicallyon a clean
main(59/55/4 there).npx tsc --noEmitreports nothing in this file.Checklist
main