INNER CODE UNIT · TypeScript

getAnonymousBucketId

Ammaar-Alam/minebench · middleware.ts:229

function getAnonymousBucketId(req: NextRequest, ip: string | null): string {
  // stable fallback for clients that block cookies
  return `anon:${stableHash(`${ip ?? "no-ip"}|${getHeaderFingerprint(req)}`)}`;
}

function getRateLimitSession(req: NextRequest, fallbackBucketId: string) {
  const existing = req.cookies.get(RATE_LIMIT_SESSION_COOKIE)?.value?.trim();
  if (existing) return { bucketId: existing, cookieValue: null, isNew: false };
  const id = crypto.randomUUID();
  return {
    // fallback catches clients that drop the cookie
    bucketId: fallbackBucketId,
    cookieValue: id,
    isNew: true,
  };
}

export async function middleware(req: NextRequest) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…