chore: Consistent policy checks in integration callbacks (#14221)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-10-22 07:27:12 -04:00
1 parent 45bf9e290c
commit cf578accf9
8 files changed
+79 -4

No files matched your search

+18 -1
View File
@@ -1,4 +1,4 @@
import { buildUser } from "@server/test/factories";
import { buildUser, buildViewer } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
import { SetupAction } from "./schema";
@@ -74,4 +74,21 @@ describe("#github.callback", () => {
);
expect(res.status).toEqual(400);
});
it.each([
["member", buildUser],
["viewer", buildViewer],
])("should not allow a %s to create an integration", async (_, build) => {
const user = await build();
const state = JSON.stringify({ teamId: user.teamId, nonce: "nonce" });
const res = await server.get(
`/api/github.callback?state=${encodeURIComponent(state)}&code=123&setup_action=${SetupAction.install}&installation_id=1`,
user,
{
redirect: "manual",
headers: { Cookie: "githubOAuthNonce=nonce" },
}
);
expect(res.status).toEqual(403);
});
});
+2
View File
@@ -9,6 +9,7 @@ import { transaction } from "@server/middlewares/transaction";
import validate from "@server/middlewares/validate";
import validateWebhook from "@server/middlewares/validateWebhook";
import { IntegrationAuthentication, Integration } from "@server/models";
import { authorize } from "@server/policies";
import type { APIContext } from "@server/types";
import { verifyOAuthStateNonce } from "@server/utils/oauth";
import { RequestHelper } from "@server/utils/RequestHelper";
@@ -61,6 +62,7 @@ router.get(
}
verifyOAuthStateNonce(ctx, GitHubOAuthNonceCookie, parsedState.nonce);
authorize(user, "createIntegration", user.team);
const client = await GitHub.authenticateAsUser(code!, state);
const installationsByUser = await client.requestAppInstallations();