Skip to content

Hardening proposals of issue #285 (items 2–9) - #336

Merged
codeling merged 8 commits into
mainfrom
ccr-84fdc1eb-x6t92a
Nov 21, 2026
Merged

codeling merged 8 commits into
mainfrom
ccr-84fdc1eb-x6t92a

Conversation

@codeling

@codeling codeling commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

This implements the open items of #285 that were chosen. One commit per item. The items not done here have their own issues: #337 (making database failures visible, item 1), #338 (the Login Only backstop, item 3) and #339 (the mailpit mail test, item 10).

Closes #285.

Changes

6. Response headers

  • The page shown to a blocked address now also sends Content-Security-Policy: frame-ancestors 'none' and X-Frame-Options: DENY.
  • The unblock page sends X-Frame-Options: DENY and nosniff. It gets no CSP header, because one would replace a policy the site may already send.

5. Proxy configuration

  • When a request doesn't come through the configured proxy, the warning is logged at most once an hour per address (LockHelper::due(), 64 stamp files), not on every request.
  • The proxy tab has a self-test: the admin's own request (REMOTE_ADDR, forwarding headers) and the address BFStop takes from it.
  • The header setting now warns that Client-Ip and X-Cluster-Client-Ip are only safe if the proxy overwrites them.

3. Login Only mode

  • The blocking-mode description says which logins "Login Only" covers, and recommends "Full Site" for sites with third-party logins.

7. Web server

  • HtaccessHelper::webServer() tells Apache, LiteSpeed and nginx apart. .htaccess mode is refused on nginx, and LiteSpeed gets its own warning. The .htaccess warnings only show where the file is used.
  • Self-check: a "Check .htaccess" button on the settings page (HtaccessCheckHelper):
    • It makes a probe directory next to the .htaccess file. The probe's own .htaccess uses the block section's form (<If> + Require all denied) and refuses one query.
    • It requests the probe's file over HTTP, from the site's own address, once with that query and once with another, then removes the directory.
    • It reports one of: works / ignored (AllowOverride, or not Apache) / breaks the site (500) / couldn't check, with the reason.
    • tests/ci/apache-htaccess.sh also checks the probe against a real Apache. This resolves the TODO in DisplayController.
  • nginx deny file: a new setting, nginxDenyFile, used with "Full Site" (NginxDenyFile):
    • It holds the active blocks as deny lines in a *.conf file for nginx to include.
    • It's rewritten as a whole, atomically, on each block, unblock and change of a block, on saving the settings, and by the daily maintenance.
    • Entries overlapping the allow list or a trusted proxy are left out.
    • Only a file that starts with BFStop's header is ever overwritten. nginx has to be reloaded to read it; the setting's description says how.

8. Request cost

  • In "Full Site" mode, blocked requests to the backend and the API are refused in onAfterInitialise, before routing. None of the pages a blocked address may reach is there. The site and "Login Only" still wait for the router, and the early check's queries aren't repeated after routing.

4. Password recovery while blocked

  • A blocked address may submit the recovery forms at most 10 times an hour (BlockPolicy::RecoverySubmissionsPerHour). They're counted against the newest active block, in the new columns recovery_requests/recovery_since of #__bfstop_bannedip (install SQL and the 2.0.0 update). The views stay reachable.
  • The reminder setting's description recommends a captcha for these forms.

2. User Actions Log

  • ActionLogHelper records in Joomla's User Actions Log:
    • blocks added, changed and lifted;
    • allow-list entries added, changed and removed;
    • .htaccess entries added and removed;
    • settings saved (only the names of the changed settings);
    • purges of failed logins and user-name statistics;
    • pruning and clearing BFStop's log;
    • blocks lifted through an unblock link.
  • The plugin's automatic blocks aren't recorded.
  • The component's installer registers com_bfstop in #__action_logs_extensions and ticks it under "Events To Log" when it's new there. Uninstalling removes it again.

9. Supply chain

  • release.yml attests the build provenance of the zips and SHA256SUMS with actions/attest-build-provenance v4.2.2, pinned by SHA. The package README and the release notes explain gh attestation verify.

New strings are in all 10 languages.

Tests

  • Unit: LockHelper::due().
  • Integration:
    • the proxy warning is rate-limited;
    • webServer(), the probe files, and the nginx refusal;
    • the settings self-test and the .htaccess check (with a fake server);
    • the new headers;
    • blocked backend and API requests are refused before routing, but not in Login Only mode;
    • the recovery limit (repository and request);
    • User Actions Log registration and entries, and the names of the changed settings;
    • NginxDenyFile (content, which files it may overwrite, following the block list).
  • Apache CI job: the probe against a real Apache.
  • I couldn't run PHPUnit in this environment, so CI runs the suites. The language lint, the workflow lint and php -l pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AFJFMRAm2uvNjFHsxUU4VL

- 6: the page of a blocked address sends frame-ancestors 'none' and
  X-Frame-Options: DENY (it is echoed without the template); the unblock
  page sends X-Frame-Options: DENY and nosniff (no CSP there: it would
  replace a policy the site sends already).
- 5: a request which bypassed the configured proxy is logged once an hour
  per address (LockHelper::due(), 64 stamp files keyed like the lock
  slots), not on every request; the settings show a check with the
  administrator's own request (REMOTE_ADDR, forwarding headers, the
  address BFStop uses); the header setting says Client-Ip and
  X-Cluster-Client-Ip are only safe if the proxy overwrites them.
- 3: the blocking-mode description says which logins "Login Only" covers
  and recommends "Full Site" for sites with third-party logins.
- 7: HtaccessHelper::webServer() tells Apache, LiteSpeed and nginx apart;
  .htaccess mode is refused on nginx, LiteSpeed gets a specific warning,
  and the .htaccess warnings only show where the file is used.
- 9: the release zips and sums get a build provenance attestation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMRAm2uvNjFHsxUU4VL
…tem 8)

In "Full Site" mode (with or without .htaccess), nothing routing tells can
change the answer for the backend and the API: the unblock page and the
password recovery are pages of the site. onAfterInitialise refuses those
requests already; what it found (allow list, active blocks) is reused after
routing instead of being asked again. The site and "Login Only" still wait
for the router.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMRAm2uvNjFHsxUU4VL
, item 4)

A blocked client is let through to the password recovery, and its forms
send mails (the username reminder has no limit in Joomla). Their
submissions are counted against the newest active block (new columns
recovery_requests/recovery_since of #__bfstop_bannedip, install SQL and the
2.0.0 update): at most BlockPolicy::RecoverySubmissionsPerHour (10) an
hour, then the blocked page; the views stay reachable. Fails open. The
reminder setting's description recommends a captcha for these forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMRAm2uvNjFHsxUU4VL
…, item 2)

ActionLogHelper writes to com_actionlogs (ActionlogModel::addLog(), as
Joomla's own action log plugins do) when com_bfstop is among its "Events To
Log": blocks added/changed (postSaveHook) and lifted, allow-list entries
added/changed/removed, .htaccess entries added/removed, settings saved
(names of the changed settings only), purges of failed logins and user name
statistics, pruning and clearing BFStop's log, and blocks lifted with an
unblock link. Not the plugin's automatic blocks. The component's installer
registers com_bfstop in #__action_logs_extensions and, when it is new there,
ticks it in loggable_extensions; uninstalling takes it out again. Messages
in all 10 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMRAm2uvNjFHsxUU4VL
…s (issue #285, item 7)

A toolbar button (settings.checkHtaccess, core.admin) runs
HtaccessCheckHelper: a probe directory next to the .htaccess file, whose own
.htaccess has an <If> of the block section's form with "Require all denied"
for an address no client has or the query deny=<token>
(HtaccessHelper::writeProbe()). Its file is requested over HTTP from the
site's own address with ?allow= (must be served) and ?deny= (must be
refused); the directory is removed again. Results: effective, ignored,
broken (500) or unknown with the reason. The probe is also checked against
a real Apache in tests/ci/apache-htaccess.sh. Resolves the TODO in
DisplayController.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMRAm2uvNjFHsxUU4VL
New setting nginxDenyFile (with "Full Site"): NginxDenyFile keeps the
active blocks (BlockRepository::activeAddresses(), newest first, at most
MaxBlockLines) as "deny" lines in a *.conf file for nginx to include. It is
rewritten as a whole, atomically, after a block (BlockService), an unblock
(backend and token, through UnblockHelper), a block saved by hand, a change
of the settings (the former file is emptied) and by the daily maintenance.
Entries overlapping the allow list or a trusted proxy are left out. Only a
file which starts with BFStop's header is overwritten, and only *.conf
(NginxdenyfileRule refuses the others). nginx has to be reloaded to read
it; the setting's description says how.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMRAm2uvNjFHsxUU4VL
@codeling codeling changed the title Hardening proposals of issue #285 (items 3, 5, 6, 7, 9) Hardening proposals of issue #285 (items 2–9) Nov 21, 2026
ActionLogHelper checked for Joomla\CMS\Extension\MVCFactoryServiceInterface,
which doesn't exist, so nothing reached the User Actions Log (CI:
testWhatAdministratorsDoGoesToTheUserActionsLog, and phpstan's
class.notFound). It is Joomla\CMS\MVC\Factory\MVCFactoryServiceInterface.
The unblock page sets its headers in one loop, so the baseline entry of
setHeader() shrinks to 2 instead of growing to 5.

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

The "broken" message (status 500) says the directives need Apache 2.4 or
later, not exactly 2.4. The "ignored" message no longer says that other
web servers don't read .htaccess files: nginx doesn't, OpenLiteSpeed reads
only their rewrite rules, and LiteSpeed Enterprise may not support every
directive of the block section. All 10 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFJFMRAm2uvNjFHsxUU4VL
@codeling
codeling merged commit 6982ee6 into main Nov 21, 2026
20 checks passed
@codeling
codeling deleted the ccr-84fdc1eb-x6t92a branch November 21, 2026 22:50
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.

Hardening proposals beyond the security fixes

2 participants