Skip to content

Code smells in plugin and component #283

Closed

Description

@codeling

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

  1. codeling commented on Nov 20, 2026

    @codeling
    OwnerAuthor

    All sixteen items are done in main; closing. I checked each one against the code on main (f274b23).

    # Status
    C1 getToken() is bin2hex(random_bytes(20)), fallback gone (#317)
    C2 NotifierHelper::OneDay and the repositories' settings are constants (#317)
    C3 No stacked docblocks left
    C4 The component's LogHelper uses LoggerHelper::fromSettings(), which applies logMaxSize
    C5 testNotify() uses $success ? 'message' : 'error' (#317)
    C6 LogModel reads the file once, via LoggerHelper::getLogFiles(), with ordering (#317)
    C7 The pass-through BlocklistModel::getItems() is removed (#323); the HtblocklistModel overrides do real work and stay
    C8 public on every controller, view and table method; $this->app throughout (#317, #323)
    C9 The views declare typed properties
    C10 One $ipAddress === '' check in both handlers (#317)
    C11 send() (#282)
    C12 checkWhetherPluginInstalled() returns false and uses the query builder with type/folder/element
    C13 phpstan level 5 with a baseline in CI (#319); the baseline now has 61 entries, two fewer after #325
    C14 The purge folds the blocks it deletes into #__bfstop_offence (kept a year, at most 10000 addresses), and countPrevious() adds it, so a slow attacker still escalates (#324)
    C15 HtaccessHelper reads the file once into before / section / after and writes it back once; extract() and insert() are gone (#325)
    C16 Every catch in the library, plugin and component is \Throwable (#317, #323)

    Two decisions came out of C14 and C15:

    • C14 memory window: the issue left it open. An address is forgotten a year after its latest block began. It is a constant (BlockRepository::OffenceMemoryDays), not a setting.
    • C15 several sections: a file with several BFStop sections now gets one, with all their addresses, where it used to be written once per section. Everything else is byte for byte unchanged on the 126 cases I compared.

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions