Skip to content

Code smells of #283 (2/3): keep the escalation history when old blocks are purged (C14) - #324

Merged
codeling merged 2 commits into
ccr-140f02b2-828xlpfrom
ccr-140f02b2-828xlp-c14
Nov 20, 2026
Merged

codeling merged 2 commits into
ccr-140f02b2-828xlpfrom
ccr-140f02b2-828xlp-c14

Conversation

@codeling

Copy link
Copy Markdown
Owner

Part 2 of 3 for #283. Stacked on #323: the base is that PR's branch, so retarget to main once it has merged.

Problem

maxBlocksBefore and progressiveBlockDuration count an address's earlier blocks (BlockRepository::countPrevious()). The daily purge deletes ended blocks after deleteOld weeks (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

  • New table #__bfstop_offence (address, number of blocks, latest block), in the install and uninstall scripts for MySQL and PostgreSQL and in updates/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, so countPrevious() 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() (in keepWithinBounds()) 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.
  • Tests: purged blocks still count (administrator-lifted ones don't, mail-lifted ones do), a second purge adds nothing, a purge of 1200 blocks across batches, and the pruning. CHANGELOG entry.

Testing

php -l only. 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, and UpdateSqlTest.


Generated by Claude Code

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
@codeling
codeling added this pull request to stack #326 November 20, 2026 22:02
@codeling
codeling merged commit f274b23 into main Nov 20, 2026
20 checks passed
@codeling
codeling deleted the ccr-140f02b2-828xlp-c14 branch November 20, 2026 22:06
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.

2 participants