Skip to content

Commit 75dc1ae

Browse files
committed
security: rate-limit /auth/refresh
Refresh is unauthenticated (expired/absent access token) and rotates sessions but had no rate limiter, so a stolen refresh token could be hammered. Add a per-IP limiter (login thresholds, own bucket), matching login/register. NOTE: full refresh-token reuse detection (revoke the session family when an already-rotated token is presented) is deferred — it needs a session-family tombstone migration + raw-pgx repo changes on the auth hot path, which warrant integration testing against a real DB. Token-at-rest hashing (done) already removes the DB-leak theft vector.
1 parent 223387b commit 75dc1ae

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

internal/gateway/router.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ func NewRouter(p RouterParams) http.Handler {
155155
p.AuthRateLimiters.LoginCfg,
156156
"register",
157157
)
158+
// Refresh is unauthenticated (the access token is expired/absent) and rotates
159+
// sessions; throttle per-IP so a stolen refresh token can't be hammered.
160+
refreshRL := middleware.AuthRateLimit(
161+
p.AuthRateLimiters.Login,
162+
p.AuthRateLimiters.LoginCfg,
163+
"refresh",
164+
)
158165
acceptInviteRL := middleware.AuthRateLimit(
159166
p.AuthRateLimiters.AcceptInvitation,
160167
p.AuthRateLimiters.AcceptInvitationCfg,
@@ -173,7 +180,7 @@ func NewRouter(p RouterParams) http.Handler {
173180
api.With(registerRL).Post("/auth/register", p.IdentityHandler.Register)
174181
api.With(loginRL).Post("/auth/login", p.IdentityHandler.Login)
175182
api.Post("/auth/verify-email", p.IdentityHandler.VerifyEmail)
176-
api.Post("/auth/refresh", p.IdentityHandler.RefreshToken)
183+
api.With(refreshRL).Post("/auth/refresh", p.IdentityHandler.RefreshToken)
177184

178185
// Public webhook endpoints (authenticated by their respective handlers).
179186
api.Post("/webhooks/remnawave", p.WebhookHandler.ServeHTTP)

0 commit comments

Comments
 (0)