MergeJudge security model
MergeJudge is a GitHub App + Action that triages pull requests. It needs write access to post reviews and (optionally) store learning data. This document explains what it can write, why, and how to constrain it.
Looking for how MergeJudge checks pull requests for security issues (secrets, unsafe execution, and the optional
review.security: truechecklist for injection, authorization, secrets/crypto, webhooks/SSRF and AI tools)? See Rubric packs: Security review mode.
Threat model (short)
| Trust boundary | Rule |
|---|---|
| PR title, body, paths, diffs | Untrusted. Wrapped in <untrusted_pr_data>; the model is told to ignore instructions inside. |
.mergejudge.yml, policy files, rubric config | Trusted, read from the base branch tip only (never the PR head). A PR cannot loosen its own rules. |
| LLM output | Validated (known paths, diff-hunk lines, evidence quotes). Can only raise risk, never lower it (one opt-in exception: lanes.code_auto). |
| Learning feedback | Only users with write access; bot actors ignored. Stored on a dedicated branch. |
What the App can write
With the recommended App permissions (pull_requests: write, contents: write, checks: write, issues: write, metadata: read):
| Write | Where | Why |
|---|---|---|
| Sticky summary + inline review comments | The PR under review | Product output |
Check run mergejudge/lane | The PR head SHA | CI signal |
| APPROVE / dismiss own approval | The PR (when approval config allows) | Optional bot approval |
| Resolve/unresolve own review threads | The PR | Clear stale findings (contents: write required by GitHub) |
| Append lessons JSONL | Only learning.branch (default mergejudge-learning) | Learning loop |
| Proposal file + branch | Only mergejudge/proposal-* | Suggested config edits (PR opened, never merged by MergeJudge) |
| Setup config file + branch (hosted panel only) | Only mergejudge/setup-config, one file (the config path, .mergejudge.yml by default) | Starter config from the panel's setup wizard, and "Edit settings" changes to an existing config (PR opened or the open setup PR updated, never merged). Only a user with write access to that repo on GitHub can start it (reading the file for "Edit settings" needs the same access). The wizard passes this branch to the same write guard as the learning branch; the edit code also refuses any other branch or file path before a request is made, and never takes a branch or path from the request. A leftover mergejudge/setup-config branch with no open PR is reset to a single new commit on the default branch (the guard's branch reset), never deleted. Edits change only the review mode, review.security, provider, protected paths, learning, the lanes.code_auto switch and line limits, and the approval choice of the file; the audit entry repo.setup_edit_pr lists which of those changed, not their values. |
MergeJudge never merges PRs itself. It never pushes to main / master / release*, and it refuses a learning.branch that equals the default branch or matches those names.
Code enforcement
All git/contents writes go through a single guard (core/writes.ts → createGuardedWriter in the open-source mergejudge-runner repository). Calls to repos.createOrUpdateFileContents / git.createRef / git.deleteRef outside that wrapper are rejected by a lint test there.
Recommended repository rulesets
Use these where your GitHub account supports repository rules (public repos, and some private ones). Replace APP_ID with your MergeJudge GitHub App id.
Learning branch (allow App writes; block humans / force-push / delete)
{
"name": "MergeJudge learning branch",
"target": "branch",
"enforcement": "active",
"bypass_actors": [
{ "actor_id": APP_ID, "actor_type": "Integration", "bypass_mode": "always" }
],
"conditions": {
"ref_name": { "include": ["refs/heads/mergejudge-learning"], "exclude": [] }
},
"rules": [
{ "type": "deletion" },
{ "type": "non_fast_forward" },
{ "type": "update", "parameters": { "update_allows_fetch_and_merge": false } }
]
}Default branch (no MergeJudge bypass)
Keep your normal default-branch ruleset without adding the MergeJudge app as a bypass actor. The Action already refuses writes to the default branch in code.
Free private repositories
GitHub returns HTTP 403 for rulesets/classic branch protection on free private repos (GitHub asks you to change the account type or make the repository public). Options:
- Move to an account type that supports them, or make the repo public, then apply the JSON above; or
- Rely on the in-code write guard (always on) and restrict who has repo write access.
Untrusted content & config
- Diffs/titles/bodies are sanitized and delimiter-spoof-resistant before they reach the LLM.
- Policy files are injected in a separate trusted
<repo_policy>block and cannot make a file safer than the rules. - Config and policy paths are fetched with
ref = base branch name(current tip), falling back to the base SHA only on fetch error — never from the PR head.
Model key policy (Worker)
On the hosted service there are three AI paths:
- Your own key (BYOK) from the panel, used for that installation's reviews.
- Free AI reviews, only for public repositories with no BYOK key and no runner, when free AI is enabled and within the monthly limits. The AI step uses the Cloudflare Workers AI binding on our Worker (
diffmode only). Private repositories never use this path. - Runner: the AI step runs on your machine; our Worker still reads the PR for rules (and may pass a job payload, except in deep-local mode).
MergeJudge's own Anthropic, OpenAI or similar provider API keys are not used for other users' reviews. The free path uses the Workers AI binding, not those provider keys.
The rules below apply to any model API key held by a Worker (BYOK and Worker secrets), and stop a repo config from steering those keys anywhere else. They do not describe the free Workers AI binding (that path has no user api_key_env).
A repo's .mergejudge.yml chooses provider.type, base_url and api_key_env, so the config is treated as untrusted when picking a key. The Worker applies these rules:
Allowlist. Only the Worker secrets named in
WORKER_MODEL_KEYScan ever be model keys:ANTHROPIC_API_KEY,OPENAI_API_KEY,GLM_API_KEY,ZAI_API_KEY,OPENROUTER_API_KEY. No other env value (SESSION_SECRET,MASTER_KEY,GITHUB_APP_PRIVATE_KEY,GITHUB_WEBHOOK_SECRET,GITHUB_OAUTH_CLIENT_SECRET, ...) is passed to provider code at all.Pinned hosts. Each allowed secret is only sent to its provider's official host, over
httpson the default port, matched on the exact hostname:Worker secret Allowed host ANTHROPIC_API_KEYapi.anthropic.comOPENAI_API_KEYapi.openai.comGLM_API_KEY,ZAI_API_KEYapi.z.ai(paygo/api/paas/v4and coding/api/coding/paas/v4)OPENROUTER_API_KEYopenrouter.aiThe host is taken from the endpoint the provider will actually call (
provider.base_url, else the type's default). If it points anywhere else, Worker secrets are not used.Custom endpoints use BYOK only. For
openai-compatibleor any custombase_url, only the installation's own key stored in D1 (provider_keys, AES-GCM withMASTER_KEY) can be used. A D1 key with the requested name always wins over a Worker secret, and works on any endpoint.Refusal. If no usable key exists, the review runs rules-only (the normal missing-key path). The Worker logs a warning and the PR comment says why. Both name the key, never its value.
workers-aiuses theAIbinding and needs no key, so these rules do not affect it.
The GitHub Action reads keys from the environment of your own workflow step; you decide which secrets it sees.
Runner isolation
The open-source runner passes each engine CLI a minimal environment, removes ANTHROPIC_API_KEY, OPENAI_API_KEY and CODEX_API_KEY, and starts it with no tools (or a read-only sandbox) in an empty temporary directory. See what stays on your machine.
Reporting issues
If you find a way for a PR to write outside the learning / proposal branch prefixes, or to lower its own lane via prompt injection, please open a private security advisory on github.com/gauravsharmaGG/mergejudge-runner, or email contact@gauravsharma.dev.