server icon indicating copy to clipboard operation
server copied to clipboard

Enforce HTTPS via .htaccess edit

Open LukasReschke opened this issue 10 years ago • 58 comments

Also offer GUI checkbox, check https://help.nextcloud.com/t/enforce-https-via-htaccess-file-integrity-check-error/663/4

LukasReschke avatar Jun 16 '16 11:06 LukasReschke

@LukasReschke You can already force HTTPs in the config/config.php file.

'forcessl' => true,
'forceSSLforSubdomains' => true,

williambargentball avatar Jun 17 '16 07:06 williambargentball

The forcessl-lines in config.php do not have an effect in my installation.

ambux avatar Jun 17 '16 08:06 ambux

@LukasReschke You can already force HTTPs in the config/config.php file.

They aren't present anymore since some versions - it was removed in 8.1 https://github.com/owncloud/core/pull/14651

MorrisJobke avatar Jun 17 '16 13:06 MorrisJobke

@MorrisJobke Oh, well it's still in the documentation. https://docs.nextcloud.org/server/9/admin_manual/configuration_server/config_sample_php_parameters.html?highlight=config

williambargentball avatar Jun 17 '16 13:06 williambargentball

@MorrisJobke Oh, well it's still in the documentation.

I can't find it on that page anymore 🙈 Could you check again? I searched for forcessl.

MorrisJobke avatar Jun 17 '16 14:06 MorrisJobke

Awesome, its been removed

williambargentball avatar Jun 17 '16 15:06 williambargentball

enabling https redirecting directly in .htaccess via checkbox in Adminarea would be really nice :)

https://forum.owncloud.org/viewtopic.php?f=21&t=34397&p=110792#p110792

<IfModule mod_rewrite.c>
RewriteEngine on
#-
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#-
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
RewriteRule ^remote/(.*) remote.php [QSA,L]
RewriteRule ^(build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*
RewriteRule ^(\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]

and so on ..

maybe setting up via checkbox in the Adminarea if this works :

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

and resetting up the HASH'es and correcting them ..

best regards Blacky

blackcrack avatar Jun 17 '16 15:06 blackcrack

i have simply done this in my webserver configuration (nginx). If we introduce a GUI checkbox in admin panel, we should make sure, that the user is able to access the installation via https (iframe with a token?!). Otherwise you may get locked out of your installation, once you enable that checkbox.

Spacefish avatar Jun 19 '16 23:06 Spacefish

This integrity check error also happens when you need to enable/modify the HTTP Strict Transport Security header in htaccess, see https://docs.nextcloud.com/server/9/admin_manual/configuration_server/harden_server.html#enable-http-strict-transport-security. How about adding this option to the GUI in the same run?

sushidave avatar Aug 03 '16 11:08 sushidave

Why was the checkbox removed with 8.1 😕 ..I think it caused bugs? @LukasReschke

MariusBluem avatar Aug 03 '16 13:08 MariusBluem

+1 :confused: .. a more easy possible would it be, change the .htaccess'es and make 2 of them, by check a checkbox change they are and change the hashes also.. as a suggestion for have the possible also use every a ssl protocol by any addresses and move it to https in any case, by checking the Checkbox '[X] Every using a Https Protocol '.

best regards Blacky

blackcrack avatar Aug 04 '16 16:08 blackcrack

Hi there, I was on Nextcloud 9.53 and made a manual update on my shared Hoster to Nextcloud 10. Everything works fine, but i got also the integrity check error if i modify my .htaccess in the main directory /nextcloud. I've tried to copy my .htaccess from my old Nextcloud and also modify the new .htaccess from Nextcloud 10. Both attemps ends in the integrity check error for the .htaccess file. In Nextcloud 9.53 it was no problem to edit this file. The integrity check had nothing to complain about.

So, does Nextcloud 10 now check also the .htaccess files and how can I successfully implement my code? I've added this lines:

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule (.*) https://my-domain.com/nextcloud/$1 [R=301,L]
Header set Strict-Transport-Security "max-age=31536000" env=HTTPS

Someone got an idea?

Thanks in advance!

Lancer107 avatar Aug 28 '16 11:08 Lancer107

I do have the same problem with the .htaccess file. I would really like to have this checkbox in the admin area :+1:

ggeorgg avatar Sep 01 '16 11:09 ggeorgg

In NextCloud 9.53 i have made the same adjustments in the .htaccess and the integrity check was OK. May it's a bug in Version 10? The best way i can imagine would be an option to exclude some files like the .htaccess.

Lancer107 avatar Sep 01 '16 17:09 Lancer107

humm.. :

-----snipp-----Version 9-----------------------
<IfModule mod_rewrite.c>
  RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
  RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
  RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
  RewriteRule ^remote/(.*) remote.php [QSA,L]
  RewriteRule ^(build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*
  RewriteRule ^(\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]

  # Rewrite rules for `front_controller_active`
  Options -MultiViews
~~~blablabla~~~~

blackcrack avatar Sep 01 '16 17:09 blackcrack

Oh what a pit, I am hosting on HostEurope and also use a rewrite rule in .htaccess for HTTPS support.

The integrity hint gives me the actual hash of my changed .htaccess file. Any way to correct the expected hash value manually?

Best Regards,

Martin

Martin-By avatar Sep 04 '16 17:09 Martin-By

nope, i have the same problem and looking over away for have a https automatical .. i have try to change the hash-file but it have works not.. unfortunately so i change only the .htaccess file and accept the message about the wrong hash .. :\ but i use at moment the vers. 9 because the automagically update procedure do curiously not work..
best regards Blacky

blackcrack avatar Sep 04 '16 19:09 blackcrack

A quick summary as of today and under a freshly installed Nextcloud 10.0:

  • HTTPS not enforced by default.
  • 'forcessl' => true in config/config.php has no effect.
  • Out-of-the-box .htaccess does not contain any rules enforcing secure connections either.
  • The security check at /settings/admin detects and warns about this security risk, providing a link to docs on "security tips".
  • The link (to #admin-tips) is broken (at least under my fresh installation in Spanish).

As the default installation is currently unsecure by default, I'd suggest reconsidering the priority assigned to this issue.

JaimeObregon avatar Sep 17 '16 23:09 JaimeObregon

Manual workaround is that after adding the two extra lines for enforcing https (see @blackcrack comment above) just do this: $ sha512sum .htaccess $ vim core/signature.json ... replace the hash for .htaccess, save and exit And viola, enforced https and no signature complaints from the system.

zpuskas avatar Nov 06 '16 09:11 zpuskas

Well, that will not realy work... I have already tested this solution, but if i "manipulate" the signatures, the following Error appears:

`Technical information

The following list covers which files have failed the integrity check. Please read the previous linked documentation to learn more about the errors and how to fix them.

Results

  • core
    • EXCEPTION
      • OC\IntegrityCheck\Exceptions\InvalidSignatureException
      • Signature could not get verified.`

So, this is not a fine solution for out Problem...

Lancer107 avatar Nov 06 '16 12:11 Lancer107