-
Notifications
You must be signed in to change notification settings - Fork 21
Fix project permission bypass #3915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
BunsDev
wants to merge
3
commits into
main
from
codex/fix-unauthenticated-project-grant-vulnerability
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,10 @@ | ||
| import { NextResponse } from "next/server"; | ||
|
|
||
| import { | ||
| ProjectAccessDeniedError, | ||
| resolveGrantProposal, | ||
| } from "@/lib/project-permissions"; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
|
|
||
| function rejectRelayedApproval(payload: Record<string, unknown>): Response | null { | ||
| if ( | ||
| payload.familiarId != null || | ||
| payload.proposedBy != null || | ||
| payload.claimedHumanApproval === true | ||
| ) { | ||
| return NextResponse.json( | ||
| { ok: false, error: "proposal decisions must be confirmed directly by the human" }, | ||
| { status: 403 }, | ||
| ); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| export async function PATCH( | ||
| req: Request, | ||
| { params: rawParams }: { params: Promise<{ id: string }> }, | ||
| ) { | ||
| const params = await rawParams; | ||
| let payload: Record<string, unknown>; | ||
| try { | ||
| payload = (await req.json()) as Record<string, unknown>; | ||
| } catch { | ||
| return NextResponse.json({ ok: false, error: "invalid JSON body" }, { status: 400 }); | ||
| } | ||
| const rejected = rejectRelayedApproval(payload); | ||
| if (rejected) return rejected; | ||
| const decision = payload.decision === "accepted" || payload.decision === "rejected" | ||
| ? payload.decision | ||
| : null; | ||
| if (!decision) { | ||
| return NextResponse.json( | ||
| { ok: false, error: "decision must be accepted or rejected" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
| try { | ||
| const proposal = await resolveGrantProposal({ | ||
| proposalId: params.id, | ||
| decision, | ||
| }); | ||
| return NextResponse.json({ ok: true, proposal }); | ||
| } catch (error) { | ||
| if (error instanceof ProjectAccessDeniedError) { | ||
| return NextResponse.json({ ok: false, error: error.message }, { status: error.status }); | ||
| } | ||
| throw error; | ||
| } | ||
| export async function PATCH() { | ||
| return NextResponse.json( | ||
| { ok: false, error: "proposal decisions require an authenticated human approval flow" }, | ||
| { status: 403 }, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,20 @@ | ||
| import { NextResponse } from "next/server"; | ||
|
|
||
| import { | ||
| ProjectAccessDeniedError, | ||
| createGrantProposal, | ||
| listGrantProposals, | ||
| } from "@/lib/project-permissions"; | ||
| import { listGrantProposals } from "@/lib/project-permissions"; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
|
|
||
| function proposalMutationDenied() { | ||
| return NextResponse.json( | ||
| { ok: false, error: "grant proposals require an authenticated Supreme approval flow" }, | ||
| { status: 403 }, | ||
| ); | ||
| } | ||
|
|
||
| export async function GET() { | ||
| return NextResponse.json({ ok: true, proposals: await listGrantProposals() }); | ||
| } | ||
|
|
||
| export async function POST(req: Request) { | ||
| let payload: Record<string, unknown>; | ||
| try { | ||
| payload = (await req.json()) as Record<string, unknown>; | ||
| } catch { | ||
| return NextResponse.json({ ok: false, error: "invalid JSON body" }, { status: 400 }); | ||
| } | ||
| const proposedBy = typeof payload.proposedBy === "string" ? payload.proposedBy.trim() : ""; | ||
| const targetFamiliarId = typeof payload.targetFamiliarId === "string" | ||
| ? payload.targetFamiliarId.trim() | ||
| : ""; | ||
| const projectId = typeof payload.projectId === "string" ? payload.projectId.trim() : ""; | ||
| if (!proposedBy || !targetFamiliarId || !projectId) { | ||
| return NextResponse.json( | ||
| { ok: false, error: "proposedBy, targetFamiliarId, and projectId are required" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
| try { | ||
| const proposal = await createGrantProposal({ | ||
| proposedBy: proposedBy, | ||
| targetFamiliarId: targetFamiliarId, | ||
| projectId: projectId, | ||
| claimedHumanApproval: payload.claimedHumanApproval === true, | ||
| }); | ||
| return NextResponse.json({ ok: true, proposal }, { status: 201 }); | ||
| } catch (error) { | ||
| if (error instanceof ProjectAccessDeniedError) { | ||
| return NextResponse.json({ ok: false, error: error.message }, { status: error.status }); | ||
| } | ||
| throw error; | ||
| } | ||
| export async function POST() { | ||
| return proposalMutationDenied(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,76 +1,24 @@ | ||
| import { NextResponse } from "next/server"; | ||
|
|
||
| import { | ||
| grantProjectToFamiliar, | ||
| listProjectGrants, | ||
| revokeProjectFromFamiliar, | ||
| } from "@/lib/project-permissions"; | ||
| import { listProjectGrants } from "@/lib/project-permissions"; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
|
|
||
| function rejectRelayedApproval(payload: Record<string, unknown>): Response | null { | ||
| if ( | ||
| payload.familiarId != null || | ||
| payload.proposedBy != null || | ||
| payload.claimedHumanApproval === true | ||
| ) { | ||
| return NextResponse.json( | ||
| { ok: false, error: "grant changes must be confirmed directly by the human" }, | ||
| { status: 403 }, | ||
| ); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| async function readPayload(req: Request): Promise<Record<string, unknown> | Response> { | ||
| try { | ||
| return (await req.json()) as Record<string, unknown>; | ||
| } catch { | ||
| return NextResponse.json({ ok: false, error: "invalid JSON body" }, { status: 400 }); | ||
| } | ||
| } | ||
|
|
||
| function grantInput(payload: Record<string, unknown>) { | ||
| const targetFamiliarId = typeof payload.targetFamiliarId === "string" | ||
| ? payload.targetFamiliarId.trim() | ||
| : ""; | ||
| const projectId = typeof payload.projectId === "string" ? payload.projectId.trim() : ""; | ||
| if (!targetFamiliarId || !projectId) return null; | ||
| return { familiarId: targetFamiliarId, projectId }; | ||
| function directGrantMutationDenied() { | ||
| return NextResponse.json( | ||
| { ok: false, error: "project grant changes require an authenticated human approval flow" }, | ||
| { status: 403 }, | ||
| ); | ||
| } | ||
|
|
||
| export async function GET() { | ||
| return NextResponse.json({ ok: true, grants: await listProjectGrants() }); | ||
| } | ||
|
BunsDev marked this conversation as resolved.
|
||
|
|
||
| export async function POST(req: Request) { | ||
| const payload = await readPayload(req); | ||
| if (payload instanceof Response) return payload; | ||
| const rejected = rejectRelayedApproval(payload); | ||
| if (rejected) return rejected; | ||
| const input = grantInput(payload); | ||
| if (!input) { | ||
| return NextResponse.json( | ||
| { ok: false, error: "targetFamiliarId and projectId are required" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
| await grantProjectToFamiliar({ ...input, source: "human" }); | ||
| return NextResponse.json({ ok: true }); | ||
| export async function POST() { | ||
| return directGrantMutationDenied(); | ||
| } | ||
|
|
||
| export async function DELETE(req: Request) { | ||
| const payload = await readPayload(req); | ||
| if (payload instanceof Response) return payload; | ||
| const rejected = rejectRelayedApproval(payload); | ||
| if (rejected) return rejected; | ||
| const input = grantInput(payload); | ||
| if (!input) { | ||
| return NextResponse.json( | ||
| { ok: false, error: "targetFamiliarId and projectId are required" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
| const revoked = await revokeProjectFromFamiliar(input); | ||
| return NextResponse.json({ ok: true, revoked }); | ||
| export async function DELETE() { | ||
| return directGrantMutationDenied(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.