There is a big problem with tgcaptcha. It is very easy to bypass
tgcaptcha just by crafting a call to the method /send without the
captcha information.
This call gives you an error 'Incorrect value' which is normal.
But this one works without a problem. The tgcaptcha.validator is never
called.
http://127.0.0.1:8080/send?name=dddd
I don't have enough knowledge of turbogears widget yet, to understand
how to fix this.
-fred-
Here is the sample code I used:
from turbogears import (controllers, expose, flash, validate,
error_handler, exception_handler)
from turbogears import widgets, validators
from tgcaptcha import CaptchaField
class TestForm(widgets.WidgetsList):
name = widgets.TextField(
validator=validators.NotEmpty(),
label="Name:")
captcha = CaptchaField(
label=' ',
help_text=_("Enter the text shown in the image"))
form = widgets.TableForm(fields=TestForm(), method="GET",
action="/send", submit_text=_("Send"),)
class Root(controllers.RootController):
@expose(template="jojo.templates.welcome")
def index(self, **kw):
print '-' * 78
print kw
return dict(form=form)
@expose()
@validate(form=form)
@error_handler(index)
def send(self, **kw):
return kw
Yes I did some experiments and I came to the same conclusion. The
problem seems to be with CompoundFormFields. These fields are
validated only if a reference to that widget is present in the URL.
I have posted a messages on the TG mailing list but I never got any
answer. Maybe because the mail subject was TGCaptcha...
-fred-