fix: security & data-safety hardening across server and CLI - #13
Open
aoruLola wants to merge 4 commits into
Open
fix: security & data-safety hardening across server and CLI#13aoruLola wants to merge 4 commits into
aoruLola wants to merge 4 commits into
Conversation
- high_risk: fail closed when HIGH_RISK_SIGNATURE_REQUIRED is set but no signing secret is configured, instead of falling back to a hardcoded secret shipped in source; verify signatures in constant time via blake3::Hash equality rather than hex string comparison. - auth: give the in-memory API key cache a TTL (API_KEY_CACHE_TTL_SECS, default 60s) so a DB-side revocation or permission change is honored within the TTL instead of being trusted forever; drop stale entries when the DB reports a key invalid. - auth: make refresh-token rotation atomic via a single conditional UPDATE (rotate_refresh_token); rows_affected == 0 is treated as replay and burns the token family, closing the concurrent-refresh replay window. - auth: list_keys_persistent returns only DB-backed hashed keys when a DB is configured, so raw secret prefixes are never echoed by list_keys. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- versioning: allow a draft-first changeset (base=ROOT, head never advanced) to be promoted by mirroring submit's ROOT acceptance rule in promote_changeset and changeset_gate (head_accepts_base). Adds regression test. - versioning: persist each snapshot under its changeset's actual branch instead of always the default branch (snapshots are keyed by branch_name). - versioning: add an optimistic state_version guard (migration 202602260018) so a concurrent writer's update is detected as a conflict rather than silently clobbered. Single-instance behavior is unchanged. - versioning: opt-in separation of duties (HYPERTIDE_REQUIRE_SEPARATE_APPROVER) rejecting self-approve/self-promote. - lock: unlock/expired-renew use owner-scoped DB deletes and an ownership guard on renew upsert, so a stale cached view cannot delete or steal a lock that another owner re-acquired. Force-release stays owner-blind. - storage: on a dedup hit, compare object size via metadata instead of reading the whole existing object back into memory and re-hashing it; integrity is still verified on retrieve. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- witness: summary() recomputes each receipt's HMAC over the referenced checkpoint material (constant-time verify_slice) and counts only configured, signature-verified witnesses toward quorum. Previously quorum was a raw row count, so forged receipts could fake it. - checkpoint: build generate_checkpoint inside one REPEATABLE READ transaction holding the audit advisory lock, so log head/size and the table counts describe a single consistent moment (removes a TOCTOU). - replay: key the replayed lock set by (repo_id, file_path) to match DB uniqueness; always full-scan events (the checkpoint marker has no state snapshot, so a suffix replay produced spurious mismatches). - audit_chain: report `checked` from a running verified counter instead of deriving it from seq, which has gaps from rolled-back appends. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- workspace: write state atomically (temp file + rename) with 0600 file / 0700 dir permissions on Unix, and auto-create .hypertide/.gitignore so plaintext credentials can't be world-readable or accidentally committed. - checkpoint restore/branch: run the same pre-flight as checkout (staged / local-modification / untracked-collision checks) and add --force, instead of overwriting local files unconditionally. - sync: materialize snapshot content and update checked_out_assets when advancing the base pointer, and refuse (or --force) on local divergence, fixing a silent lost update where a later submit discarded intervening changes. - confirm_dangerous: return a non-zero error on cancel and hard-fail in a non-TTY without --yes, instead of exiting 0 as a silent no-op. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A focused security- and correctness-hardening batch surfaced by a multi-subsystem review (auth/rate-limiting, storage/versioning/locks, trust/audit chain, and the CLI). Each change is grounded in a concrete failure scenario. All findings verified against the code;
cargo clippy,cargo fmt --check, and the full test suite pass (server 85 incl. a new regression test, CLI 42).Server — auth & request path
blake3::Hash).API_KEY_CACHE_TTL_SECS, default 60s): DB-side revocation / permission changes are honored within the TTL instead of forever; stale entries dropped when the DB reports invalid.UPDATE;rows_affected == 0⇒ replay ⇒ family revoked. Closes the concurrent-refresh replay window.list_keysno longer leaks raw secret prefixes (returns DB-hashed keys when a DB is configured).Server — locks, versioning, storage
state_versionguard (migration202602260018): concurrent-writer clobbering becomes a detectable conflict; single-instance behavior unchanged.HYPERTIDE_REQUIRE_SEPARATE_APPROVER) rejecting self-approve/self-promote.Server — trust / audit / replay
summary()recomputes each receipt's HMAC over checkpoint material and counts only configured, verified witnesses (was a raw row count → forgeable).generate_checkpointruns in one REPEATABLE READ transaction under the audit advisory lock (removes a TOCTOU).(repo_id, file_path); always full-scan (the checkpoint marker holds no state snapshot, so suffix replay reported spurious mismatches).checkedcounter (no longer derived from gap-proneseq).CLI — data & credential safety
0600/0700perms and auto.hypertide/.gitignore— plaintext credentials can't be world-readable or accidentally committed.checkpoint restore/branchno longer overwrite local files unconditionally (checkout-style pre-flight +--force).syncmaterializes content and updates tracked hashes when advancing the base pointer, refusing on divergence (+--force) — fixes a silent lost update.confirm_dangerousreturns non-zero on cancel and hard-fails in a non-TTY without--yes(was exit 0 no-op).Deliberately deferred (need a threat-model / product decision)
state_root).🤖 Generated with Claude Code