CMS Security & Optimization Tips

From Beginner to Advanced

Made with Reveal.js

Introduction

CMS Security & Optimization Tips

Why Droomlapress?

CMS Drupal 8 Joomla 3.8 Wordpress 4.8
Minimum 5.5.9+ 5.3.10+ 5.2.4+

The Basics

PHP

Requirements

Recommended 7+
Branch Active Support Until Security Support Until

Besides:

7.1 1 Dec 2018 01 Dec 2019
7.0 3 Dec 2017 03 Dec 2018
5.6 19 Jan 2017 31 Dec 2018
5.5 21 Jul 2016
5.4 03 Sep 2015

CMS Security & Optimization Tips

CMS Security & Optimization Tips

Administrator Access

Denies access to /admin/ by default but allows /user/

Allows access to /administrator/ by default

Allows access to /admin/ and /wp-admin/ by default (redirects both urls to wp-login.php)

CMS Security & Optimization Tips

Administrator Access

IPv4/6 Black/White Lists

Brute Force detection

CMS Security & Optimization Tips

*Never hack core!

In the most general sense, hacking core is bad because of the security, maintenance, and compatibility problems that making changes to core files can cause with your site. It can cause unforeseen and bizarre problems with the display of a website and can also be a root cause of issues that can bring down a website entirely.

CMS Security & Optimization Tips

CMS & Extensions Updates

CMS Security & Optimization Tips

CMS & Extensions Updates

  • All updates to be implemented with user consent (one-click update)
  • Plugins and themes: one-click update

  • All updates to be implemented with user consent (one-click update)
  • Most Modules, Components & Plugins: one-click update
  • minor/security updates done automatically!
  • major updates to be implemented with user consent (one-click update)
  • Plugins and themes: one-click update

Tips for 3rd party extensions:
- "Less is More"
- Check: Compatibility, Security*, Sustainability

*Joomla! Vulnerable Extensions List
 

CMS Security & Optimization Tips

.htaccess

- extensive htaccess rules
- enabled by default

adequate htaccess rules, present by default but needs to be renamed in order to work

.htaccess is a configuration file for use on web servers running the Apache Web Server software. .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer.

# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
  </IfModule>
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Set the default handler.
DirectoryIndex index.php index.html index.htm

# Add correct encoding for SVGZ.
AddType image/svg+xml svg svgz
AddEncoding gzip svgz

# Most of the following PHP settings cannot be changed at runtime. See
# sites/default/default.settings.php and
# Drupal\Core\DrupalKernel::bootEnvironment() for settings that can be
# changed at runtime.

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value assert.active                   0
  php_flag session.auto_start               off
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_flag mbstring.encoding_translation    off
  # PHP 5.6 has deprecated $HTTP_RAW_POST_DATA and produces warnings if this is
  # not set.
  php_value always_populate_raw_post_data   -1
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Set a fallback resource if mod_rewrite is not enabled. This allows Drupal to
# work without clean URLs. This requires Apache version >= 2.2.16. If Drupal is
# not accessed by the top level URL (i.e.: http://example.com/drupal/ instead of
# http://example.com/), the path to index.php will need to be adjusted.
<IfModule !mod_rewrite.c>
  FallbackResource /index.php
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Set "protossl" to "s" if we were accessed via https://.  This is used later
  # if you enable "www." stripping or enforcement, in order to ensure that
  # you don't bounce between http and https.
  RewriteRule ^ - [E=protossl]
  RewriteCond %{HTTPS} on
  RewriteRule ^ - [E=protossl:s]

  # Make sure Authorization HTTP header is available to PHP
  # even when running as CGI or FastCGI.
  RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

  # Block access to "hidden" directories whose names begin with a period. This
  # includes directories used by version control systems such as Subversion or
  # Git to store control files. Files whose names begin with a period, as well
  # as the control files used by CVS, are protected by the FilesMatch directive
  # above.
  #
  # NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
  # not possible to block access to entire directories from .htaccess because
  # <DirectoryMatch> is not allowed here.
  #
  # If you do not have mod_rewrite installed, you should remove these
  # directories from your webroot or otherwise protect them from being
  # downloaded.
  RewriteRule "/\.|^\.(?!well-known/)" - [F]

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/foo will be redirected to http://www.example.com/foo)
  # uncomment the following:
  # RewriteCond %{HTTP_HOST} .
  # RewriteCond %{HTTP_HOST} !^www\. [NC]
  # RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/foo will be redirected to http://example.com/foo)
  # uncomment the following:
  # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  # RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Redirect common PHP files to their new locations.
  RewriteCond %{REQUEST_URI} ^(.*)?/(install.php) [OR]
  RewriteCond %{REQUEST_URI} ^(.*)?/(rebuild.php)
  RewriteCond %{REQUEST_URI} !core
  RewriteRule ^ %1/core/%2 [L,QSA,R=301]

  # Rewrite install.php during installation to see if mod_rewrite is working
  RewriteRule ^core/install.php core/install.php?rewrite=ok [QSA,L]

  # Pass all requests not referring directly to files in the filesystem to
  # index.php.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

  # For security reasons, deny access to other PHP files on public sites.
  # Note: The following URI conditions are not anchored at the start (^),
  # because Drupal may be located in a subdirectory. To further improve
  # security, you can replace '!/' with '!^/'.
  # Allow access to PHP files in /core (like authorize.php or install.php):
  RewriteCond %{REQUEST_URI} !/core/[^/]*\.php$
  # Allow access to test-specific PHP files:
  RewriteCond %{REQUEST_URI} !/core/modules/system/tests/https?.php
  # Allow access to Statistics module's custom front controller.
  # Copy and adapt this rule to directly execute PHP files in contributed or
  # custom modules or to run another PHP application in the same directory.
  RewriteCond %{REQUEST_URI} !/core/modules/statistics/statistics.php$
  # Deny access to any other PHP files that do not match the rules above.
  # Specifically, disallow autoload.php from being served directly.
  RewriteRule "^(.+/.*|autoload)\.php($|/)" - [F]

  # Rules to correctly serve gzip compressed CSS and JS files.
  # Requires both mod_rewrite and mod_headers to be enabled.
  <IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

    # Serve gzip compressed JS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
    RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header set Content-Encoding gzip
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>
</IfModule>

