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
6 changes: 6 additions & 0 deletions .dev.vars.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
GITHUB_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nSET_WITH_WRANGLER_SECRET\n-----END PRIVATE KEY-----"
GITHUB_WEBHOOK_SECRET="replace-with-at-least-32-random-bytes"
# Browser onboarding is opt-in. Configure public client IDs/scopes in Wrangler.
# Generate a separate 32-byte base64url key locally; never reuse the webhook secret.
WEB_SESSION_KEY="set-only-for-disposable-local-tests-or-with-wrangler-secret"
GITHUB_CLIENT_SECRET="registered-github-app-website-client-secret"
# Only for an approved confidential OpenAI website client:
# OPENAI_WEB_CLIENT_SECRET="registered-client-secret"
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
run: npm run test:clean
- run: npm run check
- run: npm run test:workers
- name: Verify pinned Codex catalog without inference
run: npm run catalog:check
- name: Install pinned browser for local web acceptance
run: node node_modules/playwright/cli.js install --with-deps chromium
- name: Browser onboarding against local workerd and D1 (synthetic providers)
run: npm run test:web
- run: docker build --tag codexbot-review:local .
- run: npm run test:sandbox
- name: Verify pinned Trivy and reject vulnerable runtime images
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased — security remediation pass

- Add bounded immutable file-index/context-socket exploration, simple Python/Rust dependencies, unchanged-caller fixtures and concise evidence-driven review guidance. Keep the reviewer read-only, network-disabled and credential-free; drain/cancel lookups and revoke the read token during cleanup. Improve native review summaries without changing verdict policy or publication fingerprints.
- Implement GitHub website PKCE authentication, encrypted one-use state and sessions, CSRF/Origin checks, live installation/admin reconciliation and a responsive browser repository/account dashboard. Add additive migration 0004; existing CLI envelopes are preserved.
- Add exact-base setup/configuration update PRs, protected Environments and encrypted Environment-secret provisioning. Hosted ChatGPT OAuth accepts only the actual registered client/auth method/scopes and signed workspace identity. Missing registration values keep activation disabled. API-key billing remains separate.
- Add encrypted pending provisioning recovery, stable provisioning IDs, atomic owner-checked operation heartbeats and session-lease interlocks. Hosted refresh remains behind strict OIDC/run/tenant validation and version CAS; ambiguous refresh requires reconnect. No production credentials or existing sessions are changed by these source changes.
- Generate dashboard model/effort choices from the exact pinned native catalog, including advertised ultra effort; retain explicit command/config/default precedence. Add real workerd/D1 browser acceptance with synthetic providers, libsodium interoperability and concurrency/fault regressions.
- Disable automatic Cloudflare URL traces with explicit operator approval for OAuth privacy; retain safe structured logs. Add post-merge paired pin-PR preparation without guessed SHAs, automatic merge or deployment. See docs/web-onboarding.md for registration, migration and activation gates.

- Fix unattended Codex inspection with `approvalPolicy: never` under unchanged external Docker isolation. Keep client approval/tool grants denied and fail on denied/missing inspection, incomplete context, inconclusive/quarantined/truncated analysis or invalid review locations. Preserve safe separate COMMENT publication. Add per-review `--model` with model-specific effort validation and existing quota/idempotency binding. No schema, credential or permission migration; coordinate runner/Worker/caller pins.

- Classify rejected Responses replies with their actual upstream status (including 2xx), fixed Content-Type category and body presence. Extract only allowlisted codes/parameters from bounded JSON errors; keep non-SSE success responses fail-closed and provider metadata confined to the credential-proxy boundary.
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

An Apache-2.0 GitHub App for Codex pull request reviews on repository-owned GitHub Actions runners. The Cloudflare Worker authenticates requests and publishes native reviews; it never runs Codex.

