[DE / EN] Fantastic .htaccess settings and where to find them

CBACK Forum >= v4.4.0

 
cback
Admin
Avatar
Geschlecht:
Herkunft: Saarland
Alter: 37
Homepage: cback.net
Beiträge: 17610
Dabei seit: 12 / 2003
Betreff:

[DE / EN] Fantastic .htaccess settings and where to find them

 · 
Gepostet: 28.06.2018 - 18:09 Uhr  ·  #1
DE
Mit dem CBACK Forum in der Version 4.4.0 haben wir zum ersten Mal einige Empfehlungen für einige teilweise recht neue im Webstandard verankerte Techniken zu unserer Standard .htaccess hinzugefügt, die von Webmastern aktiviert werden können, um die Sicherheit und Privatsphäre für ihre Nutzer zu verbessern und auch für ihre Webhosting / Serverumgebung. Diese Einstellungen sind per Standard noch auskommentiert, werden aber in diesem Tutorial erklärt, sodass Webmaster entscheiden können, welche Optionen sie auf ihrer Seite aktivieren können und welche vielleicht nicht. Nutzer von älteren CBACK Forum 4 Versionen finden im Thread mit dem Update-Changelog der Version 4.4.0 auch eine gesonderte Anleitung, welche Änderungen an einer bestehenden .htaccess auszuführen sind, sodass diese Konfigurationsempfehlungen dort ebenfalls vorhanden sind.

Wie kann ich die einzelnen hier angesprochenen Konfigurationswerte in der .htaccess aktivieren?
Im Standardpaket sind die zusätzlichen Konfigurationsempfehlungen zunächst noch auskommentiert. Dies geschieht bei .htaccess Dateien mit einer Raute (#) vor der entsprechenden Konfigurationszeile. Um einen gewissen Konfigurationspunkt zu aktivieren ist es notwendig, die Raute vor der entsprechenden Zeile zu entfernen.

Beispiel:
So sieht eine noch deaktivierte Zeile aus:
Code
  # Header set Referrer-Policy "same-origin"


Und so kann man sie aktivieren:
Code
  Header set Referrer-Policy "same-origin"



Warum nicht einfach alle aktivieren?
Nicht jede Serverumgebung / Hosterumgebung bzw. auch nicht jede Variante einer eingesetzten Seite ist in der Lage alle Konfigurationen global zu verwenden. Hier ist es wichtig, dass Du je nach Deinem eigenen Fall entscheidest und weshalb in diesem Tutorial einige der neuen Konfigurationspunkte und was sie tun beschrieben werden. Fehler in der Konfiguration merkst Du übrigens, wenn Du nur noch weiße Seiten siehst, einen "Fehler 500" erhälst oder diverse Plugins oder Seiten Deiner Webseite nicht mehr richtig funktionieren.


Los geht's
Nachfolgend jeweils der Code der (im Standard deaktivierten) Zeilen in der .htaccess des CF4 und die Beschreibung was sie tun und in welchen Fällen man die entsprechende Konfiguration besser nicht einschalten sollte, um keine Probleme zu bekommen.

Code
Header always append X-Frame-Options SAMEORIGIN

Diese Einstellung vermeidet, dass Webseiten, die außerhalb Deiner eigenen Domain liegen, Deine Seite in einen Frame einbetten können. Dies verhindert einige XSS Szenarien. Sofern Du Deine Webseite nicht irgendwo selbst in Frames außerhalb Deiner eigenen Primärdomain eingebunden hast empfiehlt es sich, diese Einstellung auf jeden Fall zu aktivieren.

Code
Header set X-Content-Type-Options nosniff

Diese Einstellung weist den Browser dazu an bei unbekannten Dateitypen nicht zu "raten", um welche Art Datei es sich handeln könnte. Normalerweise ist beim CF4 auch bei Nutzung des Attachments System diese Einstellung ohne Probleme zu aktivieren. Solltest Du irgendwo auf Deiner Webseite außerhalb des CBACK Forums oder mit diversen Plugins Probleme bekommen, dass diverse Dateien vom Browser blockiert werden, dann stelle sicher, dass diese Dateien jeweils ihre korrekten MIME Types verwenden/senden oder deaktiviere diese Zeile in der .htaccess wieder. Diese Einstellung erhöht die Sicherheit Deiner Hostingumgebung und zwingt Scripte dazu, mit ihren liefernden Dateien/Dateitypen korrekt umzugehen.

Code
Header set Referrer-Policy "same-origin"

Diese Einstellung verhindert, dass die Herkunft (Referrer) Deiner Seite außerhalb Deiner Domain mitgeteilt wird. Wenn jemand also in Deinem Forum einen externen Link einbindet und Benutzer drauf klicken, sieht die Zielseite nicht mehr, dass jemand von Deiner Seite gekommen ist. Diese Einstellung kann man normalerweise in jeder Umgebung gefahrlos aktivieren. Sie macht Trackern und Fingerprintern das Leben schwerer und verbessert die Sicherheit und Privatspähre Deiner Nutzer, da eventuelle Parameter an der URL nicht mehr an Drittseiten übermittelt werden.

Wenn Du auch auf der eigenen Seite die Übermittlung des Referrers verhindern möchtest, kannst Du statt "same-origin" übrigens auch "no-referrer" verwenden. Dies kann jedoch Probleme mit anderen .htaccess Einstellungen verursachen, z.B. wenn Du festgelegt hast, dass Einbettungen von Bildern außerhalb Deiner eigenen Seite verboten werden sollen. (Der CBACK MediaManager bietet beispielsweise so eine Konfiguration an).

Code
Header set X-XSS-Protection "1; mode=block"

Aktiviere diese Einstellung bitte nur, wenn Du nicht den Google ReCAPTCHA2 benutzt und auch keine Werbesysteme oder Soziale Netzwerke per Plugin verwendest, die externe Scripte auf Deiner Seite einbinden! Diese Einstellung verhindert, dass externe Scripte außerhalb Deiner eigenen Domain eingebunden werden. Sofern Du diese Zeile aktivierst wäre zum Beispiel im CF4 Standardpaket die Nutzung der Google ReCAPTCHA2 nicht mehr möglich, da das von Google bereitgestellte externe Script dann blockiert wird. Sofern Du jedoch nur die CF4 CAPTCHA verwendest und auch keine Werbebanner mit externen Scripten auf Deine Seite bringst, kannst Du für eine höhere Sicherheit Deiner User diese Option aktivieren. Denke aber daran, dass Du sie aktiviert hast, sonst wunderst Du Dich, wenn künftig eventuelle externe Scripte nicht mehr laden.

Code
Header set Strict-Transport-Security "max-age=2592000" env=HTTPS

Aktiviere diese Option nur, wenn Deine Seite erfolgreich und 100% sicher (grünes Schloss-Symbol) per https erreichbar ist! Für die Einrichtung von https kann Dir der https Assistent helfen. Normalerweise sollte danach überall im CF4 eine vollständig verschlüsselte Verbindung vorliegen. Falls Du selbst Änderungen vorgenommen hast und noch ein gelbes Warndreieck auf Deinen https Seiten erhälst ("mixed content") kann das Aktivieren dieser Option zu Fehlern führen. Diese Option weist Deinen Browser strikt an, ausschließlich verschlüsselte Verbindungen herzustellen.


Code

RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)
RewriteRule .* - [R=405,L]

