Repository navigation
Closed
Labels
Description
This came out of a review of the plugin and component at 2501aca (bfstop) / cfe9835 (com_bfstop). None of these items is a security problem; they make the code harder to read, test or change. Line numbers refer to those commits. The security fixes are in the stacked PRs #275–#282 and codeling/com_bfstop#41–#45, and the deprecations are in #274.
| # | Where | Smell | Suggested change |
|---|---|---|---|
| C1 | src/Helper/TokenHelper.php:15-49 |
The fallback generator getRandToken() is dead code: random_int() throws in exactly the cases where random_bytes() does. sha1() of 64 random bytes is also an indirect way to get 160 bits. |
return bin2hex(random_bytes(20)); and delete the fallback. The TokenHelperTest expectations (40 hex characters) stay the same. |
| C2 | src/Helper/DatabaseHelper.php:25-57, NotifierHelper::$ONE_DAY |
Configuration as public static $…: mutable globals that any code can change at runtime. |
public const (keep the names, or rename to the UpperCamel style the other constants use). |
| C3 | src/Extension/Bfstop.php:53-63, DatabaseHelper.php:916-928 |
Orphaned docblocks: two docblocks are stacked, and the first one describes something else (default settings / savePluginSetting). |
Move each to the member it describes. |
| C4 | com_bfstop admin/src/Helper/LogHelper.php:27 |
new LoggerHelper($loglevel) ignores the logMaxSize setting, so component-side logging rotates at the default 5 MB whatever is configured. |
Pass LoggerHelper::maxBytesFromMegabytes($params->get('logMaxSize', …)) as the plugin does. |
| C5 | com_bfstop SettingsController::testNotify() (lines 101-103) |
The message type is $result ? 'notice' : 'error', but $result can be an error string, so failures are shown as notices. |
$success ? 'message' : 'error'. |
| C6 | com_bfstop admin/src/Model/LogModel.php:36, 75, 81 |
Ordering is "currently unused". Every page and getTotal() read the log file from the start, and the file name is hard-coded instead of LoggerHelper::LogFile. The rotated generation (.1.log.php) is never shown. |
Read the file once (or from the end with SplFileObject), support the date ordering, and use LoggerHelper::getLogFiles(). |
| C7 | com_bfstop BlocklistModel, HtblocklistModel |
getItems()/getTotal() overrides that only call parent. |
Delete them. |
| C8 | com_bfstop controllers | Methods without visibility (function unblock(), function purge(), function display()), and a mix of Factory::getApplication() and $this->app. |
Add public, and use $this->app / $this->input throughout. |
| C9 | com_bfstop views (Tokenunblock, Ipinfo, the lists) |
Undeclared dynamic properties ($this->token, $this->message, $this->ipInfo, …). They only work because Joomla's AbstractView has #[AllowDynamicProperties]. |
Declare them as protected properties with types. |
| C10 | Bfstop.php:650, :845 |
empty($ipAddress) || $ipAddress === '' is redundant. onUserLogin() has no empty-address check at all, and records a known IP ''. |
One $ipAddress === '' check in both handlers. |
| C11 | NotifierHelper.php:120 |
$mail->Send(): the wrong case for PHPMailer's send(). |
Fixed in #282. |
| C12 | com_bfstop DisplayController::checkWhetherPluginInstalled() |
Returns null on the exception path (falsy, so the display stops with only a DB-error message). The raw SQL uses name='…', while the plugin uses type/folder/element. |
Return false explicitly, and use the query builder with type/folder/element (see A7 in the architecture issue). |
| C13 | everywhere | Allman braces and tabs, while Joomla uses PSR-12. There is no static analysis in CI: phpstan at level 5 would have found C5, C10 and C12. | Add phpstan (with the Joomla stubs) to the CI lint job, with a baseline. Whether to switch the coding style is your decision. |
| C14 | DatabaseHelper::purgeOldEntries() |
Deleting expired blocks after deleteOld (4 weeks by default) also deletes the history that maxBlocksBefore/progressive escalation counts. A slow attacker, one block every 5 weeks, never escalates. |
Keep a compact per-address offence counter (address, count, last offence) that is not purged with the blocks, or purge blocks only after the escalation window. |
| C15 | HtaccessHelper (before #275), Bfstop::block() |
Copied BFLP code with getHeader()/getFooter()/prefix-based line handling. #275 replaces most of it. What is left (extract()/insert() with the marker state machine) is still hard to follow. |
Parse the file into before / section / after once, and write it back once. |
| C16 | DatabaseHelper |
Every method catches \Exception and returns a different neutral value (0, [], false, true, ''). It also misses \Error subclasses (TypeError, ValueError). |
See A6 in the architecture issue; at least catch \Throwable where the intent is "never break the request". |
Most of these are mechanical. C1, C2, C3, C5, C7, C8, C10 and C11 could go into one small PR; C6, C13, C14 and C15 each deserve their own.
Activity
Merge pull request #317 (code smells)
Code smells of issue #283 (C7, C8, C16): visibility, a pass-through o…
Keep the escalation history when old blocks are purged (issue #283, C14)
HtaccessHelper: read the file once into before/section/after and writ…
Merge pull request #325 (fix code smells)
codeling commentedon Nov 20, 2026
All sixteen items are done in
main; closing. I checked each one against the code onmain(f274b23).getToken()isbin2hex(random_bytes(20)), fallback gone (#317)NotifierHelper::OneDayand the repositories' settings are constants (#317)LogHelperusesLoggerHelper::fromSettings(), which applieslogMaxSizetestNotify()uses$success ? 'message' : 'error'(#317)LogModelreads the file once, viaLoggerHelper::getLogFiles(), with ordering (#317)BlocklistModel::getItems()is removed (#323); theHtblocklistModeloverrides do real work and staypublicon every controller, view and table method;$this->appthroughout (#317, #323)$ipAddress === ''check in both handlers (#317)send()(#282)checkWhetherPluginInstalled()returnsfalseand uses the query builder with type/folder/element#__bfstop_offence(kept a year, at most 10000 addresses), andcountPrevious()adds it, so a slow attacker still escalates (#324)HtaccessHelperreads the file once into before / section / after and writes it back once;extract()andinsert()are gone (#325)catchin the library, plugin and component is\Throwable(#317, #323)Two decisions came out of C14 and C15:
BlockRepository::OffenceMemoryDays), not a setting.Generated by Claude Code