tug*_*gce 6 firebase firebase-hosting
我一直在寻找通过IP率限制请求的方法,但无法找到任何资源.基本上我正在寻找的是一种实现防火墙逻辑的方法.我知道我可以使用数据库规则限制经过身份验证的用户请求,但是如何限制页面点击?例如,我只希望每个IP允许每分钟150个请求.有没有办法做到这一点?否则,攻击Blaze计划的小企业会不容易?
Mic*_*igh 11
Firebaser在这里.
目前无法使用Firebase托管基于IP地址进行速率限制.我们的CDN合作伙伴包括针对(D)DoS攻击的一些内置保护,但目前无法配置.在未来,我们计划进行成本控制,以便您可以手动设置自己的全局使用限制,以防止意外的大额账单.
与此同时,我们发现这通常不是问题.如果您确实遇到了怀疑是滥用的用法,请联系Firebase支持,我们将与您一起解决问题,让每个人都满意.
目前的速率限制似乎是使用一些中间件,例如express-rate-limiter。然后在您的 server.ts(如果是 JavaScript,则为 .js)文件中,您可以执行以下操作:
import * as express from 'express';
import * as rateLimit from 'express-rate-limit';
const server: Express = express();
server.set('trust proxy', 1); // Enable because the application is behind reverse proxy (Firebase).
server.use(
rateLimit({
max: 100, // Max 100 connections per windowMs can be done before sending HTTP 429 (Too Many Requests) response code. After 100 requests within 15 minutes block the IP.
message:
'This IP has been temporarily blocked due to too many requests, please try again later.',
windowMs: 15 * 60 * 1000 // In milliseconds, keep records of requests in memory for 15 minutes.
})
);
Run Code Online (Sandbox Code Playgroud)
或者,如果您不想阻止 IP,而是使用express-slow-down减慢它的速度。
| 归档时间: |
|
| 查看次数: |
1241 次 |
| 最近记录: |