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

@@ -36,11 +36,32 @@ const (
RegulationPDPL = coredata.RegulationPDPL
)
type RegulationSource = coredata.RegulationSource
const (
RegulationSourceDetected = coredata.RegulationSourceDetected
RegulationSourceDefault = coredata.RegulationSourceDefault
)
const (
ConsentModeOptIn = "OPT_IN"
ConsentModeOptOut = "OPT_OUT"
)
// ResolveRegulation returns the regulation to apply for a visitor along
// with its source. It defaults to GDPR when geolocation is unresolved
// (cc is nil) or when the resolved country maps to no known regulation,
// ensuring the strictest opt-in consent model applies by default.
func ResolveRegulation(cc *coredata.CountryCode) (Regulation, RegulationSource) {
if cc != nil {
if reg := RegulationForCountry(*cc); reg != RegulationNone {
return reg, RegulationSourceDetected
}
}
return RegulationGDPR, RegulationSourceDefault
}
// RegulationForCountry maps a country code to the applicable privacy
// regulation. For countries with no known cookie-consent regulation it
// returns RegulationNone.