array( 'title' => __('The site is not using HTTPS', 'all-in-one-wp-content-security'), 'explanation' => __('The WordPress and site address settings use http://, so logins, cookies and form data travel unencrypted.', 'all-in-one-wp-content-security'), 'impact' => __('Passwords and session cookies can be intercepted on public networks, and browsers mark the site as "Not secure".', 'all-in-one-wp-content-security'), 'remediation' => __('Install a TLS certificate (most hosts offer a free Let\'s Encrypt certificate) and switch the site addresses to https://.', 'all-in-one-wp-content-security'), 'steps' => array( __('Enable a certificate for the domain in your hosting control panel.', 'all-in-one-wp-content-security'), __('Use Tools → Site Health → "Update your site to use HTTPS", or change both addresses in Settings → General to https://.', 'all-in-one-wp-content-security'), __('Redirect http:// to https:// at the server level.', 'all-in-one-wp-content-security'), ), 'docs' => array(self::doc(__('HTTPS for WordPress', 'all-in-one-wp-content-security'), 'https://developer.wordpress.org/advanced-administration/security/https/')), 'permission' => __('Hosting control panel and WordPress administrator', 'all-in-one-wp-content-security'), ), 'server.tls_certificate' => array( 'title' => __('TLS certificate problem', 'all-in-one-wp-content-security'), 'explanation' => __('The certificate presented for the site\'s domain is expired, expires soon, is not trusted or does not match the domain.', 'all-in-one-wp-content-security'), 'impact' => __('Visitors get a full-page browser warning, and automated services (payments, APIs) stop connecting to the site.', 'all-in-one-wp-content-security'), 'remediation' => __('Renew or reconfigure the certificate in the hosting control panel; make sure automatic renewal works.', 'all-in-one-wp-content-security'), 'steps' => array( __('Renew the certificate (or re-issue it for the correct domain names).', 'all-in-one-wp-content-security'), __('If your host renews Let\'s Encrypt certificates automatically, ask why renewal failed (DNS, CDN or redirect issues are typical).', 'all-in-one-wp-content-security'), __('Note: this check connects from the server itself; if the site is behind a CDN, the certificate visitors see may differ.', 'all-in-one-wp-content-security'), ), 'permission' => __('Hosting control panel or server administrator', 'all-in-one-wp-content-security'), ), ); } public function run($context) { $findings = array(); $home = home_url('/'); if (!wp_is_using_https()) { // Test HTTPS for real (wp_is_https_supported() reports true before its detection has run) $probe = AOWPCS_Loopback::request(set_url_scheme($home, 'https'), array('cache' => false)); $supported = $probe['error'] === '' && $probe['status'] > 0 && $probe['status'] < 500; $production = AOWPCS_Plugin::is_production(); $findings[] = $this->issue('server.https_missing', $production ? 'high' : 'low', 'https', $supported ? __('HTTPS already works for this domain, but the site addresses still use http://.', 'all-in-one-wp-content-security') : __('The site addresses use http://.', 'all-in-one-wp-content-security'), array( 'detected' => $home, 'expected' => 'https://', 'evidence' => array(__('Site address', 'all-in-one-wp-content-security') => $home, __('WordPress address', 'all-in-one-wp-content-security') => site_url('/'), __('HTTPS available', 'all-in-one-wp-content-security') => $supported ? __('yes', 'all-in-one-wp-content-security') : __('not detected', 'all-in-one-wp-content-security')), )); $findings[] = $this->unknown('server.tls_certificate', __('The site does not use HTTPS.', 'all-in-one-wp-content-security')); return $findings; } $host = wp_parse_url($home, PHP_URL_HOST); $port = wp_parse_url($home, PHP_URL_PORT) ?: 443; if (!function_exists('openssl_x509_parse') || !function_exists('stream_socket_client')) { $findings[] = $this->unknown('server.tls_certificate', __('The PHP OpenSSL extension is not available.', 'all-in-one-wp-content-security')); return $findings; } $result = self::certificate($host, $port, true); if (is_wp_error($result)) { // Distinguish an untrusted certificate from a network problem $insecure = self::certificate($host, $port, false); if (is_wp_error($insecure)) { /* translators: 1: host, 2: port, 3: error */ $findings[] = $this->unknown('server.tls_certificate', sprintf(__('Could not connect to %1$s:%2$d from the server (%3$s).', 'all-in-one-wp-content-security'), $host, $port, $insecure->get_error_message())); return $findings; } /* translators: %s: host */ $findings[] = $this->issue('server.tls_certificate', 'high', $host, sprintf(__('The certificate for %s is not trusted or does not match the domain.', 'all-in-one-wp-content-security'), $host), array( 'confidence' => 'likely', 'detected' => $result->get_error_message(), 'expected' => __('A valid certificate issued for the domain by a trusted authority', 'all-in-one-wp-content-security'), 'evidence' => self::evidence($insecure), )); return $findings; } $days = (int) floor(($result['valid_to'] - time()) / DAY_IN_SECONDS); $evidence = self::evidence($result); if ($days < 0) { /* translators: %s: value */ $findings[] = $this->issue('server.tls_certificate', 'critical', $host, sprintf(__('The certificate for %1$s expired %2$d days ago.', 'all-in-one-wp-content-security'), $host, abs($days)), array('detected' => sprintf(__('Expired on %s', 'all-in-one-wp-content-security'), $evidence[__('Valid until', 'all-in-one-wp-content-security')]), 'evidence' => $evidence)); } elseif ($days <= 3) { /* translators: Placeholder is a number or value shown in the message */ $findings[] = $this->issue('server.tls_certificate', 'high', $host, sprintf(__('The certificate for %1$s expires in %2$d days.', 'all-in-one-wp-content-security'), $host, $days), array('detected' => sprintf(_n('%d day left', '%d days left', $days, 'all-in-one-wp-content-security'), $days), 'expected' => __('Renewed well before expiry', 'all-in-one-wp-content-security'), 'evidence' => $evidence)); } elseif ($days <= 14) { /* translators: Placeholder is a number or value shown in the message */ $findings[] = $this->issue('server.tls_certificate', 'medium', $host, sprintf(__('The certificate for %1$s expires in %2$d days.', 'all-in-one-wp-content-security'), $host, $days), array('detected' => sprintf(_n('%d day left', '%d days left', $days, 'all-in-one-wp-content-security'), $days), 'expected' => __('Renewed well before expiry', 'all-in-one-wp-content-security'), 'evidence' => $evidence)); } else { /* translators: 1: days, 2: value */ $findings[] = $this->pass('server.tls_certificate', sprintf(__('The certificate is valid for %1$d more days (until %2$s).', 'all-in-one-wp-content-security'), $days, $evidence[__('Valid until', 'all-in-one-wp-content-security')]), $evidence); } AOWPCS_Settings::set_state('tls_certificate', array('host' => $host, 'valid_to' => $result['valid_to'], 'issuer' => $result['issuer'], 'checked' => AOWPCS_Plugin::now())); return $findings; } /** * Certificate details for host:port. With $verify the chain and host name are validated. */ public static function certificate($host, $port, $verify) { $context = stream_context_create(array('ssl' => array( 'capture_peer_cert' => true, 'verify_peer' => $verify, 'verify_peer_name' => $verify, 'allow_self_signed' => !$verify, 'peer_name' => $host, 'SNI_enabled' => true, 'cafile' => ABSPATH . WPINC . '/certificates/ca-bundle.crt', ))); $errno = 0; $errstr = ''; $client = @stream_socket_client('ssl://' . $host . ':' . $port, $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context); if (!$client) { $error = error_get_last(); $message = $errstr !== '' ? $errstr : ($error ? $error['message'] : __('connection failed', 'all-in-one-wp-content-security')); return new WP_Error('aowpcs_tls', preg_replace('/^stream_socket_client\(\):\s*/', '', $message)); } $params = stream_context_get_params($client); fclose($client); if (empty($params['options']['ssl']['peer_certificate'])) { return new WP_Error('aowpcs_tls', __('No certificate was presented.', 'all-in-one-wp-content-security')); } $cert = openssl_x509_parse($params['options']['ssl']['peer_certificate']); if (!is_array($cert)) { return new WP_Error('aowpcs_tls', __('The certificate could not be read.', 'all-in-one-wp-content-security')); } $names = array(); if (!empty($cert['extensions']['subjectAltName'])) { foreach (explode(',', $cert['extensions']['subjectAltName']) as $name) { $names[] = trim(str_replace('DNS:', '', $name)); } } return array( 'subject' => isset($cert['subject']['CN']) ? $cert['subject']['CN'] : '', 'issuer' => isset($cert['issuer']['O']) ? $cert['issuer']['O'] : (isset($cert['issuer']['CN']) ? $cert['issuer']['CN'] : ''), 'valid_from' => (int) $cert['validFrom_time_t'], 'valid_to' => (int) $cert['validTo_time_t'], 'names' => array_slice($names, 0, 10), ); } private static function evidence($cert) { return array( __('Subject', 'all-in-one-wp-content-security') => $cert['subject'], __('Issuer', 'all-in-one-wp-content-security') => $cert['issuer'], __('Valid from', 'all-in-one-wp-content-security') => wp_date(get_option('date_format'), $cert['valid_from']), __('Valid until', 'all-in-one-wp-content-security') => wp_date(get_option('date_format'), $cert['valid_to']), __('Names', 'all-in-one-wp-content-security') => $cert['names'], ); } } /** * HTTP security headers and CORS, as actually served for the home page */ class AOWPCS_Check_Server_Headers extends AOWPCS_Check { public function id() { return 'server.headers'; } public function category() { return 'server'; } public function cost() { return 'network'; } public function needs_loopback() { return true; } public function rules() { $headers_doc = self::doc(__('OWASP HTTP headers cheat sheet', 'all-in-one-wp-content-security'), 'https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html'); $manager = __('Firewall & Protection → Security headers can send this header for you (PHP, works on every server) after showing exactly what will change.', 'all-in-one-wp-content-security'); $panel = __('WordPress administrator (header manager) or web server configuration', 'all-in-one-wp-content-security'); return array( 'server.header_hsts' => array( 'title' => __('HTTP Strict Transport Security (HSTS) is not set', 'all-in-one-wp-content-security'), 'kind' => 'hardening', 'explanation' => __('The Strict-Transport-Security header tells browsers to only ever use HTTPS for the site.', 'all-in-one-wp-content-security'), 'impact' => __('Without it, the first request a visitor makes over http:// can be intercepted and downgraded on hostile networks. This is a missing hardening measure, not an exploitable vulnerability.', 'all-in-one-wp-content-security'), 'remediation' => __('Enable HSTS, starting with a short max-age; only add includeSubDomains when every subdomain supports HTTPS.', 'all-in-one-wp-content-security'), 'steps' => array( $manager, __('Start with the test value (5 minutes), check the site, then raise it to one year.', 'all-in-one-wp-content-security'), __('HSTS is remembered by browsers: do not enable includeSubDomains unless all subdomains work over HTTPS.', 'all-in-one-wp-content-security'), ), 'docs' => array(self::doc('Strict-Transport-Security (MDN)', 'https://developer.mozilla.org/docs/Web/HTTP/Headers/Strict-Transport-Security'), $headers_doc), 'permission' => $panel, 'fix' => 'header_hsts', ), 'server.header_csp' => array( 'title' => __('No Content Security Policy is set', 'all-in-one-wp-content-security'), 'kind' => 'hardening', 'explanation' => __('A Content-Security-Policy limits where scripts, frames and other resources may be loaded from, which reduces the impact of cross-site scripting.', 'all-in-one-wp-content-security'), 'impact' => __('A missing policy is common and not a vulnerability by itself. A strict policy can break themes and plugins, so it must be introduced carefully (report-only first).', 'all-in-one-wp-content-security'), 'remediation' => __('Start with a minimal policy in report-only mode and tighten it gradually.', 'all-in-one-wp-content-security'), 'steps' => array( __('Firewall & Protection → Security headers: enable the Content-Security-Policy in "report-only" mode with the suggested minimal policy (object-src \'none\'; base-uri \'self\'; frame-ancestors \'self\').', 'all-in-one-wp-content-security'), __('Use "Check compatibility" to see which external resources your home page loads.', 'all-in-one-wp-content-security'), __('Only switch to enforcing mode when the browser console shows no violations on your important pages.', 'all-in-one-wp-content-security'), ), 'docs' => array(self::doc('Content-Security-Policy (MDN)', 'https://developer.mozilla.org/docs/Web/HTTP/CSP'), $headers_doc), 'permission' => $panel, ), 'server.header_nosniff' => array( 'title' => __('X-Content-Type-Options is not set', 'all-in-one-wp-content-security'), 'kind' => 'hardening', 'explanation' => __('"X-Content-Type-Options: nosniff" stops browsers from guessing the type of a file, so an uploaded text file cannot be run as a script.', 'all-in-one-wp-content-security'), 'impact' => __('Low: a missing hardening header. It is safe to enable on practically every site.', 'all-in-one-wp-content-security'), 'remediation' => __('Send "X-Content-Type-Options: nosniff".', 'all-in-one-wp-content-security'), 'steps' => array($manager), 'docs' => array(self::doc('X-Content-Type-Options (MDN)', 'https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Content-Type-Options')), 'permission' => $panel, 'fix' => 'headers_basic', ), 'server.header_referrer' => array( 'title' => __('No Referrer-Policy is set', 'all-in-one-wp-content-security'), 'kind' => 'informational', 'explanation' => __('Referrer-Policy controls how much of your URLs is sent to other sites when visitors follow links.', 'all-in-one-wp-content-security'), 'impact' => __('Informational: current browsers already default to "strict-origin-when-cross-origin". Setting it explicitly also covers older browsers.', 'all-in-one-wp-content-security'), 'remediation' => __('Send "Referrer-Policy: strict-origin-when-cross-origin".', 'all-in-one-wp-content-security'), 'steps' => array($manager), 'docs' => array(self::doc('Referrer-Policy (MDN)', 'https://developer.mozilla.org/docs/Web/HTTP/Headers/Referrer-Policy')), 'permission' => $panel, 'fix' => 'headers_basic', ), 'server.header_clickjacking' => array( 'title' => __('Pages can be embedded by other sites (clickjacking protection missing)', 'all-in-one-wp-content-security'), 'kind' => 'hardening', 'explanation' => __('Neither X-Frame-Options nor the CSP frame-ancestors directive is set for the front end, so any site can show your pages in a frame. WordPress already protects the login page and the dashboard.', 'all-in-one-wp-content-security'), 'impact' => __('An attacker can overlay your page in a frame to trick visitors into clicking buttons (for example on forms or checkouts). Sites that must be embedded elsewhere should allow those origins explicitly.', 'all-in-one-wp-content-security'), 'remediation' => __('Send "X-Frame-Options: SAMEORIGIN" (or a CSP frame-ancestors directive).', 'all-in-one-wp-content-security'), 'steps' => array($manager, __('If partners embed your pages, use a CSP frame-ancestors directive listing them instead.', 'all-in-one-wp-content-security')), 'docs' => array(self::doc('X-Frame-Options (MDN)', 'https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Frame-Options')), 'permission' => $panel, 'fix' => 'headers_basic', ), 'server.header_invalid' => array( 'title' => __('A security header is malformed or obsolete', 'all-in-one-wp-content-security'), 'kind' => 'misconfiguration', 'explanation' => __('A security header is sent with a value browsers cannot parse (so it is ignored), or an obsolete header is still sent.', 'all-in-one-wp-content-security'), 'impact' => __('Malformed headers give a false sense of protection. "X-XSS-Protection: 1; mode=block" can even introduce information leaks in old browsers and is ignored by current ones.', 'all-in-one-wp-content-security'), 'remediation' => __('Correct or remove the header where it is set (server configuration, .htaccess, another plugin or the CDN).', 'all-in-one-wp-content-security'), 'steps' => array( __('Find where the header is set: .htaccess (look for "Header set"), Nginx configuration, a plugin, or your CDN dashboard.', 'all-in-one-wp-content-security'), __('Fix the syntax shown in the evidence, or remove obsolete headers (X-XSS-Protection, Expect-CT, Feature-Policy).', 'all-in-one-wp-content-security'), ), 'docs' => array($headers_doc), 'permission' => __('Web server configuration, plugin settings or CDN dashboard', 'all-in-one-wp-content-security'), ), 'server.cors_misconfigured' => array( 'title' => __('Cross-origin resource sharing (CORS) is misconfigured', 'all-in-one-wp-content-security'), 'kind' => 'misconfiguration', 'explanation' => __('The Access-Control-Allow-Origin header of the home page is invalid, or it echoes any origin together with Access-Control-Allow-Credentials: true. (WordPress\' own REST API reflects origins by design and relies on nonces; it is not tested here.)', 'all-in-one-wp-content-security'), 'impact' => __('Echoing arbitrary origins with credentials lets any website read pages as the logged-in visitor. An invalid value breaks legitimate cross-origin requests.', 'all-in-one-wp-content-security'), 'remediation' => __('Only allow the specific origins that need access, or remove the header.', 'all-in-one-wp-content-security'), 'steps' => array(__('Find where Access-Control-Allow-Origin is set (.htaccess, server configuration, a plugin or CDN) and replace it with a fixed list of trusted origins, or remove it.', 'all-in-one-wp-content-security')), 'docs' => array(self::doc('CORS (MDN)', 'https://developer.mozilla.org/docs/Web/HTTP/CORS')), 'permission' => __('Web server configuration, plugin settings or CDN dashboard', 'all-in-one-wp-content-security'), ), 'server.version_disclosure' => array( 'title' => __('Server software versions are disclosed in headers', 'all-in-one-wp-content-security'), 'kind' => 'informational', 'explanation' => __('The Server or X-Powered-By header includes exact version numbers.', 'all-in-one-wp-content-security'), 'impact' => __('Informational: it makes it easier to target known issues of those versions. Keeping the software updated matters far more.', 'all-in-one-wp-content-security'), 'remediation' => __('Optionally hide versions: ServerTokens Prod (Apache), server_tokens off (Nginx), expose_php = Off (PHP).', 'all-in-one-wp-content-security'), 'steps' => array(__('Ask your host or change the server configuration as described; these settings cannot be changed from WordPress.', 'all-in-one-wp-content-security')), 'permission' => __('Server administrator', 'all-in-one-wp-content-security'), ), ); } /** * Validation problems of a header value ('' when fine) */ public static function header_problem($name, $value) { switch ($name) { case 'permissions-policy': foreach (array_map('trim', explode(',', $value)) as $directive) { if ($directive === '') { continue; } if (!preg_match('/^[a-z0-9-]+=(\*|\(\s*(self|\*|"[^"]+"|\s)*\s*\)|self)$/i', $directive)) { /* translators: %s: directive */ return sprintf(__('Invalid Permissions-Policy directive "%s" (the whole header is ignored by browsers). Use the form feature=(self) or feature=().', 'all-in-one-wp-content-security'), $directive); } } return ''; case 'access-control-allow-origin': $value = trim($value); if ($value === '*' || $value === 'null' || preg_match('#^https?://[a-z0-9.\-]+(:\d+)?$#i', $value)) { return ''; } /* translators: %s: value */ return sprintf(__('"%s" is not a valid origin, so cross-origin requests to the site fail.', 'all-in-one-wp-content-security'), $value); case 'x-xss-protection': return trim($value) !== '0' ? __('X-XSS-Protection is obsolete; current browsers ignore it and old ones can leak information. Remove it or set it to 0.', 'all-in-one-wp-content-security') : ''; case 'expect-ct': return __('Expect-CT is obsolete and ignored by browsers. Remove it.', 'all-in-one-wp-content-security'); case 'feature-policy': return __('Feature-Policy was replaced by Permissions-Policy. Remove it.', 'all-in-one-wp-content-security'); } return ''; } public function run($context) { $findings = array(); $response = AOWPCS_Loopback::request(home_url('/'), array('redirects' => 3, 'cache' => false)); if ($response['error'] !== '' || $response['status'] >= 500) { /* translators: %d: response status */ return $this->all_unknown($response['error'] !== '' ? $response['error'] : sprintf(__('The home page returned HTTP %d.', 'all-in-one-wp-content-security'), $response['status'])); } $h = $response['headers']; $https = wp_is_using_https(); $note = array(__('Checked URL', 'all-in-one-wp-content-security') => home_url('/'), __('Note', 'all-in-one-wp-content-security') => __('Headers as returned to the server itself; a CDN in front of the site may add or remove headers.', 'all-in-one-wp-content-security')); // HSTS if ($https) { if (empty($h['strict-transport-security'])) { $findings[] = $this->issue('server.header_hsts', 'low', 'strict-transport-security', __('The Strict-Transport-Security header is missing.', 'all-in-one-wp-content-security'), array('detected' => __('missing', 'all-in-one-wp-content-security'), 'expected' => 'max-age=31536000', 'evidence' => $note)); } else { $findings[] = $this->pass('server.header_hsts', 'Strict-Transport-Security: ' . $h['strict-transport-security']); } } else { $findings[] = $this->unknown('server.header_hsts', __('HSTS only applies to sites served over HTTPS.', 'all-in-one-wp-content-security')); } // CSP $csp = isset($h['content-security-policy']) ? $h['content-security-policy'] : ''; $csp_ro = isset($h['content-security-policy-report-only']) ? $h['content-security-policy-report-only'] : ''; if ($csp === '' && $csp_ro === '') { $findings[] = $this->issue('server.header_csp', 'low', 'content-security-policy', __('No Content-Security-Policy header is sent.', 'all-in-one-wp-content-security'), array('detected' => __('missing', 'all-in-one-wp-content-security'), 'expected' => __('A policy (report-only to start with)', 'all-in-one-wp-content-security'), 'evidence' => $note)); } else { /* translators: %s: csp ro */ $summary = $csp !== '' ? sprintf(__('Content-Security-Policy is enforced: %s', 'all-in-one-wp-content-security'), $csp) : sprintf(__('Content-Security-Policy is in report-only mode: %s', 'all-in-one-wp-content-security'), $csp_ro); $findings[] = $this->pass('server.header_csp', $summary); } // nosniff if (empty($h['x-content-type-options']) || strtolower(trim($h['x-content-type-options'])) !== 'nosniff') { $findings[] = $this->issue('server.header_nosniff', 'low', 'x-content-type-options', __('"X-Content-Type-Options: nosniff" is not sent.', 'all-in-one-wp-content-security'), array('detected' => isset($h['x-content-type-options']) ? $h['x-content-type-options'] : __('missing', 'all-in-one-wp-content-security'), 'expected' => 'nosniff', 'evidence' => $note)); } // Referrer-Policy if (empty($h['referrer-policy'])) { $findings[] = $this->issue('server.header_referrer', 'low', 'referrer-policy', __('No Referrer-Policy header is sent (browsers default to strict-origin-when-cross-origin).', 'all-in-one-wp-content-security'), array('kind' => 'informational', 'detected' => __('missing', 'all-in-one-wp-content-security'), 'expected' => 'strict-origin-when-cross-origin', 'evidence' => $note)); } // Clickjacking $policy = $csp !== '' ? $csp : ''; if (empty($h['x-frame-options']) && stripos($policy, 'frame-ancestors') === false) { $findings[] = $this->issue('server.header_clickjacking', 'low', 'x-frame-options', __('Front-end pages can be embedded in frames by any site.', 'all-in-one-wp-content-security'), array('detected' => __('No X-Frame-Options or frame-ancestors', 'all-in-one-wp-content-security'), 'expected' => 'X-Frame-Options: SAMEORIGIN', 'evidence' => $note)); } // Malformed or obsolete headers foreach (array('permissions-policy', 'access-control-allow-origin', 'x-xss-protection', 'expect-ct', 'feature-policy') as $name) { if (!isset($h[$name])) { continue; } $problem = self::header_problem($name, $h[$name]); if ($problem === '') { continue; } $rule = $name === 'access-control-allow-origin' ? 'server.cors_misconfigured' : 'server.header_invalid'; $findings[] = $this->issue($rule, $rule === 'server.cors_misconfigured' ? 'medium' : 'low', $name, $problem, array( 'detected' => $name . ': ' . $h[$name], 'evidence' => $note, )); } // CORS: does the home page echo arbitrary origins with credentials? $origin = 'https://aowpcs-cors-test.invalid'; $cors = AOWPCS_Loopback::request(home_url('/'), array('headers' => array('Origin' => $origin), 'cache' => false)); if ($cors['error'] === '' && isset($cors['headers']['access-control-allow-origin'])) { $allow = trim($cors['headers']['access-control-allow-origin']); $credentials = isset($cors['headers']['access-control-allow-credentials']) && strtolower(trim($cors['headers']['access-control-allow-credentials'])) === 'true'; if ($allow === $origin && $credentials) { $findings[] = $this->issue('server.cors_misconfigured', 'high', 'cors-reflect', __('The home page allows any origin to read it with the visitor\'s cookies.', 'all-in-one-wp-content-security'), array( 'kind' => 'vulnerability', 'confidence' => 'confirmed', 'detected' => sprintf('Access-Control-Allow-Origin: %s, Access-Control-Allow-Credentials: true', $allow), 'expected' => __('A fixed list of trusted origins, or no CORS headers', 'all-in-one-wp-content-security'), 'evidence' => array(__('Test origin sent', 'all-in-one-wp-content-security') => $origin), )); } } // Version disclosure $disclosed = array(); if (!empty($h['server']) && preg_match('/\d+\.\d+/', $h['server'])) { $disclosed['Server'] = $h['server']; } if (!empty($h['x-powered-by']) && preg_match('/\d+\.\d+/', $h['x-powered-by'])) { $disclosed['X-Powered-By'] = $h['x-powered-by']; } if ($disclosed) { $findings[] = $this->issue('server.version_disclosure', 'low', 'server-versions', __('Response headers reveal software versions.', 'all-in-one-wp-content-security'), array('kind' => 'informational', 'evidence' => $disclosed)); } return $findings; } } /** * Rules written to .htaccess by version 2.0 of this plugin */ class AOWPCS_Check_Server_Legacy_Rules extends AOWPCS_Check { public function id() { return 'server.legacy_rules'; } public function category() { return 'server'; } public function rules() { return array( 'server.legacy_headers_block' => array( 'title' => __('Security header rules from version 2.0 of this plugin are still active', 'all-in-one-wp-content-security'), 'kind' => 'misconfiguration', 'explanation' => __('Version 2.0 wrote a fixed block of headers into .htaccess. It contains an invalid placeholder header (Access-Control-Allow-Origin "ADD YOUR SITE URL"), obsolete headers, a malformed Permissions-Policy and a strict Content-Security-Policy that blocks external scripts, fonts, embeds and images — also in the dashboard.', 'all-in-one-wp-content-security'), 'impact' => __('The strict policy can silently break features (analytics, maps, video, fonts, payment widgets), and the invalid header breaks legitimate cross-origin requests.', 'all-in-one-wp-content-security'), 'remediation' => __('Replace the block with the header manager, which sends valid headers and introduces the Content-Security-Policy in report-only mode.', 'all-in-one-wp-content-security'), 'steps' => array( __('Use "Apply fix": the old block is backed up and removed, and the header manager is enabled with equivalent, valid headers. The site is checked afterwards and the change is rolled back automatically if it returns errors.', 'all-in-one-wp-content-security'), __('Manual alternative: delete the lines between "# BEGIN All-in-One WP Content Security" and "# END All-in-One WP Content Security" in .htaccess.', 'all-in-one-wp-content-security'), ), 'permission' => __('WordPress administrator (writable .htaccess) or file access', 'all-in-one-wp-content-security'), 'fix' => 'legacy_headers', ), 'server.legacy_xmlrpc_rule' => array( 'title' => __('The XML-RPC rule from version 2.0 uses Apache 2.2 syntax', 'all-in-one-wp-content-security'), 'kind' => 'misconfiguration', 'explanation' => __('Version 2.0 blocked xmlrpc.php with "Order Deny,Allow / Deny from all", which only works on Apache 2.4 when the mod_access_compat compatibility module is loaded.', 'all-in-one-wp-content-security'), 'impact' => __('The site works today, but a server change that removes mod_access_compat would make the whole site return "500 Internal Server Error".', 'all-in-one-wp-content-security'), 'remediation' => __('Rewrite the rule with Apache 2.4 syntax (with a 2.2 fallback).', 'all-in-one-wp-content-security'), 'steps' => array(__('Use "Apply fix" to rewrite the block (backed up, verified, rolled back automatically on errors).', 'all-in-one-wp-content-security')), 'permission' => __('WordPress administrator (writable .htaccess) or file access', 'all-in-one-wp-content-security'), 'fix' => 'legacy_xmlrpc', ), ); } public function run($context) { $findings = array(); foreach (AOWPCS_Htaccess::root_files() as $file) { $body = AOWPCS_Htaccess::read_block($file, AOWPCS_Htaccess::LEGACY_HEADERS); if ($body !== null) { $problems = array(); if (stripos($body, 'ADD YOUR SITE URL') !== false) { $problems[] = 'Access-Control-Allow-Origin "ADD YOUR SITE URL"'; } foreach (array('X-XSS-Protection', 'Feature-Policy', 'Expect-CT') as $header) { if (stripos($body, $header) !== false) { /* translators: %s: header */ $problems[] = sprintf(__('%s (obsolete)', 'all-in-one-wp-content-security'), $header); } } if (stripos($body, 'Content-Security-Policy') !== false) { $problems[] = __('Strict Content-Security-Policy (default-src \'self\')', 'all-in-one-wp-content-security'); } $findings[] = $this->issue('server.legacy_headers_block', $problems ? 'medium' : 'low', AOWPCS_Plugin::relative_path($file) . '#headers', __('The security header block written by version 2.0 is still in .htaccess.', 'all-in-one-wp-content-security'), array( 'evidence' => array(__('File', 'all-in-one-wp-content-security') => AOWPCS_Plugin::relative_path($file), __('Problems', 'all-in-one-wp-content-security') => $problems, __('Web server reads .htaccess', 'all-in-one-wp-content-security') => AOWPCS_Environment::uses_htaccess() ? __('yes', 'all-in-one-wp-content-security') : __('no (block has no effect)', 'all-in-one-wp-content-security')), )); } $xmlrpc = AOWPCS_Htaccess::read_block($file, AOWPCS_Htaccess::XMLRPC); if ($xmlrpc !== null && AOWPCS_Htaccess::is_legacy_xmlrpc_block($xmlrpc)) { $findings[] = $this->issue('server.legacy_xmlrpc_rule', 'low', AOWPCS_Plugin::relative_path($file) . '#xmlrpc', __('The XML-RPC block uses Apache 2.2 syntax.', 'all-in-one-wp-content-security'), array( 'detected' => 'Order Deny,Allow / Deny from all', 'expected' => 'Require all denied (Apache 2.4)', 'evidence' => array(__('File', 'all-in-one-wp-content-security') => AOWPCS_Plugin::relative_path($file)), )); } } return $findings; } } /** * Findings derived from monitored traffic */ class AOWPCS_Check_Traffic extends AOWPCS_Check { public function id() { return 'traffic.analysis'; } public function category() { return 'traffic'; } public function rules() { return array( 'traffic.login_attacks' => array( 'title' => __('Password-guessing attempts are hitting the login', 'all-in-one-wp-content-security'), 'kind' => 'informational', 'explanation' => __('Many failed logins were recorded in the last 24 hours. Automated password guessing against WordPress sites is constant background noise; what matters is whether it can succeed.', 'all-in-one-wp-content-security'), 'impact' => __('With weak passwords an account can eventually be guessed; the requests also cost server resources.', 'all-in-one-wp-content-security'), 'remediation' => __('Enable login protection (temporary blocks after repeated failures) and use strong, unique passwords — ideally with two-factor authentication.', 'all-in-one-wp-content-security'), 'steps' => array( __('Use "Apply fix" to enable login protection with the default limits (5 failures in 15 minutes → 15 minute block, escalating).', 'all-in-one-wp-content-security'), __('Make sure all administrators use strong passwords; consider a two-factor plugin.', 'all-in-one-wp-content-security'), ), 'docs' => array(self::doc(__('Brute force attacks', 'all-in-one-wp-content-security'), 'https://developer.wordpress.org/advanced-administration/security/brute-force/')), 'fix' => 'login_protection', ), 'traffic.proxy_unconfigured' => array( 'title' => __('Visitor IP addresses cannot be determined reliably', 'all-in-one-wp-content-security'), 'kind' => 'misconfiguration', 'explanation' => __('One address sent requests with a forwarding header for several different visitors, but it is not configured as a trusted proxy. Behind a proxy, load balancer or CDN every visitor appears to have the proxy\'s address.', 'all-in-one-wp-content-security'), 'impact' => __('Logs show the proxy instead of visitors, and blocking the proxy\'s address would block everyone behind it, so automatic blocks of that address are refused until this is resolved.', 'all-in-one-wp-content-security'), 'remediation' => __('Declare the proxy in Settings → Monitoring & privacy (Cloudflare preset, or the proxy addresses and header), or confirm that the site is not behind a proxy.', 'all-in-one-wp-content-security'), 'steps' => array( __('If you use Cloudflare, enable the Cloudflare preset.', 'all-in-one-wp-content-security'), __('Otherwise enter the proxy/load balancer addresses and select the header it uses (usually X-Forwarded-For). Ask your host if unsure.', 'all-in-one-wp-content-security'), __('If visitors connect to the server directly, the header was sent by the clients themselves: enable "This site is not behind a proxy".', 'all-in-one-wp-content-security'), ), ), 'traffic.xmlrpc_abuse' => array( 'title' => __('xmlrpc.php receives a high number of requests', 'all-in-one-wp-content-security'), 'kind' => 'informational', 'explanation' => __('XML-RPC received many requests in the last 24 hours while it is fully enabled. Besides legitimate apps, xmlrpc.php is used for password guessing (many attempts per request with system.multicall) and pingback abuse.', 'all-in-one-wp-content-security'), 'impact' => __('Amplified password guessing and server load.', 'all-in-one-wp-content-security'), 'remediation' => __('Restrict XML-RPC: disable it completely if no app needs it, otherwise block system.multicall and pingbacks.', 'all-in-one-wp-content-security'), 'steps' => array( __('Check whether you use Jetpack, the WordPress mobile apps or a remote publishing tool that needs XML-RPC.', 'all-in-one-wp-content-security'), __('Use "Apply fix" to disable pingbacks and system.multicall (safe for most apps), or disable XML-RPC completely in Firewall & Protection.', 'all-in-one-wp-content-security'), ), 'fix' => 'xmlrpc_restrict', ), ); } public function run($context) { if (!AOWPCS_Settings::get('traffic_monitoring')) { return $this->all_unknown(__('Traffic monitoring is disabled (Settings → Monitoring & privacy).', 'all-in-one-wp-content-security')); } $findings = array(); $since = AOWPCS_Plugin::gmt_ago(DAY_IN_SECONDS); $failed = AOWPCS_Event_Log::count(array('event_type' => 'login_failed', 'since' => $since)); $lockouts = AOWPCS_Event_Log::count(array('event_type' => 'login_lockout', 'since' => $since)); if ($failed >= 20) { $protected = AOWPCS_Settings::get('login_protection') && !AOWPCS_Plugin::safe_mode(); $findings[] = $this->issue('traffic.login_attacks', $protected ? 'low' : 'medium', 'login', $protected /* translators: 1: failed, 2: lockouts */ ? sprintf(__('%1$d failed logins in 24 hours; %2$d addresses were blocked temporarily.', 'all-in-one-wp-content-security'), $failed, $lockouts) /* translators: %d: failed */ : sprintf(__('%d failed logins in 24 hours while login protection is off.', 'all-in-one-wp-content-security'), $failed), array( 'kind' => $protected ? 'informational' : 'hardening', 'evidence' => array(__('Failed logins (24 h)', 'all-in-one-wp-content-security') => $failed, __('Temporary blocks (24 h)', 'all-in-one-wp-content-security') => $lockouts, __('Login protection', 'all-in-one-wp-content-security') => $protected ? __('on', 'all-in-one-wp-content-security') : __('off', 'all-in-one-wp-content-security')), )); } $proxies = AOWPCS_IP::detected_proxies(); $proxy = AOWPCS_Settings::state('proxy_seen'); if ($proxies !== array() && is_array($proxy)) { $findings[] = $this->issue('traffic.proxy_unconfigured', 'medium', 'proxy', __('Requests arrive through a proxy or CDN that is not configured.', 'all-in-one-wp-content-security'), array( 'evidence' => array(__('Proxy addresses seen', 'all-in-one-wp-content-security') => implode(', ', array_keys($proxies)), __('Forwarding header', 'all-in-one-wp-content-security') => $proxy['header'], __('Last seen', 'all-in-one-wp-content-security') => AOWPCS_Plugin::format_time(max($proxies))), )); } $xmlrpc = AOWPCS_Event_Log::counter_total('xmlrpc', $since); if ($xmlrpc >= 100 && AOWPCS_Settings::get('xmlrpc_mode') === 'off' && !AOWPCS_Settings::get('xmlrpc_block_multicall')) { /* translators: %d: xmlrpc */ $findings[] = $this->issue('traffic.xmlrpc_abuse', 'medium', 'xmlrpc', sprintf(__('%d requests to xmlrpc.php in 24 hours with XML-RPC fully enabled.', 'all-in-one-wp-content-security'), $xmlrpc), array( 'kind' => 'hardening', 'evidence' => array(__('Requests (24 h)', 'all-in-one-wp-content-security') => $xmlrpc), )); } return $findings; } }