Repository navigation
Aegis Phase-0 + Phase-1 rule corpus, GIN-24 token reuse fix - #41
Conversation
…tore Introduces `packages/core/src/auth/token-store.ts` — a new `TokenStore` class that enforces one-time-use semantics on every auth token category: - One-time tokens (magic link, password reset, email verification): `consumeToken` atomically marks `usedAt` before returning; any replay raises `TokenAlreadyUsedError` with the original consumption timestamp. - Refresh tokens: `rotateRefreshToken` invalidates the old record before issuing a replacement — no window exists between check and use. Replaying the rotated-away token raises `TokenAlreadyUsedError`. - Logout: `revokeToken` marks a token revoked regardless of current status; subsequent consume or rotate calls raise `TokenRevokedError`. Error precedence: used > revoked > expired, so replay detection always surfaces the most actionable signal even when the token is also past TTL. Adds 49 tests in `test/token-store.test.ts` covering: - Happy-path issue/consume/rotate/revoke - Replay attack scenarios for each token category - Token theft simulation (attacker replays stolen refresh token) - Expiry, revocation, and precedence edge cases - Immutability of returned `AuthToken` snapshots All 359 tests pass (20 test files). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Scaffold @heybeaux/lattice-aegis (Phase 0) and port the AutoHarness risk-rule corpus to JSON rule packs (Phase 1) for the predictive governance harness. - 106 rules across 5 packs (bash/file/injection/pii/secrets), traced to AutoHarness source and fidelity-audited; fixed 5 spurious regex flags that broadened matching beyond source - rule loader (validate, flag-restrict, ReDoS budget guard), 3-layer merge cascade with strictness invariant, combinator-aware safe-command allowlist, strictest-of evaluation contract - verify-rulepacks.mjs (all green), 17 package tests passing - design docs: build plan, rulepack spec, action_failed label spec, Sonder Phase-3.5 scope Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 50 minutes and 56 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughIntroduces the ChangesAegis governance harness (
Core TokenStore (
Sequence Diagram(s)sequenceDiagram
participant Hook as aegis-hook (PreToolUse)
participant Loader as loadPack / mergeLayers
participant Evaluator as evaluate
participant SafeCmd as isSafeCommand
participant Sonder as Sonder checkGate
Hook->>Loader: load + merge builtin/user/project packs
Loader-->>Evaluator: CompiledRule[]
Hook->>SafeCmd: isSafeCommand(command, allowlist)
SafeCmd-->>Hook: true / false (fast path)
Hook->>Evaluator: evaluate(ToolCall, CompiledRule[], opts{prediction})
Evaluator->>Evaluator: iterate rules → RuleHit[], maxSeverity
Evaluator->>Evaluator: severityFloorAction via SeverityTable
Evaluator->>Evaluator: predictionAction via PredictionThresholds
Evaluator->>Evaluator: strictestOf → Evaluation{action, decidedBy}
Evaluator-->>Hook: Evaluation
Hook->>Sonder: checkGate(Evaluation.action, signedEvidence)
Sonder-->>Hook: veto / allow (signed audit entry)
sequenceDiagram
participant Client
participant TokenStore
participant ErrorHandler
Client->>TokenStore: issueToken(userId, purpose, {kind, expiresInMs})
TokenStore-->>Client: AuthToken (frozen, pending)
Client->>TokenStore: consumeToken(value)
TokenStore->>TokenStore: requireRecord → assertConsumable
alt token reused / revoked / expired
TokenStore-->>ErrorHandler: TokenAlreadyUsedError / TokenRevokedError / TokenExpiredError
else valid
TokenStore-->>Client: AuthToken (used, usedAt set)
end
Client->>TokenStore: rotateRefreshToken(value)
TokenStore->>TokenStore: enforce kind=refresh, assertConsumable
TokenStore->>TokenStore: mark old used, issueToken new refresh
TokenStore-->>Client: RotateResult {consumed, next}
Client->>TokenStore: revokeToken(value)
TokenStore->>TokenStore: idempotent revoke (no-op if missing/already revoked)
TokenStore-->>Client: void
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
# Conflicts: # packages/core/src/index.ts
Summary
@heybeaux/lattice-aegis) — rule-pack + evaluation contract, ReDoS-guarded loader, 3-layer cascade merge with strictness invariant, combinator-aware safe-command allowlist,strictest_of(severity_floor, prediction)combination ruleTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
.gitignoreto exclude coverage artifacts.Tests
Chores