# Various header fixes.
<IfModule mod_headers.c>
  # Disable content sniffing, since it's an attack vector.
  Header always set X-Content-Type-Options nosniff
  # Disable Proxy header, since it's an attack vector.
  RequestHeader unset Proxy
</IfModule>
# @package    Joomla
# @copyright  Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
# @license    GNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations.  It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that disallows changing it in
# your .htaccess file.  If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's.  If they work,
# it has been set by your server administrator and you do not need it set here.
##

## No directory listings
IndexIgnore *

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

inadequate htaccess rules (only hides index.php from urls), enabled by default

CMS Security & Optimization Tips

.htaccess

Pass all requests not referring directly to files in the filesystem to index.php – SEF URLs
No directory listings
Rewrite rules to block out some common exploits
Protect sensitive files and directories
RewriteBase for VirtualDocumentRoot
Canonical www
Files caching
Correctly serve gzip compressed CSS and JS files

Wishlist:

  • Advanced server protection rules
  • Protection for SQL and file injections
  • No Directory listings
  • browser caching & optimal expiration time
  • Automatic compression of resources

 

  • Disallow visual fingerprinting
  • Referrer filtering for common media files
  • Disguise file extensions
  • Block external POST requests
  • Protect .htaccess  & config files

Default htaccess settings

CMS Security & Optimization Tips

.htaccess

While it may not be an All-In-One prevention solution...

...it still prevents quite a lot!

Veeeery Useful Sources:

CMS Security & Optimization Tips

Other Security Tips

SSL

BACKUP

Akeeba Backup Extension

CMS Security & Optimization Tips

Examples of "good practice"

CMS Security & Optimization Tips

Optimization Tips
(=SEO)

Be friendly towards

Search Engines

Social Media

Users

- SEF URLs

- Customizable Page Titles, Meta
Data, keywords etc

- img alt tags / link title tags

- Navigation (HTML, not images!)

