Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden GUI by adding a CSP, XSS protection and referrer hiding #2212

Merged
merged 5 commits into from
Mar 27, 2018

Conversation

fabianfrz
Copy link
Member

this should stay on master for longer time since it may have side effects like blocking resources.

Copy link
Member Author

@fabianfrz fabianfrz left a comment

Choose a reason for hiding this comment

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

Added some description

@@ -204,5 +204,10 @@ public function beforeExecuteRoute($dispatcher)

// append ACL object to view
$this->view->acl = new \OPNsense\Core\ACL();
$this->response->setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval';");
Copy link
Member Author

Choose a reason for hiding this comment

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

will only allow resources directly from the firewall and additional embedded in the HTML, style attributes and JavaScript eval.

@@ -204,5 +204,10 @@ public function beforeExecuteRoute($dispatcher)

// append ACL object to view
$this->view->acl = new \OPNsense\Core\ACL();
$this->response->setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval';");
$this->response->setHeader('X-Frame-Options', "SAMEORIGIN");
Copy link
Member Author

Choose a reason for hiding this comment

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

Allow framing only in the context of the firewall itself (no framing by another website) - avoid clickjacking

Copy link
Member

Choose a reason for hiding this comment

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

@fabianfrz this one is already in there https://github.com/opnsense/core/blob/18.1.2/src/opnsense/mvc/app/controllers/OPNsense/Base/IndexController.php#L77 , we could move it to Base and make sure the classes deriving from index move to base. What do you think?

Copy link
Member Author

@fabianfrz fabianfrz Feb 24, 2018

Choose a reason for hiding this comment

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

So it should be removed from the index controller since it inherits controllerbase and security should be enforced on all controllers - even those which are not IndexControllers.

Short note: There is currently no controller, which is based on ControllerBase.

$this->response->setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval';");
$this->response->setHeader('X-Frame-Options', "SAMEORIGIN");
$this->response->setHeader('X-Content-Type-Options', "nosniff");
$this->response->setHeader('X-XSS-Protection', "1; mode=block");
Copy link
Member Author

Choose a reason for hiding this comment

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

block entire page if the browser detects XSS

$this->response->setHeader('X-Frame-Options', "SAMEORIGIN");
$this->response->setHeader('X-Content-Type-Options', "nosniff");
$this->response->setHeader('X-XSS-Protection', "1; mode=block");
$this->response->setHeader('Referrer-Policy', "same-origin");
Copy link
Member Author

Choose a reason for hiding this comment

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

do not show the referrer to other pages if the user clicks a link in the GUI.

@AdSchellevis AdSchellevis self-assigned this Feb 18, 2018
@AdSchellevis
Copy link
Member

@fabianfrz we should indeed be careful with this, let me review and test this as soon as I can find some time for it.

@L1ghtn1ng
Copy link

L1ghtn1ng commented Feb 18, 2018 via email

@fabianfrz
Copy link
Member Author

looks like it works on static pages as well.

@fabianfrz fabianfrz changed the title Harden GUI Controllers by adding a CSP, XSS protection and referrer hiding Harden GUI by adding a CSP, XSS protection and referrer hiding Feb 19, 2018
src/www/head.inc Outdated
header('X-Content-Type-Options: nosniff');
header('X-XSS-Protection: 1; mode=block');
header('Referrer-Policy: same-origin');

Copy link
Member

Choose a reason for hiding this comment

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

probably better to move the headers here https://github.com/opnsense/core/blob/18.1.2/src/www/guiconfig.inc#L38 as the csrf checks are also there.

Copy link
Member

@fichtner fichtner left a comment

Choose a reason for hiding this comment

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

I have a question but no objections. Please don't merge before 18.1.3 is out though.

*/
public function beforeExecuteRoute($dispatcher)
{
parent::beforeExecuteRoute($dispatcher);
Copy link
Member

Choose a reason for hiding this comment

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

Wasn‘t this here before we added the x header below? Should it be deleted?

Copy link
Member

Choose a reason for hiding this comment

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

@fichtner should be safe to delete, falls back to ControllerBase->beforeExecuteRoute()

@fabianfrz
Copy link
Member Author

ping

@AdSchellevis
Copy link
Member

pong, sorry a bit busy. will pull it in now.

@AdSchellevis AdSchellevis merged commit 3a49512 into opnsense:master Mar 27, 2018
@AdSchellevis
Copy link
Member

@fabianfrz I'm going to drop the "default-src 'self';" in the security policy for the mvc code, this prevents plugins from using anything like open streetmap, which causes issues on some of our plugins. Not sure if this is the only issue with the more tightened security yet though. We might look into something at a later point to add trusted domains in the controller area, although I'm not sure what the best option is there yet.

@fabianfrz fabianfrz deleted the harden_gui_controllers branch April 19, 2018 19:54
@fabianfrz
Copy link
Member Author

Maybe inject or replace the values with properties like the values for the mutable controller. So secure defaults are kept.

BTW: Which plugin is using OSM? It should only require image-src to add the domain.
Openlayers or leaflet should be placed in the plugin.

@AdSchellevis
Copy link
Member

some custom work. adding the desired domains would indeed be better, but this needs a bit of work for a clear hook.

@fabianfrz
Copy link
Member Author

I dont think so. Adding a property $csp-image-source to the controller base should work and the defaults are the values of my pull request. Any controller that inherits the base controller, can override the default just by adding it in the class. In that case it would be controller wide which should not be a huge issue because most controllers do have 1-3 actions

@AdSchellevis
Copy link
Member

@fabianfrz this a8f54d2 should do the trick

@fabianfrz
Copy link
Member Author

Exactly the implementation I had in mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants