From 4ec075fa80709e25a13549c4b651d2854ba4732b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Fri, 24 Apr 2026 17:39:30 +0400 Subject: [PATCH] Limit detected cookies to 100 per request in cookie banner SDK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server rejects requests with more than 100 cookies but the client had no matching cap, causing the entire batch to be lost on cookie-heavy pages. Flush now drains at most 100 entries and re-schedules for the remainder. Signed-off-by: Émile Ré --- packages/cookie-banner/src/detector.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/cookie-banner/src/detector.ts b/packages/cookie-banner/src/detector.ts index c15b9f0ef..b8e727a07 100644 --- a/packages/cookie-banner/src/detector.ts +++ b/packages/cookie-banner/src/detector.ts @@ -21,6 +21,7 @@ interface DetectedCookieEntry { } const DEBOUNCE_MS = 2_000; +const MAX_COOKIES_PER_REQUEST = 100; export class CookieDetector { private readonly reportUrl: URL; @@ -118,13 +119,23 @@ export class CookieDetector { } private flush(): void { - const entries = Array.from(this.pending.values()); - this.pending.clear(); - if (entries.length === 0) return; + if (this.pending.size === 0) return; + + const iter = this.pending.entries(); + const entries: DetectedCookieEntry[] = []; + for (const [key, entry] of iter) { + entries.push(entry); + this.pending.delete(key); + if (entries.length >= MAX_COOKIES_PER_REQUEST) break; + } void fetchJSON(this.reportUrl, { method: "POST", body: { cookies: entries }, }).catch(() => {}); + + if (this.pending.size > 0) { + this.scheduleFlush(); + } } }