networking, nextcloud, security

NextCloud, a security analysis

There is no privacy without security.

First, I would like to scare everyone a little bit in order to have people appreciate the extent of  this statement.

As the figure that opens the post indicates, there are thousands of vulnerable Owncloud/NextCloud instances out there. It will surprise many just how easy is to detect those by trying out common URL paths during an IP sweep.

But let’s hear all this from NextCloud creator himself

It certainly is a good amount of work keeping your system secure and up to date, but we have to think that we risk exposing our most private data.

Let our analysis begin.

NextCloudPi

At the end of the day, NextCloud is a web service that needs to be run on a system. This means that the system needs to be secure as well as the web application. I will use NextCloudPi as an example, but many things will apply to other installations.

Let’s see how NextCloudPi deals with this

  • Unattended security updates: NextCloudPi automatically applies the latest security patches.
  • Fail2Ban brute force protection: not only for NextCloud but also for SSH
  • HTTPS by default: any attempt to use HTTP will be redirected to HTTPS
  • HTTP Strict Transport Security (HSTS)
  • Let’s Encrypt CA signed trusted certificates.
  • ModSecurity WAF: web application firewall configured to work with NextCloud
  • TLSv1.2: NextCloudPi only accepts modern cryptographic protocols.
  • Strong Forward Secrecy: ECDH based CipherSuites.

We will explain these more in the last section.

NextCloud

From the NextCloud developers side, they already do quite a bit.

They use secure configurations whenever they can. We can see how they try to protect the user in different places of their code. More on that later.

They also provide very nice documentation on hardening your system, and warn the user whenever an update is available, and perform really helpful checks in the admin page.

One thing that they have yet to improve, as they admit in the video, is the ability to roll out automatic security updates for NC the in the way WordPress already does. That is challenging but if properly done, it would definitely help deal with the current situation of so many outdated installations.

I understand those people. It is the third time I upgrade my personal cloud and it is really time consuming. It is one of the reasons I came up with NextCloudPi, as I have automated the process not only for myself, but for other people.

Other nice security features were added to NC 11, such as two step verification, CSRF protection, built-in brute force protection and more. You can check them out in this article.

Testing tools

NextCloud Security Scan

However, not everything is under the control of the developers. The system where NC runs is not, for example, and that is why they have come up with an online service where you can assess how vulnerable your NC installation is.

NextCloud Security Scan

I resurrected an old OwnCloud 8 instance that I had lying around and compared to the latest NextCloudPi based on NC 11.0.2. Let’s see the results, and we will explain some of the vulnerabilities in the last section.

OwnCloud 8.1.3
OwnCloud 8.3 in-security

OwnCloud 8.3 in-security
NextCloudPi 11.0.2
NextCloudPi 11.0.2
NextCloudPi 11.0.2

Good job, NC developers!

SSL Labs

SSL Labs provides an amazing free service to test the security of your server.

A+ in SSL labs test

NextCloudPi passes with flying colors! We will discuss some of the vulnerabilities and protections in the last section.

We can harden the security even more by specifying that we only allow TLSv1.2. We can do so by using the following line of configuration

TLSv1.2 only

The implication of this is that older browsers will not be able to access our cloud. In my opinion that is just fine, because we benefit from having a smaller attack surface not only for known vulnerabilities, but also for potential new ones that can be discovered for the older protocols.

Lots of red here

If this is not desireable, for instance because your phone is Android < 4.4, it is okay to leave it as

Only disable SSL

The compatibility with older clients is now greatly expanded.

More green, but is that better?

Finally, we can see what other vulnerabilities are present in our system

Details
Other tools

These are other free services where you can have your website security evaluated.

https://securityheaders.io/
https://observatory.mozilla.org/

Details

If you would like to know a little bit more about some of the weird acronyms and concepts that have been appearing throughout this post, a brief explanation follows.

Security headers

First, let’s look at the response headers from our NextCloud instance related to security

  • Strict-Transport-Security, abbreviated HSTS, is a security mechanism where the server tells the browser that only HTTPS can be used. The browser will refuse to connect if the certificate can’t be trusted or through normal HTTP, and will automatically convert any link that uses HTTP to HTTPS.
  • The server signature is hidden, through the use of ModSecurity as explained in this post.
  • X-Frame-Options: “SAMEORIGIN”, specifies that only frames originating in your cloud can be rendered. This is a protection against clickjacking.
  • X-XSS-Protection: “1; mode=block”, configures Internet Explorer to block any XSS attempt, which means that only scripts hosted in your cloud will be executed.
  • X-Content-Type-Options: “nosniff”, disables MIME type sniffing in Internet Explorer which is an unsafe feature that can be subject to attacks by specially crafted downloads of resources.
  • X-permited-cross-domain-policies: “none”, disallows embedding of your content in other media, such as PDF and Adobe Flash. The server will refuse such requests.
  • content-security-policy, also known as CSP, is a mechanism where the server instructs the browser what types of data are going to be served. The client will whitelist those and refuse all others.
  • X-Firefox-Spdy: “h2”, indicates HTTP/2, which de facto only works with HTTPS, as major browsers decided only to serve HTTP/2 over HTTPS.
Firefox refusing to connect insecurely because of HSTS

Most of these security headers are put in place by NextCloud, and only HSTS, hiding server signature and using HTTP/2 are part of the server configuration of NextCloudPi.

CSRF

Also, NextCloud has protection against cross site request forgery (CSRF) attacks. Places like lib/base.php and core/ajax/update.php provide same site cookies and checks for the validity of the requests.

