New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a honeypot field to collections.add form to catch spammy bots (bug 1211012). #828
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
import commonware.log | ||
from tower import ugettext as _, ugettext_lazy as _lazy | ||
from django_statsd.clients import statsd | ||
|
||
import amo | ||
from amo.utils import clean_nl, has_links, slug_validator, slugify | ||
|
@@ -48,7 +49,6 @@ class AddonsForm(Form): | |
required=False) | ||
|
||
def clean_addon(self): | ||
|
||
addons = [] | ||
for a in self.data.getlist('addon'): | ||
try: | ||
|
@@ -136,13 +136,30 @@ class CollectionForm(ModelForm): | |
icon = forms.FileField(label=_lazy(u'Icon'), | ||
required=False) | ||
|
||
# This is just a honeypot field for bots to get caught | ||
# L10n: bots is short for robots | ||
your_name = forms.CharField( | ||
label=_lazy( | ||
u"Please don't fill out this field, it's used to catch bots"), | ||
required=False) | ||
|
||
def __init__(self, *args, **kw): | ||
super(CollectionForm, self).__init__(*args, **kw) | ||
# You can't edit the slugs for the special types. | ||
if (self.instance and | ||
self.instance.type in amo.COLLECTION_SPECIAL_SLUGS): | ||
del self.fields['slug'] | ||
|
||
def clean(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could instead be done in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I didn't wanted it related to a field in the error messages so that it could be shown eventually at the top of the form in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. So please add a comment explaining that ;) thanks! |
||
# Check the honeypot here instead of 'clean_your_name' so the | ||
# error message appears at the top of the form in the __all__ section | ||
if self.cleaned_data['your_name']: | ||
statsd.incr('collections.honeypotted') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in addition to this, I'd suggest also adding a log statement because grepping the logs could be helpful |
||
log.info('Bot trapped in honeypot at collections.create') | ||
raise forms.ValidationError( | ||
"You've been flagged as spam, sorry about that.") | ||
return super(CollectionForm, self).clean() | ||
|
||
def clean_name(self): | ||
name = self.cleaned_data['name'] | ||
if BlacklistedName.blocked(name): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3396,6 +3396,11 @@ td.input { | |
padding: 1em; | ||
} | ||
|
||
/* Hide this honeypot field for our users */ | ||
.collection-create input[name="your_name"] { | ||
display: none; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe some (most?) of the bots out there know how to detect a |
||
} | ||
|
||
.contributor span { | ||
position: relative; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add a comment above this formatted like
# L10n: bots is short for robots
then the localizers will see it in their web interface. It might help them out since English colloquialism can trip them up.