The best way to control Claude Code, Codex and more from any computer or phone
fix(server): Git LFS images in pull request descriptions load the object, not its pointer (#35466)
Julius Marminge committed
Nov 14, 2026 at 20:44 UTC
5a31f1749d4f96b94cc682113e221cd520cdc591
3 files changed
+87
-1
packages/source-control-github/src/server/gitHubMediaFetch.test.ts
+64
@@ -125,6 +125,70 @@ describe("GitHubMediaFetch", () => {
125
);
126
});
127
128
+ it.effect("serves a Git LFS file's object, not the pointer a raw read returns", () => {
129
+ const object = "\x89PNG real object bytes";
130
+ const oid = "5a8f16132efe3eb67a8dea335571beac2745147010dabcedde78dbe708e6bccd";
131
+ const pointer = `version https://git-lfs.github.com/spec/v1\noid sha256:${oid}\nsize ${object.length}\n`;
132
+ return Effect.gen(function* () {
133
+ const fetchMedia = yield* GitHubMediaFetch.make;
134
+ const response = yield* fetchMedia({
135
+ url: "https://raw.githubusercontent.com/owner/repo/HEAD/art/background.png",
136
+ headers: {},
137
+ });
138
+ expect(response?.status).toBe(200);
139
+ expect(yield* response!.text).toBe(object);
140
+ }).pipe(
141
+ Effect.provide(
142
+ Layer.merge(
143
+ Layer.mock(GitHubRest.GitHubRest)({}),
144
+ Layer.mock(GitHubCredentials.GitHubCredentials)({
145
+ get: (host) =>
146
+ Effect.succeed({
147
+ host,
148
+ token: Redacted.make("signed-in"),
149
+ source: "gh" as const,
150
+ fingerprint: "fingerprint",
151
+ }),
152
+ }),
153
+ ),
154
+ ),
155
+ // GitHub's two routes to the object: the LFS media host and the Git LFS batch API.
156
+ Effect.provideService(
157
+ HttpClient.HttpClient,
158
+ HttpClient.make((request) => {
159
+ const url = new URL(request.url);
160
+ const respond = (body: string | null, init: ResponseInit) =>
161
+ Effect.succeed(HttpClientResponse.fromWeb(request, new Response(body, init)));
162
+ if (url.hostname === "raw.githubusercontent.com") {
163
+ return respond(pointer, { headers: { "content-type": "text/plain; charset=utf-8" } });
164
+ }
165
+ if (
166
+ url.hostname === "media.githubusercontent.com" ||
167
+ url.hostname === "lfs.example.com"
168
+ ) {
169
+ return respond(object, { headers: { "content-type": "image/png" } });
170
+ }
171
+ if (url.pathname.endsWith(".git/info/lfs/objects/batch")) {
172
+ return respond(
173
+ JSON.stringify({
174
+ objects: [
175
+ {
176
+ oid,
177
+ size: object.length,
178
+ actions: { download: { href: `https://lfs.example.com/${oid}` } },
179
+ },
180
+ ],
181
+ }),
182
+ { headers: { "content-type": "application/vnd.git-lfs+json" } },
183
+ );
184
+ }
185
+ return respond(null, { status: 404 });
186
+ }),
187
+ ),
188
+ Effect.scoped,
189
+ );
190
+ });
191
+
192
it.effect("keeps the credential off the object store a redirect hands the media to", () => {
193
const authorizations: Array<[string, string | undefined]> = [];
194
return Effect.gen(function* () {
packages/source-control-github/src/server/gitHubMediaFetch.ts
+15
-1
@@ -9,7 +9,7 @@ import {
9
type HttpClientResponse,
10
} from "effect/http";
11
12
-import { GITHUB_CREDENTIALED_MEDIA_HOSTS } from "../shared/gitHubMedia.ts";
12
+import { GITHUB_CREDENTIALED_MEDIA_HOSTS, gitHubLfsMediaUrl } from "../shared/gitHubMedia.ts";
13
14
import * as GitHubCredentials from "./GitHubCredentials.ts";
15
import * as GitHubRest from "./GitHubRest.ts";
@@ -164,6 +164,20 @@ export const make = Effect.gen(function* () {
164
request.headers,
165
signedIn?.token ?? null,
166
);
167
+ const lfsUrl = gitHubLfsMediaUrl(request.url);
168
+ if (lfsUrl !== null && response !== null && contentTypeOf(response) === "text/plain") {
169
+ const lfs = yield* fetchFollowingRedirects(
170
+ lfsUrl,
171
+ request.headers,
172
+ signedIn?.token ?? null,
173
+ );
174
+ if (
175
+ (lfs?.status === 200 || lfs?.status === 206) &&
176
+ MEDIA_CONTENT_TYPE_PATTERN.test(contentTypeOf(lfs))
177
+ ) {
178
+ return lfs;
179
+ }
180
+ }
181
if (response === null || contentTypeOf(response) !== "text/html") return response;
182
}
183
if (cacheKey === null || repository === undefined || signedIn === null) return response;
packages/source-control-github/src/shared/gitHubMedia.ts
+8
@@ -46,6 +46,14 @@ function rawFile(fetchUrl: string): SourceControlMediaUrl {
46
return media(fetchUrl, COMMIT_SHA_PATTERN.test(ref) ? { immutable: true } : {});
47
}
48
49
+/** Where GitHub serves a Git LFS object; a raw read of an LFS-tracked file returns its pointer. */
50
+export function gitHubLfsMediaUrl(rawUrl: string): string | null {
51
+ const url = URL.parse(rawUrl);
52
+ return url?.protocol === "https:" && url.hostname.toLowerCase() === RAW_HOST
53
+ ? `https://${LFS_HOST}/media${url.pathname}${url.search}`
54
+ : null;
55
+}
56
+
57
export function gitHubMediaUrl(url: URL): SourceControlMediaUrl | null {
58
if (url.protocol !== "https:") return null;
59
const host = url.hostname.toLowerCase();