Skip to content

Commit e4542e0

Browse files
committed
fix: reject malformed honeypot timestamps
1 parent 1151013 commit e4542e0

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
- Ignore malformed honeypot timestamps instead of raising an exception.
78
- Update contributor branch workflow guidance and PR CI to target `main`.
89

910
## [1.3.0] - 2026-04-21

tests/test_form.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ def test_form_submission_is_ignored_when_honeypot_time_is_too_short(self):
102102
self.assert_submission_count(0)
103103
self.assertContains(resp, "Thank you for your message")
104104

105+
def test_form_submission_is_ignored_when_honeypot_time_is_invalid(self):
106+
for value in ("", "not-a-timestamp"):
107+
with self.subTest(value=value):
108+
resp = self.post_form(whf_time=value)
109+
self.assert_submission_count(0)
110+
self.assertContains(resp, "Thank you for your message")
111+
105112
def test_form_submission_is_ignored_when_honeypot_text_is_filled(self):
106113
"""
107114
Test that a form submission is unsuccessful

tests/test_methods.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ def test_time_diff_thresholds(self, mock_time):
2929
for label, submitted_time, expected in cases:
3030
with self.subTest(label=label):
3131
self.assertEqual(self.form.time_diff(submitted_time, self.interval), expected)
32+
33+
def test_time_diff_rejects_invalid_values(self):
34+
cases = [
35+
("empty string", ""),
36+
("non-numeric string", "not-a-timestamp"),
37+
("none", None),
38+
]
39+
40+
for label, submitted_time in cases:
41+
with self.subTest(label=label):
42+
self.assertFalse(self.form.time_diff(submitted_time, self.interval))

wagtail_honeypot/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def process_form_submission(self, form):
4444
@staticmethod
4545
def time_diff(value, interval):
4646
now_time = str(time.time()).split(".")[0]
47-
diff = abs(int(now_time) - int(value))
47+
try:
48+
submitted_time = int(value)
49+
except (TypeError, ValueError):
50+
return False
51+
diff = abs(int(now_time) - submitted_time)
4852
return True if diff > interval else False
4953

5054
class Meta:

0 commit comments

Comments
 (0)