GDPR compliance — IPs are HMAC-SHA256'd (truncated to 16 hex chars) before being pushed to the Redis queue, so only pseudonymous tokens are ever stored. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
25 lines
626 B
TypeScript
25 lines
626 B
TypeScript
import { createHmac } from "node:crypto";
|
|
|
|
export interface RequestLogEntry {
|
|
ip: string;
|
|
path: string;
|
|
method: string;
|
|
statusCode: number;
|
|
userAgent: string;
|
|
timestamp: string;
|
|
}
|
|
|
|
export function anonymizeIp(ip: string): string {
|
|
const secret = useRuntimeConfig().adminPassword || "default-hmac-key";
|
|
return createHmac("sha256", secret).update(ip).digest("hex").slice(0, 16);
|
|
}
|
|
|
|
export function logRequest(data: RequestLogEntry): void {
|
|
try {
|
|
const redis = getRedis();
|
|
redis.lpush("request-logs", JSON.stringify(data)).catch(() => {});
|
|
} catch {
|
|
// Never let logging break API responses
|
|
}
|
|
}
|