From ed9831a734dd35fbbf13d14556d874d25cfe89ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Wed, 10 Jun 2026 17:48:07 +0200 Subject: [PATCH] Default cookie consent to GDPR and track its source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é --- .../CookieBannerConsentRecordPage.tsx | 6 ++ .../CookieBannerConsentRecordsPage.tsx | 1 + .../_components/ConsentRecordRow.tsx | 6 ++ .../cookieConsentRecord/get.operation.ts | 1 + .../cookieConsentRecord/getAll.operation.ts | 1 + pkg/cmd/consent-record/list/list.go | 25 ++++-- pkg/cmd/consent-record/view/view.go | 28 ++++--- pkg/cookiebanner/regulation.go | 21 +++++ pkg/cookiebanner/regulation_test.go | 74 ++++++++++++++++ pkg/cookiebanner/service.go | 22 ++--- pkg/coredata/cookie_consent_record.go | 7 ++ pkg/coredata/migrations/20260610T152400Z.sql | 20 +++++ pkg/coredata/regulation_source.go | 84 +++++++++++++++++++ .../v1/graphql/cookie_consent_record.graphql | 13 +++ .../console/v1/types/cookie_consent_record.go | 19 +++-- pkg/server/api/cookiebanner/v1/handler.go | 39 ++++----- pkg/server/api/mcp/v1/specification.yaml | 11 +++ .../api/mcp/v1/types/cookie_consent_record.go | 1 + 18 files changed, 315 insertions(+), 64 deletions(-) create mode 100644 pkg/cookiebanner/regulation_test.go create mode 100644 pkg/coredata/migrations/20260610T152400Z.sql create mode 100644 pkg/coredata/regulation_source.go diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/CookieBannerConsentRecordPage.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/CookieBannerConsentRecordPage.tsx index c66303dd5..abd6033db 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/CookieBannerConsentRecordPage.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/CookieBannerConsentRecordPage.tsx @@ -58,6 +58,7 @@ export const cookieBannerConsentRecordPageQuery = graphql` userAgent sdkVersion regulation + regulationSource countryCode consentData createdAt @@ -159,6 +160,11 @@ export default function CookieBannerConsentRecordPage({ {record.regulation || "-"} + + + {record.regulationSource || "-"} + + {record.countryCode || "-"} diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/CookieBannerConsentRecordsPage.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/CookieBannerConsentRecordsPage.tsx index 138d24ead..2f16da78d 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/CookieBannerConsentRecordsPage.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/CookieBannerConsentRecordsPage.tsx @@ -217,6 +217,7 @@ export default function CookieBannerConsentRecordsPage({ {__("IP Address")} {__("SDK Version")} {__("Regulation")} + {__("Source")} {__("Country")} {__("Date")} diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/_components/ConsentRecordRow.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/_components/ConsentRecordRow.tsx index e4a23f8f6..818a79867 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/_components/ConsentRecordRow.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/consent-records/_components/ConsentRecordRow.tsx @@ -36,6 +36,7 @@ const consentRecordFragment = graphql` ipAddress sdkVersion regulation + regulationSource countryCode createdAt } @@ -81,6 +82,11 @@ export function ConsentRecordRow({ recordKey }: ConsentRecordRowProps) { {record.regulation || "-"} + + + {record.regulationSource || "-"} + + {record.countryCode || "-"} diff --git a/packages/n8n-node/nodes/Probo/actions/cookieConsentRecord/get.operation.ts b/packages/n8n-node/nodes/Probo/actions/cookieConsentRecord/get.operation.ts index 5386467a6..4c00ff196 100644 --- a/packages/n8n-node/nodes/Probo/actions/cookieConsentRecord/get.operation.ts +++ b/packages/n8n-node/nodes/Probo/actions/cookieConsentRecord/get.operation.ts @@ -50,6 +50,7 @@ export async function execute( action sdkVersion regulation + regulationSource countryCode createdAt } diff --git a/packages/n8n-node/nodes/Probo/actions/cookieConsentRecord/getAll.operation.ts b/packages/n8n-node/nodes/Probo/actions/cookieConsentRecord/getAll.operation.ts index fd68db6f0..6f20c2237 100644 --- a/packages/n8n-node/nodes/Probo/actions/cookieConsentRecord/getAll.operation.ts +++ b/packages/n8n-node/nodes/Probo/actions/cookieConsentRecord/getAll.operation.ts @@ -153,6 +153,7 @@ export async function execute( action sdkVersion regulation + regulationSource countryCode createdAt } diff --git a/pkg/cmd/consent-record/list/list.go b/pkg/cmd/consent-record/list/list.go index 0c0312663..6af63489d 100644 --- a/pkg/cmd/consent-record/list/list.go +++ b/pkg/cmd/consent-record/list/list.go @@ -37,6 +37,7 @@ query($id: ID!, $first: Int, $after: CursorKey, $filter: CookieConsentRecordFilt action sdkVersion regulation + regulationSource countryCode createdAt } @@ -52,13 +53,14 @@ query($id: ID!, $first: Int, $after: CursorKey, $filter: CookieConsentRecordFilt ` type consentRecord struct { - ID string `json:"id"` - VisitorID string `json:"visitorId"` - Action string `json:"action"` - SDKVersion string `json:"sdkVersion"` - Regulation *string `json:"regulation"` - CountryCode *string `json:"countryCode"` - CreatedAt string `json:"createdAt"` + ID string `json:"id"` + VisitorID string `json:"visitorId"` + Action string `json:"action"` + SDKVersion string `json:"sdkVersion"` + Regulation *string `json:"regulation"` + RegulationSource *string `json:"regulationSource"` + CountryCode *string `json:"countryCode"` + CreatedAt string `json:"createdAt"` } func NewCmdList(f *cmdutil.Factory) *cobra.Command { @@ -165,15 +167,20 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command { regulation = *r.Regulation } + regulationSource := "-" + if r.RegulationSource != nil { + regulationSource = *r.RegulationSource + } + countryCode := "-" if r.CountryCode != nil { countryCode = *r.CountryCode } - rows = append(rows, []string{r.ID, r.VisitorID, r.Action, r.SDKVersion, regulation, countryCode, r.CreatedAt}) + rows = append(rows, []string{r.ID, r.VisitorID, r.Action, r.SDKVersion, regulation, regulationSource, countryCode, r.CreatedAt}) } - t := cmdutil.NewTable("ID", "VISITOR ID", "ACTION", "SDK VERSION", "REGULATION", "COUNTRY", "CREATED AT").Rows(rows...) + t := cmdutil.NewTable("ID", "VISITOR ID", "ACTION", "SDK VERSION", "REGULATION", "SOURCE", "COUNTRY", "CREATED AT").Rows(rows...) _, _ = fmt.Fprintln(f.IOStreams.Out, t) if totalCount > len(records) { diff --git a/pkg/cmd/consent-record/view/view.go b/pkg/cmd/consent-record/view/view.go index 2b600027d..62579d6ce 100644 --- a/pkg/cmd/consent-record/view/view.go +++ b/pkg/cmd/consent-record/view/view.go @@ -37,6 +37,7 @@ query($id: ID!) { action sdkVersion regulation + regulationSource countryCode createdAt } @@ -46,17 +47,18 @@ query($id: ID!) { type viewResponse struct { Node *struct { - Typename string `json:"__typename"` - ID string `json:"id"` - VisitorID string `json:"visitorId"` - IPAddress *string `json:"ipAddress"` - UserAgent *string `json:"userAgent"` - ConsentData string `json:"consentData"` - Action string `json:"action"` - SdkVersion string `json:"sdkVersion"` - Regulation *string `json:"regulation"` - CountryCode *string `json:"countryCode"` - CreatedAt string `json:"createdAt"` + Typename string `json:"__typename"` + ID string `json:"id"` + VisitorID string `json:"visitorId"` + IPAddress *string `json:"ipAddress"` + UserAgent *string `json:"userAgent"` + ConsentData string `json:"consentData"` + Action string `json:"action"` + SdkVersion string `json:"sdkVersion"` + Regulation *string `json:"regulation"` + RegulationSource *string `json:"regulationSource"` + CountryCode *string `json:"countryCode"` + CreatedAt string `json:"createdAt"` } `json:"node"` } @@ -124,6 +126,10 @@ func NewCmdView(f *cmdutil.Factory) *cobra.Command { _, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Regulation:"), *v.Regulation) } + if v.RegulationSource != nil { + _, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Regulation Source:"), *v.RegulationSource) + } + if v.CountryCode != nil { _, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Country Code:"), *v.CountryCode) } diff --git a/pkg/cookiebanner/regulation.go b/pkg/cookiebanner/regulation.go index e140e3676..53dbc6c92 100644 --- a/pkg/cookiebanner/regulation.go +++ b/pkg/cookiebanner/regulation.go @@ -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. diff --git a/pkg/cookiebanner/regulation_test.go b/pkg/cookiebanner/regulation_test.go new file mode 100644 index 000000000..89ed05bfa --- /dev/null +++ b/pkg/cookiebanner/regulation_test.go @@ -0,0 +1,74 @@ +// Copyright (c) 2026 Probo Inc . +// +// 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 cookiebanner + +import ( + "testing" + + "github.com/stretchr/testify/require" + "go.probo.inc/probo/pkg/coredata" +) + +func TestResolveRegulation(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + countryCode *coredata.CountryCode + wantRegulation Regulation + wantSource RegulationSource + }{ + { + name: "unresolved geolocation defaults to GDPR", + countryCode: nil, + wantRegulation: RegulationGDPR, + wantSource: RegulationSourceDefault, + }, + { + name: "country with no known regulation defaults to GDPR", + countryCode: new(coredata.CountryCodeAQ), + wantRegulation: RegulationGDPR, + wantSource: RegulationSourceDefault, + }, + { + name: "EU country resolves to GDPR as detected", + countryCode: new(coredata.CountryCodeFR), + wantRegulation: RegulationGDPR, + wantSource: RegulationSourceDetected, + }, + { + name: "US resolves to CCPA as detected", + countryCode: new(coredata.CountryCodeUS), + wantRegulation: RegulationCCPA, + wantSource: RegulationSourceDetected, + }, + { + name: "UK resolves to UK GDPR as detected", + countryCode: new(coredata.CountryCodeGB), + wantRegulation: RegulationUKGDPR, + wantSource: RegulationSourceDetected, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + regulation, source := ResolveRegulation(tt.countryCode) + require.Equal(t, tt.wantRegulation, regulation) + require.Equal(t, tt.wantSource, source) + }) + } +} diff --git a/pkg/cookiebanner/service.go b/pkg/cookiebanner/service.go index 85a32cad9..934cee2fc 100644 --- a/pkg/cookiebanner/service.go +++ b/pkg/cookiebanner/service.go @@ -96,16 +96,17 @@ type ( } RecordConsentRequest struct { - Version int - VisitorID string - IPAddress *string - UserAgent *string - ConsentData json.RawMessage - Action coredata.CookieConsentAction - SdkVersion string - Regulation *Regulation - CountryCode *coredata.CountryCode - ConsentMode *coredata.CookieConsentMode + Version int + VisitorID string + IPAddress *string + UserAgent *string + ConsentData json.RawMessage + Action coredata.CookieConsentAction + SdkVersion string + Regulation *Regulation + RegulationSource coredata.RegulationSource + CountryCode *coredata.CountryCode + ConsentMode *coredata.CookieConsentMode } DetectedCookie struct { @@ -2076,6 +2077,7 @@ func (s *Service) RecordConsent( Action: req.Action, SdkVersion: req.SdkVersion, Regulation: req.Regulation, + RegulationSource: &req.RegulationSource, CountryCode: req.CountryCode, ConsentMode: req.ConsentMode, CreatedAt: time.Now(), diff --git a/pkg/coredata/cookie_consent_record.go b/pkg/coredata/cookie_consent_record.go index a4f5fb19a..c7a84a892 100644 --- a/pkg/coredata/cookie_consent_record.go +++ b/pkg/coredata/cookie_consent_record.go @@ -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 diff --git a/pkg/coredata/migrations/20260610T152400Z.sql b/pkg/coredata/migrations/20260610T152400Z.sql new file mode 100644 index 000000000..fc63ee9a8 --- /dev/null +++ b/pkg/coredata/migrations/20260610T152400Z.sql @@ -0,0 +1,20 @@ +-- Copyright (c) 2026 Probo Inc . +-- +-- 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; diff --git a/pkg/coredata/regulation_source.go b/pkg/coredata/regulation_source.go new file mode 100644 index 000000000..508ffea37 --- /dev/null +++ b/pkg/coredata/regulation_source.go @@ -0,0 +1,84 @@ +// Copyright (c) 2026 Probo Inc . +// +// 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) + } +} diff --git a/pkg/server/api/console/v1/graphql/cookie_consent_record.graphql b/pkg/server/api/console/v1/graphql/cookie_consent_record.graphql index e31765ebe..bae1c68c0 100644 --- a/pkg/server/api/console/v1/graphql/cookie_consent_record.graphql +++ b/pkg/server/api/console/v1/graphql/cookie_consent_record.graphql @@ -96,6 +96,18 @@ enum Regulation ) } +enum RegulationSource + @goModel(model: "go.probo.inc/probo/pkg/coredata.RegulationSource") { + DETECTED + @goEnum( + value: "go.probo.inc/probo/pkg/coredata.RegulationSourceDetected" + ) + DEFAULT + @goEnum( + value: "go.probo.inc/probo/pkg/coredata.RegulationSourceDefault" + ) +} + enum CookieConsentRecordOrderField @goModel( model: "go.probo.inc/probo/pkg/coredata.CookieConsentRecordOrderField" @@ -131,6 +143,7 @@ type CookieConsentRecord implements Node { action: CookieConsentAction! sdkVersion: String! regulation: Regulation + regulationSource: RegulationSource countryCode: CountryCode createdAt: Datetime! } diff --git a/pkg/server/api/console/v1/types/cookie_consent_record.go b/pkg/server/api/console/v1/types/cookie_consent_record.go index 3881445b5..a79eca372 100644 --- a/pkg/server/api/console/v1/types/cookie_consent_record.go +++ b/pkg/server/api/console/v1/types/cookie_consent_record.go @@ -75,14 +75,15 @@ func NewCookieConsentRecord(r *coredata.CookieConsentRecord) *CookieConsentRecor CookieBannerVersion: &CookieBannerVersion{ ID: r.CookieBannerVersionID, }, - VisitorID: r.VisitorID, - IPAddress: r.IPAddress, - UserAgent: r.UserAgent, - ConsentData: string(r.ConsentData), - Action: r.Action, - SdkVersion: r.SdkVersion, - Regulation: r.Regulation, - CountryCode: r.CountryCode, - CreatedAt: r.CreatedAt, + VisitorID: r.VisitorID, + IPAddress: r.IPAddress, + UserAgent: r.UserAgent, + ConsentData: string(r.ConsentData), + Action: r.Action, + SdkVersion: r.SdkVersion, + Regulation: r.Regulation, + RegulationSource: r.RegulationSource, + CountryCode: r.CountryCode, + CreatedAt: r.CreatedAt, } } diff --git a/pkg/server/api/cookiebanner/v1/handler.go b/pkg/server/api/cookiebanner/v1/handler.go index a7d88283d..c051f3b8c 100644 --- a/pkg/server/api/cookiebanner/v1/handler.go +++ b/pkg/server/api/cookiebanner/v1/handler.go @@ -76,11 +76,7 @@ func (h *Handler) handleGetConfig(w http.ResponseWriter, r *http.Request) { lang := r.URL.Query().Get("lang") sdkVersion := sdkVersionFromContext(r.Context()) cc := h.resolveCountryCode(r) - - var regulation cookiebanner.Regulation - if cc != nil { - regulation = cookiebanner.RegulationForCountry(*cc) - } + regulation, _ := cookiebanner.ResolveRegulation(cc) config, err := h.cookieBannerSvc.GetActiveBannerConfig(r.Context(), bannerID, lang, regulation, sdkVersion) if err != nil { @@ -197,29 +193,22 @@ func (h *Handler) handlePostConsent(w http.ResponseWriter, r *http.Request) { ua := r.UserAgent() sdkVersion := sdkVersionFromContext(r.Context()) cc := h.resolveCountryCode(r) + regulation, regulationSource := cookiebanner.ResolveRegulation(cc) - var ( - regulation *cookiebanner.Regulation - resolvedRegulation cookiebanner.Regulation - ) - if cc != nil { - resolvedRegulation = cookiebanner.RegulationForCountry(*cc) - regulation = &resolvedRegulation - } - - cm := coredata.CookieConsentMode(cookiebanner.ConsentModeForRegulation(resolvedRegulation)) + cm := coredata.CookieConsentMode(cookiebanner.ConsentModeForRegulation(regulation)) req := cookiebanner.RecordConsentRequest{ - Version: body.Version, - VisitorID: body.VisitorID, - IPAddress: &ip, - UserAgent: &ua, - ConsentData: body.ConsentData, - Action: body.Action, - SdkVersion: sdkVersion, - Regulation: regulation, - CountryCode: cc, - ConsentMode: &cm, + Version: body.Version, + VisitorID: body.VisitorID, + IPAddress: &ip, + UserAgent: &ua, + ConsentData: body.ConsentData, + Action: body.Action, + SdkVersion: sdkVersion, + Regulation: ®ulation, + RegulationSource: regulationSource, + CountryCode: cc, + ConsentMode: &cm, } record, err := h.cookieBannerSvc.RecordConsent(r.Context(), bannerID, req) diff --git a/pkg/server/api/mcp/v1/specification.yaml b/pkg/server/api/mcp/v1/specification.yaml index bea28d635..1cfd20f5a 100644 --- a/pkg/server/api/mcp/v1/specification.yaml +++ b/pkg/server/api/mcp/v1/specification.yaml @@ -216,6 +216,13 @@ components: - PDPL go.probo.inc/mcpgen/type: go.probo.inc/probo/pkg/coredata.Regulation + RegulationSource: + type: string + enum: + - DETECTED + - DEFAULT + go.probo.inc/mcpgen/type: go.probo.inc/probo/pkg/coredata.RegulationSource + CountryCode: type: string enum: @@ -9715,6 +9722,10 @@ components: $ref: "#/components/schemas/Regulation" description: Applicable regulation nullable: true + regulation_source: + $ref: "#/components/schemas/RegulationSource" + description: Whether the regulation was detected from geolocation or defaulted to GDPR + nullable: true country_code: $ref: "#/components/schemas/CountryCode" description: Visitor country code (ISO 3166-1 alpha-2) diff --git a/pkg/server/api/mcp/v1/types/cookie_consent_record.go b/pkg/server/api/mcp/v1/types/cookie_consent_record.go index bc8334796..27dac329d 100644 --- a/pkg/server/api/mcp/v1/types/cookie_consent_record.go +++ b/pkg/server/api/mcp/v1/types/cookie_consent_record.go @@ -36,6 +36,7 @@ func NewCookieConsentRecord(r *coredata.CookieConsentRecord) *CookieConsentRecor Action: CookieConsentRecordAction(r.Action), SdkVersion: r.SdkVersion, Regulation: r.Regulation, + RegulationSource: r.RegulationSource, CountryCode: r.CountryCode, CreatedAt: r.CreatedAt, }