fix: keep auto-update repos readable and refuse LFS pointers from jsDelivr

Without owner access, a reviewer visit to an auto-update repository tried
a GitHub API refresh and failed with token_expired; it now skips the
refresh and serves the stored tree. jsDelivr returns Git LFS pointers,
which match their blob SHA, so they are now refused like on the raw path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-28 21:17:27 +00:00
1 parent 4e10e6662d
commit 5b350aaebe
3 files changed
+52 -19

No files matched your search

+18
View File
@@ -38,6 +38,24 @@ describe("jsDelivr access without owner credentials", function () {
expect(error.message).to.equal("token_expired");
});
it("refuses Git LFS pointers, which jsDelivr serves instead of the file", async () => {
const pointer = "version https://git-lfs.github.com/spec/v1\noid sha256:" + "b".repeat(64) + "\nsize 123\n";
got.stream = () => Readable.from([pointer]);
const source = new GitHubStream({ repoId: "r", organization: "owner", repoName: "repo", commit, getToken: () => PUBLIC_CDN_TOKEN });
const error = await (async () => { for await (const _ of await source.downloadWithFallback(PUBLIC_CDN_TOKEN, "blob-sha", "big.bin")) void _; })().catch(e => e);
expect(error.message).to.equal("upstream_error");
});
it("skips the automatic refresh, which needs the GitHub API", async () => {
const Repository = require("../src/core/Repository").default;
const GitHubBase = require("../src/core/source/GitHubBase").default;
const repo = Object.create(Repository.prototype);
repo._model = { options: { update: true, expirationMode: "never" }, lastView: new Date(0), source: {} };
Object.defineProperty(repo, "source", { value: Object.create(GitHubBase.prototype) });
repo.getToken = async () => PUBLIC_CDN_TOKEN;
await repo.refreshIfNeeded();
});
it("encodes owner, repository and path segments", () => {
expect(jsDelivrFileUrl("o", "r", commit, "x/%2e")).to.equal(`https://cdn.jsdelivr.net/gh/o/r@${commit}/x/%252e`);
for (const path of ["../x", "a/./b", "a//b", ""]) expect(() => jsDelivrFileUrl("o", "r", commit, path)).to.throw("invalid_path");