Skip to content

fix: verify published heads after a purge (audit ST-D1) - #3

Open
HecFranco wants to merge 4 commits into
mainfrom
fix/st-d1
Open

HecFranco wants to merge 4 commits into
mainfrom
fix/st-d1

Conversation

@HecFranco

Copy link
Copy Markdown
Contributor

Fixes the remaining findings of audit ST (Appendix ST delta) for 0.1.1.

ST-D1 (Low): published heads after a purge

  • --heads-out and --publish-heads now write {hash, seq, at} per chain (VerificationReport::$headLinks).
  • A missing published head is accepted only when an anchor on that chain has first_kept_seq > seq, or anchor_hash == hash. No column added: both are already on working_time_chain_anchor (no migration; noted in UPGRADING).
  • Legacy 0.1.0 heads files (bare hashes) are refused (exit 2) with a message pointing to --heads-out (the safer option: without seq a purge cannot be told from a removed tail). Bare hashes passed to the PHP API are excused only by their own anchor.
  • Extra hardening: an anchor past the chain's first link is reported as anchor_after_start (a purge only removes a prefix), so a forged anchor past the published head no longer excuses a removed tail while links remain. A chain the purge emptied reports its last anchor as head.
  • The auditor's probe is now PurgeTest::testAHeadPublishedAfterAPurgeStillCatchesARemovedTail (SQLite, MySQL, MariaDB, PG): real purge → --heads-out → delete the last workday's links, segments and row with the purge flag → verify --heads reports NOT intact (published_head_missing, exit 1).

Info: default EM by name

DoctrineTransactionRunner treats a configured doctrine.entity_manager that resolves to the registry's default manager as shared, so release() and refuseForeignChanges() apply. Tests: unit (default vs private name) and HostKindsTest parametrised with entity_manager: default.

Docs

UPGRADING "To 0.1.0" now says first release (composer require); Unreleased section with the heads-file migration; CHANGELOG [Unreleased] Fixed; SECURITY/USAGE updated.

Local results

  • PHPUnit SQLite full: 399 tests / 8 500 assertions, UTC and Europe/Madrid; coverage 100% (classes 148/148, methods 689/689, lines 4079/4079).
  • Database suite: MySQL 8.4 107 / 7 517, MariaDB 11.4 107 / 7 517, PostgreSQL 16 107 / 7 520, each in UTC and Europe/Madrid.
  • PHPStan, PHP-CS-Fixer, Rector, Igor (0 KO / 0 WARN, worker mode with kernel reset false): clean.

🤖 Generated with Claude Code

- --heads-out and --publish-heads record {hash, seq, at}; a missing
  published head is accepted only when an anchor of the chain has
  first_kept_seq > seq or anchor_hash == hash (no schema change).
- 0.1.0 heads files (bare hashes) are refused with exit 2; bare hashes
  passed to the API are excused only by their own anchor.
- An anchor past the chain's first link is reported as anchor_after_start;
  an emptied chain reports its last anchor as its head.
- DoctrineTransactionRunner: a configured entity manager name that
  resolves to the registry's default manager is shared, so release()
  and refuseForeignChanges() apply (audit ST Info).
- UPGRADING: 0.1.0 is the first release (composer require).
@github-actions

Copy link
Copy Markdown

@coderabbitai review

…t ST-D1b)

- A missing head with its seq is excused only when seq is below the
  chain start (first link, or the last anchor's first_kept_seq for an
  emptied chain); the anchor_hash shortcut is gone for such heads.
- Exports record {hash, seq} in chain_heads; bare hashes (0.1.0 rows,
  API callers) keep the weaker 0.1.0 rule, documented in UPGRADING.
- The genesis is a head only with seq 0.
- Anchors with first_kept_seq < 2 are reported as anchor_seq_invalid.
- Regression tests for probes c and c2 on SQLite, MySQL, MariaDB, PG.
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