feat: Rate limit API token requests

600 per minute per token, in the Redis that sessions already require.
Cookie sessions are untouched. A Redis failure falls through rather than
refusing traffic — it is already a larger problem and should not become a
second outage.
This commit is contained in:
2026-08-12 14:51:22 +00:00
parent 2685e9ad06
commit 3b4c87a292
3 changed files with 63 additions and 0 deletions
+5
View File
@@ -59,6 +59,11 @@ func PingRedis(ctx context.Context) error {
return rdb.Ping(ctx).Err()
}
// Redis exposes the session client for callers that need a counter rather than
// a session. There is one Redis in this deployment and adding a second client
// would double the connection pool for no reason.
func Redis() *redis.Client { return rdb }
func randomHex(n int) (string, error) {
b := make([]byte, n)
if _, err := rand.Read(b); err != nil {