Repository navigation
Security
Current as of v1.3.1. Longhand's threat model, trust boundaries, and hardening live in SECURITY.md in the main repo. That's the canonical document — this page is a summary and a pointer.
-
Local-only. Nothing you stored leaves your machine unless you turn on the opt-in
longhand backup(1.3.0+), which pushes the exported archive — secret-shaped strings masked in the copy — to the git remote you chose atbackup init, and only after a consent screen; see Backup & Restore. Otherwise network activity is limited to the one-time embedding-model download (~80MB, cached outside the data directory), an optional once-daily version check against pypi.org, and commands you explicitly run. The version check is opt-out (LONGHAND_NO_UPDATE_CHECK=1) and structurally excluded from the actual hook/plumbing entry points (ingest-session,ingest-live,__prompt-hook-run,mcp-server,context,backfill-episodes) — but it does fire on exit ofshared-mcp,mcp serve,demo, the scheduled reconciler'sreconcile --fix, and a backgroundingestthat recall (the prompt hook's included) spawns when no project matches, gated by a 24-hour cache so that's rarely more than once a day in practice.longhand doctorforces a fresh check on every run. See Configuration for the full picture. -
No shell, ever. The only subprocesses are list-form argv, never a shell string:
launchctl, and detached workers from one spawn helper — the self-healpython -m longhand ingestandbackfill-episodes, which take no arguments derived from JSONL content or tool output, and (since 1.3.1) the busy-lock retriesingest-live/ingest-session --transcript <path> --wait-lock 600 --data-dir <dir>, whose only non-constant values are the transcript path from the hook's stdin JSON (written by Claude Code) and the data directory. Every worker starts in the data directory, so alonghand/package in the session's project (a session inside a Longhand checkout) can't run in place of the installed one. Since 1.3.0 the opt-in backup adds a third site:git, always with-c protocol.ext.allow=never(and-C <clone>for everything butcloneandls-remote), with--before any remote or path git takes positionally, and for GitHub remotesgh repo view/gh repo create; the remote URL is validated before it is ever passed (no leading-, no::transport helper). -
Parameterized SQL everywhere. No user-supplied value is interpolated into SQL — every filter goes through a bound parameter, and
LIKEwildcards are escaped. -
Read-only on source files.
~/.claude/projects/(and Codex's~/.codex/) are never written to. -
Fail-open hooks. A Longhand crash inside any hook exits 0 without blocking Claude Code — enforced by
tests/test_hook_guarantees.py. They don't all fail identically:UserPromptSubmitprints{}(injecting nothing);SessionEndandStopjust exit 0 with no stdout, leaving a breadcrumb forreconcileto catch later — on any failure forSessionEnd; forStop(1.3.1+) only when its busy-lock retry gives up (lock-timeout) or can't start (retry-spawn-failed).
SECURITY.md's threat table currently lists 10 rows: command injection via tool output, SQL injection via search queries, path traversal via file_path filters, OOM via oversized JSONL files (500MB/file, 50MB/line hard caps), OOM via huge hook prompts (256KB stdin bound), DoS via pathological LIKE patterns (filter strings capped and escaped), a hook crash reaching Claude Code (fail-open, try/except wraps everything), malformed JSONL crashing the ingestor (bad lines are skipped, parsing continues), duplicate UUIDs across subagent streams (disambiguated with a counter suffix at parse time), and embedding-service exfiltration (the local ONNX model never calls out). See the repo doc for the one-line mitigation on each.
Five items, not four:
-
Local filesystem read access — if an attacker already has read access to your home directory, they already have the source JSONLs; storing the same data in
~/.longhand/doesn't increase exposure. - A malicious MCP client — the MCP server trusts its transport; don't point an untrusted client at your local stdio server.
-
Secrets in prompts that get written to JSONL — mitigated, not solved, by opt-in redaction (
longhand config --set redact.enabled=truepluslonghand redact --applyfor data ingested earlier). Detection is pattern-based, not exhaustive, so "don't paste secrets" remains the first line of defense. -
A malicious Claude Code session — Longhand assumes the JSONL in
~/.claude/projects/came from a legitimate Claude Code instance; a hostile single line still can't do worse than get skipped by the line-length cap. - At-rest encryption — Longhand stores plain SQLite and Chroma files. Use filesystem-level encryption (FileVault, LUKS) if you need this.
- Parser: 500MB per session file, 50MB per JSONL line — a line over the limit is skipped, not crashed on, and the rest of the file keeps parsing.
-
Filters: the SQLite-backed keyword/path/project filters (
list_projects,list_sessions, and similar) are truncated to 500 characters before use via a shared helper. Two things this does not cover: the shared server's ownLIKE-escaping helper has no length cap (only itssearchphrase argument is separately capped at 200 characters — see below), and semanticsearch'sfile_path_containsis an untruncated Python substring check, not a SQL filter. - Hooks: stdin bounded to 256KB; prompts capped at 8,000 characters before reaching the recall pipeline.
-
Semantic MCP server:
limitcapped at 1,000, search queries capped at 2,000 characters. Where a tool caps output at all (see MCP Tools Reference), that cap is itself capped at 200,000 characters — except a caller can passmax_chars <= 0to disable truncation entirely on those same tools, so 200,000 is a ceiling on the tunable cap, not an unconditional one. -
Shared MCP server: search phrases capped at 200 characters,
limitcapped at 50, text/raw-JSON reads served in 8,000-character slices, connection opened read-only, and every query runs against a fixed per-query work budget independent of any argument passed. - Codex capture: up to 50 rollouts per run, each up to 16 MiB and 20,000 events; larger ones are deferred, never partially imported.
LonghandStore creates ~/.longhand/ with mode=0o700 (owner-only) explicitly, and logs/ is created 0700 by the background-job spawner, the hook-error logger, and schedule install-reconciler. Since 1.3.1 the busy-lock retries keep one PID marker per transcript in live-retry/ and session-retry/, created 0700, each marker 0600. In practice 0700 isn't always what lands on ~/.longhand/ itself: the update-check cache writer and longhand config --set create it with a bare mkdir(exist_ok=True) (the process's default umask, often 0755), and schedule install-reconciler and the hook-error logger (when a hook fails before any store exists) create logs/ with parents=True, which applies the mode to logs/ only — so a missing ~/.longhand/ above it gets the umask too. Because mkdir(..., exist_ok=True) never tightens a directory that already exists, whichever code path gets there first decides the permissions for good (#99). The ingest lockfile (.ingest.lock) is explicitly 0600 wherever it's created. The SQLite and Chroma files themselves inherit the process umask inside whatever mode the directory ended up at.
The 13 patterns redact_text/scan_text match: aws_access_key_id, aws_secret_access_key, github_token, anthropic_key, openai_key, google_api_key, slack_token, stripe_key, ssh_private_key, jwt_token, db_url_with_password, ssn, credit_card (must pass the Luhn check and contain at least 3 distinct digits — so low-variety placeholders like 4111…/4242… aren't flagged, but other standard test card numbers are). Detection is pattern-based, not exhaustive — an arbitrary high-entropy string isn't caught. Matched values are never logged, printed, or stored; masks keep only the first/last 4 characters and the length. See Configuration → Hook configuration (the Redaction subsection) for what's covered at parse time versus only by the retroactive longhand redact scan (there's a gap between the two — #110).
Full audit notes, trust boundary diagrams, and parameterized-SQL guarantees are in SECURITY.md. If you find something, open an issue or contact the maintainer directly.