大网数据广告活动
服务器运维问答

Apache httpd whitelist access control via X-Forwarded-For header

· 52CE 我爱测

I have the following httpd.conf file which I am using to test X-Forwarded-For header IP whitelisting. Note that the conf.d directory is empty: Include conf.modules.d/*.conf ServerRoot "/etc/httpd" Listen 80 Listen 443 User dev Gr…

问题原文

原帖链接 · mikeb · CC BY-SA 4.0

I have the following httpd.conf file which I am using to test X-Forwarded-For header IP whitelisting. Note that the conf.d directory is empty:

Include conf.modules.d/*.conf
ServerRoot "/etc/httpd"
Listen 80
Listen 443

User dev
Group dev
ServerAdmin root@localhost
ServerName my-httpd-server

<Directory />
AllowOverride none
Require all denied
</Directory>

<Files ".ht*">
Require all denied
</Files>

<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>


AddDefaultCharset UTF-8

<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options -Indexes +FollowSymLinks
    AllowOverride None
    LogLevel debug
    Order deny,allow
    Deny from all
    #Satisfy any


    SetEnvIf X-Forwarded-For ^171.159.192.10 letmein

    Allow from env=letmein

     Satisfy any
</Directory>


IncludeOptional conf.d/*.conf

When I cURL to get the local page with this server, it works regardless of the XFF header:

curl -H 'X-Forwarded-For: 8.8.8.8' http://localhost

curl http://localhost

These work, but print the following in the error log (These requests should not work):

[Mon Dec 17 10:24:53.346021 2018] [access_compat:error] [pid 12] [client 172.17.0.1:49010] AH01797: client denied by server configuration: /var/www/html/
[Mon Dec 17 10:24:53.346614 2018] [authz_core:debug] [pid 12] mod_authz_core.c(809): [client 172.17.0.1:49010] AH01626: authorization result of Require all granted: granted
[Mon Dec 17 10:24:53.347603 2018] [authz_core:debug] [pid 12] mod_authz_core.c(809): [client 172.17.0.1:49010] AH01626: authorization result of <RequireAny>: granted

The following request from the whitelisted IP works but without the logging noise:

curl -H 'X-Forwarded-For: 171.159.192.10' http://localhost:8181/

What is causing the requests that should fail to return the web page? I get the message that it should be denied based on the config?

已采纳解答

原帖链接 · SteamerJ · CC BY-SA 4.0

I think you need the satisfy any bit to be changed to satisfy all. That refers to allowing a user if they meet the authentication OR access requirements. Since I don't see an authtype set, it's defaulted to AuthType none which I think allows them to pass in. satisfy all means Authentication AND Access are required to be met.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。