diff --git a/README.md b/README.md index b7daaeb..d43b877 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,9 @@ 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, 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 b430733..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. @@ -51,6 +55,47 @@ 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, "; "))}) + } + // 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", + 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 8a76ce6..76ce6c1 100644 --- a/check_test.go +++ b/check_test.go @@ -257,9 +257,17 @@ 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"}}, + 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) != 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) != 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: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 c14a102..87264ce 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' => [], '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; 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 @@ -365,6 +372,24 @@ 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; + } + // 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 4fb677b..f642208 100644 --- a/facts.go +++ b/facts.go @@ -199,8 +199,30 @@ 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"` + // 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 +// 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