Skip to content

fix(audit): clamp timestamps forward on clock step-back (AUDIT-001) - #219

Merged
imran-siddique merged 1 commit into
mainfrom
fix/security-medium-audit-monotonic
Jun 6, 2026
Merged

fix(audit): clamp timestamps forward on clock step-back (AUDIT-001)#219
imran-siddique merged 1 commit into
mainfrom
fix/security-medium-audit-monotonic

Conversation

@imran-siddique

Copy link
Copy Markdown
Member

Summary

  • AuditChain.append() used datetime.now(UTC) with no guard, so a backward NTP step or clock adjustment could produce entries with timestamps earlier than the previous entry
  • Clamp now to max(now, prev_entry.timestamp_utc) before assigning — the sequence number already provides strict ordering; this prevents confusing human-readable audit trails
  • Two new tests: backward clock is clamped, forward clock is preserved as-is

Fixes #166.

Test plan

  • pytest tests/unit/test_audit.py — all 18 pass including 2 new AUDIT-001 tests
  • pytest full suite — no regressions

…AUDIT-001)

Closes #166.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imran-siddique
imran-siddique merged commit 137e0f9 into main Jun 6, 2026
0 of 7 checks passed
@imran-siddique
imran-siddique deleted the fix/security-medium-audit-monotonic branch July 29, 2026 23:20
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.

MEDIUM: audit_chain entries use wall-clock time without monotonic guard — entries can appear out of order (AUDIT-001)

1 participant