Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Pull request images hosted on GitHub Enterprise (*.ghe.com) do not render in the pull request viewer #34367

ClosedFreshlyBrewedCode(GitHub profile, opens in a new tab) opened this issue 2 comments

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Sign in to a GitHub Enterprise Cloud tenant with gh auth login --hostname <tenant>.ghe.com. The tenant's organization should require enterprise sign-in (SAML/SSO), and the account must be able to read a private repository there.
  2. In that repository, open a pull request whose description contains either:
    • an uploaded image (https://<tenant>.ghe.com/user-attachments/assets/<uuid>), or
    • an image committed to the repository (https://<tenant>.ghe.com/<owner>/<repo>/blob/<ref>/<path>.png?raw=true).
  3. Open the pull request in T3 Code's built-in pull request viewer.

Expected behavior

Both images render, as they do for equivalent pull requests on github.com. The server fetches them with the gh credential for the pull request's host.

Actual behavior

Both images appear broken. The pull request's text, comments and other details on the same host load normally.

Cause (from source): gitHubMediaUrl in packages/source-control-github/src/shared/gitHubMedia.ts only recognizes github.com, www.github.com, raw.githubusercontent.com and media.githubusercontent.com. For any other host it returns null. The image is then rendered as a plain <img src>, and the client has no session for the Enterprise host. Running the function from v0.1.8 (identical on main) gives:

https://github.com/user-attachments/assets/<uuid>             -> { fetchUrl: "https://github.com/user-attachments/assets/<uuid>", ... }
https://github.com/o/r/blob/main/a.png?raw=true               -> { fetchUrl: "https://raw.githubusercontent.com/o/r/main/a.png", ... }
https://example.ghe.com/user-attachments/assets/<uuid>        -> null
https://example.ghe.com/o/r/blob/main/a.png?raw=true          -> null
https://ghes.example.com/user-attachments/assets/<uuid>       -> null

packages/source-control-github/src/server/gitHubMediaFetch.ts also assumes github.com, so accepting the URL in gitHubMediaUrl alone would not fix it:

  • It reads the credential with credentials.get("github.com") rather than the media's host.
  • uploadRepository requires hostname === "github.com".
  • The SAML fallback renderSignedUrl posts to markdown on host: "github.com". It only accepts a signed URL on private-user-images.githubusercontent.com that has a jwt parameter.
  • GITHUB_CREDENTIALED_MEDIA_HOSTS only lists github.com hosts.

How a *.ghe.com tenant behaves (checked with curl, using the gh token for the tenant):

RequestResult
GET https://<tenant>.ghe.com/user-attachments/assets/<uuid>, no auth302 to /login
same, Authorization: Bearer <gh token>200 text/html (the enterprise sign-in page, like the github.com SAML case)
POST https://api.<tenant>.ghe.com/markdown with ![](<attachment url>), mode: gfm, context: <owner>/<repo><img src> is https://objects-origin.<tenant>.ghe.com/... with X-Amz-* signature parameters (X-Amz-Expires=300). It is not private-user-images.githubusercontent.com and has no jwt parameter.
GET that signed URL, no auth307 to an Azure Blob Storage host, then 200 image/png
GET https://<tenant>.ghe.com/<owner>/<repo>/blob/<ref>/<path>.png?raw=true, bearer302 to /login
GET https://raw.<tenant>.ghe.com/<owner>/<repo>/<ref>/<path>.png, bearer200 image/png
GET https://api.<tenant>.ghe.com/repos/<owner>/<repo>/contents/<path>?ref=<ref>, Accept: application/vnd.github.raw, bearer200

So the same approach as on github.com works on *.ghe.com, with tenant-specific hosts:

  • Rewrite repository file links to raw.<tenant>.ghe.com, the equivalent of raw.githubusercontent.com.
  • Resolve uploads through the tenant's markdown render endpoint and accept its objects-origin.<tenant>.ghe.com signed URL.
  • Look up the credential for the tenant host.

Credential lookup (GitHubCredentials) and pull request host detection already handle *.ghe.com. This looks like a gap in the media path only, not missing Enterprise support.

Impact

Minor bug or occasional failure

Version or commit

0.1.8 (desktop). The media files are unchanged on main @ a577e94.

Environment

macOS, T3 Code desktop 0.1.8, GitHub Enterprise Cloud with data residency (*.ghe.com) with enterprise sign-in, gh authenticated to the tenant

Logs or stack traces

Not collected. According to the source, these URLs never reach the server media fetch; the client loads them directly, so no server log entry is expected.

Workaround

Open the pull request in a browser that is signed in to the Enterprise tenant.

Not verified

  • GitHub Enterprise Server (self-hosted) was not tested. It goes through the same gitHubMediaUrl path (third line above), but its raw-file and signed-upload hosts may differ from *.ghe.com.
  • A *.ghe.com organization without enterprise sign-in was not tested.
  • No patch was written or tested. The host behaviour above was checked with curl, not through a modified T3 Code build.
  1. I tried to reproduce this on the current build and could not.

    Not seen in a running app: that needs a GitHub Enterprise Cloud (*.ghe.com) tenant with enterprise sign-in and a private repo, which no worker has. On origin/main d50a6fdc30 I confirmed the reporter's source analysis and added assertions to the existing 'fetches every spelling of an upload or committed file from one canonical URL' test in packages/source-control-github/src/shared/definition.test.ts. definition.mediaUrl(new URL('https://acme.ghe.com/user-attachments/assets/')) returns null on main (AssertionError: expected undefined to be 'https://acme.ghe.com/user-attachments/...'). A blob ?raw=true link on acme.ghe.com is also expected to map to https://raw.acme.ghe.com/owner/repo/main/docs/shot.png. Ran with vp test run src/shared/definition.test.ts -t "every spelling" in packages/source-control-github: 1 failed. Pushed as factory/repro-34367 (9d6ac35898).

    Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

  2. juliusmarminge closed this

  3. Thanks for looking into this, and for the unit test on factory/repro-34367. This still happens for me on desktop 0.1.8 (macOS). Below is a reproduction of the visible symptom that doesn't need a GitHub Enterprise tenant.

    Repro without a tenant (real Chromium, current main @ ee90bdc9)

    This adds one test to apps/web/src/components/pullRequest/PullRequestMarkdown.browser.test.tsx. It renders a pull request body with the real PullRequestMarkdown component and checks how each image is loaded: through the server's credentialed media fetch, or as a plain <img src>.

    it.each([
      ["github.com upload", "https://github.com/user-attachments/assets/7195f963-51a9-4331-be74-3e06be760422"],
      ["github.com committed file", "https://github.com/owner/repo/blob/main/docs/shot.png?raw=true"],
      ["ghe.com upload", "https://acme.ghe.com/user-attachments/assets/7195f963-51a9-4331-be74-3e06be760422"],
      ["ghe.com committed file", "https://acme.ghe.com/owner/repo/blob/main/docs/shot.png?raw=true"],
      ["GHES upload", "https://github.acme.test/user-attachments/assets/7195f963-51a9-4331-be74-3e06be760422"],
    ])("%s is fetched by the server, not loaded directly", async (_label, image) => {
      setup();
      await using screen = await renderBody("github", { repository: "owner/repo", text: `![shot](${image})` });
      await vi.waitFor(() =>
        expect(requested.length + screen.container.querySelectorAll("img").length).toBeGreaterThan(0),
      );
      const direct = [...screen.container.querySelectorAll("img")].map((img) => img.getAttribute("src"));
      expect(direct).toEqual([]);
      expect(requested).toEqual([expect.objectContaining({ repository: "owner/repo" })]);
    });

    cd apps/web && vp test run --project browser src/components/pullRequest/PullRequestMarkdown.browser.test.tsx -t "fetched by the server"

    ✓ github.com upload          server-fetched=true
    ✓ github.com committed file  server-fetched=true
    × ghe.com upload             server-fetched=false  direct-img-src=["https://acme.ghe.com/user-attachments/assets/7195f963-…"]
    × ghe.com committed file     server-fetched=false  direct-img-src=["https://acme.ghe.com/owner/repo/blob/main/docs/shot.png?raw=true"]
    × GHES upload                server-fetched=false  direct-img-src=["https://github.acme.test/user-attachments/assets/7195f963-…"]
    Tests  3 failed | 2 passed

    So in the running app, Enterprise images are loaded directly by the webview, with no credential. The issue body shows what an Enterprise host does with such a request: 302 to /login. The webview has no session for that host, so the image breaks. A tenant is only needed to watch that last step, not to reproduce the bug.

    Could you reopen this? I'm happy to test a fix against a real *.ghe.com tenant.

Sign in to join this conversation.