The Wayback Machine - https://web.archive.org/web/20220717084021/https://github.com/nextcloud/nextcloudpi/issues/408
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

deny access to apache using public IP #408

Open
testbird opened this issue Feb 12, 2018 · 20 comments
Open

deny access to apache using public IP #408

testbird opened this issue Feb 12, 2018 · 20 comments

Comments

@testbird
Copy link
Contributor

@testbird testbird commented Feb 12, 2018

I found many unsolicited access attemps even in the NC admin interface log complaining about "secure domain" failures. These were requests using the external IP as domain.

Instead of having apache listening and NC block these request, maybe apached could be configured right away to only answer requests using IPs (instead of dns domain names) if they are local IPs.

Here is an example restricting request based on the source IP, which is another thing, but maybe the same ranges can be used to bypass a "apache secure domains configuration"
https://salsa.debian.org/freedombox-team/plinth/commit/21d6174ba052e22926f05b0a6806e3fa7f83c8f1

This is like in this question (however, the actual config for the solution there is at the duplicate question):
https://serverfault.com/questions/786809/block-direct-ip-connections-to-apache-web-server

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 13, 2018

hi, that is exactly what ncp-web does but... I do want to access to NextCloudPi from outside my local IPs.

I want to access from my phone, from work, and so on.

@testbird
Copy link
Contributor Author

@testbird testbird commented Feb 13, 2018

I want to access from my phone, from work, and so on.

Sure. But you know and use your (dyn)DNS name to access, while portscanners and search bots just try IPs (http://1.2.3.4 etc.) and spider whatever they find. What I thought about would have a similar result as if NC would return nothing in response to requests for "non-trusted domains" instead of the info page, ideally it would be as if the port wasn't opened at all in the firewall.

Its like the solution to this question (actual config of the solution is at the duplicate question)
https://serverfault.com/questions/786809/block-direct-ip-connections-to-apache-web-server

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 13, 2018

ok, I get you now... well that is interesting then, I just wonder if there will be use cases of people wanting to access through external IP address.

otherwise, I think it's worth implementing it

feeling brave to throw a PR at me? :P

@nachoparker nachoparker changed the title access attemps using external IP deny access from apache using public IP Feb 13, 2018
@testbird
Copy link
Contributor Author

@testbird testbird commented Feb 13, 2018

Yes, the use case would be those with a static IP and avoiding tracking of their DNS lookups (connection activity).

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 13, 2018

@testbird

feeling brave to throw a PR at me? :P

@testbird
Copy link
Contributor Author

@testbird testbird commented Feb 13, 2018

You don't necessarily need to ask. I do make PRs if I think it's reachable for me and I'm able to.
Still struggling with my docker container.

(In looking for above, I came accross a potentially vast apache config
https://askubuntu.com/questions/922085/i-need-rules-to-drop-some-malicious-apache-connection)

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 13, 2018

haha it was worth a try ;D

@theCalcaholic
Copy link
Collaborator

@theCalcaholic theCalcaholic commented Feb 14, 2018

It should definitely disabled if no domain is defined and probably not be enabled by default. I'm using NCP behind a static IP for instance - probably a few others as well.

Of course most will still use a domain (especially for proper TLS), but it would be confusing if you couldn't reach the instance by IP - which is also often necessary for debugging purposes.

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 14, 2018

It should definitely disabled if no domain is defined and probably not be enabled by default. I'm using NCP behind a static IP for instance - probably a few others as well.

Do you access from outside through static IP, not by DDNS domain name? It is true that we would block many attack attempts by implementing this.

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 14, 2018

Regardless of wether we do it or not, I am wondering if the following would work ( in /etc/apache2/sites-enabled/nextcloud.conf )

<RequireAny>
      Require host *
      Require local
      Require ip 192.168
      Require ip 172
      Require ip 10
</RequireAny>

We would need to test if host * would capture any hostname, but not direct access by IP. The other lines I know that work because are copied from ncp.conf, so they could be commented out for the test.

<RequireAny>
      Require host *
</RequireAny>

In that case, the above config should not allow any IP access (local or otherwise), but should allow domain access.

@theCalcaholic
Copy link
Collaborator

@theCalcaholic theCalcaholic commented Feb 14, 2018

@nachoparker I do for testing/debugging purposes mainly (port/DNS setup and such).

@testbird
Copy link
Contributor Author

@testbird testbird commented Feb 14, 2018

I think you'll still be able to test the port forwarding as you see a "not allowed" message from apache.

@testbird
Copy link
Contributor Author

@testbird testbird commented Feb 14, 2018

From what I read in the links above "host *" would have to be in the first (used as default) virtual host stanza (whichever that may be with multiple files).

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 15, 2018

in a quick test, host * it didn't work, I guess that the solution would be to, if anything, add these lines only when we set up DDNS

<RequireAny>
      Require local
      Require ip 192.168
      Require ip 172
      Require ip 10
</RequireAny>
@testbird
Copy link
Contributor Author

@testbird testbird commented Feb 15, 2018

maybe a regexp is expected? .*

@testbird
Copy link
Contributor Author

@testbird testbird commented Feb 15, 2018

No, i actually just commented out "Require host localhost", it checks the domain of the ip the request is comming from, and reverse lookup does not work for every ip, and not at all in the docker container.

The solution to this issue is, as in the linked answers above, have a first "dummy" virtualhost block everything (it gets used as fallback for non defined virtual hosts).

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 22, 2018

The solution to this issue is, as in the linked answers above, have a first "dummy" virtualhost block everything (it gets used as fallback for non defined virtual hosts).

I aggree, it would be nice if somebody could come up with this configuration, as my hands are pretty full right now

@Aeon512
Copy link
Contributor

@Aeon512 Aeon512 commented Feb 23, 2018

Just wanted to throw in my opinion on this.
Why not using the geoip database, and overing an option in NCP to specify which countries are allowed to externally access NextCloud?

Usually, there are only a few countries where you usually want to have access from, so you would filter out a lot of unwanted accesses.

Having said that, the best approach is still to enabled the two factor authentication plugin in NextCloud and enforce this for all users.

@nachoparker
Copy link
Member

@nachoparker nachoparker commented Feb 26, 2018

Thanks

Usually, there are only a few countries where you usually want to have access from, so you would filter out a lot of unwanted accesses.

This would prevent us from using Tor

@testbird testbird changed the title deny access from apache using public IP deny access to apache using public IP Jun 16, 2018
@szaimen
Copy link

@szaimen szaimen commented Nov 28, 2020

Hey, maybe something here can be useful?
https://github.com/nextcloud/vm/blob/master/network/geoblock.sh

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