somratpro commited on
Commit
ad703e3
Β·
1 Parent(s): f9ac23b

debug: scan Redis DB 0/1/2 + keyspace in debug-logs

Browse files
Files changed (1) hide show
  1. health-server.js +24 -32
health-server.js CHANGED
@@ -1943,40 +1943,32 @@ const server = http.createServer((req, res) => {
1943
  let redisSection = "=== REDIS codeVerifier CHECK ===\n";
1944
  try {
1945
  const { execSync } = require("child_process");
1946
- const keys = execSync(
1947
- 'redis-cli -h 127.0.0.1 -p 6379 keys "login:*" 2>/dev/null', { timeout: 5000 }
1948
- ).toString().trim();
1949
-
1950
- if (!keys) {
1951
- redisSection += "(no login:* keys in Redis β€” request_token may not have been called yet)";
1952
- } else {
1953
- redisSection += `Found keys:\n`;
1954
- for (const key of keys.split("\n").filter(Boolean).slice(0, 5)) {
1955
- const val = execSync(
1956
- `redis-cli -h 127.0.0.1 -p 6379 get "${key}" 2>/dev/null`, { timeout: 5000 }
1957
- ).toString().trim();
1958
- const ttl = execSync(
1959
- `redis-cli -h 127.0.0.1 -p 6379 ttl "${key}" 2>/dev/null`, { timeout: 5000 }
1960
- ).toString().trim();
1961
- if (!val) {
1962
- redisSection += ` ${key}: (empty or missing!)\n`;
1963
- continue;
 
 
 
 
 
1964
  }
1965
- const colonIdx = val.indexOf(":");
1966
- const token = colonIdx > 0 ? val.slice(0, colonIdx) : "(none β€” no colon found!)";
1967
- const secret = colonIdx > 0 ? val.slice(colonIdx + 1) : "(none β€” no colon found!)";
1968
- const extraColons = (val.match(/:/g) || []).length - 1;
1969
- const tokenShow = token.slice(0, 12) + "... (len=" + token.length + ")";
1970
- const secretShow = secret.slice(0, 12) + "... (len=" + secret.length + ")";
1971
- const note = colonIdx < 0
1972
- ? "⚠ NO COLON β€” split will fail β†’ empty secret β†’ bad signature!"
1973
- : extraColons > 0
1974
- ? `⚠ ${extraColons} extra colon(s) in value β€” split(':')[1] truncates secret!`
1975
- : secret.length < 30
1976
- ? "⚠ secret looks short β€” might be truncated"
1977
- : "βœ“ format ok";
1978
- redisSection += ` ${key}\n token : ${tokenShow}\n secret: ${secretShow}\n ttl : ${ttl}s\n note : ${note}\n`;
1979
  }
 
1980
  }
1981
  } catch (e) {
1982
  redisSection += `(redis-cli error: ${e.message})`;
 
1943
  let redisSection = "=== REDIS codeVerifier CHECK ===\n";
1944
  try {
1945
  const { execSync } = require("child_process");
1946
+ const rc = (cmd) => { try { return execSync(cmd, { timeout: 5000 }).toString().trim(); } catch(e) { return "(err: " + e.message.slice(0,60) + ")"; } };
1947
+
1948
+ const keyspace = rc("redis-cli -h 127.0.0.1 -p 6379 info keyspace 2>/dev/null");
1949
+ redisSection += `Redis keyspace:\n${keyspace || "(empty)"}\n\n`;
1950
+
1951
+ // Check DB 0 (default) and DB 1 for all keys
1952
+ for (const db of [0, 1, 2]) {
1953
+ const dbFlag = db === 0 ? "" : `-n ${db}`;
1954
+ const allKeys = rc(`redis-cli -h 127.0.0.1 -p 6379 ${dbFlag} keys "*" 2>/dev/null`);
1955
+ const loginKeys = rc(`redis-cli -h 127.0.0.1 -p 6379 ${dbFlag} keys "login:*" 2>/dev/null`);
1956
+ redisSection += `DB ${db}: total keys preview: ${allKeys ? allKeys.split("\n").slice(0,8).join(", ") : "(none)"}\n`;
1957
+ redisSection += `DB ${db}: login:* keys: ${loginKeys || "(none)"}\n`;
1958
+ if (loginKeys && !loginKeys.startsWith("(")) {
1959
+ for (const key of loginKeys.split("\n").filter(Boolean).slice(0, 3)) {
1960
+ const val = rc(`redis-cli -h 127.0.0.1 -p 6379 ${dbFlag} get "${key}" 2>/dev/null`);
1961
+ const ttl = rc(`redis-cli -h 127.0.0.1 -p 6379 ${dbFlag} ttl "${key}" 2>/dev/null`);
1962
+ if (!val) { redisSection += ` ${key}: EMPTY!\n`; continue; }
1963
+ const colonIdx = val.indexOf(":");
1964
+ const token = colonIdx > 0 ? val.slice(0, colonIdx) : "";
1965
+ const secret = colonIdx > 0 ? val.slice(colonIdx + 1) : "";
1966
+ const extraColons = (val.match(/:/g) || []).length - 1;
1967
+ const note = colonIdx < 0 ? "⚠ NO COLON!" : extraColons > 0 ? `⚠ ${extraColons} extra colon(s)` : secret.length < 30 ? "⚠ secret short" : "βœ“ ok";
1968
+ redisSection += ` ${key} [TTL=${ttl}s]\n token: ${token.slice(0,12)}... (len=${token.length})\n secret: ${secret.slice(0,12)}... (len=${secret.length})\n note: ${note}\n`;
1969
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1970
  }
1971
+ redisSection += "\n";
1972
  }
1973
  } catch (e) {
1974
  redisSection += `(redis-cli error: ${e.message})`;