spring-projects / spring-projects/spring-session

Spring session (redis) - Add support for using redis serializers for keys in RedisOperationsSessionRepository

Open
#699 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
1.9k
Forks
1.2k
Avg merge
4h 27m
Merged PRs (30d)
55

Description

I'm using Spring session 1.1.1 release and storing my sessions in redis. We wanted to change the way session data is stored in redis this is due to the fact all session details are stored in redis in the clear. This makes it open for any security breach. We wanted it to be encrypted and hence I did following changes to supply a custom serializer to spring redis session.

@Autowired
@Qualifier("sessionRedisTemplate")
private RedisTemplate<Object, Object> redisTemplate;

@PostConstruct
public void postConstruct() {
	/* 
	 * genericRedisSerializer & stringRedisSerializers are custom implementations
	 * that encrypts contents before putting it in redis (both keys and values)
	 */
	redisTemplate.setKeySerializer(genericRedisSerializer);
	redisTemplate.setHashKeySerializer(genericRedisSerializer);
	redisTemplate.setDefaultSerializer(genericRedisSerializer);
	redisTemplate.setHashValueSerializer(genericRedisSerializer);
	redisTemplate.setValueSerializer(genericRedisSerializer);
	redisTemplate.setStringSerializer(stringRedisSerializer);
}

This works well but leaves behind a list of indexes that aren't cleared (spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:username). Overtime this gets really large enough for us to run through scripts in redis to clear them.

Upon further investigation we found that Redis keyspace notification handler in RedisOperationsSessionRepository doesn't perform deserialization of the keys before retrieving it from the message. This fails the asynchronous process and hence leading to these indexes to live forever.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in RedisOperationsSessionRepository, focusing on its Redis keyspace notification handler and how keys are retrieved from messages. Verify how custom key serializers affect deserialization, then ensure the affected session indexes are cleared correctly when notifications are processed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis, spring
Domain
backend, databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.