Skip to content

Index the failed logins; unblock link to the site also after API logins; CI keeps its downloads - #266

Merged
codeling merged 3 commits into
mainfrom
ccr-f557f83f-uk6a4f
Nov 9, 2026
Merged

codeling merged 3 commits into
mainfrom
ccr-f557f83f-uk6a4f

Conversation

@codeling

@codeling codeling commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Index the failed logins (e29dab8)

Every failed login counts the failed logins of its address within the check interval, twice. A block lists them and checks which accounts they went against, and the adaptive delay counts those of the last hour. None of these had an index: only username_logtime existed, on a table kept at up to 200,000 rows.

New indexes on #__bfstop_failedlogin:

  • (ipaddress, logtime) for the per-address lookups;
  • (logtime) for the last hour and the purge by age.

They are in both install scripts and in the 2.0.0 update, marked CAN FAIL like username_logtime.

Performance

Measured with the plugin's own DatabaseHelper on 200,000 rows: 50,000 addresses with a few attempts each over 4 weeks, plus one repeat offender with 600 handled attempts and 9 fresh ones. Times in ms, median of 50 runs; inserts are the mean of 2 × 1000:

PostgreSQL 16 before after MariaDB 10.11 before after
count per address (each failed login, twice) 8.87 0.18 21.64 0.32
other accounts of address (when blocking) 8.22 0.18 188.21 0.35
list of address (admin mail on block) 8.19 0.36 26.86 0.72
count of last hour (adaptive delay) 8.07 0.16 18.38 0.15
insert of a failed login 1.37 1.31 0.82 0.88

The insert cost doesn't change measurably: the differences are within run-to-run noise. I also tried (ipaddress, handled, logtime). It was at most 0.1 ms faster, on MariaDB, and that index would have to be updated whenever handled changes.

Tests

  • InstallTest::testLookupsOfFailedLoginsAreIndexed checks the indexes after an installation, on PostgreSQL and MySQL alike.
  • UpgradeTest::testFailedLoginsAreIndexed (CI) checks them after the update from 1.5.2.
  • Checked locally on MariaDB: the install script creates the indexes, and the update statements add them to a table shaped like 1.5.2's (a second run fails as expected, which CAN FAIL covers).

Unblock link from API logins (bd6f5bd)

The unblock mail's link was Uri::base() with a trailing administrator/ cut off. In the API, Uri::base() is …/api/. So an address blocked for failed API logins (#265) got a link to api/index.php?option=com_bfstop&view=tokenunblock…, where there is no unblock page. I confirmed this with a real API request through php-cgi. Uri::root() is the site's address in every application, so the link now uses that.

UnblockLinkTest builds the link through php-cgi in each application's directory. Joomla only derives its addresses from the script name outside the CLI, and PHP's built-in web server counts as CLI, so the existing fixtures couldn't show the bug. The test fails with the old code for the API and passes now. It is skipped where php-cgi isn't installed. The CI runners have it, so it runs in every integration job.

CI keeps its downloads (a50cff5)

Every integration and update job downloaded its Joomla package (tens of megabytes) from GitHub again, and the update job also downloaded BFStop 1.5.2. Both now go through the new tests/ci/fetch-verified.sh:

  • With DOWNLOAD_CACHE set, a copy there is used if its SHA-256 is the expected one. Otherwise it is downloaded again and the copy is replaced.
  • A download is retried 3 times, 15 s apart, on transient errors (timeouts, 429, 5xx). curl honours Retry-After.
  • As before, nothing that fails the checksum is written to the target file.

CI keeps ~/.cache/bfstop-ci with actions/cache (pinned, v6.1.0). The key is the Joomla version, plus the hash of previous-release.sha256 for the update. The component's CI gets the same in codeling/com_bfstop#34.

On this PR's first run, every key missed: each job downloaded its packages, and one job per key saved them. The others log "another job may be creating this cache", which is a warning, not a failure. Later runs, and other branches once this is on main, start from those copies.

Checked locally: a cache miss downloads and caches the file. A hit works with the network cut off. A corrupted copy is detected, downloaded again and repaired. A wrong checksum exits 1 and writes no file. Without DOWNLOAD_CACHE it works as before. A local server answering 503 twice and then the file made curl retry and succeed after the Retry-After delay.

