Add banner ID to probo_consent cookie

Include a `bid` field in the consent cookie so it explicitly
identifies which cookie banner it belongs to, making validation
direct instead of relying on the visitor ID as an implicit
discriminator. Existing cookies without `bid` self-heal on the
next load by falling through to the API fetch.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-24 18:36:45 +04:00
parent d9db93911b
commit d7eec08cd2
8 changed files with 54 additions and 1 deletions

View File

@@ -132,7 +132,7 @@ export class CookieBannerClient {
this.startDetector(config);
const cookie = getConsentCookie();
if (cookie && cookie.v === config.version && cookie.vid === this.visitorId) {
if (cookie && cookie.bid === this.bannerId && cookie.v === config.version && cookie.vid === this.visitorId) {
this.consent = {
visitor_id: cookie.vid,
version: cookie.v,
@@ -164,6 +164,7 @@ export class CookieBannerClient {
this._gpcApplied = apiConsent.action === "GPC";
setConsentCookie(
{
bid: this.bannerId,
v: apiConsent.version,
vid: apiConsent.visitor_id,
action: apiConsent.action,
@@ -270,6 +271,7 @@ export class CookieBannerClient {
setConsentCookie(
{
bid: this.bannerId,
v: cfg.version,
vid: this.visitorId,
action,
@@ -286,6 +288,7 @@ export class CookieBannerClient {
version: cfg.version,
action,
consent_data: consentData,
sdk_version: __SDK_VERSION__,
};
void fetchJSON<ConsentRecord>(url, { method: "POST", body })
.then(() => void flush(this.bannerId))

View File

@@ -18,6 +18,7 @@ export const COOKIE_NAME = "probo_consent";
const SECONDS_PER_DAY = 86400;
export interface ConsentCookie {
bid: string;
v: number;
vid: string;
action: ConsentAction;

15
packages/cookie-banner/src/globals.d.ts vendored Normal file
View File

@@ -0,0 +1,15 @@
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
declare const __SDK_VERSION__: string;