Diese zwei Zeilen musst Du gleichzeitig auskommentieren, wenn Du diese Einstellung nutzen willst. Normalerweise kannst Du sie gefahrlos aktivieren. Hierbei werden alle "exotischen" und eher nicht benötigten Anfragen auf Deinen Server blockiert. Das verbessert die Sicherheit Deiner Hostingumgebung deutlich. Im CF4 selbst und mit gängigen Plugins sollten die hier vorgeschlagenen Request Methods GET, POST und HEAD normalerweise vollständig ausreichen, um alle Funktionen problemlos verwenden zu können. Falls Du einmal wegen anderen Scripten weitere benötigst kannst Du diese oben jeweils mit | getrennt ergänzen.



Generell empfiehlt es sich auch, dass Du via .htaccess oder in den Einstellungen Deines Hosters Dich für eine gewünschte Primär-Domain entscheidest. Beispiel: Wenn Du https korrekt konfiguriert hast, sollten alle Anfragen über http:// automatisch auf https:// umleiten. Und wenn Du eine Domain jeweils mit oder ohne www. bevorzugst, dann sollte die jeweils andere Variante auf Deine bevorzugte Domain umleiten (wie Du sie auch im Forum konfiguriert hast). Dies erhöht zum einen die Sicherheit (https erzwingen, sofern Deine https Konfiguration korrekt ist, was Du u.a. mit dem https Assistenten des CF4 prüfen kannst), zum anderen vermeidet es Probleme mit dem Login und vermeidet "duplicate Content" bei Suchmaschinen. Tutorials hierzu findest Du reichlich im Web, hier im Forum selbst und auch als Beispiel in den .htaccess Dateien aller CF4 Versionen, weshalb in diesem Tutorial nicht weiter darauf eingegangen wird.




EN
With the CBACK forum in the version 4.4.0 we have - for the first time - added some recommendations for some (particially also quite new) technologies that were adapted into the web standard to our standard .htaccess, which can be activated by webmasters to improve security and privacy for their users and also to enrich the security for their webhosting / server environment. These settings are still commented out by default, but are explained in this tutorial so that webmasters can decide which options they should or should not activate on their specific site. Users of older CBACK Forum 4 versions will find the new .htaccess rules in the thread with the update changelog of version 4.4.0, so you can add these new suggestions to your existing .htaccess file without problems.