- Breadcrumbs, sitemap, pagination
- Schema Markup & Structured Data (HTML markup, com'on people!)

- Open Graph Meta Tags

- Social Media Signals

- Integrated Social Media Feeds

- Fresh & Interesting Content

 

- Responsive Design

- Inclusive / Accessible Design

- Site Search

- Google PageSpeed Insights

- Content Delivery Network (CDN)
- Resources Compression

- Analytics

CMS Security & Optimization Tips

Optimization Tips

Search Engines

- SEF URLs

Where SEF = Search Engine Friendly, so a URL that does NOT look like this:

Joomla

Drupal

Wordpress

- Customizable Page Titles, Meta Data keywords, descriptions etc (by default)

- img alt tags / link title tags

CMS-Independent, useful for increased content visibility, thus good SEO

- Navigation (HTML, not images!)

Drupal, Joomla & Wordpress have HTML/CSS Navigation by default

CMS Security & Optimization Tips

Optimization Tips

Search Engines

- Schema Markup & Structured Data

<div>
 <h1>Avatar</h1>
 <span>Director: James Cameron (born August 16, 1954)</span>
 <span>Science fiction</span>
 <a href="../movies/avatar-theatrical-trailer.html">Trailer</a>
</div>
<div itemscope itemtype ="http://schema.org/Movie">
  <h1 itemprop="name">Avatar</h1>
  <span>Director: <span itemprop="director">James Cameron</span> 
(born August 16, 1954)</span>
  <span itemprop="genre">Science fiction</span>
  <a href="../movies/avatar-theatrical-trailer.html" 
itemprop="trailer">Trailer</a>
</div>

CMS Security & Optimization Tips

Optimization Tips

Search Engines

- Schema Markup & Structured Data

Contact us:

210 1234567

Contact us:

210 1234567

<a href="tel:+302101234567">
210 1234567</a>
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Restaurant",
  "image": [
    "https://example.com/photos/1x1/photo.jpg",
    "https://example.com/photos/4x3/photo.jpg",
    "https://example.com/photos/16x9/photo.jpg"
   ],
  "@id": "http://davessteakhouse.example.com",
  "name": "Dave's Steak House",
  "address": {
    "@type": "PostalAddress",
    "streetAddress": "148 W 51st St",
    "addressLocality": "New York",
    "addressRegion": "NY",
    "postalCode": "10019",
    "addressCountry": "US"
  },
  "geo": {
    "@type": "GeoCoordinates",
    "latitude": 40.761293,
    "longitude": -73.982294
  },
  "url": "http://www.example.com/restaurant-locations/manhattan",
  "telephone": "+12122459600",
  "openingHoursSpecification": [
    {
      "@type": "OpeningHoursSpecification",
      "dayOfWeek": [
        "Monday",
        "Tuesday"
      ],
      "opens": "11:30",
      "closes": "22:00"
    },
    {
      "@type": "OpeningHoursSpecification",
      "dayOfWeek": [
        "Wednesday",
        "Thursday",
        "Friday"
      ],
      "opens": "11:30",
      "closes": "23:00"
    },
    {
      "@type": "OpeningHoursSpecification",
      "dayOfWeek": "Saturday",
      "opens": "16:00",
      "closes": "23:00"
    },
    {
      "@type": "OpeningHoursSpecification",
      "dayOfWeek": "Sunday",
      "opens": "16:00",
      "closes": "22:00"
    }
  ],
  "menu": "http://www.example.com/menu",
  "acceptsReservations": "True"
}
</script>

CMS Security & Optimization Tips

Optimization Tips

Search Engines

- Schema Markup & Structured Data

Deploy on CMS via

HTML

or

3rd Party Extensions

CMS Security & Optimization Tips

Optimization Tips

Social Media

- Social Media Signals

- Integrated Social Media Feeds

- Fresh & Interesting Content!

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="keywords" content="hackathon, crowd hackathons, χακαθον, fintech hackathon, hackathon ethics" />
<meta name="description" content="Τα τελευταία χρόνια παρατηρείται 
μια εκθετική αύξηση των Hackathons σε όλον τον κόσμο, και φυσικά 
η Ελλάδα δεν θα μπορούσε να αποτελέσει εξαίρεση από αυτή την τάση..." />
<meta property="og:type" content="website" />
<meta property="og:title" content="Τί είναι τα Hackathons και γιατί δεν χρειάζεται να πας σε κάποια" />
<meta property="og:url" content="http://www.rinenweb.eu/blog/crowd-hackathons" />
<meta property="og:image" content="http://www.rinenweb.eu/images/blog/hackathon.jpg" />
<meta property="fb:app_id" content="394442757654193" />
<meta property="article:author" content="https://www.facebook.com/rinenweb" />

CMS Security & Optimization Tips

Optimization Tips

Users
(or Browsers)

- Responsive Design

- Inclusive / Accessible Design

- Site Search

Viewport set? Text too small to read?

Clickable elements too close together?

Content wider than screen?
 

Google's Mobile-Friendly Test

& Mobile Usability report @ Search Console (Webmaster Tools)

CMS Security & Optimization Tips

Optimization Tips

Users
(or Browsers)

- Content Delivery Network (CDN)

- Analytics

- Reduce server response time (or change server)

- Optimize images (google does it for you if you want)

- Minify HTML/CSS/JavaScript

- Enable GZIP Compression (mod_deflate in .htaccess)

- Prioritize visible (above-the-fold) content

- Leverage browser caching (through CMS or .htaccess)

 

Look for a provider that:

- supports the new HTTP/2 protocol
- uses optimized SSD servers
- offers SSL options such as Let’s Encrypt

3rd party extensions for Droomlapress

Feedback, Feedback, Feedback!

CMS Security & Optimization Tips

Optimization Tips

Well, you could look for 3rd party extensions...

CMS Security & Optimization Tips

CMS Security & Optimization Tips

From Beginner to Advanced

Made with Reveal.js

Questions?

Comments?