Skip to content

Commit 353c366

Browse files
Ben ThomasCopilot
authored andcommitted
fix(hub): reject expanded installation permissions
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent da5c4fa commit 353c366

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎hub/server/integrations/github/create-installation-access-token/index.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,34 @@ describe("createInstallationAccessToken()", () => {
223223
await expect(mintToken()).rejects.toMatchObject({ code: "permission_denied" })
224224
})
225225

226+
it("rejects a token that includes any additional permission", async () => {
227+
const mintToken = createInstallationAccessToken({
228+
appId: "123",
229+
installationId: "456",
230+
organization: "github",
231+
signer: { sign: vi.fn().mockResolvedValue("app-jwt") },
232+
fetch: vi
233+
.fn<typeof fetch>()
234+
.mockResolvedValueOnce(successfulInstallationResponse())
235+
.mockResolvedValueOnce(
236+
new Response(
237+
JSON.stringify({
238+
expires_at: "2026-11-12T19:00:00.000Z",
239+
permissions: {
240+
contents: "write",
241+
organization_copilot_requests: "read",
242+
},
243+
token: "overprivileged-token",
244+
}),
245+
{ status: 201, headers: { "content-type": "application/json" } },
246+
),
247+
),
248+
now: () => now,
249+
})
250+
251+
await expect(mintToken()).rejects.toMatchObject({ code: "permission_denied" })
252+
})
253+
226254
it.each(["installation", "token"] as const)(
227255
"classifies an unreadable %s response as transient unavailability",
228256
async (responseType) => {

‎hub/server/integrations/github/create-installation-access-token/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const responseSchema = z
1010
.object({
1111
organization_copilot_requests: z.literal("read"),
1212
})
13-
.loose(),
13+
.strict(),
1414
token: z.string().min(1).max(2_000),
1515
})
1616
.loose()

0 commit comments

Comments
 (0)