Skip to content

fix(browser-session): resolve repo id from HTML page for private repos#111

Open
sevastyanovio wants to merge 1 commit into
Addono:mainfrom
sevastyanovio:fix/browser-session-private-repo-id
Open

fix(browser-session): resolve repo id from HTML page for private repos#111
sevastyanovio wants to merge 1 commit into
Addono:mainfrom
sevastyanovio:fix/browser-session-private-repo-id

Conversation

@sevastyanovio
Copy link
Copy Markdown

Problem

The browser-session strategy fails on private repositories with:

Error: Cannot access repository. Session may have expired.

getRepositoryId() looks up the repo id via https://api.github.com/repos/{owner}/{repo}, but the REST API only accepts token auth — a session cookie is rejected. For a private repo that returns 404, so the upload aborts before it starts.

Reproduced directly:

api.github.com/repos/<private>  with Cookie  -> 404
api.github.com/repos/<private>  with token   -> 200

The subsequent upload/policies/assets + confirm calls hit github.com (the web host), where the cookie is the correct auth — so only the repo-id lookup was on the wrong host/auth. (Public repos work today only because the unauthenticated API call returns 200.)

Fix

When authenticating by cookie, fall back to reading the id from the repository's HTML page (octolytics-dimension-repository_id meta tag), which the same cookie can load. Token-based callers keep using the REST API unchanged.

Minimal, additive: the API path stays the default, so public-repo and token flows are untouched; the HTML fallback only triggers when the API rejects a cookie.

Tests

npm run test:unit → 317 passing. Added coverage for:

  • API rejects cookie (404) → id resolved from the HTML page → upload succeeds
  • repo page missing the marker → UploadError(REPO_ID_FETCH_FAILED)
  • API and page both reject → AuthenticationError

npm run typecheck and eslint clean.

The browser-session strategy looked up the repository id via
api.github.com, which only accepts token auth. With cookie-based
credentials (the usual browser-session case) that returns 404 on private
repositories, so every upload failed with "Cannot access repository.
Session may have expired."

When authenticating by cookie, fall back to reading the id from the
repository's HTML page (the octolytics-dimension-repository_id meta tag),
which the same cookie can load. Token-based callers keep using the REST
API. Adds unit coverage for the fallback success path, a page without the
marker, and the both-rejected auth-failure case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant