Repository navigation
Code smells of #283 (2/3): keep the escalation history when old blocks are purged (C14) - #324
Merged
Merged
Conversation
The purge deleted the blocks maxBlocksBefore and progressiveBlockDuration count, so an attacker returning every five weeks never escalated. The purge now folds the blocks it deletes (except those lifted by an administrator, which never counted) into #__bfstop_offence, one row per address, kept for a year and at most 10000 addresses; countPrevious() adds it to the live blocks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFJFMNpwNryanqvRcQvqDc
RepositoryRulesTest: queries only through the base class, no catch outside FailurePolicy. The transaction around counting and deleting is a try/finally helper in Repository (the exception still reaches failOpen()), and the offence row is updated through execute() after looking whether it exists, like DnsCacheRepository::put(). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFJFMNpwNryanqvRcQvqDc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 2 of 3 for #283. Stacked on #323: the base is that PR's branch, so retarget to
mainonce it has merged.Problem
maxBlocksBeforeandprogressiveBlockDurationcount an address's earlier blocks (BlockRepository::countPrevious()). The daily purge deletes ended blocks afterdeleteOldweeks (4 by default), so an attacker who is blocked once every five weeks never has more than one block on record and never escalates.Change
#__bfstop_offence(address, number of blocks, latest block), in the install and uninstall scripts for MySQL and PostgreSQL and inupdates/2.0.0.sql(2.0.0 is unreleased).purgeEndedBefore()counts the blocks it deletes into that table first, 500 at a time and in one transaction per batch, so a failure between counting and deleting doesn't count them twice. Blocks an administrator lifted are not counted; they didn't count before either, socountPrevious()means what it did.countPrevious()adds the stored count to the live blocks in the same query, so the number of queries per block doesn't change.pruneOffences()(inkeepWithinBounds()) forgets an address a year after its latest block began, and keeps at most 10000 addresses, oldest first, like the DNS cache. The issue left the window open; this makes the memory a year instead of the four weeks it was in practice. It is a constant (BlockRepository::OffenceMemoryDays), not a new setting.Testing
php -lonly. The integration tests need a Joomla tree (JOOMLA_ROOT) that this environment doesn't have, so CI is the first run of the new SQL and tests. Worth a look in that run: the PostgreSQL job, andUpdateSqlTest.Generated by Claude Code