new version
This commit is contained in:
@@ -88,10 +88,7 @@ func redirectURIMatches(redirectURIsJSON json.RawMessage, redirectURI string) bo
|
||||
}
|
||||
|
||||
func verifyClientSecret(stored, provided string) bool {
|
||||
if stored == "" {
|
||||
return true
|
||||
}
|
||||
if provided == "" {
|
||||
if stored == "" || provided == "" {
|
||||
return false
|
||||
}
|
||||
if strings.HasPrefix(stored, "$2") {
|
||||
|
||||
@@ -268,7 +268,9 @@ func (s *Service) RevokeToken(ctx context.Context, auth ClientAuth, rawToken str
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = s.oauth.DeleteRefreshTokenByID(ctx, row.ID)
|
||||
if err := s.oauth.DeleteRefreshTokenByID(ctx, row.ID); err != nil {
|
||||
return models.ErrInternal
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,23 @@ var (
|
||||
Max: 5,
|
||||
Window: time.Hour,
|
||||
}
|
||||
|
||||
TokenRateLimit = RateLimitConfig{
|
||||
Max: 20,
|
||||
Window: time.Minute,
|
||||
BlockFor: 5 * time.Minute,
|
||||
}
|
||||
|
||||
RevokeRateLimit = RateLimitConfig{
|
||||
Max: 30,
|
||||
Window: time.Minute,
|
||||
}
|
||||
|
||||
RefreshRateLimit = RateLimitConfig{
|
||||
Max: 30,
|
||||
Window: time.Minute,
|
||||
BlockFor: 5 * time.Minute,
|
||||
}
|
||||
)
|
||||
|
||||
type RateLimiter struct {
|
||||
@@ -42,7 +59,7 @@ func (r *RateLimiter) Allow(ctx context.Context, key string, cfg RateLimitConfig
|
||||
if cfg.BlockFor > 0 {
|
||||
blocked, err := r.redis.Exists(ctx, blockKey).Result()
|
||||
if err != nil {
|
||||
return true, 0, nil
|
||||
return false, 0, fmt.Errorf("rate limiter: %w", err)
|
||||
}
|
||||
if blocked > 0 {
|
||||
return false, 0, nil
|
||||
@@ -53,7 +70,7 @@ func (r *RateLimiter) Allow(ctx context.Context, key string, cfg RateLimitConfig
|
||||
incrCmd := pipe.Incr(ctx, counterKey)
|
||||
pipe.Expire(ctx, counterKey, cfg.Window)
|
||||
if _, err := pipe.Exec(ctx); err != nil {
|
||||
return true, 0, nil
|
||||
return false, 0, fmt.Errorf("rate limiter: %w", err)
|
||||
}
|
||||
|
||||
count := int(incrCmd.Val())
|
||||
|
||||
Reference in New Issue
Block a user