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

Can I use rate-limiting with HTTP basic authentication in Apache?

· 52CE 我爱测

So I'm running a few popular web applications on my server. I want these to be reachable from any computer without creating too many vulnerabilities. I am using Apache 2.4.29 as my HTTP server. My current idea for hiding potentia…

问题原文

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

So I'm running a few popular web applications on my server. I want these to be reachable from any computer without creating too many vulnerabilities.

I am using Apache 2.4.29 as my HTTP server. My current idea for hiding potential security vulnerabilities in my applications from attackers is to enable HTTP basic authentication (AuthType Basic) for the relevant virtual hosts as an additional security layer. Of course, I'm only allowing SSL connections.

Now this is all quite easy to accomplish. But my question is this: how can I best avoid brute force style attacks with HTTP basic authentication? I.e., how can I enable rate limiting?

My current plan is something like this:

Since I'm using ufw (Uncomplicated Firewall) to limit SSH connections, I thought I could do the same on a specific port I use for HTTPS. However, I see two problems with this:

  1. Can't an attacker just use Connection: Keep-Alive and keep trying different passwords without even reconnecting? So limiting incoming connections wouldn't be of any use here.
  2. If I disabled Connection: Keep-Alive somehow, I guess I would run into trouble with the underlying web applications, since they would require a lot of individual connections so the browser can retrieve additional files.

It would be perfect if I could instruct Apache to only keep the connection going for authenticated users and drop it for failed attempts. Is there a way to do this? I am actually not sure what is the default behavior and don't understand enough about HTTP to easily test this.

The KeepAlive and MaxKeepAliveRequests settings in Apache can apparently be configured on a per virtual host basis, but I'm not sure how I could change these settings based on a successful authentication.

已采纳解答

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

HTTP basic authentication is done by sending an additional header in the each and every request the client makes, i.e. for each and every resource.

Authorization: Basic <credentials>

If you do not provide this header in a request, you will be prompted to provide credentials.

There is thus no single login page which you can protect by any kind of rate limiting or firewall rules. Rate limiting all pages also is not an option. Should you rate limit each IP address to only one request per second, valid users can only fetch one resource per second. Loading a web page, two style sheets, and four images, would thus take at least seven seconds.

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

资料来源与适用范围

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

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

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