The failures of the earlier run were 503/504 gateway errors on GitHub release downloads, not rate limiting. They also hit unrelated single requests from another network at the same time, and rate limiting would show up as 429 or 403.

Not changed

The link still uses the request's host unless Joomla's $live_site is set, just like Joomla's own password-reset mails. That needs a decision and is discussed separately.

Testing

Local, Joomla 5.4.10 on PostgreSQL 16: 407 tests OK, 3 skipped for environment reasons (--testsuite unit,integration). check-versions, check-workflows, php -l and xmllint pass. CI is green on all 18 checks, including the MySQL/MariaDB sites and the upgrade from 1.5.2.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AFJFMPv7CSqgJJ93QJvYfL

Every failed login counts the failed logins of its address within the
check interval (twice), a block lists them and checks which accounts
they went against, and the adaptive delay counts those of the last
hour - all without an index (only username_logtime existed), on a
table kept at up to 200000 rows.

Measured with the plugin's DatabaseHelper on 200000 rows (50000
addresses, a repeat offender), median of 50 runs, ms:

                              PostgreSQL 16    MariaDB 10.11
                              before  after    before  after
  count per address            8.87   0.18     21.64   0.32
  other accounts of address    8.22   0.18    188.21   0.35
  list of address              8.19   0.36     26.86   0.72
  count of the last hour       8.07   0.16     18.38   0.15
  insert of a failed login     1.37   1.31      0.82   0.88  (mean of 2x1000)

(ipaddress, handled, logtime) was no faster in a way that matters
(0.1 ms on MariaDB) and would have to be updated with every change of
"handled". The indexes are in both install scripts and in the 2.0.0
update (marked CAN FAIL, like username_logtime); tests check that they
exist after an installation and after the update from 1.5.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMPv7CSqgJJ93QJvYfL
The link was Uri::base() with a trailing "administrator/" cut off. In
the API, Uri::base() is .../api/, so an address blocked for failed API
logins was mailed a link to api/index.php?option=com_bfstop&..., where
there is no unblock page. Uri::root() is the site's address in every
application.

UnblockLinkTest builds the link in a script in each application's
directory run through php-cgi (skipped without it): Joomla derives its
addresses from the script name only outside the CLI, and PHP's built-in
web server counts as CLI, so the fixtures couldn't show it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMPv7CSqgJJ93QJvYfL

codeling commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

CI is red on this head (bd6f5bd) for a reason outside this PR. Nine Joomla integration and upgrade jobs failed in tests/ci/install-joomla.sh or tests/ci/upgrade-test.sh while downloading the Joomla package from GitHub releases (curl: (22) … 503/504, or curl: (56) Connection died), before any test ran. The same downloads failed outside CI at the same time.

I re-ran the failed jobs once. The first re-run to finish ("Update from the previous release (Joomla 5.4.10, mysql:8.0)") failed again with a 503 on the Joomla download. The rest are still running.

The jobs that got past the download passed:

  • Joomla 6.2.0 / PostgreSQL 17 and Joomla 6.1.4 / MariaDB 11.4: the full integration suite, including the new index check.
  • Update from 1.5.2 on MariaDB: includes the new check that the update adds the indexes.
  • Syntax, unit tests, package and language checks.

There's no fix for the outage itself. I'll keep watching the PR until all jobs are green.


Generated by Claude Code

Every integration and update job fetched its Joomla package (tens of
megabytes) and, for the update, the previous BFStop release from GitHub
again. The downloads now go through tests/ci/fetch-verified.sh, which
takes a copy from DOWNLOAD_CACHE if its SHA-256 is the expected one
(else downloads it again and replaces the copy), and retries a download
a few times on transient errors (timeouts, 429, 5xx), honouring
Retry-After. CI keeps that directory with actions/cache, per Joomla
version (and previous release, for the update).

Nothing which doesn't match the checksum is written to the target file,
as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMPv7CSqgJJ93QJvYfL
@codeling codeling changed the title Index the failed logins by address and time; unblock link to the site also after API logins Index the failed logins; unblock link to the site also after API logins; CI keeps its downloads Nov 9, 2026
@codeling
codeling merged commit 70dfe79 into main Nov 9, 2026
18 checks passed
@codeling
codeling deleted the ccr-f557f83f-uk6a4f branch November 9, 2026 19:56
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