fix: stop falling back to the shared GitHub token

When a repository, gist or pull request owner had no usable GitHub
credential, content was fetched with the operator's GITHUB_TOKEN. That token
shares one rate limit with its account, so these fallbacks exhausted it and
made unrelated requests wait and time out. Owners now get token_expired (401),
which already asks them to renew their connection, and the server no longer
reads GITHUB_TOKEN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-28 19:35:32 +00:00
1 parent 62c3bf1daf
commit 341b0cc973
7 files changed
+38 -15

No files matched your search

+18
View File
@@ -173,6 +173,24 @@ describeMongo("credential access (MongoDB)", function () {
expect((await GistModel.collection.findOne({ _id: gist.model._id })).source.accessToken).to.equal(undefined);
expect((await PullModel.collection.findOne({ _id: pull.model._id })).source.accessToken).to.equal(undefined);
});
it("never borrows a shared operator token when the owner has no GitHub access", async () => {
const Gist = require("../src/core/Gist").default;
const PullRequest = require("../src/core/PullRequest").default;
const Repository = require("../src/core/Repository").default;
process.env.GITHUB_TOKEN = "operator-token";
try {
const resources = [
new Gist(await GistModel.create({ owner: owner._id, gistId: "no-access-gist", source: { gistId: "no-access" } })),
new PullRequest(await PullModel.create({ owner: owner._id, pullRequestId: "no-access-pr", source: { pullRequestId: "2" } })),
new Repository(await RepoModel.create({ owner: owner._id, repoId: "no-access-repo", source: { type: "GitHubStream" } })),
];
for (const resource of resources) {
const error = await resource.getToken().then(() => null, e => e);
expect(error?.message).to.equal("token_expired");
expect(error.httpStatus).to.equal(401);
}
} finally { delete process.env.GITHUB_TOKEN; }
});
it("refreshes a repository credential without copying it onto the repository", async () => {
const Repository = require("../src/core/Repository").default;
const repo = new Repository(await RepoModel.create({ owner: owner._id, repoId: "test-repo", source: { type: "GitHubStream" } }));