Redis passport session cookies continue to be generated

My express application uses PassportJS to store an auth session, but it creates an absurd number of keys in the redis store, and all the keys look the same:

"{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{}}"

They have a TTL, but the store is growing in size for no good reason. Any idea why they are being created? My keys look like this:

"sess:8R3A-k6dARJvxXFdAXr5nTG7MeC7JTxb"
"sess:s4VYC-k-nmfSf7n-qGQJimFmt30EYNDp"
"sess:BS7WO92Nyl5R0wAbJ-Vo9o8w1apu0kp7"
"sess:0B1AKS6-MCclPvOXV0nlvNio8U8fxyQO"
"sess:v0UWf60LMwKmMVZgo4RWumX313yPsiD0"

If I just look into it, about 10 keys are generated every two or two times.

Here's what my session code looks like:

var express = require('express'),
    ....
    session = require('express-session'),
    redisStore = require('connect-redis')(session);

...
    app.use(express.static(path.resolve('./public')));

    //Redis
    var redisClient = redisHelper.init();

    app.use(session({
        secret: '...',
        store: new redisStore({
            client: redisClient,
            ttl: 86400
        }),
        resave: false,
        saveUninitialized: false,
        cookie:{maxAge:86400}
    }));

    //Passport
    app.use(passport.initialize());
    app.use(passport.session());
...

The Redis init function returns an instance of the redis client:

exports.init = function () {
    redisClient = redis.createClient(config.redis.port, config.redis.server, {});

    redisClient.auth(config.redis.auth);

    redisClient.on('error', function (error) {
        //TODO: log the error
        winston.error('Error while talking to Redis', {message: error});
    });

    return redisClient;
};
+4
source share

Source: https://habr.com/ru/post/1626224/


All Articles