Default cookie consent to GDPR and track its source

When IP geolocation does not resolve a country, or resolves one with no
known cookie-consent regulation (common on localhost and unmapped
regions), the banner previously fell back to OPT_OUT with no recorded
regulation. Apply GDPR (OPT_IN) as the safe default in that case so the
strictest consent model wins when origin is unknown.

To keep consent records auditable, stamp each one with a regulation
source of DETECTED (resolved from geolocation) or DEFAULT (fell back to
GDPR). The shared cookiebanner.ResolveRegulation helper centralizes the
decision for both the config and consent endpoints, and the new value is
exposed through GraphQL, MCP, the CLI, the n8n node, and the console
consent-records views.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-06-10 17:48:07 +02:00
parent e3ccb76b03
commit ed9831a734
18 changed files with 315 additions and 64 deletions

View File

@@ -42,6 +42,7 @@ type (
Action CookieConsentAction `db:"action"`
SdkVersion string `db:"sdk_version"`
Regulation *Regulation `db:"regulation"`
RegulationSource *RegulationSource `db:"regulation_source"`
CountryCode *CountryCode `db:"country_code"`
ConsentMode *CookieConsentMode `db:"consent_mode"`
CreatedAt time.Time `db:"created_at"`
@@ -119,6 +120,7 @@ SELECT
action,
sdk_version,
regulation,
regulation_source,
country_code,
consent_mode,
created_at
@@ -206,6 +208,7 @@ INSERT INTO cookie_consent_records (
action,
sdk_version,
regulation,
regulation_source,
country_code,
consent_mode,
created_at
@@ -222,6 +225,7 @@ INSERT INTO cookie_consent_records (
@action,
@sdk_version,
@regulation,
@regulation_source,
@country_code,
@consent_mode,
@created_at
@@ -241,6 +245,7 @@ INSERT INTO cookie_consent_records (
"action": r.Action,
"sdk_version": r.SdkVersion,
"regulation": r.Regulation,
"regulation_source": r.RegulationSource,
"country_code": r.CountryCode,
"consent_mode": r.ConsentMode,
"created_at": r.CreatedAt,
@@ -273,6 +278,7 @@ SELECT
action,
sdk_version,
regulation,
regulation_source,
country_code,
consent_mode,
created_at
@@ -327,6 +333,7 @@ SELECT
action,
sdk_version,
regulation,
regulation_source,
country_code,
consent_mode,
created_at

View File

@@ -0,0 +1,20 @@
-- Copyright (c) 2026 Probo Inc <hello@probo.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.
-- Record whether the regulation stamped on a consent was detected from the
-- visitor's geolocation or defaulted to GDPR (when geolocation was unresolved
-- or mapped to no known regulation). Pre-existing rows stay NULL.
CREATE TYPE regulation_source AS ENUM ('DETECTED', 'DEFAULT');
ALTER TABLE cookie_consent_records ADD COLUMN regulation_source regulation_source;

View File

@@ -0,0 +1,84 @@
// Copyright (c) 2026 Probo Inc <hello@probo.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.
package coredata
import (
"encoding"
"fmt"
)
// RegulationSource records whether the regulation applied to a consent
// was detected from the visitor's geolocation or defaulted because
// geolocation was unresolved or mapped to no known regulation.
type RegulationSource string
const (
RegulationSourceDetected RegulationSource = "DETECTED"
RegulationSourceDefault RegulationSource = "DEFAULT"
)
var (
_ fmt.Stringer = RegulationSource("")
_ encoding.TextMarshaler = RegulationSource("")
_ encoding.TextUnmarshaler = (*RegulationSource)(nil)
)
func RegulationSources() []RegulationSource {
return []RegulationSource{
RegulationSourceDetected,
RegulationSourceDefault,
}
}
func (v RegulationSource) IsValid() bool {
switch v {
case
RegulationSourceDetected,
RegulationSourceDefault:
return true
}
return false
}
func (v RegulationSource) String() string {
return string(v)
}
func (v RegulationSource) MarshalText() ([]byte, error) {
return []byte(v.String()), nil
}
func (v *RegulationSource) UnmarshalText(text []byte) error {
val := RegulationSource(text)
if !val.IsValid() {
return fmt.Errorf("invalid RegulationSource value: %q", string(text))
}
*v = val
return nil
}
func ParseRegulationSource(s string) (RegulationSource, error) {
switch RegulationSource(s) {
case RegulationSourceDetected:
return RegulationSourceDetected, nil
case RegulationSourceDefault:
return RegulationSourceDefault, nil
default:
return "", fmt.Errorf("invalid RegulationSource value: %q", s)
}
}