alist icon indicating copy to clipboard operation
alist copied to clipboard

增加能对“请求频率”进行限制的安全策略功能

Open ppekora opened this issue 3 years ago • 5 comments

Please make sure of the following things

  • [X] I have read the documentation.
  • [X] I'm sure there are no duplicate issues or discussions.
  • [X] I'm sure this feature is not implemented.
  • [X] I'm sure it's a reasonable and popular requirement.

Description of the feature / 需求描述

有一部分人得到alist你的公开的地址之后,不知道出于什么目的,它们会故意恶意刷取请求 比如疯狂请求某一个文件的直链,达到刷爆api的效果

有些用api挂载的网盘,这些api会有限额,如果调用非常非常频繁时甚至服务供应商会封号处理 它们可能觉得好玩,或许就是为了恶心人

比如google driver的api限额

名称 限额
单帐号上传 750GB/天
单帐号下载 10TB/天
浏览次数 50000 次/天
同时打开次数 900 次/分钟
个人盘日转出 2TB/天
团队盘日转出 20TB-40TB/天
单文件大小 5TB/文件
触发了以上其中一条 等24小时后恢复

Suggested solution / 实现思路

我现在用nginx+lua+redis来分析从alist导出的日志,然后动态的增加黑名单ip拉黑处理 虽然能处理,但是显得繁琐需要另外运行一个redis

如果能采纳我的建议,我想对封禁策略进行一些建议

  1. 允许用户设定某ip对单一path的访问频率。比如/files/demo.mp4,可以设置单ip每分钟或者每小时的访问频率不超过10次
  2. 允许用户指定单ip对alist的访问频率。比如设定每个ip最多每小时能下载100次.
  3. 用户能设置ip访问的白名单或者黑名单。 等等吧

这是我目前能总结到的规则,如有纰漏恳请指正

Additional context / 附件

这个实现是有一点困难的,就是alist程序必须得到访问ip。 很多人都是用的反代或者cdn,alist得到的是诸如127.0.0.1的地址,这实现也会困难

比如nginx可以用X-Forwarded-For,来跨cdn得到源ip,当然这也会被伪造 我能力较低,给不出更加完美的建议,欢迎讨论

ppekora avatar Sep 16 '22 10:09 ppekora

Thanks for opening your first issue here! Be sure to follow the issue template!

welcome[bot] avatar Sep 16 '22 10:09 welcome[bot]

个人感觉此功能应由nginx或Apache这些web server负责一下比较好,毕竟正如你所说,获取IP是个问题 目前我个人用nginx实现了你说的需求,不过我是单IP限制全局请求次数,非单文件

flower-elf avatar Sep 16 '22 15:09 flower-elf

对,中间件可以实现这个需求,我在这里想请教一下能否集成到alist的可能性

ppekora avatar Sep 17 '22 02:09 ppekora

个人感觉此功能应由nginx或Apache这些web server负责一下比较好,毕竟正如你所说,获取IP是个问题 目前我个人用nginx实现了你说的需求,不过我是单IP限制全局请求次数,非单文件

可以指点一二吗,分享一下配置,我刚好也有这个需求,个人能力不足,无法实现

sibeix avatar Sep 21 '22 08:09 sibeix

Hello, this issue has been inactive for more than 30 days and will be closed if inactive for another 30 days.

github-actions[bot] avatar Nov 01 '22 00:11 github-actions[bot]

Hello @, this issue was closed due to inactive more than 60 days. You can reopen or recreate it if you think it should continue.

github-actions[bot] avatar Dec 08 '22 00:12 github-actions[bot]