我有一个受HTTP基本authentication保护的Apache网站。 身份validation正常工作。 现在我想通过依赖HTTP Referer头来绕过来自特定网站的用户的身份validation。
这是configuration:
SetEnvIf Referer "^http://.*.example\.org" coming_from_example_org <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Deny from all Allow from env=coming_from_example_org AuthName "login required" AuthUserFile /opt/http_basic_usernames_and_passwords AuthType Basic Require valid-user Satisfy Any </Directory>
这对HTTP正常工作,但HTTPS失败。 我的理解是,为了检查HTTP标头,必须完成SSL握手,但是,在进行SSL握手之前, apache要检查<Directory>指令,即使将它们放在configuration文件的底部。
问:我怎么能解决这个问题?
PS:我不迷恋HTTP referer头,我可以使用其他选项,允许来自已知网站的用户绕过自动authentication。
你可能会想要改进你的authentication机制, 考虑到引用标题是由客户端控制的,我期望它会花费大约18秒的时间来计算你正在做的事情并绕过它。
我会使用的机制可能涉及到为您的网站设置一个cookie,指出用户是“预先authentication”。 然后你可以在你的apacheconfiguration文件中testing这个cookie的存在(和encryption有效的)内容,并允许以这种方式访问。
我build议你使用授权脚本
即。 mod_python http://modpython.org/live/current/doc-html/dir-handlers-auh.html
你可以使用这样的东西:
def authenhandler(req): if req.headers_in.get("referer") == 'yourhostname': return apache.OK pw = req.get_basic_auth_pw() user = req.user if user == "spam" and pw == "eggs": return apache.OK else: return apache.HTTP_UNAUTHORIZED
mod_perl可以处理脚本authentication,也可能处理其他语言