Rank HTTP cookie source above pre-existing
The tracker-pattern source ranking collapsed HTTP into the PRE_EXISTING tier, so a cookie first enumerated as pre-existing and later re-observed only via a Set-Cookie response header stayed pre-existing. That left it on the agent-skipped tier (isPreExistingSource), even though an HTTP server-set cookie is real page evidence, not the extension-state catch-all the skip was built to suppress. Give HTTP its own rank between SCRIPT and EXTENSION (SCRIPT > HTTP > EXTENSION > PRE_EXISTING) in both sourceRank and the bestSource merge rollup, so an HTTP re-detection now promotes the pattern and re-arms mapping, unblocking the identification agent. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -704,11 +704,15 @@ func globMatch(pattern, name string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sourceRank converts a CookieSource into a comparable rank that
|
// sourceRank converts a CookieSource into a comparable rank that
|
||||||
// reflects signal strength: SCRIPT > EXTENSION > PRE_EXISTING. HTTP
|
// reflects signal strength: SCRIPT > HTTP > EXTENSION > PRE_EXISTING.
|
||||||
// and nil collapse into the PRE_EXISTING rank because bestSource
|
// SCRIPT is a real page tracker observed being written by page JS;
|
||||||
// already normalises them; if a future caller hands us either, the
|
// HTTP is a real server-set cookie (a Set-Cookie response header),
|
||||||
// ranking still produces a sane "no promotion" outcome against
|
// which is page evidence just like SCRIPT and so must outrank both
|
||||||
// PRE_EXISTING/EXTENSION/SCRIPT existing values.
|
// browser-extension state and the PRE_EXISTING catch-all — otherwise a
|
||||||
|
// cookie first enumerated as PRE_EXISTING and later re-observed only
|
||||||
|
// via Set-Cookie would stay PRE_EXISTING and remain agent-skipped.
|
||||||
|
// EXTENSION is high-confidence extension state; PRE_EXISTING (and nil)
|
||||||
|
// is the low-signal catch-all.
|
||||||
func sourceRank(s *coredata.CookieSource) int {
|
func sourceRank(s *coredata.CookieSource) int {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return 0
|
return 0
|
||||||
@@ -716,6 +720,8 @@ func sourceRank(s *coredata.CookieSource) int {
|
|||||||
|
|
||||||
switch *s {
|
switch *s {
|
||||||
case coredata.CookieSourceScript:
|
case coredata.CookieSourceScript:
|
||||||
|
return 3
|
||||||
|
case coredata.CookieSourceHTTP:
|
||||||
return 2
|
return 2
|
||||||
case coredata.CookieSourceExtension:
|
case coredata.CookieSourceExtension:
|
||||||
return 1
|
return 1
|
||||||
@@ -733,17 +739,19 @@ func shouldPromoteSource(existing, candidate *coredata.CookieSource) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// bestSource rolls up the source values of a group of exact patterns
|
// bestSource rolls up the source values of a group of exact patterns
|
||||||
// being merged into a single glob. Precedence is SCRIPT > EXTENSION
|
// being merged into a single glob. Precedence is SCRIPT > HTTP >
|
||||||
// > PRE_EXISTING, mirroring both the page-script-wins rule in
|
// EXTENSION > PRE_EXISTING, mirroring the asymmetric signal strength of
|
||||||
// detected_trackers and the asymmetric signal strength of each
|
// each bucket: SCRIPT is high-confidence page evidence (a real page
|
||||||
// bucket: SCRIPT is high-confidence page evidence (a real page
|
// tracker), HTTP is a real server-set cookie (a Set-Cookie response
|
||||||
// tracker), EXTENSION is high-confidence extension evidence, and
|
// header) and is page evidence too, EXTENSION is high-confidence
|
||||||
// PRE_EXISTING is the catch-all that may include extension state
|
// extension state, and PRE_EXISTING is the catch-all that may include
|
||||||
// injected before SDK load. HTTP and nil collapse into PRE_EXISTING
|
// extension state injected before SDK load. nil collapses into
|
||||||
// here, preserving the original two-value rollup behaviour for
|
// PRE_EXISTING.
|
||||||
// non-script values.
|
|
||||||
func bestSource(patterns []*coredata.TrackerPattern) *coredata.CookieSource {
|
func bestSource(patterns []*coredata.TrackerPattern) *coredata.CookieSource {
|
||||||
var hasExtension bool
|
var (
|
||||||
|
hasHTTP bool
|
||||||
|
hasExtension bool
|
||||||
|
)
|
||||||
|
|
||||||
for _, p := range patterns {
|
for _, p := range patterns {
|
||||||
if p.Source == nil {
|
if p.Source == nil {
|
||||||
@@ -753,20 +761,25 @@ func bestSource(patterns []*coredata.TrackerPattern) *coredata.CookieSource {
|
|||||||
switch *p.Source {
|
switch *p.Source {
|
||||||
case coredata.CookieSourceScript:
|
case coredata.CookieSourceScript:
|
||||||
return p.Source
|
return p.Source
|
||||||
|
case coredata.CookieSourceHTTP:
|
||||||
|
hasHTTP = true
|
||||||
case coredata.CookieSourceExtension:
|
case coredata.CookieSourceExtension:
|
||||||
hasExtension = true
|
hasExtension = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasExtension {
|
switch {
|
||||||
|
case hasHTTP:
|
||||||
|
src := coredata.CookieSourceHTTP
|
||||||
|
return &src
|
||||||
|
case hasExtension:
|
||||||
src := coredata.CookieSourceExtension
|
src := coredata.CookieSourceExtension
|
||||||
return &src
|
return &src
|
||||||
}
|
default:
|
||||||
|
|
||||||
src := coredata.CookieSourcePreExisting
|
src := coredata.CookieSourcePreExisting
|
||||||
|
|
||||||
return &src
|
return &src
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// inheritedMapping rolls up the resolved org ThirdParty of a group of
|
// inheritedMapping rolls up the resolved org ThirdParty of a group of
|
||||||
// exact patterns being merged into a glob, so the glob can be seeded
|
// exact patterns being merged into a glob, so the glob can be seeded
|
||||||
|
|||||||
@@ -1159,15 +1159,45 @@ func TestShouldPromoteSource(t *testing.T) {
|
|||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "HTTP collapses to PRE_EXISTING rank: does not promote SCRIPT",
|
name: "HTTP does not promote to SCRIPT (HTTP ranks below SCRIPT)",
|
||||||
existing: &script,
|
existing: &script,
|
||||||
candidate: &http,
|
candidate: &http,
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "HTTP collapses to PRE_EXISTING rank: equal to nil existing",
|
name: "nil existing promotes to HTTP",
|
||||||
existing: nil,
|
existing: nil,
|
||||||
candidate: &http,
|
candidate: &http,
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "PRE_EXISTING promotes to HTTP",
|
||||||
|
existing: &preExisting,
|
||||||
|
candidate: &http,
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "EXTENSION promotes to HTTP (real server cookie outranks extension state)",
|
||||||
|
existing: &extension,
|
||||||
|
candidate: &http,
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HTTP promotes to SCRIPT",
|
||||||
|
existing: &http,
|
||||||
|
candidate: &script,
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HTTP does not promote to EXTENSION",
|
||||||
|
existing: &http,
|
||||||
|
candidate: &extension,
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HTTP does not promote to PRE_EXISTING",
|
||||||
|
existing: &http,
|
||||||
|
candidate: &preExisting,
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user