fix(dataexchange): add InboxMaxBytes byte-budget cap to prevent disk DoS (PILOT-276)#10
fix(dataexchange): add InboxMaxBytes byte-budget cap to prevent disk DoS (PILOT-276)#10matthew-pilot wants to merge 2 commits into
Conversation
Add three tests that demonstrate the lack of byte-based cap on inbox storage: TestSaveInboxMessage_ByteBudgetEnforced, TestSaveInboxMessage_NoByteBudget_Unbounded, and TestEvictInboxOverflow_ByteBasedEvictsOldest. These tests currently FAIL because InboxMaxBytes is not implemented yet.
…DoS (PILOT-276) saveInboxMessage previously trusted InboxMaxFiles (file-count cap, default 10000) with eviction only every 64th write. Between eviction passes, up to 63 messages could accumulate with no cap on per-message size — worst-case 63 × 256 MiB ≈ 16 GiB of disk usage before the periodic eviction scan trims it. This change adds: 1. InboxMaxBytes (int64) to ServiceConfig — when > 0, enables byte-budget enforcement. 2. inboxTotalBytes helper — sums on-disk sizes of inbox files. 3. Pre-write budget check in saveInboxMessage — estimates pending JSON overhead + payload, evicts if over budget, and rejects with error + 'inbox.full' event if still over. 4. evictInboxOverflowByBytes — FIFO eviction by size instead of file count. When InboxMaxBytes is unset (zero), the old InboxMaxFiles behaviour is fully preserved (backward-compatible). The new path is only active when the operator explicitly configures InboxMaxBytes. Closes PILOT-276
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🦾 Matthew PR Check — #10 PILOT-276Status
VerdictCLEAN — all CI green, narrow single-service change, thorough test coverage. Ready for operator review. 🤖 matthew-pr-worker · Wave 1 (pr-status) |
🦜 Matthew Explains — #10 PILOT-276What this doesAdds Why this mattersBefore this fix,
How it works
Security impactDefense-in-depth against disk-DoS. The file-count cap alone was a coarse control vulnerable to large-payload peers. The byte budget closes the gap — even with 63 files accumulating between eviction passes, total disk usage stays bounded. Test coverage
🤖 matthew-pr-worker · Wave 1 (pr-explain) |
What failed
saveInboxMessagetrusted onlyInboxMaxFiles(file-count cap, default 10000) with eviction running every 64th write. Between eviction passes, up to 63 messages could accumulate with no cap on per-message size — worst-case 63 × 256 MiB ≈ 16 GiB of disk usage before the periodic eviction scan trims it.Why this fix
Adds
InboxMaxBytes int64toServiceConfig. When set:saveInboxMessageestimates overhead + payload, evicts if over, rejects with error +inbox.fullevent if still over.evictInboxOverflowByBytesdoes FIFO eviction by size instead of file count.When
InboxMaxBytesis unset (zero), the oldInboxMaxFilesbehaviour is fully preserved (backward-compatible).Verification
go build ./...— cleango vet ./...— cleango test ./... -count=1 -timeout 120s— all passing (including 3 new byte-budget tests)Diff stat
Closes PILOT-276