log token revoke as a security event

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 00:59:19 +00:00
co-authored by Claude Opus 4.8
parent c345bd40ae
commit fd2c82da84
2 changed files with 22 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
import type { Handler } from 'hono';
import { blacklistToken, cleanupExpiredTokens } from 'officerdb';
import { clientIp } from './client-ip';
// Distress: blacklist the current token (same as signout) but log it as a security event.
export const revokeHandler: Handler = async (ctx) => {
const user = ctx.get('user') as { jti: string; exp: number; email?: string };
const origin = ctx.get('origin') as string | undefined;
console.warn(
`[SECURITY] token revoked (distress) — user=${user.email || '?'}, origin=${origin || '-'}, ip=${clientIp(ctx)} — ${new Date().toISOString()}`,
);
await blacklistToken(user.jti, user.exp);
cleanupExpiredTokens().catch(() => {});
return ctx.json({ ok: true });
};