Verhindern, dass Benutzer Dateien über eine URL auf dem lighttpd-Webserver öffnen

1419
Daniel Jørgensen

Ich habe eine Website, die JSON-Dateien zum Speichern von Einstellungen verwendet. Diese Dateien befinden sich in einem Unterordner, so dass es aussieht /settings/settings.json.

Wenn ich die IP-Adresse in das lokale Netzwerk eingebe, kann http://192.168.1.1/settings/settings.jsonich den Inhalt der JSON sehen. Ich muss das irgendwie verhindern, und ich denke, dass ich dies vielleicht über eine .htaccess-Datei machen kann, aber nicht sicher. Der Domainname ( 192.168.1.1) ist dynamisch und kann sich von Zeit zu Zeit ändern. Ich muss also einen dynamischen Weg finden, um dies zu verhindern.

1

1 Antwort auf die Frage

0
DavidPostill

I am able to see the contents of the json. I need to prevent this somehow

If you are using Apache, then you can use:

  • A .htacess file

  • A Directory block in httpd.conf (better performance)

If you are using Lighttpd, then you can use:

  • A url.access-deny directive in lighttpd.conf

See below for instructions.


Apache - Using a .htacess file

Create a .htaccess file in the settings directory with the following content:

deny from all 

That will deny access to any file in that folder.

Note:

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.

Source Apache HTTP Server Tutorial: .htaccess files


Apache - Using a Directory block in httpd.conf

Add the following to your httpd.conf file

<Directory "/settings"> Require all denied </Directory> 

Lighttpd - Using a url.access-deny directive in lighttpd.conf

The mod_access module is used to deny access to files and directories.

  1. Edit /etc/lighttpd/lighttpd.conf file as follows:

    vi lighttpd.conf 
  2. Add the following code to enable mod_access:

    server.modules += ( "mod_access" ) 
  3. Add regex as follows:

    # deny access to /settings $HTTP["url"] =~ "^/settings/" { url.access-deny = ("") } 
  4. Save and close the file.

  5. Check for syntax errors:

    lighttpd -t -f /etc/lighttpd/lighttpd.conf 
  6. If no errors then restart the lighttpd web server:

    service lighttpd restart 

Source Lighttpd Deny Access To Folders / Directories. Script has been tweaked to match the requirements of the question.


Further Reading

Ich kann keine httpd.conf-Datei in meinem System finden. Ich habe es mit `find / -name httpd.conf` gesucht, aber es wird nichts zurückgegeben. Könnte es einen anderen Namen haben? Ich benutze lighttpd bei einer Debian-Variante Daniel Jørgensen vor 8 Jahren 0
@ DanielJørgensen Anweisungen für Lighttpd hinzugefügt. Die Datei ist /etc/lighttpd/lighttpd.conf/, hat jedoch eine andere Syntax als Apache. DavidPostill vor 8 Jahren 0