Skip to content
CodeSpider
GitHub

Security & Threat Model

CodeSpider treats every pull request title, body, diff, comment, and PR-head configuration file as untrusted input.

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
  1. 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.
  2. Host RCE via Untrusted PR Tests: Host-side go test execution is disabled. run_proof_test requires sandbox.mode: container and !IsFork, running inside a network-disabled, read-only, non-privileged container with memory/CPU/PID caps.
  3. Policy Bypass via PR-Head .codespider.yaml: The worker loads .codespider.yaml from the trusted base branch mirror (ReadMirrorFile) rather than the PR head worktree.
  4. Cross-Repository Exfiltration from Fork PRs: Fork PRs (IsFork == true) are stripped of CapCrossRepoRead, CapWriteWorktree, CapPushCommits, CapIsolatedExec, and CapMutateMemory.
  5. Credential Exfiltration via CloneURL or Error Logs: workspace.Manager.WithAllowedOrigin(cfg.GiteaBaseURL) refuses clone/push URLs whose scheme://host does not match the configured Gitea origin; tokens are redacted from error strings.
  6. Stale Commit / TOCTOU Race on Review or Push: VerifyHeadUnchanged checks remote PR Head.SHA before posting reviews, and CommitAndPush checks git ls-remote against expectedHeadSHA before pushing.
  7. Unauthorized Memory Poisoning: memory.Store.RecordFeedback and UpsertRule block untrusted PR comments from mutating org-wide rules.
  8. Admin Token Leakage in URLs: Operations Console & SSE (/events) authenticate via HttpOnly; SameSite=Strict HMAC-signed session cookie (POST /api/session).

3. Hardening added after fed7f5c (verified against ee66683)

Section titled “3. Hardening added after fed7f5c (verified against ee66683)”
  1. Fork PRs use base-branch rules: CodeSpider reviews the fork’s proposed changes, but reads settings, instruction files, path_instructions, and CODEOWNERS from the base branch. The reconciler applies fork restrictions to the PR as well.
  2. Symlink-safe reads: Repository config, skill files, search_code, and the static analyzers read through workspace.ReadSafeFile, so a symlink in a PR cannot pull host files into the prompt. .git directories are skipped case-insensitively, and WriteSafeFile rejects case-variant .git paths on every OS.
  3. Sandbox hardening: package_dir is passed to the container shell as a positional argument instead of being interpolated. PoC validation rejects import "C", net/* (except the pure parsing packages net/url, net/netip, net/mail), and syscall/*.
  4. Strict revision input: SpeculativeMergeCheck accepts only hex commit SHAs and passes them after --; ReadMirrorFile rejects : and whitespace in refs.
  5. 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.
  6. Web console and state: A malformed Origin header now fails the CSRF check closed, webhook metric labels are bounded against header spam, and state.json is written with mode 0600.
  7. CLI parity: codespider review now honors sandbox.require_image_digest like the daemon.
  • Use a dedicated codespider Gitea user with least-privilege repository permissions.
  • Set gitea.allow_unsigned_webhooks: false and a strong gitea.webhook_secret.
  • Keep agent.enable_write: false and sandbox.mode: "disabled" during pilot rollout.
  • Set server.admin_token if 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.