How can I enable the settings in my .htaccess?
The additional configuration recommendations are initially commented out in the standard package. For .htaccess files this is done with a hash char (#) before the corresponding configuration line. To activate a certain configuration item, it is necessary to remove the hash before the corresponding line.

Example:
This is how a still deactivated config line looks like:
Code
  # Header set Referrer-Policy "same-origin"


This is how you enable it:
Code
  Header set Referrer-Policy "same-origin"



Why not just activate them all?
Not every Sever environment / Hoster is able to support all the things mentioned here. And some individual changes at your page could cause some of these settings to make more problems than they solve. It is important that you decide individually what you can enable and what you should leave deactivated. If you cause an error with your new configuration you often see just a blank page when accessing your site or you will get an "Error 500". And possibly some scripts or plugins on your site stop working. This depends on what you maybe did to your site yourself outside the "out of the box" Version of the CF4. And this is why we explain in this tutorial what these settings will do to make it easier for you to decide what is ok for you and what is not.


Let's get started
In the following parts of this tutorial you will find the (deactivated by default) code from the .htaccess and an explaination below what this setting will do if you enable it. And when its maybe a good idea to leave it deactivated so your site still works without problems.

Code
Header always append X-Frame-Options SAMEORIGIN

This setting prevents your page to be embedded in a Frame outside of your own domain. This prevents some XSS Scenarios. If you have not embedded your page in frames somewhere you can (and should) enable this.

Code
Header set X-Content-Type-Options nosniff

This setting instructs the browser not to "guess" what type of file it might be when it comes to unknown file types. Normally with the CF4 this can be activated without problems even when using the Attachment System etc. If you get problems somewhere on your website outside of the CBACK Forum or with various plugins that some files are being blocked by the browser, please make sure that these files all use and send their correct MIME types. If you still get problems disable this line in the .htaccess again. This setting increases the security of your hosting environment and forces scripts to handle their files / file types correctly.

Code
Header set Referrer-Policy "same-origin"

This setting prevents the origin (referrer) of your page from being transmitted outside your own domain. So if someone uses an external link in your forum and users click on it, the destination page will no longer see that someone came from your site. This setting normally can be safely activated in any environment. It makes life more difficult for trackers and fingerprinters and improves security and privacy for your users, since any parameters at the URL are no longer transmitted to third parties.

If you also want to prevent the transmission of the referrer within your own page, you can also use "no-referrer" instead of "same-origin". However, this can cause problems with other .htaccess settings, e.g. if you have specified that embedding images outside of your own site should be prohibited. (For example, the CBACK MediaManager offers such a configuration).

Code
Header set X-XSS-Protection "1; mode=block"

Please only activate this setting if you DON'T use Google ReCAPTCHA2 or other external scripts like social network plugins or adbanners on your site. This setting prevents scripts from being embedded from other sources than your own domain. If you activate this line the usage of the Google ReCAPTCHA2 in the CF4 standard package would no longer be possible, because the Google-provided external script will be blocked. However, if you only use the CF4 CAPTCHA and do not use banner ads with external scripts on your site or social networks and stuff, you can activate this option for greater security for your users. Remember, however, that you have activated it, otherwise you would wonder in the future if any external scripts no longer load on your server.

Code
Header set Strict-Transport-Security "max-age=2592000" env=HTTPS

Only activate this option if your page can be reached successfully and 100% securely (green lock icon) via https! If you still get "mixed content" warnings or have no https configured at all you will get a lot of problems when enabling that setting. This setting ensures, that the browser only accepts completely encrypted connections to your site via https.


Code

RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)
RewriteRule .* - [R=405,L]

You must comment out these two lines at the same time, if you want to use this setting. Normally you can activate it safely. This blocks all "exotic" and rather unnecessary requests to your server. This significantly improves the security of your hosting environment. The CF4 itself and its most common plugins only use the suggested methods GET, POST and HEAD. If you ever need more because of other scripts you can add these with the | as seperator in the first line.



In general, it is also recommended that you configure automatic redirects to your primary domain via .htaccess or in your hoster's settings. Example: If you have configured https correctly, all requests should automatically redirect to https://. Even if somebody tries to access your site just with http://. And if you prefer a domain with or without www., then the other variant should redirect to your preferred domain (as you configured it in the forum settings). This increases security (enforcing https if your https configuration is correct, which you can check with the https wizard of the CF4) and it avoids login problems and "duplicate content" problems with search engines. You can find tutorials for this in the web, here in the forum itself and also as an example in the .htaccess files of all CF4 versions, which is why this tutorial does not deal with it further.
Gewählte Zitate für Mehrfachzitierung:   0

Registrierte in diesem Topic

Aktuell kein registrierter in diesem Bereich

Die Statistik zeigt, wer in den letzten 5 Minuten online war. Erneuerung alle 90 Sekunden.