Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
13c3195
initial implemention of the new plg_system_httpheader
zero-24 Oct 10, 2017
4582036
add missing files
zero-24 Oct 10, 2017
e0257b5
fix language file header
zero-24 Oct 10, 2017
52dfc16
fix since tags
zero-24 Oct 10, 2017
a111a92
cleanline at the end of the file
zero-24 Oct 10, 2017
772a112
thanks @brianteeman & @quy
zero-24 Oct 10, 2017
52bb783
fix a error drone found
zero-24 Oct 10, 2017
7320cba
add STS + reduce the code + add the behavior that custom values allwa…
zero-24 Oct 10, 2017
ba5b510
drop descriptions based on feedback by @brianteeman add postinstall …
zero-24 Oct 11, 2017
27001c1
disabled per on upgrades
zero-24 Oct 11, 2017
fb0aed5
integer
zero-24 Oct 11, 2017
85d23f6
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Oct 12, 2017
acec5bd
add siggestions by @brianteeman
zero-24 Oct 12, 2017
0c58082
typo thnaks @quy & @brianteeman
zero-24 Oct 12, 2017
e30dba2
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 4, 2017
d0d1a75
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 5, 2017
077a5ef
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 7, 2017
a701f1f
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 8, 2017
c1f673b
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 10, 2017
355cb9a
newline
zero-24 Nov 11, 2017
a882970
drone
zero-24 Nov 11, 2017
3484e6e
drone
zero-24 Nov 11, 2017
f5226e0
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 12, 2017
d09572f
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 15, 2017
c126ee6
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 16, 2017
727246b
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 17, 2017
ee7d431
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 19, 2017
f205cb8
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 20, 2017
6e9ebce
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 21, 2017
1f57773
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 22, 2017
14883f9
getSubscribedEvents
zero-24 Nov 23, 2017
87ce91f
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 23, 2017
883754c
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 24, 2017
d638421
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 25, 2017
61deaf1
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Nov 30, 2017
bb65291
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Dec 2, 2017
153f887
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Dec 5, 2017
85a9d13
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Dec 7, 2017
9a952a3
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Dec 12, 2017
d69c433
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Dec 14, 2017
dd48f04
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Dec 16, 2017
5768ded
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Dec 21, 2017
fe3503e
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Dec 27, 2017
085c825
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Jan 7, 2018
afc5f75
merge conflicts
zero-24 Jan 18, 2018
b4a753f
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Jan 18, 2018
eadb926
update extension id's and up to 4.0-dev
zero-24 Jan 20, 2018
e94ef5d
Merge branch '4.0-dev' of github.com:joomla/joomla-cms into security-…
zero-24 Jan 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(486, 'plg_system_httpheader', 'plugin', 'httpheader', 'system', 0, 1, 1, 0, '', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);