CSRF are attacks that take advantage of the fact that you are logged in and NC trusts you, so for instance they can insert a malicious URL in an image in another tab in another website that performs an authenticated operation on your system, say changing the admin password.

As soon as you open the tab and the browser tries to load the image at that URL the malicious operation triggers, because you have an active session cookie in the same browser.

The most straightforward way to prevent this is to create random session token and to require it in every request. The code in the malicious tab has no way of knowing it because it was not served by the legitimate web server.

TLS fallback attacks

The encryption protocol that the web uses nowadays is TLS. TLS is the replacement for the older SSL, which is around 20 years old and still around on some clients.

I will quote this excellent source

There are five protocols in the SSL/TLS family: SSL v2, SSL v3, TLS v1.0, TLS v1.1, and TLS v1.2:

SSL v2 is insecure and must not be used. This protocol version is so bad that it can be used to attack RSA keys and sites with the same name even if they are on an entirely different servers (the DROWN attack).

SSL v3 is insecure when used with HTTP (the POODLE attack) and weak when used with other protocols. It’s also obsolete and shouldn’t be used.

TLS v1.0 is also a legacy protocol that shouldn’t be used, but it’s typically still necessary in practice. Its major weakness (BEAST) has been mitigated in modern browsers, but other problems remain.

TLS v1.1 and v1.2 are both without known security issues, but only v1.2 provides modern cryptographic algorithms.

TLS v1.2 should be your main protocol because it’s the only version that offers modern authenticated encryption (also known as AEAD). If you don’t support TLS v1.2 today, your security is lacking.

A TLS fallback attack occurs when the a MITM tricks the browser and server into using a legacy insecure protocol in order to exploit it, so it can bypass TLSv1.2.

It is a downgrade attack caused by browsers not being strict in the protocol negotiation and allowing vulnerable protocols to go through. There is good information on this page, but it sums up to “browsers decided they prefer to render all pages rather than refusing to work with buggy servers”. This is browsers wars for you.

The mechanism to deal with this situation is TLS Fallback Signaling Cipher Suite Value (SCSV), which allows the browser to signal a server that it indeed supports the newest protocol while at the same time, saying that it supports the old suite for the old buggy servers to accept it. A modern server that is able to read this extra information will act in consequence and refuse the protocol downgrade.

There is a number of important attacks based on this, like

You can see that NextCloudPi is protected against those in the SSL labs report, as the openSSL version that ships with NextCloudPi supports TLS_FALLBACK_SCSV.

This is easy to test. Let’s try to connect using TLSv1.1 but adding the extra info that we support TLSv1.2 with the TLS_FALLBACK_SCSV mechanism.

We can see how the server refuses the illegal downgrade.

Another option I recommend is to disable SSL2 and SSL3 altogether. Like I said before, there is not enough level of paranoia for your personal cloud.

Forward secrecy

This would be long to explain properly, but let’s just say that even if somebody cannot decrypt your communications right now, it does not mean that they cannot store them and wait until they can somehow get hold of your encryption keys and then be able to read the stored contents.

If your key negotiation protocol provides protection against this situation it is said to provide forward secrecy.

The classic way of key negotiation is the RSA-key exchange mechanism which does not provide forward secrecy, but is still used by the majority of sites because it requires less CPU power. Should the server’s private key ever be compromised, all stored communication with that server would be instantly available.

Key negotiation based on the Diffie-Hellman key exchange mechanism does provide forward secrecy because the keys are negotiated, used and then disposed of. Single use disposable keys.

NextCloudPi uses Cipher Suites based on DH key exchange and that is why the suites in the test results above all start with TLS_ECDHE_.

DH stands for Diffie-Hellman. EC stands for Elliptic Curve Cryptography, which is a mathematical method for only using keys that are intrinsically stronger (require less bits for the same amount of computing power required to break it). Put it altogether and you get Elliptic Curve Diffie Hellman Exchange.

Conclusion

So hopefully by now you have a grasp of what the security for your self hosted data implies. The TL;DR takeaway message from this post is

Use NextCloudPi, activate all security extras and update NextCloud whenever you receive an alert to do so

There is always more to be done, but this is currently where we are sitting at.

Suggestions and corrections are very welcome.

References

https://www.perpetual-beta.org/weblog/security-headers.html

https://danielnixon.org/http-security-headers/

https://www.html5rocks.com/en/tutorials/security/content-security-policy/

HTTP Strict Transport Security (HSTS) – Better Security for Applications

Author: nachoparker

Humbly sharing things that I find useful [ github dockerhub ]

8 Comments on “NextCloud, a security analysis

  1. Thank you for the image, it works so smooth, just perfect. And the security addons are also very time saving.
    I´m not really a Linux pro so I have to ask you something regarding security.

    I installed your image without any changes from my side. Would I have problems if I change the database user and password or if I disable the pi user?

    1. No problem disabling the pi user at all. I also do it myself 🙂

      If you change the database credentials, you have to replicate them in /var/www/nextcloud/config/config.php

      cheers,

  2. Are you using the same MySQL password for every users? That’s not very secure. I advice to change it for every user that mounts the image automatically.

    That’s how it’s done in the Nextcloud VM.

    1. Thanks for the suggestion.

      It is also the way they do it in the Nextcloudbox Snap, so I had it in mind already.

      It is in the list of improvements to come, but I need to make some deep changes to implement it.

      Not critical, because at the point they have access to the database it is already too late, but a nice improvement for sure.

      Thanks! We need as many eyes as possible looking at these things.

Leave a Reply

Your email address will not be published. Required fields are marked *