Hosted backend: **[https://codexbot.appsolves.workers.dev](https://codexbot.appsolves.workers.dev/)**. This is the CLI and generated-workflow default. The hostname migration is staged; production availability and credential acceptance must be verified during the [operator cutover](docs/origin-migration.md). Independent installations pass their own HTTPS origin with `--backend`.
Hosted backend: **[https://codexbot.appsolves.workers.dev](https://codexbot.appsolves.workers.dev/)**. This is the canonical website, CLI and generated-workflow origin. Independent installations pass their own HTTPS origin with `--backend`.

```text
@CBReview review --effort xhigh --merge
Expand All @@ -18,13 +18,13 @@ Set `bot.trigger: "@CBReview"` to use the example above. The legacy default `@co

## Status

**Pre-release; full production review acceptance remains pending.** Unit/integration tests exercise signed webhooks, official OAuth contracts, OIDC, actual SQLite persistence, setup PR creation and GitHub publishing against mocked external APIs. The pinned official Codex binary is tested without credentials. A separate Docker check uses synthetic inference; it does not claim to have performed a real AI review. See [validation and live acceptance](docs/validation.md).
**Pre-release.** The existing production review pipeline is operational; this change preserves it. The browser onboarding and management flow is implemented and tested locally against real workerd/D1 with synthetic GitHub/OpenAI providers. It remains disabled until the operator provisions the actual approved website OAuth client, callbacks, inference scopes and workspace claim, then completes staged acceptance. No production deployment follows from a PR or local test.

Live GitHub installation, real OpenAI inference/allowance, OAuth eligibility and Cloudflare production resource usage require operator credentials and acceptance testing. Do not market this as battle-tested or deploy with automatic merge before completing those checks.
See [web onboarding, credentials and activation](docs/web-onboarding.md) for the explicit hosted credential trust boundary and remaining live gates. AI reviews can miss defects; keep independent human review and CI. Automatic merging remains disabled.

## What is implemented

- Public GitHub App installation/onboarding page, signed webhook intake, installation suspension/deletion handling and replay protection.
- Browser GitHub PKCE sign-in, installation reconciliation, responsive repository dashboard, reviewed setup/configuration PRs and approved-client hosted ChatGPT OAuth with encrypted Environment provisioning; signed webhook intake, installation suspension/deletion handling and replay protection.
- Configurable handle and command parser, default-deny whitelist/blacklist policy, RE2 matching, live GitHub identity/permission checks, separate merge policy.
- ChatGPT OSS OAuth with PKCE, state, nonce, issued-client/account validation, encrypted session provisioning, persistent host IDs, serialized refresh and token rotation/revocation.
- Independent personal API-key mode; no billing fallback between modes.
Expand All @@ -33,7 +33,11 @@ Live GitHub installation, real OpenAI inference/allowance, OAuth eligibility and
- Separate publishing job, native inline reviews, exact-commit checks, conservative approvals, and explicitly requested native exact-head merge; pending CI is held behind an App-bound required check and durable intent.
- App-authored setup PR when Workflows permission is granted; a temporary user-credential setup alternative and manual installation.

## Quick start
## Browser setup

When the operator has activated web onboarding, open the [website](https://codexbot.appsolves.workers.dev/), sign in with GitHub, install/select repositories through GitHub, choose a repository you administer, create its setup PR and connect ChatGPT or your own API key. Review and merge the PR; refresh to verify readiness. Settings propose further PRs, never silent default-branch commits. Normal onboarding requires no terminal. Public repositories support protected Environments on GitHub Free; private repositories require suitable Pro/Team/Enterprise support. Existing CLI connections remain compatible and need an explicit disconnect before switching management mode.

## CLI and self-hosted setup

Requirements: Node 24+, GitHub CLI (`gh auth login`), a GitHub App/Worker deployment, a protected default branch, and GitHub-hosted Ubuntu runners with Docker. The onboarding CLI currently requires repository administrator access to create/protect credential Environments. Windows/macOS can run onboarding; production review orchestration runs on Linux.

Expand Down
2 changes: 2 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Include the affected immutable release, boundary violated, a minimal fixture-bas
If a credential is exposed: stop workflow dispatch, revoke the credential with its provider, suspend the affected installation if needed, rotate App/webhook keys or Environment secrets as appropriate, and inspect authorized metadata privately. Removing a log or git commit does not revoke credentials or erase previous disclosure.

Recovery and release gates: [operations](docs/operations.md), [acceptance](docs/acceptance.md), [finding evidence](docs/remediation.md). The deterministic local output scanner reduces leakage risk but cannot detect all secrets or encodings. A clean AI verdict is not a security guarantee; independent human reviews and CI remain required. Disable/cancel App-owned auto-merge in GitHub during an incident; stopping the Worker alone does not cancel a previously enabled native intent.

Browser-managed OAuth introduces an explicit trusted Worker decryption boundary; CLI vaults retain their existing isolation. See [hosted security and key management](docs/web-onboarding.md). Report website/session/CSRF/provisioning issues privately. Include only fixed error codes and synthetic reproductions; never submit callback URLs, browser cookies, exported D1 credentials or raw traces.
7 changes: 5 additions & 2 deletions app-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"url": "https://codexbot.appsolves.workers.dev",
"hook_attributes": { "url": "https://codexbot.appsolves.workers.dev/webhook", "active": true },
"redirect_url": "https://codexbot.appsolves.workers.dev/",
"setup_url": "https://codexbot.appsolves.workers.dev/",
"setup_url": "https://codexbot.appsolves.workers.dev/dashboard",
"callback_urls": ["https://codexbot.appsolves.workers.dev/auth/github/callback"],
"public": true,
"default_permissions": { "metadata": "read", "contents": "write", "pull_requests": "write", "actions": "write" },
"request_oauth_on_install": false,
"setup_on_update": true,
"default_permissions": { "metadata": "read", "contents": "write", "pull_requests": "write", "actions": "write", "workflows": "write", "administration": "write", "environments": "write" },
"default_events": ["issue_comment", "pull_request"]
}
25 changes: 25 additions & 0 deletions docs/adaptive-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Bounded context exploration and review presentation

The existing immutable collection and isolated Codex execution remain in place. Changed base/head files and trusted default-branch instructions are still required evidence. Direct JS/TS dependencies, simple Python relative imports and Rust sibling modules are resolved without executing project code. Python/Go/Java test naming heuristics supplement the existing nearby tests/manifests.

The collector writes `/workspace/file-index.json`: at most 12 nonrecursive directory walks and 5,000 regular-file paths. A partial supplementary index does not invalidate a small PR. It does not imply exhaustive semantic coverage. No full recursive tree or unrelated blob download is required.

A separate trusted host Unix socket at `/run/proxy/context.sock` accepts only POST `/file` JSON with `snapshot: base|head` and a relative `path`. Successful retrieval materializes a verified file under the existing read-only reviewer mount. Paths, immutable commit/tree/blob identity, object modes, UTF-8, size and Git blob SHA are validated by the same collector. It cannot request another repository/ref, fetch URLs, follow symlinks or execute commands. There are at most 24 lookups, sharing the existing 100-call/3-MB-source/200-KB-file limits and SHA cache. Missing explicitly requested evidence makes the result incomplete and fails the review job. Optional omissions that were never needed do not.

The GitHub read token remains on the trusted host through bounded exploration, rather than being revoked before inference. It is never mounted into the reviewer or credential proxy. On completion/failure, the host aborts/drains outstanding lookups, closes the context service, revokes the token and removes temporary source. Token cleanup failure fails the review job; it does not authorize approval. The separate publisher still uses the job conclusion and exact commit to decide whether a safe COMMENT is appropriate.

The concise permanent prompt asks Codex to understand changed behavior and trace important unchanged callers, data flows, tests, security and compatibility. Trusted project guidance cannot override safety/output rules; task-specific comment context only steers attention. Untrusted repository instructions cannot change credentials, authorize publication/merge or grant tools. Existing client-side approval requests stay denied and Docker stays network=none, nonroot, read-only, capability-free and credential-free.

Human-readable summaries distinguish clean completion, advisory findings, changes requested and incomplete evidence. They omit routine “merge not requested”/mechanical decision noise. Actual native APPROVE/COMMENT/REQUEST_CHANGES decisions, confidence policy, DLP, changed-line validation, publication fingerprints and merge restrictions remain independent of that wording.

Validation: immutable lookup/path/type/budget tests, small PR in a 1,200-file repository, native Codex/Docker reads of exact diff/base/head/trusted instructions/unchanged caller/hostile-text hashes, denied writes/network/credentials and full severity/confidence/completeness summary checks. Scripted Responses exercise real tools and sandbox behavior, not real AI recognition or prompt-quality improvement. Live old/revised-prompt comparison on identical clean/buggy/security/cross-file fixtures requires separate owner authorization; no paid or ChatGPT inference is part of CI.

Runner changes require coordinated Worker/caller pins to the actual merged source revision. Never guess a merge SHA or use a branch/tag. Keep production merge disabled.

## Prompt evaluation fixtures (opt-in live, no default inference)

`tests/review-evaluation-fixtures.mjs` defines clean authorization, introduced arithmetic defect, introduced authorization bypass and a changed cents conversion with an unchanged checkout caller. Fixtures include untrusted instruction text. Offline checks validate diffs/expected changed locations and distinguish clean/findings/incomplete outcomes; they do not score an LLM's semantic quality.

The existing guarded provider acceptance supports `--case clean|buggy|security|multi-file`, `--label baseline|revised` and optional `--report-file` in an owner-protected local directory. It records only completeness, finding count, expected-line match, label/model/effort and the resolved immutable local image ID. It never stores raw model text or credentials. Failure still exits nonzero. Build the baseline and revised images from their reviewed source revisions; hold Codex version/model/effort/fixture constant and compare all four cases. Use the credential-file, deployment authorization, explicit `--allow-live-oauth` or `--allow-paid-api` and 1–3 request budget controls already documented in acceptance.md. API output remains capped. Browser-managed sessions must instead use the authorized repository workflow; do not export them to a credential file.

No live A/B run has been authorized or executed in this engineering pass. Keep quality/entitlement conclusions pending until owner-authorized acceptance; local fixture scores and scripted Docker responses are not model-quality evidence.
Loading