• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Fixing JWT Session Validation Issues with Redis

Sascha Оффлайн

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,480
Баллы
155


When building secure APIs, JWT (JSON Web Token) is one of the most popular authentication methods. It’s lightweight, stateless, and easy to integrate. But JWT has one common problem: once a token is issued, it remains valid until it expires—even if the user logs out.

This creates a security gap where someone with access to the token can still make requests until it naturally expires.

Let’s explore how to fix this using Redis.

The Problem: Token Still Valid After Logout


JWT works without server-side session tracking. Once a token is signed, the server doesn’t store it—validation is done by checking the signature.

That means:

  • If a user logs out, the token doesn’t automatically become invalid.
  • If an attacker steals or copies the token, they can use it until expiration.
The Solution: Using Redis as a Blacklist


To solve this, we can introduce a token blacklist mechanism with Redis.

Here’s how it works:


  1. When the user logs out, store the token in Redis with an expiration time matching the JWT expiry.


  2. On every API request, check if the token exists in Redis.
  • If yes → reject the request (Unauthorized or Illegal Access).
  • If no → proceed with normal JWT validation.

This way, even if someone has a stolen token, it won’t work after the user logs out.

Benefits of This Approach


Immediate logout → Users are logged out instantly, not just after JWT expiry.

Extra security → Protects against token theft and replay attacks.

*Scalable *→ Redis is fast and works well with distributed systems.

Conclusion


JWT is powerful, but without proper logout handling, it can leave your application vulnerable. By integrating Redis as a blacklist, you can ensure better session control and stronger security for your applications.



Источник:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу