-
Notifications
You must be signed in to change notification settings - Fork 38
fix(github): Deny pull request approvals at egress #1500
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8a255d7
fix(github): Deny pull request approvals at egress
sentry-junior[bot] 8bad228
refactor(github): Simplify approval egress policy
sentry-junior[bot] 04ae95d
fix(github): Fail closed on non-JSON review creates
sentry-junior[bot] e5e7633
fix(github): Inspect review bodies on plugin egress
sentry-junior[bot] 0ecf448
merge(main): Integrate owned PR update routing
sentry-junior[bot] 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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * Deterministic pull request review policy enforced before credential grant. | ||
| */ | ||
| import { EgressPolicyDenied } from "@sentry/junior-plugin-api"; | ||
| import { isRecord } from "./credential-support.js"; | ||
|
|
||
| /** Deny APPROVE while allowing change requests, comments, and dismissals. */ | ||
| export function assertGitHubPullRequestApprovalDenied(input: { | ||
| bodyText?: string; | ||
| method: string; | ||
| upstreamUrl: URL; | ||
| }): void { | ||
| if ( | ||
| input.method !== "POST" || | ||
| input.upstreamUrl.hostname.toLowerCase() !== "api.github.com" | ||
| ) { | ||
| return; | ||
| } | ||
| const match = input.upstreamUrl.pathname | ||
| .toLowerCase() | ||
| .match( | ||
| /^\/repos\/[^/]+\/[^/]+\/pulls\/[^/]+\/reviews(?:\/[^/]+\/(events))?$/, | ||
| ); | ||
| if (!match) return; | ||
|
|
||
| const isEventsPath = match[1] === "events"; | ||
| const bodyText = input.bodyText?.trim() ?? ""; | ||
| // Empty create body is a pending review. The events path always needs a body. | ||
| if (!bodyText) { | ||
| if (isEventsPath) { | ||
| throw new EgressPolicyDenied( | ||
| "GitHub pull request review submissions must include a parseable non-APPROVE event so Junior can enforce the no-approve policy.", | ||
| ); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| let body: unknown; | ||
| try { | ||
| body = JSON.parse(bodyText); | ||
| } catch { | ||
| throw new EgressPolicyDenied( | ||
| "GitHub pull request review requests must use JSON bodies so Junior can enforce the no-approve policy.", | ||
| ); | ||
| } | ||
| if (!isRecord(body)) { | ||
| throw new EgressPolicyDenied( | ||
| "GitHub pull request review requests must use JSON object bodies so Junior can enforce the no-approve policy.", | ||
| ); | ||
| } | ||
|
|
||
| let event: string | undefined; | ||
| if ("event" in body) { | ||
| if (typeof body.event !== "string" || body.event.trim().length === 0) { | ||
| throw new EgressPolicyDenied( | ||
| "GitHub pull request review submissions must include a parseable non-APPROVE event so Junior can enforce the no-approve policy.", | ||
| ); | ||
| } | ||
| event = body.event.trim().toUpperCase(); | ||
| } | ||
| if (event === "APPROVE") { | ||
| throw new EgressPolicyDenied( | ||
| "Junior cannot approve GitHub pull requests. Request changes, leave a comment review, or dismiss Junior's own review instead.", | ||
| ); | ||
| } | ||
| if (isEventsPath && event === undefined) { | ||
| throw new EgressPolicyDenied( | ||
| "GitHub pull request review submissions must include a parseable non-APPROVE event so Junior can enforce the no-approve policy.", | ||
| ); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.