mirror of
https://github.com/prosolis/gogobee.git
synced 2026-07-15 08:32:41 +00:00
Full codebase audit: 21 security/robustness fixes, 328 tests across 4 packages
Security & economy: - Credit()/Debit() reject non-positive amounts (closes infinite-money exploit) - Lottery ticket purchase uses in-transaction count check (closes TOCTOU race) - Arena bail channel ownership prevents double-close panic - Entry.ID validated before exec.Command in fetch-esteemed - Internal errors no longer leaked to users (forex, esteemed) Robustness: - safeGo() panic recovery added to 17 goroutine launch sites across 14 plugins - db.Close() added and called on shutdown - Miniflux mutex pattern fixed (snapshot-under-lock) - Silently ignored DB/JSON errors now logged (lottery_db) Performance: - Added indexes: idx_arena_runs_user(user_id, status), idx_euro_bal_user(user_id) UX: - Empty !buy args shows usage instead of "No item matching ''" - "Failed to load character" now suggests !adventure Test coverage: - internal/util/parser_test.go (19 tests: XP, levels, progress bar, commands, parsing) - internal/crypto/crypto_test.go (12 tests: encrypt/decrypt, HMAC, ParseKey) - internal/plugin/helpers_test.go (30 tests: formatNumber, calc, lottery, chat perks) - internal/plugin/audit_fixes_test.go (25 tests: safeGo, bail channels, error leaks, overflow) - internal/db/db_test.go (4 tests: Init, Close, schema indexes) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -189,6 +189,10 @@ func (p *EuroPlugin) credit(userID id.UserID, amount float64, reason string) {
|
||||
// Debit subtracts euros atomically. Returns false if this would exceed debt limit.
|
||||
// Uses a conditional UPDATE to prevent race conditions (check-and-act in one statement).
|
||||
func (p *EuroPlugin) Debit(userID id.UserID, amount float64, reason string) bool {
|
||||
if amount <= 0 {
|
||||
slog.Warn("euro: Debit called with non-positive amount", "user", userID, "amount", amount)
|
||||
return false
|
||||
}
|
||||
p.ensureBalance(userID)
|
||||
d := db.Get()
|
||||
|
||||
@@ -216,6 +220,10 @@ func (p *EuroPlugin) Debit(userID id.UserID, amount float64, reason string) bool
|
||||
|
||||
// Credit adds euros (exported for other plugins).
|
||||
func (p *EuroPlugin) Credit(userID id.UserID, amount float64, reason string) {
|
||||
if amount <= 0 {
|
||||
slog.Warn("euro: Credit called with non-positive amount", "user", userID, "amount", amount)
|
||||
return
|
||||
}
|
||||
p.ensureBalance(userID)
|
||||
p.credit(userID, amount, reason)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user