INSERT INTO `#__postinstall_messages` (`extension_id`, `title_key`, `description_key`, `action_key`, `language_extension`, `language_client_id`, `type`, `action_file`, `action`, `condition_file`, `condition_method`, `version_introduced`, `enabled`)
VALUES
(NULL, 486, 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_TITLE', 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_BODY', 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_ACTION', 'plg_system_httpheader', 1, 'action', 'site://plugins/system/httpheader/postinstall/introduction.php', 'httpheader_postinstall_action', 'site://plugins/system/httpheader/postinstall/introduction.php', 'httpheader_postinstall_condition', '4.0.0', 1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES
(486, 'plg_system_httpheader', 'plugin', 'httpheader', 'system', 0, 1, 1, 0, '', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);

INSERT INTO "#__postinstall_messages" ("extension_id", "title_key", "description_key", "action_key", "language_extension", "language_client_id", "type", "action_file", "action", "condition_file", "condition_method", "version_introduced", "enabled")
VALUES
(NULL, 486, 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_TITLE', 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_BODY', 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_ACTION', 'plg_system_httpheader', 1, 'action', 'site://plugins/system/httpheader/postinstall/introduction.php', 'httpheader_postinstall_action', 'site://plugins/system/httpheader/postinstall/introduction.php', 'httpheader_postinstall_condition', '4.0.0', 1);
31 changes: 31 additions & 0 deletions administrator/language/en-GB/en-GB.plg_system_httpheader.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
; Joomla! Project
; Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_HTTPHEADER="System - HTTPHeader"
PLG_SYSTEM_HTTPHEADER_XML_DESCRIPTION="This Plugin can set some Security HTTP Headers"
PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER="Define additional HTTP Header"
PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_DESC="Using this you can set also different values from the default ones and also additional headers when it is supported. The supported headers are: <br><ul><li>Strict-Transport-Security</li><li>Content-Security-Policy</li><li>Content-Security-Policy-Report-Only</li><li>X-Frame-Options</li><li>X-XSS-Protection</li><li>X-Content-Type-Options</li><li>Referrer-Policy</li><li>Expect-CT</li></ul>"
PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_CLIENT="Site selection"
PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_CLIENT_SITE="Site"
PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_CLIENT_ADMINISTRATOR="Administrator"
PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_CLIENT_BOTH="Both"
PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_KEY="HTTP Header"
PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_VALUE="HTTP Header Value"
PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_TITLE="HTTP Security Headers are available"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesnt seem correct I would delete the "are available"

PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_BODY="Joomla! comes with a built-in plugin that handle http security headers. It secures your site by setting the following headers with the default values:<br><ul><li><a href='https://scotthelme.co.uk/hardening-your-http-response-headers/#x-frame-options'>'X-Frame-Options: SAMEORIGIN'</a></li><li><a href='https://scotthelme.co.uk/hardening-your-http-response-headers/#x-xss-protection'>'X-XSS-Protection: 1; mode=block'</a></li><li><a href='https://scotthelme.co.uk/hardening-your-http-response-headers/#x-content-type-options'>'X-Content-Type-Options: nosniff'</a></li><li><a href='https://scotthelme.co.uk/a-new-security-header-referrer-policy/'>'Referrer-Policy: no-referrer-when-downgrade'</a></li></ul><br><br>The full list of supported headers are: <br><ul><li><a href='https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security'>Strict-Transport-Security</a></li><li><a href='https://en.wikipedia.org/wiki/Content_Security_Policy'>Content-Security-Policy</a></li><li>Content-Security-Policy-Report-Only</li><li>X-Frame-Options</li><li>X-XSS-Protection</li><li>X-Content-Type-Options</li><li>Referrer-Policy</li><li>Expect-CT</li></ul><br><br>These headers help your browser to protect your website from <a href='https://en.wikipedia.org/wiki/Cross-site_scripting'>XSS</a> and <a href='https://en.wikipedia.org/wiki/Clickjacking'>Clickjacking</a> attacks."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handles
It helps to secure your site

PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_ACTION="Enable default security headers"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY="Referrer-Policy"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_EMPTY_STRING="Empty String"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty String

An empty string value in the Referrer Policy header indicates that the site doesn't want to set a Referrer Policy here and the browser should fallback to a Referrer Policy defined via other mechanisms elsewhere

So in this case I think it is better to have the string be "disabled" or "not set"

PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_NO_REFERRER="no-referrer"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_NO_REFERRER_WHEN_DOWNGRADE="no-referrer-when-downgrade"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_SAME_ORIGIN="same-origin"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_ORIGIN="origin"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_STRICT_ORIGIN="strict-origin"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_ORIGIN_WHEN_CROSS_ORIGIN="origin-when-cross-origin"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_STRICT_ORIGIN_WEHN_CROSS_ORIGIN="strict-origin-when-cross-origin"
PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_UNSAFE_URL="unsafe-url"
PLG_SYSTEM_HTTPHEADER_XCONTENTTYPEOPTIONS="X-Content-Type-Options"
PLG_SYSTEM_HTTPHEADER_XFRAMEOPTIONS="X-Frame-Options"
PLG_SYSTEM_HTTPHEADER_XXSSPROTECTION="X-XSS-Protection"
4 changes: 3 additions & 1 deletion installation/sql/mysql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `elem
(483, 0, 'plg_media-action_crop', 'plugin', 'crop', 'media-action', 0, 1, 1, 0, '', '{}', 0, '0000-00-00 00:00:00', 0, 0, ''),
(484, 0, 'plg_media-action_resize', 'plugin', 'resize', 'media-action', 0, 1, 1, 0, '', '{}', 0, '0000-00-00 00:00:00', 0, 0, ''),
(485, 0, 'plg_media-action_rotate', 'plugin', 'rotate', 'media-action', 0, 1, 1, 0, '', '{}', 0, '0000-00-00 00:00:00', 0, 0, ''),
(486, 0, 'plg_system_httpheader', 'plugin', 'httpheader', 'system', 0, 1, 1, 0, '', '{}', 0, '0000-00-00 00:00:00', 0, 0, ''),
(509, 0, 'atum', 'template', 'atum', '', 1, 1, 1, 0, '', '', 0, '0000-00-00 00:00:00', 0, 0, ''),
(510, 0, 'aurora', 'template', 'aurora', '', 0, 1, 1, 0, '', '{"logoFile":"","fluidContainer":"0","sidebarLeftWidth":"3","sidebarRightWidth":"3"}', 0, '0000-00-00 00:00:00', 0, 0, ''),
(600, 802, 'English (en-GB)', 'language', 'en-GB', '', 0, 1, 1, 1, '', '', 0, '0000-00-00 00:00:00', 0, 0, ''),
Expand Down Expand Up @@ -1638,7 +1639,8 @@ INSERT INTO `#__postinstall_messages` (`extension_id`, `title_key`, `description
(700, 'COM_CPANEL_WELCOME_BEGINNERS_TITLE', 'COM_CPANEL_WELCOME_BEGINNERS_MESSAGE', '', 'com_cpanel', 1, 'message', '', '', '', '', '3.2.0', 1),
(700, 'COM_CPANEL_MSG_STATS_COLLECTION_TITLE', 'COM_CPANEL_MSG_STATS_COLLECTION_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/statscollection.php', 'admin_postinstall_statscollection_condition', '3.5.0', 1),
(700, 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_BODY', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_ACTION', 'plg_system_updatenotification', 1, 'action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_condition', '3.6.3', 1),
(700, 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_TITLE', 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/joomla40checks.php', 'admin_postinstall_joomla40checks_condition', '3.7.0', 1);
(700, 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_TITLE', 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/joomla40checks.php', 'admin_postinstall_joomla40checks_condition', '3.7.0', 1),
(486, 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_TITLE', 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_BODY', 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_ACTION', 'plg_system_httpheader', 1, 'action', 'site://plugins/system/httpheader/postinstall/introduction.php', 'httpheader_postinstall_action', 'site://plugins/system/httpheader/postinstall/introduction.php', 'httpheader_postinstall_condition', '4.0.0', 1);

-- --------------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion installation/sql/postgresql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem
(483, 0, 'plg_media-action_crop', 'plugin', 'crop', 'media-action', 0, 1, 1, 0, '', '{}', 0, '1970-01-01 00:00:00', 0, 0, ''),
(484, 0, 'plg_media-action_resize', 'plugin', 'resize', 'media-action', 0, 1, 1, 0, '', '{}', 0, '1970-01-01 00:00:00', 0, 0, ''),
(485, 0, 'plg_media-action_rotate', 'plugin', 'rotate', 'media-action', 0, 1, 1, 0, '', '{}', 0, '1970-01-01 00:00:00', 0, 0, ''),
(486, 0, 'plg_system_httpheader', 'plugin', 'httpheader', 'system', 0, 1, 1, 0, '', '{}', 0, '0000-00-00 00:00:00', 0, 0, ''),
(600, 802, 'English (en-GB)', 'language', 'en-GB', '', 0, 1, 1, 1, '', '', 0, '1970-01-01 00:00:00', 0, 0, ''),
(601, 802, 'English (en-GB)', 'language', 'en-GB', '', 1, 1, 1, 1, '', '', 0, '1970-01-01 00:00:00', 0, 0, ''),
(700, 0, 'files_joomla', 'file', 'joomla', '', 0, 1, 1, 1, '', '', 0, '1970-01-01 00:00:00', 0, 0, ''),
Expand Down Expand Up @@ -1620,7 +1621,8 @@ INSERT INTO "#__postinstall_messages" ("extension_id", "title_key", "description
(700, 'COM_CPANEL_WELCOME_BEGINNERS_TITLE', 'COM_CPANEL_WELCOME_BEGINNERS_MESSAGE', '', 'com_cpanel', 1, 'message', '', '', '', '', '3.2.0', 1),
(700, 'COM_CPANEL_MSG_STATS_COLLECTION_TITLE', 'COM_CPANEL_MSG_STATS_COLLECTION_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/statscollection.php', 'admin_postinstall_statscollection_condition', '3.5.0', 1),
(700, 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_BODY', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_ACTION', 'plg_system_updatenotification', 1, 'action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_condition', '3.6.3', 1),
(700, 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_TITLE', 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/joomla40checks.php', 'admin_postinstall_joomla40checks_condition', '3.7.0', 1);
(700, 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_TITLE', 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/joomla40checks.php', 'admin_postinstall_joomla40checks_condition', '3.7.0', 1),
(486, 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_TITLE', 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_BODY', 'PLG_SYSTEM_HTTPHEADER_POSTINSTALL_INTRODUCTION_ACTION', 'plg_system_httpheader', 1, 'action', 'site://plugins/system/httpheader/postinstall/introduction.php', 'httpheader_postinstall_action', 'site://plugins/system/httpheader/postinstall/introduction.php', 'httpheader_postinstall_condition', '4.0.0', 1);

--
-- Table structure for table `#__redirect_links`
Expand Down
129 changes: 129 additions & 0 deletions plugins/system/httpheader/httpheader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage System.HttpHeader
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;

/**
* Plugin class for HTTP Header
*
* @since __DEPLOY_VERSION__
*/
class PlgSystemHttpHeader extends CMSPlugin implements SubscriberInterface
{
/**
* If true, language files will be loaded automatically.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;

/**
* Application object.
*
* @var JApplicationCms
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* The list of the supported HTTP headers
*
* @var array
* @since __DEPLOY_VERSION__
*/
protected $supportedHttpHeaders = [
'Strict-Transport-Security',
'Content-Security-Policy',
'Content-Security-Policy-Report-Only',
'X-Frame-Options',
'X-XSS-Protection',
'X-Content-Type-Options',
'Referrer-Policy',
// Upcoming Header
'Expect-CT',
];

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents()
{
return [
'onAfterInitialise' => 'setHttpHeaders',
];
}

/**
* The `setHttpHeaders` methode handle the setting of the configured HTTP Headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix methode

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear this should be method without an e at the end

*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function setHttpHeaders()
{
$this->setDefaultHeader();

// Handle the additional httpheader
$httpHeaders = $this->params->get('additional_httpheader', array());

foreach ($httpHeaders as $httpHeader)
{
// Handle the client settings for each header
if (!$this->app->isClient($httpHeader->client) && $httpHeader->client != 'both')
{
continue;
}

if (in_array($httpHeader->key, $this->supportedHttpHeaders))
{
$this->app->setHeader($httpHeader->key, $httpHeader->value, true);
}
}
}

/**
* Set the default headers when enabled
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
private function setDefaultHeader()
{
// X-Frame-Options
if ($this->params->get('xframeoptions', 1) === 1)
{
$this->app->setHeader('X-Frame-Options', 'SAMEORIGIN');
}

// X-XSS-Protection
if ($this->params->get('xxssprotection', 1) === 1)
{
$this->app->setHeader('X-XSS-Protection', '1; mode=block');
}

// X-Content-Type-Options
if ($this->params->get('xcontenttypeoptions', 1) === 1)
{
$this->app->setHeader('X-Content-Type-Options', 'nosniff');
}

// Referrer-Policy
$this->app->setHeader('Referrer-Policy', $this->params->get('referrerpolicy', 'no-referrer-when-downgrade'));
}
}
76 changes: 76 additions & 0 deletions plugins/system/httpheader/httpheader.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="4.0" type="plugin" group="system" method="upgrade">
<name>plg_system_httpheader</name>
<author>Joomla! Project</author>
<creationDate>October 2017</creationDate>
<copyright>Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>4.0.0</version>
<description>PLG_SYSTEM_HTTPHEADER_XML_DESCRIPTION</description>
<files>
<folder>subform</folder>
<filename plugin="httpheader">httpheader.php</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="xframeoptions"
type="radio"
label="PLG_SYSTEM_HTTPHEADER_XFRAMEOPTIONS"
class="switcher"
default="1"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>
<field
name="xxssprotection"
type="radio"
label="PLG_SYSTEM_HTTPHEADER_XXSSPROTECTION"
class="switcher"
default="1"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>
<field
name="xcontenttypeoptions"
type="radio"
label="PLG_SYSTEM_HTTPHEADER_XCONTENTTYPEOPTIONS"
class="switcher"
default="1"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>
<field
name="referrerpolicy"
type="list"
label="PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY"
default="no-referrer-when-downgrade"
>
<option value="">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_EMPTY_STRING</option>
<option value="no-referrer">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_NO_REFERRER</option>
<option value="no-referrer-when-downgrade">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_NO_REFERRER_WHEN_DOWNGRADE</option>
<option value="same-origin">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_SAME_ORIGIN</option>
<option value="origin">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_ORIGIN</option>
<option value="strict-origin">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_STRICT_ORIGIN</option>
<option value="origin-when-cross-origin">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_ORIGIN_WHEN_CROSS_ORIGIN</option>
<option value="strict-origin-when-cross-origin">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_STRICT_ORIGIN_WEHN_CROSS_ORIGIN</option>
<option value="unsafe-url">PLG_SYSTEM_HTTPHEADER_REFERRERPOLICY_UNSAFE_URL</option>
</field>
<field
name="additional_httpheader"
type="subform"
label="PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER"
description="PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_DESC"
formsource="plugins/system/httpheader/subform/customhttpheader.xml"
multiple="true"
/>
</fieldset>
</fields>
</config>
</extension>
44 changes: 44 additions & 0 deletions plugins/system/httpheader/postinstall/introduction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage system.httpheader
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
*/

/**
* Checks if the plugin is enabled. If not it returns true, meaning that the
* message concerning the HTTPHeader Plugin should be displayed.
*
* @return integer
*
* @since 4.0
*/
function httpheader_postinstall_condition()
{
return Joomla\CMS\Plugin\PluginHelper::isEnabled('system', 'httpheader');
}

/**
* Enables the HTTPHeader plugin
*
* @return void
*
* @since 4.0
*/
function httpheader_postinstall_action()
{
// Enable the plugin
$db = JFactory::getDbo();

$query = $db->getQuery(true)
->update($db->qn('#__extensions'))
->set($db->qn('enabled') . ' = ' . $db->q(1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from #__extensions table the enabled field is not declared as a string
enabled tinyint(3) NOT NULL DEFAULT 0,

->where($db->qn('type') . ' = ' . $db->q('plugin'))
->where($db->qn('folder') . ' = ' . $db->q('system'))
->where($db->qn('element') . ' = ' . $db->q('plg_system_httpheader'));
$db->setQuery($query);
$db->execute();
}
23 changes: 23 additions & 0 deletions plugins/system/httpheader/subform/customhttpheader.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<field
name="key"
type="text"
label="PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_KEY"
/>
<field
name="value"
type="text"
label="PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_VALUE"
/>
<field
name="client"
type="radio"
label="PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_CLIENT"
default="site"
>
<option value="site">PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_CLIENT_SITE</option>
<option value="administrator">PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_CLIENT_ADMINISTRATOR</option>
<option value="both">PLG_SYSTEM_HTTPHEADER_ADDITIONAL_HEADER_CLIENT_BOTH</option>
</field>
</form>