Complete assignment thoroughly: Target Worktree…
- User
Complete assignment thoroughly:
Target
Worktree
/Users/bnjoroge/preloop-gh-app-api-compat. Files:crates/preloop-runner-server/src/github_app.rs,crates/preloop-runner-server/src/github_push.rs,crates/preloop-runner-server/src/dispatch_auth.rs. Do NOT edit other files.Change (seven items, all verified open at head b4c00985)
- Blank webhook secrets (P0) —
GitHubAppCredentials::webhook_secretsin github_app.rs (~line 279-290) pushesapp.webhook_secretunconditionally whenSome. An empty-string secret makes webhook signature verification publicly forgeable. Skipsecret.is_empty()(both the registry loop and, for symmetry, the legacylegacyparameter — but note the legacy param already comes fromPRELOOP_WEBHOOK_SECRETwhich is filtered non-empty at load in state.rs; still guard it). - installation_id override without owner check (P1) —
installation_id_forin github_app.rs (~line 883) returnscreds.installation_id(per-App override) or the env override (installation_id_override(),PRELOOP_GITHUB_APP_INSTALLATION_ID) without verifying the installation actually belongs toowner. This makesselect_app_for_repo(line ~513) claim an App covers ANY owner's repo, so multi-App selection and minting target the wrong installation (GitHub returns a token that cannot access the repo, or selects the wrong App entirely). Fix: when the installation id comes from an override (per-App or env), verify the installation's owning account matchesowner— GET{api_base}/app/installations/{id}with the App JWT and compareaccount.login(case-insensitive) toowner; on mismatch return an error (anyhow::bail!with a clear message naming owner, installation id, and the account that owns it). Cache the verified owner per (app_id, installation_id) in a small in-memory cache (add aMutex<HashMap<(String,u64), String>>field or reuse the existinginstallation_cachepattern — follow the existing cache style in the file; TTL not required but a bounded map is fine). Only the override paths need verification; discovery (find_installation) already matches the owner. Keep behavior identical for the discovery and cache paths. - push_token stops at first App (P1) —
push_tokenin github_push.rs (~line 385) callsselect_app_for_repo(shared, repository).awaitwhich returns the FIRST App installed on the owner; if that App's installation cannot access the repo, fails and push-back never tries later Apps. Fix: try every candidate. Add a helper in github_app.rs (pub(crate)) that returns all candidate in registry order (legacy when no registry; otherwise every registry App whose for the owner succeeds, honoring overrides) — i.e., the same iteration does, but collecting ALL matches instead of returning the first. Rewrite to return (single-App legacy fallback preserved: registry with 1 app falls back to when installation lookup fails, exactly as today). In , iterate the candidates minting via ; return the first success; on failure of all candidates, fall through to as today (keep the existing warn! on mint failure).
- Blank webhook secrets (P0) —
Assistant
Now let me read the remaining parts of github_app.rs and the other two files in full.
Assistant
Now the dispatch_auth.rs file:
Assistant
Now let me check
state.rsto understandSharedState,static_github_pat, and howgithub_app/github_appsrelate:Assistant
Let me read the test fixture and the ledger test in detail:
Assistant
I have the complete picture. Now let me make the edits. Starting with
github_app.rs— item 1 (webhook secrets) and item 2 (new cache field + constructors):Assistant
Now item 3 — rewrite
select_app_for_repoand addcandidate_apps_for_repo:Assistant
Now item 2's core change — owner verification on the override paths in
installation_id_forplus the new helper:Assistant
Now
github_push.rs— item 3'spush_tokeniterating all candidates:Assistant
Now
dispatch_auth.rs— items 7+8 (ledger fast path) and item 4 (JWT exp cap):Assistant
All eight items applied. Now a careful compile-read review of every edited region:
Assistant
All constructor sites updated. Now reviewing the
dispatch_auth.rsedits:Assistant
All edits verified. Let me check test helpers that sign JWTs — item 4's exp cap could affect them:
Assistant
Let me do a final review of the complete diff to make sure the changes are exactly scoped:
Assistant
Other agents are concurrently editing the same worktree (I see
has_contents_writein the shared diff — that's from a peer). Let me check the current state ofdispatch_auth.rsaround that addition and see how the concurrent test changes interact with my work:Assistant
The peer's
has_contents_writecoexists cleanly with my edits. Let me review the fullgithub_app.rsdiff to confirm only my intended changes are present:Assistant
All diffs are exactly as intended. One test-impact finding to coordinate: the ledger-actor change (item 7) alters the actor asserted by
dispatch_with_own_minted_token_authenticates_offline_via_ledger(dispatch_tests.rs:827), which is outside my assigned files. Let me flag it to the coordinator:Assistant
All changes verified. Final structural checks pass. Yielding the report: