From b9fb1b7c59a26120d2e3a776d992e48d87e58c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Thu, 12 Nov 2026 11:58:09 -0300 Subject: [PATCH 1/3] Flag Gravity Forms forms whose honeypot throws caught submissions away A form with its honeypot set to "Do not create an entry" loses every real person the honeypot catches (a stale page failing state validation) without a trace. The retention check now lists those forms, one review flag per site, so they can be set to keep caught submissions as spam. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 ++ check_retention.go | 19 +++++++++++++++++++ check_test.go | 5 ++++- collector.php | 11 +++++++++-- facts.go | 14 ++++++++++++-- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b7daaeb..a35b3ed 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ It flags: - personal data kept with no end: Gravity Forms forms with entries over two years old and no retention period, and shops with orders over two years old that never anonymise completed orders. Only counts and dates are collected +- Gravity Forms forms whose honeypot throws caught submissions away instead + of keeping them as spam: a real person it catches is lost without a trace On a multisite every site is covered; facts from sites other than the main one are tagged with their blog id, and network admins show as `super_admin`. diff --git a/check_retention.go b/check_retention.go index b430733..06a8d8d 100644 --- a/check_retention.go +++ b/check_retention.go @@ -51,6 +51,25 @@ func (c *checker) retention() { len(s.ids), s.entries, s.oldest.Format("2006-01-02")), Untrusted: fmt.Sprintf("blog %d: %s", b, strings.Join(s.list, "; "))}) } + // Forms throwing away what their honeypot catches, one flag per site. + hp := map[int][]FormHoneypot{} + var hpBlogs []int + for _, f := range r.Honeypot { + if hp[f.Blog] == nil { + hpBlogs = append(hpBlogs, f.Blog) + } + hp[f.Blog] = append(hp[f.Blog], f) + } + for _, b := range hpBlogs { + var ids, list []string + for _, f := range hp[b] { + ids = append(ids, fmt.Sprint(f.FormID)) + list = append(list, fmt.Sprintf("form %d %q", f.FormID, f.Title)) + } + c.flag(Flag{ID: fmt.Sprintf("retention:honeypot:%d:%s", b, short(ids...)), Severity: Review, Kind: KindRetention, + Message: fmt.Sprintf("%d forms throw away what their honeypot catches, so a real person it catches (a stale page failing state validation) is lost unseen: set Form Settings → Spam to keep them as spam", len(ids)), + Untrusted: fmt.Sprintf("blog %d: %s", b, strings.Join(list, "; "))}) + } for _, w := range r.Woo { t, isOld := old(w.Oldest) if w.Orders == 0 || !isOld || w.Settings["anonymize_completed_orders"] != "" { diff --git a/check_test.go b/check_test.go index 8a76ce6..3c1dd3d 100644 --- a/check_test.go +++ b/check_test.go @@ -257,9 +257,12 @@ func TestRetention(t *testing.T) { {Blog: 1, Orders: 5000, Oldest: "2018-05-01 00:00:00", Settings: map[string]string{"anonymize_completed_orders": "", "delete_inactive_accounts": "24 months"}}, {Blog: 2, Orders: 10, Oldest: "2018-05-01 00:00:00", Settings: map[string]string{"anonymize_completed_orders": "7 years"}}, }, + Honeypot: []FormHoneypot{{Blog: 2, FormID: 4, Title: "Contest"}, {Blog: 2, FormID: 6, Title: "Contact"}}, } got := kind(judge(nil, s, Policy{}, nil), KindRetention) - if len(got) != 2 || !strings.HasPrefix(got[0].ID, "retention:forms:1:") || !strings.Contains(got[0].Message, "1 forms keep every entry (900") || got[1].ID != "retention:woo:1" { + if len(got) != 3 || !strings.HasPrefix(got[0].ID, "retention:forms:1:") || !strings.Contains(got[0].Message, "1 forms keep every entry (900") || + !strings.HasPrefix(got[1].ID, "retention:honeypot:2:") || !strings.HasPrefix(got[1].Message, "2 forms throw away what their honeypot catches") || + got[1].Untrusted != `blog 2: form 4 "Contest"; form 6 "Contact"` || got[2].ID != "retention:woo:1" { t.Fatalf("retention flags %+v", got) } } diff --git a/collector.php b/collector.php index c14a102..eaead78 100644 --- a/collector.php +++ b/collector.php @@ -339,16 +339,23 @@ function_exists('proc_nice') && @proc_nice(19); // How long personal data is kept: per Gravity Forms form its entry count, // oldest entry and retention setting; per WooCommerce shop its order count, // oldest order and the anonymise/delete settings. Counts and dates only. -$wpda['retention'] = ['forms' => [], 'woo' => []]; +// Also every active form whose honeypot throws a caught submission away +// instead of keeping it as spam: a real person caught by it is lost unseen. +$wpda['retention'] = ['forms' => [], 'woo' => [], 'honeypot' => []]; empty($wpda_skip['retention']) && $wpda_each(function (int $blog) use ($wpdb, &$wpda) { $has = fn (string $t) => (bool) $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($t))); $p = $wpdb->prefix; if ($has("{$p}gf_entry") && $has("{$p}gf_form")) { $meta = []; if ($has("{$p}gf_form_meta")) { - foreach ($wpdb->get_results("SELECT form_id, display_meta FROM {$p}gf_form_meta") as $m) { + $sql = "SELECT m.form_id, m.display_meta, f.title, f.is_active, f.is_trash FROM {$p}gf_form_meta m JOIN {$p}gf_form f ON f.id = m.form_id"; + foreach ($wpdb->get_results($sql) as $m) { $d = json_decode((string) $m->display_meta, true); $meta[(int) $m->form_id] = $d['personalData']['retention'] ?? []; + // Unset is spam since Gravity Forms 2.9.8. + if (!empty($d['enableHoneypot']) && ($d['honeypotAction'] ?? 'spam') === 'abort' && $m->is_active && !$m->is_trash) { + $wpda['retention']['honeypot'][] = ['blog' => $blog, 'form_id' => (int) $m->form_id, 'title' => substr((string) $m->title, 0, 120)]; + } } } $sql = "SELECT f.id, f.title, COUNT(e.id) AS n, MIN(e.date_created) AS oldest FROM {$p}gf_form f diff --git a/facts.go b/facts.go index 4fb677b..7d99467 100644 --- a/facts.go +++ b/facts.go @@ -199,8 +199,18 @@ type PluginChecksum struct { // RetentionFacts is how long personal data is kept: counts, dates and settings. type RetentionFacts struct { - Forms []FormRetention `json:"forms"` - Woo []WooRetention `json:"woo"` + Forms []FormRetention `json:"forms"` + Woo []WooRetention `json:"woo"` + Honeypot []FormHoneypot `json:"honeypot"` +} + +// FormHoneypot is an active Gravity Forms form whose honeypot throws caught +// submissions away (Spam → "Do not create an entry") instead of keeping them +// as spam. +type FormHoneypot struct { + Blog int `json:"blog"` + FormID int `json:"form_id"` + Title string `json:"title"` } // FormRetention is one Gravity Forms form: Policy is its Personal Data From 79aa16f84e6eda34841cb1ccd230cb274aafe6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Thu, 12 Nov 2026 12:18:03 -0300 Subject: [PATCH 2/3] Flag CleanTalk deleting the Gravity Forms entries it judges spam Unless its "save Gravity Forms spam" setting is on, CleanTalk deletes the entry, so a real person it catches is lost. One review flag per blog. Co-Authored-By: Claude Opus 5.5 --- README.md | 3 ++- check_retention.go | 5 +++++ check_test.go | 10 ++++++---- collector.php | 11 ++++++++++- facts.go | 3 +++ 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a35b3ed..d43b877 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,8 @@ It flags: years old and no retention period, and shops with orders over two years old that never anonymise completed orders. Only counts and dates are collected - Gravity Forms forms whose honeypot throws caught submissions away instead - of keeping them as spam: a real person it catches is lost without a trace + of keeping them as spam, and CleanTalk deleting the Gravity Forms entries + it judges spam: a real person either catches is lost without a trace On a multisite every site is covered; facts from sites other than the main one are tagged with their blog id, and network admins show as `super_admin`. diff --git a/check_retention.go b/check_retention.go index 06a8d8d..1f5b741 100644 --- a/check_retention.go +++ b/check_retention.go @@ -70,6 +70,11 @@ func (c *checker) retention() { Message: fmt.Sprintf("%d forms throw away what their honeypot catches, so a real person it catches (a stale page failing state validation) is lost unseen: set Form Settings → Spam to keep them as spam", len(ids)), Untrusted: fmt.Sprintf("blog %d: %s", b, strings.Join(list, "; "))}) } + for _, b := range r.CleanTalkDeletes { + c.flag(Flag{ID: fmt.Sprintf("retention:cleantalk:%d", b), Severity: Review, Kind: KindRetention, + Message: "CleanTalk deletes the Gravity Forms entries it judges spam, so a real person it catches is lost unseen: turn on its setting to save Gravity Forms spam", + Untrusted: fmt.Sprintf("blog %d", b)}) + } for _, w := range r.Woo { t, isOld := old(w.Oldest) if w.Orders == 0 || !isOld || w.Settings["anonymize_completed_orders"] != "" { diff --git a/check_test.go b/check_test.go index 3c1dd3d..69fbbad 100644 --- a/check_test.go +++ b/check_test.go @@ -257,12 +257,14 @@ func TestRetention(t *testing.T) { {Blog: 1, Orders: 5000, Oldest: "2018-05-01 00:00:00", Settings: map[string]string{"anonymize_completed_orders": "", "delete_inactive_accounts": "24 months"}}, {Blog: 2, Orders: 10, Oldest: "2018-05-01 00:00:00", Settings: map[string]string{"anonymize_completed_orders": "7 years"}}, }, - Honeypot: []FormHoneypot{{Blog: 2, FormID: 4, Title: "Contest"}, {Blog: 2, FormID: 6, Title: "Contact"}}, + Honeypot: []FormHoneypot{{Blog: 2, FormID: 4, Title: "Contest"}, {Blog: 2, FormID: 6, Title: "Contact"}}, + CleanTalkDeletes: []int{3}, } got := kind(judge(nil, s, Policy{}, nil), KindRetention) - if len(got) != 3 || !strings.HasPrefix(got[0].ID, "retention:forms:1:") || !strings.Contains(got[0].Message, "1 forms keep every entry (900") || - !strings.HasPrefix(got[1].ID, "retention:honeypot:2:") || !strings.HasPrefix(got[1].Message, "2 forms throw away what their honeypot catches") || - got[1].Untrusted != `blog 2: form 4 "Contest"; form 6 "Contact"` || got[2].ID != "retention:woo:1" { + if len(got) != 4 || got[0].ID != "retention:cleantalk:3" || !strings.HasPrefix(got[0].Message, "CleanTalk deletes") || + !strings.HasPrefix(got[1].ID, "retention:forms:1:") || !strings.Contains(got[1].Message, "1 forms keep every entry (900") || + !strings.HasPrefix(got[2].ID, "retention:honeypot:2:") || !strings.HasPrefix(got[2].Message, "2 forms throw away what their honeypot catches") || + got[2].Untrusted != `blog 2: form 4 "Contest"; form 6 "Contact"` || got[3].ID != "retention:woo:1" { t.Fatalf("retention flags %+v", got) } } diff --git a/collector.php b/collector.php index eaead78..bf57711 100644 --- a/collector.php +++ b/collector.php @@ -341,7 +341,7 @@ function_exists('proc_nice') && @proc_nice(19); // oldest order and the anonymise/delete settings. Counts and dates only. // Also every active form whose honeypot throws a caught submission away // instead of keeping it as spam: a real person caught by it is lost unseen. -$wpda['retention'] = ['forms' => [], 'woo' => [], 'honeypot' => []]; +$wpda['retention'] = ['forms' => [], 'woo' => [], 'honeypot' => [], 'cleantalk_deletes' => []]; empty($wpda_skip['retention']) && $wpda_each(function (int $blog) use ($wpdb, &$wpda) { $has = fn (string $t) => (bool) $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($t))); $p = $wpdb->prefix; @@ -372,6 +372,15 @@ function_exists('proc_nice') && @proc_nice(19); 'days' => (int) ($r['retain_entries_days'] ?? 0), ]; } + // CleanTalk deletes the Gravity Forms entries it judges spam unless + // its "save spam" setting is on. + $plugin = 'cleantalk-spam-protect/cleantalk.php'; + $ct = get_option('cleantalk_settings'); + $active = in_array($plugin, (array) get_option('active_plugins', []), true) + || (is_multisite() && isset(((array) get_site_option('active_sitewide_plugins', []))[$plugin])); + if ($active && is_array($ct) && !empty($ct['forms__contact_forms_test']) && empty($ct['forms__gravityforms_save_spam'])) { + $wpda['retention']['cleantalk_deletes'][] = $blog; + } } if (get_option('woocommerce_version') === false) { return; diff --git a/facts.go b/facts.go index 7d99467..3b441cd 100644 --- a/facts.go +++ b/facts.go @@ -202,6 +202,9 @@ type RetentionFacts struct { Forms []FormRetention `json:"forms"` Woo []WooRetention `json:"woo"` Honeypot []FormHoneypot `json:"honeypot"` + // CleanTalkDeletes are the blogs where CleanTalk deletes the Gravity + // Forms entries it judges spam (its "save spam" setting off). + CleanTalkDeletes []int `json:"cleantalk_deletes"` } // FormHoneypot is an active Gravity Forms form whose honeypot throws caught From 0b40b791c68e35b66b12de3a03255ae46bcbdf1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Thu, 12 Nov 2026 14:33:57 -0300 Subject: [PATCH 3/3] Flag a Gravity Forms state token lifespan under a year and a day Gravity Forms rejects every submission from a page cached longer than its state token lives (48 h by default). Where Gravity Forms is active, the collector reads gform_state_lifespan as mu-plugins set it and the check flags anything under 366 days. Co-Authored-By: Claude Opus 5.5 --- check_retention.go | 21 +++++++++++++++++++++ check_test.go | 7 +++++-- collector.php | 11 ++++++++++- facts.go | 9 +++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/check_retention.go b/check_retention.go index 1f5b741..535239d 100644 --- a/check_retention.go +++ b/check_retention.go @@ -10,6 +10,10 @@ import ( // a retention setting is flagged. const RetentionAfter = 2 * 365 * 24 * time.Hour +// StateLifespanMin is the shortest Gravity Forms state token lifespan that +// outlives any page cache: a year and a day. +const StateLifespanMin = 366 * 24 * time.Hour + // retention: forms and shops keeping personal data past RetentionAfter with // no setting that ends it. One flag per site's forms, its ID covering them, // so accepting holds until another form starts keeping old entries. @@ -70,6 +74,23 @@ func (c *checker) retention() { Message: fmt.Sprintf("%d forms throw away what their honeypot catches, so a real person it catches (a stale page failing state validation) is lost unseen: set Form Settings → Spam to keep them as spam", len(ids)), Untrusted: fmt.Sprintf("blog %d: %s", b, strings.Join(list, "; "))}) } + // A state token shorter than StateLifespanMin, one flag per site: a + // cached page older than it has every submission rejected. + var brief []string + least := 0 + for _, s := range r.StateLifespan { + if s.Seconds < int(StateLifespanMin.Seconds()) { + brief = append(brief, fmt.Sprint(s.Blog)) + if least == 0 || s.Seconds < least { + least = s.Seconds + } + } + } + if len(brief) > 0 { + c.flag(Flag{ID: "retention:state-lifespan", Severity: Review, Kind: KindRetention, + Message: fmt.Sprintf("Gravity Forms' state token lasts %d h, so every submission from a page cached longer is rejected: set gform_state_lifespan to 366 days in a mu-plugin (a theme's filter doesn't count here)", least/3600), + Untrusted: "blogs " + strings.Join(brief, ", ")}) + } for _, b := range r.CleanTalkDeletes { c.flag(Flag{ID: fmt.Sprintf("retention:cleantalk:%d", b), Severity: Review, Kind: KindRetention, Message: "CleanTalk deletes the Gravity Forms entries it judges spam, so a real person it catches is lost unseen: turn on its setting to save Gravity Forms spam", diff --git a/check_test.go b/check_test.go index 69fbbad..76ce6c1 100644 --- a/check_test.go +++ b/check_test.go @@ -259,12 +259,15 @@ func TestRetention(t *testing.T) { }, Honeypot: []FormHoneypot{{Blog: 2, FormID: 4, Title: "Contest"}, {Blog: 2, FormID: 6, Title: "Contact"}}, CleanTalkDeletes: []int{3}, + StateLifespan: []StateLifespan{{Blog: 1, Seconds: 366 * 86400}, {Blog: 2, Seconds: 7 * 86400}, {Blog: 3, Seconds: 2 * 86400}}, } got := kind(judge(nil, s, Policy{}, nil), KindRetention) - if len(got) != 4 || got[0].ID != "retention:cleantalk:3" || !strings.HasPrefix(got[0].Message, "CleanTalk deletes") || + if len(got) != 5 || got[0].ID != "retention:cleantalk:3" || !strings.HasPrefix(got[0].Message, "CleanTalk deletes") || !strings.HasPrefix(got[1].ID, "retention:forms:1:") || !strings.Contains(got[1].Message, "1 forms keep every entry (900") || !strings.HasPrefix(got[2].ID, "retention:honeypot:2:") || !strings.HasPrefix(got[2].Message, "2 forms throw away what their honeypot catches") || - got[2].Untrusted != `blog 2: form 4 "Contest"; form 6 "Contact"` || got[3].ID != "retention:woo:1" { + got[2].Untrusted != `blog 2: form 4 "Contest"; form 6 "Contact"` || + got[3].ID != "retention:state-lifespan" || !strings.HasPrefix(got[3].Message, "Gravity Forms' state token lasts 48 h") || got[3].Untrusted != "blogs 2, 3" || + got[4].ID != "retention:woo:1" { t.Fatalf("retention flags %+v", got) } } diff --git a/collector.php b/collector.php index bf57711..87264ce 100644 --- a/collector.php +++ b/collector.php @@ -341,7 +341,7 @@ function_exists('proc_nice') && @proc_nice(19); // oldest order and the anonymise/delete settings. Counts and dates only. // Also every active form whose honeypot throws a caught submission away // instead of keeping it as spam: a real person caught by it is lost unseen. -$wpda['retention'] = ['forms' => [], 'woo' => [], 'honeypot' => [], 'cleantalk_deletes' => []]; +$wpda['retention'] = ['forms' => [], 'woo' => [], 'honeypot' => [], 'cleantalk_deletes' => [], 'state_lifespan' => []]; empty($wpda_skip['retention']) && $wpda_each(function (int $blog) use ($wpdb, &$wpda) { $has = fn (string $t) => (bool) $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($t))); $p = $wpdb->prefix; @@ -381,6 +381,15 @@ function_exists('proc_nice') && @proc_nice(19); if ($active && is_array($ct) && !empty($ct['forms__contact_forms_test']) && empty($ct['forms__gravityforms_save_spam'])) { $wpda['retention']['cleantalk_deletes'][] = $blog; } + // How long a rendered form's state token stays valid: Gravity Forms + // rejects submissions from a page cached longer. Its default is 48 h; + // only mu-plugins can raise it here (themes and plugins aren't loaded). + $gf = 'gravityforms/gravityforms.php'; + if (in_array($gf, (array) get_option('active_plugins', []), true) + || (is_multisite() && isset(((array) get_site_option('active_sitewide_plugins', []))[$gf]))) { + $life = apply_filters('gform_state_lifespan', 2 * DAY_IN_SECONDS, 0); + $wpda['retention']['state_lifespan'][] = ['blog' => $blog, 'seconds' => is_int($life) ? $life : 2 * DAY_IN_SECONDS]; + } } if (get_option('woocommerce_version') === false) { return; diff --git a/facts.go b/facts.go index 3b441cd..f642208 100644 --- a/facts.go +++ b/facts.go @@ -205,6 +205,15 @@ type RetentionFacts struct { // CleanTalkDeletes are the blogs where CleanTalk deletes the Gravity // Forms entries it judges spam (its "save spam" setting off). CleanTalkDeletes []int `json:"cleantalk_deletes"` + // StateLifespan is, per blog with Gravity Forms active, how long its + // state token stays valid as mu-plugins set it (gform_state_lifespan). + StateLifespan []StateLifespan `json:"state_lifespan"` +} + +// StateLifespan is one blog's Gravity Forms state token lifespan. +type StateLifespan struct { + Blog int `json:"blog"` + Seconds int `json:"seconds"` } // FormHoneypot is an active Gravity Forms form whose honeypot throws caught