fix(api): require real GitHub write access for BYOK key writes (closes #674) - #682
Conversation
…#674) The secret-bearing BYOK key writes (POST/DELETE /v1/repos/:owner/:repo/ai-key) were gated only by the maintainer scope, which admits a caller who authored a PR with author_association OWNER/MEMBER/COLLABORATOR — i.e. an org MEMBER (mere org membership) or a read-only COLLABORATOR could set/replace/delete a repo's provider key. Add requireRepoKeyWriteAccess: on top of the maintainer gate, a session caller must have real GitHub write access (admin/maintain/write) to the repo, resolved via the installation (getRepositoryCollaboratorPermission) rather than inferred from a PR association. Operators and server-to-server tokens are exempt; it fails closed (403 insufficient_repo_permission) when write access can't be verified. The non-secret ai-review config (PUT /ai-review) and the read-only GET /ai-key status keep the existing maintainer gate. This is the deferred follow-up from the BYOK security audit — done now via real push-permission resolution so it does not lock out legitimate org maintainers (who surface no OWNER author_association on org repos). Tests: admin → 200; read-only collaborator (in scope via a PR) → 403; operator bypasses the push check; no-installation → 403; GET status still readable. Closes #674. Part of #525.
|
Note Gittensory Gate skippedPR closed before full evaluation. No late first comment was created.
💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers. |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
gittensory · advisory review Reviewed 2 changed file(s) — two independent AI reviewers. Suggested action: ✅ Safe to merge — both reviewers found no blocking issues. Reviewer A · Suggestions
Worth double-checking
Reviewer B · Worth double-checking
|
The final BYOK security-audit follow-up — the one I deferred from #680, now done via real push-permission resolution.
Problem
The secret-bearing BYOK key writes (
POST/DELETE /v1/repos/:owner/:repo/ai-key) were gated only by the maintainer scope, which admits a caller who authored a PR withauthor_associationofOWNER/MEMBER/COLLABORATOR. So an org MEMBER (mere org membership, not repo write) or a read-only COLLABORATOR who opened a single PR could set/replace/delete a repo's provider key.Fix
New
requireRepoKeyWriteAccessgate on the key write routes: on top of the maintainer gate, a session caller must have real GitHub write access (admin/maintain/write) to the repo, resolved via the installation (getRepositoryCollaboratorPermission) rather than inferred from a PR association. Operators and server-to-server tokens are exempt. It fails closed (403 insufficient_repo_permission) when write access can't be verified.PUT /ai-review) and the read-onlyGET /ai-keystatus keep the existing maintainer gate.OWNERauthor-association, so a naive narrowing would have excluded them — the reason this was deferred from fix(ai-review): BYOK round 2 — key-lifecycle audit, budget separation, per-record salt #680).Tests
insufficient_repo_permission(POST + DELETE); GET status still readableVerification
typecheck✅ ·test:coverage✅ (97.01% branch, 1680 tests) ·test:workers✅ ·git diff --check✅Closes #674. Part of #525.