未在端口 80 上禁用 Apache TRACE 方法

未在端口 80 上禁用 Apache TRACE 方法

我尝试了多种方法来禁用 Apache 网络服务器上的 TRACE 方法,但由于某种原因,它在端口 443 上被禁用,但在端口 80 上没有被禁用。

我已将以下指令添加到配置文件的顶部:

TraceEnable off

然后将以下内容添加到:80 和:443 VirtualHost 块:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|DELETE)
RewriteRule .* - [F]

curl --insecure -v -X TRACE当我在 Web 服务器上运行 时,我正确地获得了403 Forbiddenhttps 的 ,但200 OK获得了 http 的 。可能需要注意的是,我确实为所有到 https 的 http 连接设置了永久重定向。此 Web 服务器还作为反向代理运行。编辑:我尝试将永久重定向更改为规则mod_rewrite,但测试仍然失败curl TRACE

配置文件:

NameVirtualHost XX.XX.XX.XX:80
NameVirtualHost XX.XX.XX.XX:443

SSLSessionCache "shm:logs/ssl_scache(512000)"

Timeout 2400
ProxyTimeout 2400
ProxyBadHeader Ignore

FileETag None

Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
Header always append X-Frame-Options SAMEORIGIN
Header set X-XSS-Protection "1; mode=block"

TraceEnable off

<VirtualHost XX.XX.XX.XX:80>
   ServerName www.xxxxxxx.com:80
   ServerAlias www.xxxxxx.com
   ServerAdmin localhost@root
   RewriteEngine On
   RewriteCond %{HTTPS} !=on
   RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R]
   RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|DELETE)
   RewriteRule .* - [F]


   ErrorLog "|/usr/sbin/rotatelogs /etc/httpd/logs/error.%Y-%m-%d.log 86400"
   CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/access.%Y-%m-%d.log 86400" common

   #Redirect permanent / https://www.xxxxxxx.com:443/
</VirtualHost>

<VirtualHost XX.XX.XX.XX:443>
    Options Includes FollowSymLinks MultiViews
    ServerName www.xxxxxxxx.com:443
    ServerAlias www.xxxxxxxx.com
    ServerAdmin localhost@root

    SSLProxyEngine On
    SSLEngine On
    SSLProtocol all -SSLv2 -SSLv3
    SSLHonorCipherOrder On
    SSLCipherSuite ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
"/etc/httpd/ssl_certs/hdsisd/Apache_Plesk_Install.txt"
    SSLCertificateFile "/etc/httpd/ssl_certs/xxxxx.crt"
    SSLCertificateKeyFile "/etc/httpd/ssl_certs/server.key"
    SSLCertificateChainFile "/etc/httpd/ssl_certs/Apache_Plesk_Install.txt"

    ErrorLog "|/usr/sbin/rotatelogs /etc/httpd/logs/error.%Y-%m-%d.log 86400"
    CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/access.%Y-%m-%d.log 86400" common

    RewriteEngine On
    RewriteCond %{THE_REQUEST} !HTTP/1.1$
    RewriteRule .* - [F]
    RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|DELETE)
    RewriteRule .* - [F]
    ProxyPreserveHost On
    <Location />
        ProxyPass https://XX.XX.XX.XX/ Keepalive=On
        ProxyPassReverse https://XX.XX.XX.XX/
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>

答案1

我知道我对此已经很晚了。但这是为将来可能需要此问题的人提供的答案。问题是由于配置文件造成的,如果您注意到提问者正在使用以下重定向条件:

RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R]

将 HTTP 流量重定向到 HTTPS,这会强制服务器重定向到 HTTPS 协议并忽略这些行以下的所有内容。因此,他无法禁用 HTTP 请求上的跟踪方法。因此,解决方法是将跟踪注释移到重定向上方,如下所示:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|DELETE)
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R]
RewriteRule .* - [F]

相关内容