Add first-party verdict and guards to tracker mapping

The tracker-pattern catalog was binary (linked to a vendor or not), so
generic and first-party artifacts (loglevel keys, wallet-extension keys,
an org's own trackers) were retried forever and, once one row was wrongly
attributed, re-propagated to every organization with no re-check.

Give catalog rows a terminal attribution verdict (UNDETERMINED,
THIRD_PARTY, FIRST_PARTY): FIRST_PARTY short-circuits the whole mapping
pipeline so the artifact is never attributed again. Gate deterministic
vendor adoption behind a trust bar so only curated/operator rows
auto-propagate; lower-confidence agent/heuristic rows are reused as hints
and re-resolved, and an independent agent re-confirmation corroborates and
promotes them. Make the mapping agent emit an evidence source and reject
any attribution that lacks concrete evidence, and let it declare a
first-party verdict. Skip the speculative agent for PRE_EXISTING-source
patterns, whose low signal invites invented vendors.

Add proboctl "ctp mark-first-party" and an --attribution list filter to
audit and remediate existing wrong links, and a cursor rule documenting
migration naming so the timestamp is taken from date -u, not invented.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-06-16 13:51:31 +02:00
parent 1faa60bfba
commit 7723b33aec
16 changed files with 1277 additions and 48 deletions

View File

@@ -42,6 +42,7 @@ func NewCmdCommonTrackerPattern(f *cmdutil.Factory) *cobra.Command {
cmd.AddCommand(newCmdStats(f))
cmd.AddCommand(newCmdLink(f))
cmd.AddCommand(newCmdUnlink(f))
cmd.AddCommand(newCmdMarkFirstParty(f))
cmd.AddCommand(newCmdSetDescription(f))
return cmd

View File

@@ -36,6 +36,7 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
flagLinkedOrg string
flagKeyword string
flagState string
flagAttribution string
flagWithCommonThirdParty bool
flagWithoutDescription bool
flagSort string
@@ -57,6 +58,7 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
cmd.Flags().StringVar(&flagLinkedOrg, "linked-org", "", "Filter to catalog rows linked to an organization's patterns (GID)")
cmd.Flags().StringVar(&flagKeyword, "keyword", "", "Filter by pattern/description substring")
cmd.Flags().StringVar(&flagState, "state", "", "Filter by enrichment state (queued, enriched, unenriched)")
cmd.Flags().StringVar(&flagAttribution, "attribution", "", "Filter by attribution verdict (UNDETERMINED, THIRD_PARTY, FIRST_PARTY)")
cmd.Flags().BoolVar(&flagWithCommonThirdParty, "with-common-third-party", false, "Filter by whether the pattern is linked to a common third party (true/false); ignored when not set")
cmd.Flags().BoolVar(&flagWithoutDescription, "without-description", false, "Only patterns with a blank description")
cmd.Flags().StringVar(&flagSort, "sort", "confidence", "Sort field: pattern, confidence, created, updated, attempted")
@@ -93,7 +95,7 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
described = new(false)
}
filter, err := buildListFilter(flagTrackerType, flagMatchType, flagKeyword, flagState, withCommonThirdParty, described)
filter, err := buildListFilter(flagTrackerType, flagMatchType, flagKeyword, flagState, flagAttribution, withCommonThirdParty, described)
if err != nil {
return err
}
@@ -229,7 +231,7 @@ func renderPatternTable(cmd *cobra.Command, f *cmdutil.Factory, patterns coredat
return err
}
table := clicmdutil.NewTable("ID", "TYPE", "MATCH", "PATTERN", "CONF", "STATE", "THIRD PARTY", "LAST ATTEMPT", "CREATED", "UPDATED")
table := clicmdutil.NewTable("ID", "TYPE", "MATCH", "PATTERN", "CONF", "VERDICT", "STATE", "THIRD PARTY", "LAST ATTEMPT", "CREATED", "UPDATED")
for _, p := range patterns {
thirdParty := ""
@@ -248,6 +250,7 @@ func renderPatternTable(cmd *cobra.Command, f *cmdutil.Factory, patterns coredat
string(p.MatchType),
p.Pattern,
fmt.Sprintf("%.2f", p.Confidence),
string(p.Attribution),
enrichmentState(p),
thirdParty,
lastAttempt,
@@ -309,7 +312,7 @@ func parseOrderBy(sort, order string) (page.OrderBy[coredata.CommonTrackerPatter
}
func buildListFilter(
trackerType, matchType, keyword, state string,
trackerType, matchType, keyword, state, attribution string,
withCommonThirdParty, described *bool,
) (*coredata.CommonTrackerPatternFilter, error) {
filter := coredata.NewCommonTrackerPatternFilter()
@@ -345,6 +348,15 @@ func buildListFilter(
filter.WithState(&st)
}
if attribution != "" {
attr := coredata.CommonTrackerPatternAttribution(attribution)
if !attr.IsValid() {
return nil, fmt.Errorf("invalid --attribution value %q: valid values are UNDETERMINED, THIRD_PARTY, FIRST_PARTY", attribution)
}
filter.WithAttribution(&attr)
}
if withCommonThirdParty != nil {
filter.WithLinked(withCommonThirdParty)
}

View File

@@ -0,0 +1,148 @@
// 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.
package commontrackerpattern
import (
"context"
"fmt"
"github.com/spf13/cobra"
"go.gearno.de/kit/pg"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/proboctl/cmdutil"
)
func newCmdMarkFirstParty(f *cmdutil.Factory) *cobra.Command {
var (
flagIDs []string
flagLinkedBanner string
flagLinkedOrg string
flagCommonThirdParty string
flagTrackerType string
flagKeyword string
flagState string
flagWithoutDescription bool
flagDryRun bool
flagYes bool
)
cmd := &cobra.Command{
Use: "mark-first-party",
Short: "Mark common tracker patterns as first-party (no third party)",
Long: "Record the terminal FIRST_PARTY verdict on selected common tracker " +
"patterns: the artifact has no third party (it is the scanned site's own, " +
"a generic library/log key, or an extension key embedding the site origin). " +
"Any vendor link is cleared, and the uncategorised org tracker patterns " +
"linked to them are remapped (org third party cleared, mapping re-armed) so " +
"the pipeline drops the stale vendor; because the verdict is terminal the " +
"mapping worker leaves them unattributed. User-categorised and excluded org " +
"patterns are left untouched. Selection mirrors 'reenrich'. To re-attribute " +
"a row later, use 'link' (which returns it to THIRD_PARTY).",
Args: cobra.NoArgs,
}
cmd.Flags().StringSliceVar(&flagIDs, "id", nil, "Common tracker pattern GID(s) to mark (repeatable)")
cmd.Flags().StringVar(&flagLinkedBanner, "linked-banner", "", "Select catalog rows linked to a cookie banner's patterns (GID)")
cmd.Flags().StringVar(&flagLinkedOrg, "linked-org", "", "Select catalog rows linked to an organization's patterns (GID)")
cmd.Flags().StringVar(&flagCommonThirdParty, "common-third-party", "", "Select patterns currently linked to a common third party (slug or GID)")
cmd.Flags().StringVar(&flagTrackerType, "tracker-type", "", "Filter selected patterns by tracker type")
cmd.Flags().StringVar(&flagKeyword, "keyword", "", "Filter selected patterns by a pattern/description substring")
cmd.Flags().StringVar(&flagState, "state", "", "Filter selected patterns by enrichment state (queued, enriched, unenriched)")
cmd.Flags().BoolVar(&flagWithoutDescription, "without-description", false, "Only patterns with a blank description")
cmd.Flags().BoolVar(&flagDryRun, "dry-run", false, "Print the selected patterns without marking")
cmd.Flags().BoolVar(&flagYes, "yes", false, "Skip confirmation")
cmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
pgClient, err := f.PgClient()
if err != nil {
return err
}
ids, err := resolveReenrichIDs(
ctx,
pgClient,
flagIDs,
flagLinkedBanner,
flagLinkedOrg,
flagCommonThirdParty,
flagTrackerType,
flagKeyword,
flagState,
flagWithoutDescription,
)
if err != nil {
return err
}
out := f.IOStreams.Out
if len(ids) == 0 {
_, _ = fmt.Fprintln(out, "No common tracker patterns matched the selection.")
return nil
}
if flagDryRun {
_, _ = fmt.Fprintf(out, "Would mark %d common tracker pattern(s) as first-party.\n", len(ids))
printSample(out, ids)
return nil
}
if !flagYes {
return fmt.Errorf("about to mark %d pattern(s) as first-party; pass --yes to proceed or --dry-run to preview", len(ids))
}
var (
marked int64
remapped int64
)
if err := pgClient.WithTx(
ctx,
func(ctx context.Context, tx pg.Tx) error {
var ps coredata.CommonTrackerPatterns
marked, err = ps.SetAttributionByIDs(ctx, tx, ids, coredata.CommonTrackerPatternAttributionFirstParty)
if err != nil {
return err
}
var tps coredata.TrackerPatterns
remapped, err = tps.RequestMappingForUncategorisedByCommonTrackerPatternIDs(ctx, tx, ids)
if err != nil {
return err
}
return nil
},
); err != nil {
return fmt.Errorf("cannot mark common tracker patterns first-party: %w", err)
}
_, _ = fmt.Fprintf(
out,
"Marked %d pattern(s) first-party, remapped %d uncategorised org tracker pattern(s).\n",
marked,
remapped,
)
return nil
}
return cmd
}

View File

@@ -137,6 +137,7 @@ func renderPatternDetail(f *cmdutil.Factory, p coredata.CommonTrackerPattern, th
row("Match type:", string(p.MatchType))
row("Pattern:", p.Pattern)
row("Confidence:", fmt.Sprintf("%.2f", p.Confidence))
row("Verdict:", string(p.Attribution))
row("State:", enrichmentState(&p))
if p.MaxAgeSeconds != nil {

View File

@@ -136,6 +136,11 @@ func NewCmdCommonTrackerPatterns(f *cmdutil.Factory) *cobra.Command {
continue
}
attribution := coredata.CommonTrackerPatternAttributionUndetermined
if thirdPartyID != nil {
attribution = coredata.CommonTrackerPatternAttributionThirdParty
}
pattern := coredata.CommonTrackerPattern{
ID: gid.New(gid.NilTenant, coredata.CommonTrackerPatternEntityType),
CommonThirdPartyID: thirdPartyID,
@@ -145,6 +150,7 @@ func NewCmdCommonTrackerPatterns(f *cmdutil.Factory) *cobra.Command {
Description: p.Description,
MaxAgeSeconds: p.MaxAgeSeconds,
Confidence: p.Confidence,
Attribution: attribution,
CreatedAt: now,
UpdatedAt: now,
}