Skip to content

Bind the semgrep-core binary into analyzer receipts#21

Merged
haasonsaas merged 1 commit into
mainfrom
feat/bind-tool-digest
Jul 18, 2026
Merged

Bind the semgrep-core binary into analyzer receipts#21
haasonsaas merged 1 commit into
mainfrom
feat/bind-tool-digest

Conversation

@haasonsaas

Copy link
Copy Markdown
Collaborator

Summary

  • Receipts already named the rules bytes (config_sha256); the scanner itself was only an operator-set version string. AnalyzerIdentity gains tool_sha256 (proto field 4, wire-safe), stamped onto every receipt and signal like the config digest.
  • ROOM_ANALYZER_TOOL_FILE points roomd at the semgrep-core binary; its SHA-256 goes into the analyzer identity and every provider request (tool_sha256), and the bytes are discarded after hashing (a 204 MB binary never stays resident).
  • room-semgrep pins the binary at startup (symlinks resolved, so pipx-style installs keep working; O_NOFOLLOW regular-file read, fstat-checked) and fails closed with tool_digest_mismatch when the request digest is missing/wrong or the binary changed on disk since startup. Adapter restart required after upgrades; documented in docs/analyzer.md.
  • Canonical identity validation (internal/review) now rejects malformed tool digests in both the registry and compiler paths.

Deployment note: with the stock room-semgrep adapter, ROOM_ANALYZER_TOOL_FILE is effectively required — DIFF requests without a matching digest fail closed. PLAN-phase PARTIAL behavior is unchanged (no coverage claimed).

Test plan

  • New unit tests: wrong/empty digest → tool_digest_mismatch; symlinked tool accepted and bound to its regular target (dangling rejected); on-disk binary change after startup → fail closed; server-side identity/request stamping incl. tool-bytes discard; short-digest rejection in registry and compiler
  • go test ./..., go vet, gofmt clean; buf format/lint/generate idempotent
  • ROOM_SEMGREP_CORE=… go test -tags=semgrep_integration ./cmd/room-semgrep — real semgrep-core 1.139.0 suite passes, including via the symlinked ~/.local/bin/semgrep-core path
  • Adversarial review (fail-closed + binding analysis): approve; follow-ups (docs "every diff request" precision, error wrap, vacuous-test hardening, canonical digest validation) all applied

Receipts already named the rules bytes via config_sha256, but the
scanner that produced the findings was only an operator-set version
string. Add tool_sha256 to AnalyzerIdentity: roomd hashes the binary
named by ROOM_ANALYZER_TOOL_FILE into the analyzer identity (bytes
are discarded, never retained), sends the digest in every provider
request, and room-semgrep fails closed with tool_digest_mismatch
unless the request names the binary it pinned at startup. The tool
path is resolved through symlinks so pipx-style installs keep
working, and re-resolved on every diff request so a swapped or
upgraded binary fails until the adapter restarts.
@haasonsaas
haasonsaas merged commit 3543076 into main Jul 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant