Skip to content

Latest commit

 

History

History
165 lines (109 loc) · 8.94 KB

security.md

File metadata and controls

165 lines (109 loc) · 8.94 KB

Security (Hornet)

pollora/hornet audits a site, scans it, and tells what to fix and how. It runs on Pollora, on a classic WordPress and on Bedrock. It reads and reports: nothing is hardened, sent or changed until you ask for it.

Version 0.13: the settings, commands, hooks and abilities can still change before 1.0.

Install

composer require pollora/hornet

On Pollora nothing else is needed: Laravel discovers the service provider. The screen is in Tools > Security, and the audit is also one line of php artisan pollora:doctor. For a classic WordPress or Bedrock, see below.

Requirements: PHP 8.3, WordPress 6.9, MySQL 8 or MariaDB 11.

Settings

php artisan vendor:publish --tag=hornet-config

The file is config/pollora/hornet.php. A config/hornet.php is not read (Hornet says so in Site Health). Everything that acts on the site is off until it is written there:

return [
    'scanner' => ['schedule' => 'daily'],
    'hardening' => ['xmlrpc' => true, 'user_enumeration' => true],
    'headers' => ['content_type_options' => true],
    'journal' => ['enabled' => true],
];

Classic WordPress and Bedrock

Without Laravel, nothing loads the package for you. After composer require pollora/hornet, copy its loader to the must-use plugins:

cp vendor/pollora/hornet/stubs/pollora-hornet.php wp-content/mu-plugins/   # Bedrock: web/app/mu-plugins/

Composer's autoloader must be loaded before it. Bedrock does that already. On a classic install, require it in wp-config.php:

require __DIR__ . '/vendor/autoload.php';

Settings are a constant, defined before WordPress loads: in wp-config.php, or in a Bedrock configuration file such as config/environments/production.php. The keys are the same as in the Pollora file:

define('HORNET_CONFIG', [
    'scanner' => ['schedule' => 'daily'],
    'hardening' => ['xmlrpc' => true],
]);

If a rule ever locks you out, define('HORNET_DISABLED', true); switches everything off. It works on Pollora too.

What it looks at

  • Configuration and accounts: keys and salts, debug mode, HTTPS, file editor, versions, XML-RPC, user enumeration, open registration, application passwords, new and dormant administrators, updates and inactive plugins and themes.
  • Pollora only: APP_KEY, APP_DEBUG in production, Debugbar forced on.
  • Scan: core, plugin and theme files, plugins closed or left behind on WordPress.org, suspicious files, disguised JavaScript in the database, files the site gives away, security headers, and, opt-in, known vulnerabilities.

A score from 0 to 100 sums it up, with what to fix first. The README describes each check.

Tools > Site Health > Info also has a Hornet section: the version, the date of the last scan, what is turned on and the score. The last two are private: "Copy site info to clipboard" leaves them out.

Closing the REST API to visitors

'hardening' => [
    'restrict_rest_api' => true,
    'rest_api_allow' => ['wp/v2/posts', 'wp/v2/pages'],   // added to the defaults
],

Visitors who are not logged in get a 401, unknown routes included. Logged-in users, application passwords included, keep the whole API.

Test your front end before you turn it on: whatever it calls without a login stops working until it is listed. That includes a payment webhook or a licence server that checks its own key without logging a user in. A headless front end usually reads wp/v2, which is not open by default.

Open by default: oembed/1.0/embed, contact-form-7/v1/contact-forms, wc/store and, with pollora/headless, headless/v1. With wp/v2/posts open, turn user_enumeration on too, or ?_embed still gives the author of each post. The README has the exact rules.

Closed plugins and Composer packages

WordPress says nothing when a plugin you run is closed on WordPress.org. The scan reports it (high), and also a plugin with no release there for two years or more (low). For this it sends the folder name of each plugin to api.wordpress.org; 'disabled_checks' => ['abandoned-plugins'] stops it.

Known vulnerabilities of the project's Composer packages are a second opt-in:

'vulnerabilities' => ['enabled' => true, 'composer' => true],

enabled alone covers plugins and themes only, and composer alone does nothing. With both, the name and version of each package installed from packagist.org, development packages included, are sent to OSV (api.osv.dev). Packages from anywhere else are counted, never named.

Two-factor in the journal

With the journal on and the Two-Factor plugin, it records a second factor passed or refused, and a method turned on or off. A code or a key is never read.

A login.success marked second_factor: pending only means the password was right: login.second_factor_passed says the visitor got in. A refused second factor is login.second_factor_failed, no longer login.failed: update any alert or filter that counts login.failed.

Content-Security-Policy reports

From Hornet 0.13, the reports of your policy can be collected on the site itself:

'headers' => [
    'csp' => ['policy' => "default-src 'self'", 'collect_reports' => true],
],

It is off until you turn it on, because it opens an address anybody can write to. Only counts are kept, by directive and refused source (a keyword, a scheme or an origin), never a path, a query string or an IP address, for 30 days by default (report_retention_days, 1 to 90). Chromium, Firefox and WebKit are read, each in its own way of writing a report (from Hornet 0.13.1 for WebKit, the engine of Safari: earlier versions refused its reports). It cannot be combined with report_uri. Read them with wp hornet csp list, or in the CSP reports tab of the screen. The README gives the limits.

Notifications

Hornet can tell you when the audit finds something new, by mail, Slack, Teams, Discord, Telegram, ntfy, a signed webhook or PagerDuty. Nothing is sent until you list a channel:

'notifications' => [
    'schedule' => 'daily',   // off, hourly, twicedaily, daily
    'channels' => [
        'team' => ['type' => 'mail', 'to' => ['team@example.com'], 'min_severity' => 'critical', 'digest' => 'weekly'],
        'on-call' => ['type' => 'pagerduty', 'routing_key' => ['env' => 'HORNET_PAGERDUTY_ROUTING_KEY']],
    ],
],

From Hornet 0.12:

  • Periodic summary. A channel with 'digest' => 'daily' or 'weekly' also gets, with the first scheduled audit of the day or week, every open finding, what is new, what now passes and how many checks could not be verified. It is off by default.
  • PagerDuty. One incident per finding and site, for high and critical unless the channel sets its min_severity. routing_key is the key of an Events API v2 integration; add 'eu' => true for the EU region. Hornet does not resolve incidents: resolve them in PagerDuty. This channel takes no summary.

The README has the options of each channel, the cooldown, the rate limit and the retries.

Multisite

The screen is in the network administration, under Settings, for super administrators only. The files and the scan are shared by every site; the audit is that of one site.

From Hornet 0.11, the Journal tab shows the journals of all the sites together, newest first, with the site of each line and a site filter. Each site's own journal settings and retention apply: a site whose journal is off is left out. It reads up to 100 sites together and 1,000 events deep, and says when it stops or cannot read a site. The README has the scope of each feature.

The scan needs the scheduled tasks

Scan now and a scheduled scan run in WordPress's scheduled tasks. Pollora sets DISABLE_WP_CRON, so the server runs them (see Schedule Events):

* * * * * curl -s https://example.com/cms/wp-cron.php

Without it, Scan now waits, and the screen says why.

Command line

wp hornet status                 # the audit
wp hornet scan                   # the scan, in one go
wp hornet server-config nginx    # rules for the web server (apache, htaccess too); printed, never written
wp hornet unlock --all           # lift every login lock
wp hornet notify test team       # a test message to one channel
wp hornet csp list               # the counts of the policy reports
wp hornet journal list --by=1    # what one account did (--by from Hornet 0.13.1; --user is WP-CLI's own)

Limits

Translations are machine-made. Multisite was tried on sub-directory and sub-domain networks, not on a large one. Hornet is not a firewall, nor a signature-based malware scanner.