39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
const REVOKED_REMEMBER_LOGIN_REDIS_PREFIX = "adpanel:revoked-remember:";
|
|
const REVOKED_REMEMBER_LOGIN_TTL_SECONDS = 370 * 24 * 60 * 60;
|
|
|
|
function getRevokedRememberLoginRedisKey(rememberId) {
|
|
return REVOKED_REMEMBER_LOGIN_REDIS_PREFIX + String(rememberId);
|
|
}
|
|
|
|
// adpanel:remember-delayed-mint-revocation - a cookie can reach its owner
|
|
// before its first registry write. Revocation must forbid that future write,
|
|
// not only delete an existing field or advance the snapshot version.
|
|
const REMEMBER_LOGIN_REGISTRY_GUARDED_WRITE_LUA = [
|
|
"local v = redis.call('GET', KEYS[1])",
|
|
"if not v then v = '0' end",
|
|
"if v ~= ARGV[1] then return -1 end",
|
|
"if redis.call('EXISTS', KEYS[3]) == 1 or redis.call('EXISTS', KEYS[4]) == 1 then return -2 end",
|
|
"redis.call('HSET', KEYS[2], ARGV[2], ARGV[3])",
|
|
"redis.call('INCR', KEYS[1])",
|
|
"return 1",
|
|
].join("\n");
|
|
|
|
const REMEMBER_LOGIN_LINEAGE_REVOKE_LUA = [
|
|
"redis.call('SET', KEYS[4], '1', 'EX', ARGV[2])",
|
|
"redis.call('SET', KEYS[5], '1', 'EX', ARGV[2])",
|
|
"local members = redis.call('SMEMBERS', KEYS[3])",
|
|
"if #members > 0 then redis.call('HDEL', KEYS[2], unpack(members)) end",
|
|
"redis.call('HDEL', KEYS[2], ARGV[1])",
|
|
"redis.call('DEL', KEYS[3])",
|
|
"redis.call('INCR', KEYS[1])",
|
|
"return 1",
|
|
].join("\n");
|
|
|
|
module.exports = {
|
|
REMEMBER_LOGIN_REGISTRY_GUARDED_WRITE_LUA,
|
|
REMEMBER_LOGIN_LINEAGE_REVOKE_LUA,
|
|
REVOKED_REMEMBER_LOGIN_TTL_SECONDS,
|
|
getRevokedRememberLoginRedisKey,
|
|
}; |