Security & Threat Model
CodeSpider treats every pull request title, body, diff, comment, and PR-head configuration file as untrusted input.
1. Trust Boundaries
Section titled “1. Trust Boundaries”| Boundary | Untrusted Inputs | Trusted Inputs |
|---|---|---|
| Webhook Ingress | HTTP body and headers (until HMAC-SHA256 verified) | gitea.webhook_secret, server.admin_token |
| Pull Request Content | PR title/body, diff, source code, PR-head .codespider.yaml, comments, tool outputs |
codespider.yaml, base-branch .codespider.yaml (refs/heads/<base>), host skills/ |
| Code Execution | Any Go test, init(), or build script inside PR worktree |
Container runtime (--network=none, --cap-drop=ALL, --read-only) |
| Review Memory | Comments from external or fork contributors | Collaborator/admin feedback via authenticated API or gated commands |
2. Mitigated Threats (fed7f5c)
Section titled “2. Mitigated Threats (fed7f5c)”- Prompt Injection → Tool Privilege Escalation: Untrusted PR text and instructions are wrapped in sanitized
<untrusted_*>delimiters (policy.WrapUntrustedInput). Tool authorization is enforced in Go (policy.CheckToolAllowed) before any handler runs. - Host RCE via Untrusted PR Tests: Host-side
go testexecution is disabled.run_proof_testrequiressandbox.mode: containerand!IsFork, running inside a network-disabled, read-only, non-privileged container with memory/CPU/PID caps. - Policy Bypass via PR-Head
.codespider.yaml: The worker loads.codespider.yamlfrom the trusted base branch mirror (ReadMirrorFile) rather than the PR head worktree. - Cross-Repository Exfiltration from Fork PRs: Fork PRs (
IsFork == true) are stripped ofCapCrossRepoRead,CapWriteWorktree,CapPushCommits,CapIsolatedExec, andCapMutateMemory. - Credential Exfiltration via
CloneURLor Error Logs:workspace.Manager.WithAllowedOrigin(cfg.GiteaBaseURL)refuses clone/push URLs whosescheme://hostdoes not match the configured Gitea origin; tokens are redacted from error strings. - Stale Commit / TOCTOU Race on Review or Push:
VerifyHeadUnchangedchecks remote PRHead.SHAbefore posting reviews, andCommitAndPushchecksgit ls-remoteagainstexpectedHeadSHAbefore pushing. - Unauthorized Memory Poisoning:
memory.Store.RecordFeedbackandUpsertRuleblock untrusted PR comments from mutating org-wide rules. - Admin Token Leakage in URLs: Operations Console & SSE (
/events) authenticate viaHttpOnly; SameSite=StrictHMAC-signed session cookie (POST /api/session).
3. Hardening added after fed7f5c (verified against ee66683)
Section titled “3. Hardening added after fed7f5c (verified against ee66683)”- Fork PRs use base-branch rules: CodeSpider reviews the fork’s proposed changes, but reads settings, instruction files,
path_instructions, andCODEOWNERSfrom the base branch. The reconciler applies fork restrictions to the PR as well. - Symlink-safe reads: Repository config, skill files,
search_code, and the static analyzers read throughworkspace.ReadSafeFile, so a symlink in a PR cannot pull host files into the prompt..gitdirectories are skipped case-insensitively, andWriteSafeFilerejects case-variant.gitpaths on every OS. - Sandbox hardening:
package_diris passed to the container shell as a positional argument instead of being interpolated. PoC validation rejectsimport "C",net/*(except the pure parsing packagesnet/url,net/netip,net/mail), andsyscall/*. - Strict revision input:
SpeculativeMergeCheckaccepts only hex commit SHAs and passes them after--;ReadMirrorFilerejects:and whitespace in refs. - Blue-Team stays read-only: The verification pass now refuses any tool call outside its read-only allowlist at run time, not only in the advertised tool list.
- Web console and state: A malformed
Originheader now fails the CSRF check closed, webhook metric labels are bounded against header spam, andstate.jsonis written with mode0600. - CLI parity:
codespider reviewnow honorssandbox.require_image_digestlike the daemon.
Safe Pilot Checklist
Section titled “Safe Pilot Checklist”- Use a dedicated
codespiderGitea user with least-privilege repository permissions. - Set
gitea.allow_unsigned_webhooks: falseand a stronggitea.webhook_secret. - Keep
agent.enable_write: falseandsandbox.mode: "disabled"during pilot rollout. - Set
server.admin_tokenif the Operations Console port (:8080) is reachable outside localhost. - Disabling agent writes prevents source edits and pushes, not the bot’s ordinary PR comments and commit statuses. Scope bot credentials to one pilot repository.
- A hosted model can receive repository context even when the daemon is self-hosted. Use a private endpoint for private code that must stay on your network, or review the provider’s data policy before the pilot.