Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Security and behavior changes

- Honor public read access for authorized non-collaborator PR events only when explicitly assigned to a consenting repository admin. Private repositories, manual commands, tenant identity checks and separate merge authorization are unchanged.

- Respect the provider's earliest refresh timestamp before runtime token renewal. Bound the credential wait and workflow lifetime, preserve exclusive leases/CAS and persist rotation before inference; classify premature/unavailable refresh windows without raw credential diagnostics.

- Accept GitHub's documented immutable default OIDC subjects for new/renamed repositories, exactly binding owner ID, repository ID and Environment while retaining the legacy subject and all signed identity/workflow checks.
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Without an explicit assignment, automatic PR events use the authorized event act

The owner/administrator connects their own credential for this repository with `--allow-automatic-reviews`. The authenticated provisioning endpoint records only that administrator's explicit consent in migration 0006, after checking the protected default branch, default-branch-only Environment and named credential metadata. Trusted configuration separately opts in with `credentials.automatic_reviewer: OWNER_LOGIN` and `review.auto_review: true`. Configuration alone cannot authorize borrowing. Both ChatGPT and API-key modes remain explicit and independent.

The incoming PR-event actor still needs review authorization under `authorization`; use an appropriate whitelist, including `"*"` only when all read-capable contributors are intentionally authorized. Verified GitHub Bot actors are supported only with this explicit assignment; manual bot commands remain denied. Responsible owner identity, original trigger identity and the consent generation are snapshotted separately. The owner must remain an administrator and pass the review policy; merging additionally requires the owner's separate merge policy and an admitted automatic merge intent. No human approval is fabricated: GitHub reviews use the App identity.
The incoming PR-event actor still needs review authorization under `authorization`; use an appropriate whitelist, including `"*"` only when all read-capable contributors are intentionally authorized. For public repositories, non-collaborators have public read access even when the collaborator API returns `none`; this applies only to assigned automatic reviews, never merge permission or private access. The explicit whitelist/blacklist and owner consent are still required. Verified GitHub Bot actors are supported only with this explicit assignment; manual bot commands remain denied. Responsible owner identity, original trigger identity and the consent generation are snapshotted separately. The owner must remain an administrator and pass the review policy; merging additionally requires the owner's separate merge policy and an admitted automatic merge intent. No human approval is fabricated: GitHub reviews use the App identity.

The protected runner Environment, encryption AAD, session lease and all user quotas bind to the consenting owner, installation and repository. Contributions cannot spread usage across actor IDs or select another user's Environment. Owner credentials are never returned to contributors or placed in the model container. Manual commands always use the command author's own connection, even when unattended assignment is enabled.

Expand Down
2 changes: 2 additions & 0 deletions src/worker/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export async function ingest(event: string, payload: unknown, requestId: string,
if (!config.review.enabled || (!manual && !config.review.auto_review)) return 'disabled';
requireCondition(sender.type === 'User' || Boolean(config.credentials.automatic_reviewer), 'human_sender_required', 403);
let livePermission = await permission(github, fullName, sender.login, Number(sender.id), sender.type as 'User' | 'Bot');
// Public non-collaborators can read the repository even when the collaborator API returns none.
if (livePermission==='none' && automatic && config.credentials.automatic_reviewer && liveRepo.private===false) livePermission='read';
requireCondition(authorize(sender.login, livePermission, config.authorization), 'review_not_authorized', 403);
let actor=sender.login,actorId=Number(sender.id),automaticGrantId:string|undefined;
if (automatic && config.credentials.automatic_reviewer) {
Expand Down
4 changes: 2 additions & 2 deletions tests/github-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { stringify } from 'yaml';
import { snapshot, HEAD, BASE, WORKFLOW, files } from './fixtures.js';
export function githubFixture() {
const config = snapshot().config;
const state = { head: HEAD, base: BASE, permission: 'write', permissionAfterReview: null as string | null, userId: 5, author: 'alice', mergeState: 'CLEAN',
const state = { privateRepository:false, head: HEAD, base: BASE, permission: 'write', permissionAfterReview: null as string | null, userId: 5, author: 'alice', mergeState: 'CLEAN',
reviewDecision: 'APPROVED', autoMergeAllowed: true, reviews: [] as Record<string, unknown>[], installationId: 1, suspended: false, merged: false,
ci: 'SUCCESS', guarded: false, requiredHumans: 1, rules: [] as Record<string, unknown>[], autoMergeOwner: null as string | null,
humans: [{ id: 80, state: 'APPROVED', commit_id: HEAD, user: { id: 6, login: 'bob', type: 'User' } }] as Record<string, unknown>[],
Expand All @@ -17,7 +17,7 @@ export function githubFixture() {
const body = typeof init?.body === 'string' ? JSON.parse(init.body) as Record<string, unknown> : {};
calls.push({ method, path, body });
const ok = (value: unknown, status = 200) => Response.json(value, { status, headers: { 'Content-Type': 'application/json' } });
const repo = { id: 2, full_name: 'owner/repo', owner: { id: 3, login: 'owner' }, name: 'repo', default_branch: 'main', permissions: { admin: true } };
const repo = { private:state.privateRepository, id: 2, full_name: 'owner/repo', owner: { id: 3, login: 'owner' }, name: 'repo', default_branch: 'main', permissions: { admin: true } };
if (path === '/repos/owner/repo/installation') return ok({ id: state.installationId, suspended_at: state.suspended ? 'now' : null, permissions: { workflows: 'write' } });
if (path === '/app/installations/1/access_tokens') return ok({ token: 'fixture-installation-token', expires_at: new Date(Date.now() + 3600_000).toISOString() }, 201);
if (path === '/repos/owner/repo') return ok(repo);
Expand Down
6 changes: 4 additions & 2 deletions tests/worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,14 @@ await test('unconnected authorized contributor uses only an explicitly consentin
}));

await test('unconnected automation contributor requires explicit owner assignment and cannot use it for manual commands', async () => fixture(async (env,f) => {
f.config.credentials={mode:'api-key',automatic_reviewer:'alice'};f.config.authorization.whitelist='*';f.config.review.auto_review=true;f.state.permissionsByLogin={alice:'admin','github-actions[bot]':'read'};
f.config.credentials={mode:'api-key',automatic_reviewer:'alice'};f.config.authorization.whitelist='*';f.config.review.auto_review=true;f.state.permissionsByLogin={alice:'admin','github-actions[bot]':'none'};
const store=new Store(env.DB);
const event={action:'opened',installation:{id:1},repository:{id:2,full_name:'owner/repo'},sender:{id:41898282,login:'github-actions[bot]',type:'Bot'},number:4,pull_request:{updated_at:new Date().toISOString(),head:{sha:HEAD}}};
const send=async()=>{const request=signed(event,env.GITHUB_WEBHOOK_SECRET);request.headers.set('x-github-event','pull_request');return worker.fetch(request,env);};
f.state.privateRepository=true;assert.equal((await send()).status,403);
f.state.privateRepository=false;event.action='reopened';
assert.equal((await send()).status,200);assert.equal(f.calls.filter(call=>call.path.endsWith('/dispatches')).length,0);
await store.automaticConsent(2,1,5,'alice','api-key');event.action='reopened';
await store.automaticConsent(2,1,5,'alice','api-key');event.action='ready_for_review';
assert.equal((await send()).status,202);
const row=await env.DB.prepare('SELECT snapshot FROM requests').first<{snapshot:string}>();const request=JSON.parse(row!.snapshot);
assert.equal(request.actorId,5);assert.deepEqual(request.triggerActor,{login:'github-actions[bot]',id:41898282,type:'Bot'});
Expand Down