Git Product home page Git Product logo

drutiny's Introduction

Drutiny - automated site auditing

Drutiny logo

CI Latest Stable Version Total Downloads Latest Unstable Version License

A generic Drupal site auditing and optional remediation tool.

Installation

This repository is a baseline frame and not recommended to install by itself unless you're planning on building your own auditing tool based on top of Drutiny.

You can install Drutiny into your project with composer.

composer require drutiny/drutiny ^3.6.0

Drutiny has native target support for Git and Drush. If you wish to use these types of targets, you must install the underlying software.

Usage

Drutiny is a command line tool that can be called from the composer vendor bin directory:

./vendor/bin/drutiny

Finding targets to audit

Drutiny has a number of connectors that allow you to discover and access "Targets" to audit. Use the target:sources command to learn which sources are available.

./vendor/bin/drutiny target:sources`

When supported by the target source, use the target:list command to list all the available targets from a given source:

# List all available targets through DDEV.
./vendor/bin/drutiny target:list ddev

Finding policies available to run

Drutiny comes with a policy:list command that lists all the policies available to audit against.

./vendor/bin/drutiny policy:list

Policies provided by other packages such as drutiny/plugin-distro-common will also appear here, if they are installed.

Installing Drutiny Plugins

Additional Drutiny policies, audits, profiles and commands can be installed with composer.

$ composer search drutiny

Running an Audit

An audit of a single policy can be run against a site by using policy:audit and passing the policy name and site target:

./vendor/bin/drutiny policy:audit Drupal-8:PageCacheExpiry @drupalvm.dev

The command above would audit the site that resolved to the @drupalvm.dev drush alias against the Drupal-8:PageCacheExpiry policy.

Some policies have parameters you can specify which can be passed in at call time. Use policy:info to find out more about the parameters available for a check.

./vendor/bin/drutiny policy:audit -p value=600 Drupal-8:PageCacheExpiry @drupalvm.dev

Audits are self-contained classes that are simple to read and understand. Policies are simple YAML files that determine how to use Audit classes. Therefore, Drutiny can be extended very easily to audit for your own unique requirements. Pull requests are welcome as well, please see the contributing guide.

Running a profile of checks

A site audit is running a collection of checks that make up a profile. This allows you to audit against a specific standard, policy or best practice. Drutiny comes with some base profiles which you can find using profile:list. You can run a profile with profile:run in a simlar format to policy:audit.

./vendor/bin/drutiny profile:run d8 @drupalvm.dev

Parameters can not be passed in at runtime for profiles but are instead predefined by the profile itself.

Getting help

Because this is a Symfony Console application, you have some other familiar commands:

./vendor/bin/drutiny help profile:run

In particular, if you use the -vvv argument, then you will see all the drush commands, and SSH commands printed to the screen.

Credits

drutiny's People

Contributors

adam-bergstein avatar allierays avatar bofrost007 avatar brianreese avatar bschilt avatar das-peter avatar dependabot[bot] avatar fiasco avatar fubarhouse avatar ghazlewood avatar gollyg avatar grasmash avatar janusman avatar jgrahamdev avatar joshirohit100 avatar malikkotob avatar markf3lton avatar nigelcunningham avatar omkar-pednekar avatar paulkilla avatar rsau avatar scottreese avatar seanhamlin avatar shanefjordan avatar steveworley avatar theodorosploumis avatar thomaslafon avatar xurizaemon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drutiny's Issues

Add option to auto remediate certain issues

Perhaps a new option

--remediate

could be set that would allow certain checks to auto remediate themselves. E.g. if you expected a certain module to be enabled, and it is not, then it could enable the module for you.

New check for robotstxt variable being correct

Would be nice to be able to supply a file to which should be contained in the Drupal variable robotstxt.

Example of the default value from Drupal 7 core:

#
# robots.txt
#
# This file is to prevent the crawling and indexing of certain parts
# of your site by web crawlers and spiders run by sites like Yahoo!
# and Google. By telling these "robots" where not to go on your site,
# you save bandwidth and server resources.
#
# This file will be ignored unless it is at the root of your host:
# Used:    http://example.com/robots.txt
# Ignored: http://example.com/site/robots.txt
#
# For more information about the robots.txt standard, see:
# http://www.robotstxt.org/robotstxt.html

User-agent: *
Crawl-delay: 10
# CSS, JS, Images
Allow: /misc/*.css$
Allow: /misc/*.css?
Allow: /misc/*.js$
Allow: /misc/*.js?
Allow: /misc/*.gif
Allow: /misc/*.jpg
Allow: /misc/*.jpeg
Allow: /misc/*.png
Allow: /modules/*.css$
Allow: /modules/*.css?
Allow: /modules/*.js$
Allow: /modules/*.js?
Allow: /modules/*.gif
Allow: /modules/*.jpg
Allow: /modules/*.jpeg
Allow: /modules/*.png
Allow: /profiles/*.css$
Allow: /profiles/*.css?
Allow: /profiles/*.js$
Allow: /profiles/*.js?
Allow: /profiles/*.gif
Allow: /profiles/*.jpg
Allow: /profiles/*.jpeg
Allow: /profiles/*.png
Allow: /themes/*.css$
Allow: /themes/*.css?
Allow: /themes/*.js$
Allow: /themes/*.js?
Allow: /themes/*.gif
Allow: /themes/*.jpg
Allow: /themes/*.jpeg
Allow: /themes/*.png
# Directories
Disallow: /includes/
Disallow: /misc/
Disallow: /modules/
Disallow: /profiles/
Disallow: /scripts/
Disallow: /themes/
# Files
Disallow: /CHANGELOG.txt
Disallow: /cron.php
Disallow: /INSTALL.mysql.txt
Disallow: /INSTALL.pgsql.txt
Disallow: /INSTALL.sqlite.txt
Disallow: /install.php
Disallow: /INSTALL.txt
Disallow: /LICENSE.txt
Disallow: /MAINTAINERS.txt
Disallow: /update.php
Disallow: /UPGRADE.txt
Disallow: /xmlrpc.php
# Paths (clean URLs)
Disallow: /admin/
Disallow: /comment/reply/
Disallow: /filter/tips/
Disallow: /node/add/
Disallow: /search/
Disallow: /user/register/
Disallow: /user/password/
Disallow: /user/login/
Disallow: /user/logout/
# Paths (no clean URLs)
Disallow: /?q=admin/
Disallow: /?q=comment/reply/
Disallow: /?q=filter/tips/
Disallow: /?q=node/add/
Disallow: /?q=search/
Disallow: /?q=user/password/
Disallow: /?q=user/register/
Disallow: /?q=user/login/
Disallow: /?q=user/logout/

Recieve error when attempting to run remote SSH command with certain setup

Get the following error when running either an individual site audit or ACSF audit:
PHP Fatal error: Class 'SiteAudit\Ssh\Command' not found in /home/paulk/scripts/site-audit/src/Executor/ExecutorRemote.php on line 20

This occurs whenever we try to run an SSH command. e.g. all of the ACSF calls, or the Theme size check for an individual site.

I've tried on the following setups:

  • Ubuntu 12.04 LTS, php 5.6
  • Ubuntu 16.04 LTS, (php 7 & php5.6)

Could this be composer/autoloader related?

New check for site timezone

We should have a check to ensure that the timezone is correctly set, I would think to a specified whitelist of timezones.

$ drush --uri=https://www.sitename.gov.au/ vget date_default_timezone
date_default_timezone: Australia/Canberra

Metatag checks

All govCMS SaaS sites are required to have:

  • metatag enabled
  • metatag configured to have a canonical URL which points at production

Ensure theme development is not turned on

Bad for performance, the message appears for admins:

For easier theme development, the theme registry is being rebuilt on every page request. It is extremely important to turn off this feature on production websites.

[2.x] Documenting Check Metadata with YAML

In 1.x, checks use doctrine annotations to define check metadata. It was done this way so that the metadata and the Check class itself were together in a single file. In this way it made checks more portable. But there were however, some downsides:

  • In profiles, checks were specified by their Class and namespace which made them hard to compile and a DX barrier for contributors
  • Annotations use a pseudo code syntax which requires the actual metadata to be passed in in datatypes like strings. This means the data needs to be escaped which makes readability harder.
  • Text editors don't natively interpret annotations in comments providing no syntax highlighting
  • PHP does not parse comments and cannot find syntax errors (though doctrine provides this). This i more of an issue in Drupal than in Drutiny.
  • Multi-line data in annotations is ugly because of the * at the begining of each line. It makes management of these difficult.
  • Annotations look better for defining small pieces of data and the plan in 2.x is to use metadata more efficiently.
  • Adding HTML and markdown inside of annotations looks dirty and hard to read. It just feels like the wrong place to put annotations.

In 2.x, I re-introduced YAML as the metadata file for Checks. While this does decouple check metadata from the checks, it does make adoption from a DX standpoint easier (IMO)

  • YAML is a more broadly used and common format. It doesn't require a predefined Annotation class to use it (this is also the reason why YAML is validated in runtime).
  • The filename itself introduces a new naming format that is more DX friendly.
  • YAML is more likely to be supported in text editors
  • YAML has great multi-line support and doesn't hinder HTML or markdown and neither will require escaping.

One of the key differences between the two approaches is how they address structured data.

  • In Annotations, you define a class and only properties of that class can be provided in the annotation.
  • In YAML, there are no rules but the rules of the syntax, there is no guarantee of data structure.

Because check metadata requires structure, I also added to 2.x YAML validators at runtime which essentially is doing the same thing as Doctrine would be doing for Annotations. So this not to replace TravisCI validation but to provide more responsive feedback to Check developers and to allow more assumptions to be made in the framework about the data provided.

Version 2 rewrite

@fiasco has started a v2 branch master...fiasco:2.x

Key new features:

  • Checks have defined options now, complete with validation and default values. This helps to make this explicit, so things like profile builders could ask questions in the future.
  • Driver plugins - the ability to execute the check via a plugin system
  • Sandbox class, instead of Context
  • New console commands, check:run etc
  • Progress bar on CLI

Still needs discussion:

  • Removing the annotation from the check class, I was quite a fan of this as it kept the checks self contained. Drutiny in the early days actually had separate YAML files, and it was hard to keep the YAML and the check together, and made PRs harder to review. Essentially the crux of this issue is having multi line annotation strings.
  • Validation of the check at runtime vs TravisCI time, I personally prefer TravisCI to do this checking.

Still needs to be done:

  • Caching of drush commands (e.g. variable-get)
  • Porting of all the checks over
  • Porting of the profiles
  • Moving the namespace of checks out of a D7 and D8 folder structure and into the types of checks they are, e.g. 'security', 'performance', 'bestpractice'
  • port the phpunit tests over
  • Removal of settings based checks, and only support the check classes (as they contain additional metadata)
  • Drupal multisite and ACSF running

New check for Exchange Autodiscover URLs

.htaccess should do something with this URL, to ensure that Drupal is not forced to bootstrap in order to serve the 404. It is highly unlikely that .xml is in the fast 404 extension list, so quite often this 1 path will be thousands of bootstraps/day that you don't need.

/autodiscover/autodiscover.xml

Potential rewrite rules:

RewriteRule ^autodiscover/autodiscover\.xml$ - [L,NC,R=404]

Drush sqlq and sqlc will sometimes complain about insecure connections

Spotted in one of the checks

$ drush @SITENAME sqlq "SELECT fc.field_name, fc.data, fci.data FROM field_config fc JOIN field_config_instance fci ON fc.id = fci.field_id WHERE fc.type = 'entityreference'"
Warning: Using a password on the command line interface can be insecure.

The output string Warning: Using a password on the command line interface can be insecure. really messes up the output. Please cleanse.

Missing installation instructions

I don't see anything in the provided documentation about how to install drutiny. There's information on installing some of its requirements, but not on how to install drutiny itself.

D7 GA check unhelpful

Hi.
Your tool is included in the site audit for govCMS. While running those checks on a site that had no special GA configuration, I received the D7 GA error. It would be much more helpful if it told you what its actually expecting you to have in the "Code snippet (after)" field. Pull request coming shortly to do just that.
Thanks for your work.

Array flip warning when creating a profile

Warning: array_flip(): Can only flip STRING and INTEGER values! in site-audit/src/Profile/Profile.php on line 122
PHP Warning:  array_flip(): Can only flip STRING and INTEGER values! in site-audit/src/Profile/Profile.php on line 122

I think the structure of the command array may have changed. array_flip expects a single dimension array so it can swap keys with values. We get the above warning because the command array is a multi-dimensional array.

Example Command array item.

["SiteAudit\Check\Phantomas\PageWeight"]=>
  object(__PHP_Incomplete_Class)#38 (11) {
    ["__PHP_Incomplete_Class_Name"]=>
    string(30) "SiteAudit\Annotation\CheckInfo"
    ["title"]=>
    string(11) "Page weight"
    ["description"]=>
    string(188) "You should aim to keep your page weight as low as possible to ensure speedy download and rendering times for your site. This impacts not only your site's user experience but also it's SEO."
    ["remediation"]=>
    string(47) "Look to optimise the largest and slowest files."
    ["success"]=>
    string(111) "Page weight is smaller than <code>:max_size</code> MB. Actual size is <code>:value</code> MB. :biggest_response"
    ["failure"]=>
    string(120) "Page weight is currently larger than <code>:max_size</code> MB. Actual size is <code>:value</code> MB. :biggest_response"
    ["exception"]=>
    string(32) "Could not determine page weight."
    ["not_available"]=>
    NULL
    ["warning"]=>
    string(157) "Page weight is smaller than <code>:max_size</code> MB but larger than <code>:warning_size</code> MB. Actual size is <code>:value</code> MB. :biggest_response"
    ["notice"]=>
    NULL
    ["supports_remediation"]=>
    bool(false)
  }

New check for fast404 settings

Ideally we will ensure that some of the newer extensions are covered, extensions to look at covering by default:

  • gif
  • jpe?g
  • png
  • svg
  • ttf
  • rtf
  • cfm
  • css
  • js
  • ics
  • docx?
  • xlsx?
  • pptx?
  • nsf

Extensions you should never whitelist

This can be due to wanting to setup the redirect module for legacy paths.

  • xml
  • php
  • html?
  • aspx?
  • ashx

Stock Drupal 7

$conf['404_fast_paths_exclude'] = '/\/(?:styles)|(?:system\/files)\//';
$conf['404_fast_paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i';

Proposed setup

The default parameters should be similar to:

Images:

  • png
  • gif
  • jpeg OR jpg
  • svg
  • tiff
  • bmp
  • raw
  • webp

Office:

  • doc OR docx
  • xls OR xlsx
  • ppt OR pptx

Misc binary files:

  • swf
  • flv
  • cgi
  • dll
  • exe
  • nsf
  • cfm
  • ttf

Misc ASCII files:

  • bat
  • pl
  • asp
  • ics
  • rtf
$conf['404_fast_paths_exclude'] = '/\/(?:styles)|(?:system\/files)\//';
$conf['404_fast_paths'] = '/\.(?:png|gif|jpe?g|svg|tiff|bmp|raw|webp|docx?|xlsx?|pptx?|swf|flv|cgi|dll|exe|nsf|cfm|ttf|bat|pl|asp|ics|rtf)$/i';

Entity Reference Remediation

The output for the entity reference check shows the machine name for the field- but checks configurations per field definition and doesn't tells us exactly which field on which content type the configuration is broken- we should be able to update particular field configurations with a query to ease this.

Field conf looks like

'label' => 'Topics',
'widget' => array(
  'weight' => '6',
  - 'type' => 'options_select',
  - 'module' => 'options',
  + 'type' => 'entityreference_autocomplete',
  + 'module' => 'entityreference',
  'active' => 1,
  'settings' => array(
    'apply_chosen' => '1',
    'flatten_options' => 0,
    'flatten_sort' => 1,
  +  'match_operator' => 'CONTAINS',
  +  'size' => 60,
  +  'path' => '',
  ),
),

Bundle into a .phar and use releases

It might be a good idea now that the project has some CI that we could add a build that would create a drutiny.phar file that could be downloaded from the Github releases page.

Can use this https://github.com/box-project/box2 (which can be included via composer) and a composer script that will build the project into a phar.

Duplicate module check

I have done this in the past with

find . -name "*.module" -type f | grep -oe "[^/]*\.module" | cut -d"." -f1 | sort | uniq -c | sort -nr | awk '{if ($1 > 1) print "[" $1 "] - " $2}'

Should be easy to port this over to a check.

Please avoid the name collision with site_audit

Howdy, neat tool! Fantastic to have more techniques and approaches to a common problem.

However, it's named the same thing as the existing utility https://www.drupal.org/project/site_audit - https://github.com/fluxsauce/site_audit

I respectfully request that you name it something distinct, as currently it's literally named the same thing as my existing project.

Traditional site audits (e.g. the checklist API module or the site_audit module) in Drupal rely on having certain modules or code present on the server in order to gather the required metrics. The main issue is that if you fail to even have these modules enabled at all, then no auditing will take place in the first instance.

site_audit doesn't depend on any third-party modules, it integrates optionally with them if they exist, and it's not a module, it's a drush command with some initial Drupal Console support as well.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.