mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
fix(repo-list): block installations before picker writes, resync stale lists, clear on revoke
- A failed picker write no longer skips blocking a deleted or suspended installation: the list update now runs after it. - Lists older than 12 hours resync in the background, covering new org installs, OAuth lists and missed or reordered deliveries. - Revoking a grant clears the stored list first, and a revoked App authorization webhook clears it too. - The name index includes repositoryId to match the picker sort. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c73e992b7c
commit
f12cde1400
3 files changed
+20
-10
No files matched your search
@@ -277,6 +277,8 @@ export async function revokeGrant(ownerId: string, provider: "github" | "github-
|
||||
const token = await getCredentialToken(ownerId, provider);
|
||||
const clientId = provider === "github" ? config.CLIENT_ID : config.GITHUB_APP_CLIENT_ID;
|
||||
const clientSecret = provider === "github" ? config.CLIENT_SECRET : config.GITHUB_APP_CLIENT_SECRET;
|
||||
// Before the GitHub call: a failed revoke must not keep private repo names.
|
||||
await clearRepositoryList(ownerId, provider === "github" ? "oauth" : "github-app");
|
||||
if (token) {
|
||||
const response = await fetch(`https://api.github.com/applications/${clientId}/grant`, { method: "DELETE",
|
||||
headers: { Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`, "Content-Type": "application/json", Accept: "application/vnd.github+json" },
|
||||
@@ -286,7 +288,6 @@ export async function revokeGrant(ownerId: string, provider: "github" | "github-
|
||||
await CredentialModel.deleteMany({ ownerId, provider });
|
||||
if (provider === "github") await UserModel.updateOne({ _id: ownerId }, { $unset: { "accessTokens.github": "", "accessTokenDates.github": "" } });
|
||||
await UserModel.updateOne({ _id: ownerId }, { $set: { repositories: [] } });
|
||||
await clearRepositoryList(ownerId, provider === "github" ? "oauth" : "github-app");
|
||||
}
|
||||
router.post("/connections/disconnect-oauth", async (req, res) => {
|
||||
try {
|
||||
@@ -324,13 +325,12 @@ githubAppWebhook.post("/", express.raw({ type: "application/json", limit: "2mb"
|
||||
phase = "find_grant_owners";
|
||||
const users = await UserModel.find({ "externalIDs.github": String(body.sender.id) }).select("_id").lean();
|
||||
phase = "reconcile_grant";
|
||||
for (const user of users) await reconcileAppGrant(String(user._id));
|
||||
}
|
||||
if (["installation", "installation_repositories", "repository"].includes(String(event))) {
|
||||
// Stored picker lists first: these writes are idempotent and need no
|
||||
// GitHub call, so they apply even if the installation check below fails.
|
||||
phase = "update_repository_lists";
|
||||
await applyRepositoryWebhook(String(event), body);
|
||||
for (const user of users) {
|
||||
await reconcileAppGrant(String(user._id));
|
||||
// Private repository names must not outlive the grant; a live grant
|
||||
// simply resyncs on the next picker load.
|
||||
await clearRepositoryList(String(user._id), "github-app");
|
||||
}
|
||||
}
|
||||
if (["installation", "installation_repositories"].includes(String(event)) && Number.isSafeInteger(body.installation?.id) && String(body.installation.app_id) === config.GITHUB_APP_ID) {
|
||||
const installation = body.installation as AppInstallation;
|
||||
@@ -345,6 +345,12 @@ githubAppWebhook.post("/", express.raw({ type: "application/json", limit: "2mb"
|
||||
phase = "reconcile_installation";
|
||||
if (body.action !== "deleted") await reconcileInstallation(installation.id, revision);
|
||||
}
|
||||
if (["installation", "installation_repositories", "repository"].includes(String(event))) {
|
||||
// After the installation block: a failed picker write must never leave a
|
||||
// deleted or suspended installation usable. The lists also resync by age.
|
||||
phase = "update_repository_lists";
|
||||
await applyRepositoryWebhook(String(event), body);
|
||||
}
|
||||
return res.status(204).end();
|
||||
} catch (error) {
|
||||
const delivery = req.headers["x-github-delivery"];
|
||||
|
||||
Reference in new issue
Block a user