Русское сообщество fluxbb

Быстрый лёгкий надёжный форумный движок

Вы не вошли.

Объявление

Вы можете внести свой вклад в содержание сайта. Жертвователи попадут в почетную группу "Спонсоры". Поддержать сайт.

#1 2021-01-11 16:15:54

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Добавим чуть-чуть безопасности

По умолчанию FluxBB отдает только один заголовок безопасности X-Frame-Options.
Вот как это выглядит на fluxbb.org:
sec1.png
sec2.png

Мой пример .htaccess файла для сервера apache:

AddDefaultCharset UTF-8

<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

<ifModule mod_headers.c>
  # Set security headers if missing.
  # (This Content-Security-Policy makes almost no sense (there are many inline scripts and styles on the forum, frames from media sites are allowed).)
  #
  ### Only works in Apache 2.4.10+ (Reason, condition  -> "expr = -z% {resp: ...}") ###
  #
  Header always set Content-Security-Policy "object-src 'none';frame-ancestors 'none';base-uri 'none';form-action 'self'" "expr=-z %{resp:Content-Security-Policy}"
  Header always set Feature-Policy "accelerometer 'none';ambient-light-sensor 'none';autoplay 'none';battery 'none';camera 'none';document-domain 'self';fullscreen 'self';geolocation 'none';gyroscope 'none';magnetometer 'none';microphone 'none';midi 'none';payment 'none';picture-in-picture 'none';sync-xhr 'self';usb 'none'" "expr=-z %{resp:Feature-Policy}"
  Header always set Referrer-Policy "strict-origin-when-cross-origin" "expr=-z %{resp:Referrer-Policy}"
# for https only mode
#  Header set Strict-Transport-Security "max-age=31536000" "expr=-z %{resp:Strict-Transport-Security}"
  Header always set X-Content-Type-Options "nosniff" "expr=-z %{resp:X-Content-Type-Options}"
  Header always set X-Frame-Options "DENY" "expr=-z %{resp:X-Frame-Options}"
  Header always set X-XSS-Protection "1; mode=block" "expr=-z %{resp:X-XSS-Protection}"
  Header always set Permissions-Policy "accelerometer=(),ambient-light-sensor=(),autoplay=(),battery=(),camera=(),document-domain=(self),fullscreen=(self),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),midi=(),payment=(),picture-in-picture=(),sync-xhr=(self),usb=()" "expr=-z %{resp:Permissions-Policy}"

  # Remove headers containing php information
  Header unset X-Powered-By
  Header always unset X-Powered-By
</ifModule>

# Hiding information about the system
ServerSignature Off
#ServerTokens ProductOnly # Use only in server config, do not use in .htaccess

# More info: https://github.com/h5bp/server-configs-apache/blob/master/dist/.htaccess

Установить нормальную Content-Security-Policy проблематично sad

Редактировался Visman (2022-01-13 05:40:15)

Offline

#2 2021-01-13 19:17:10

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Добавим чуть-чуть безопасности

Пример nginx конфига:

#
# Example nginx configuration for fluxbb
# The engine is installed at the root of the site
#
server {
    listen 80;                                             # 80 port only http:
    server_name fluxbb-visman.local *.fluxbb-visman.local; # you need to set your values
    root "/www/fluxbb-visman/";                            # you need to set your values
    autoindex off;
    index index.html index.htm index.php;
    charset utf-8;
    server_tokens off;

    add_header Content-Security-Policy "object-src 'none';frame-ancestors 'none';base-uri 'none';form-action 'self'" always;
    add_header Feature-Policy "accelerometer 'none';ambient-light-sensor 'none';autoplay 'none';battery 'none';camera 'none';document-domain 'self';fullscreen 'self';geolocation 'none';gyroscope 'none';magnetometer 'none';microphone 'none';midi 'none';payment 'none';picture-in-picture 'none';sync-xhr 'self';usb 'none'" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;
#   add_header Strict-Transport-Security "max-age=31536000" always;  # for https only
    add_header X-Content-Type-Options "nosniff" always;
#   add_header X-Frame-Options "DENY" always;                        # fluxbb set this header, in nginx it is difficult to combine headers from two sources
    add_header X-XSS-Protection "1; mode=block" always;
    add_header Permissions-Policy "accelerometer=(),ambient-light-sensor=(),autoplay=(),battery=(),camera=(),document-domain=(self),fullscreen=(self),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),midi=(),payment=(),picture-in-picture=(),sync-xhr=(self),usb=()" always;

    location = /favicon.ico {
        try_files $uri =404;

        access_log off;
        log_not_found off;

        expires 1w;
    }

    location = /robots.txt {
        try_files $uri =404;

        access_log off;
        log_not_found off;
    }

    location / {
        try_files $uri =404;
    }

    location ~ /\.ht {
        return 404;
    }

    #                                                  #
    # Only php scripts located in the root of the site #
    #                                                  #
    location ~ ^/(?:[^/\\\.]+\.php)?$ {
        # regex to split $uri to $fastcgi_script_name and $fastcgi_path
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        # Check that the PHP script exists before passing it
        try_files $fastcgi_script_name =404;

        # Bypass the fact that try_files resets $fastcgi_path_info
        # see: http://trac.nginx.org/nginx/ticket/321
        set $path_info $fastcgi_path_info;                 # always equal to an empty string due to location regex
        fastcgi_param PATH_INFO $path_info;

        fastcgi_index index.php;

        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTP_PROXY      "";

        fastcgi_hide_header X-Powered-By;

        fastcgi_pass php_upstream;                         # you need to set your values
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ \.php$  {
        return 404;
    }
}

Запускаются php файлы лежащие только в корне сайта, остальные php файлы вернут 404 ошибку.

Редактировался Visman (2022-01-13 05:40:35)

Offline

Подвал доски

Под управлением FluxBB. Хостинг Hostens