Opened 6 years ago

Closed 6 years ago

#11218 closed defect (fixed)

bridgedb.HTTPServer.ReCaptchaProtectedResource.checkSolution() doesn't expect a deferred

Reported by: isis Owned by: isis
Priority: Immediate Milestone:
Component: Circumvention/BridgeDB Version:
Severity: Keywords: bridgedb-https, bridgedb-0.1.6, easy
Cc: isis, sysrqb Actual Points:
Parent ID: Points:
Reviewer: Sponsor:


From bridgedb-0.1.5, bridgedb.HTTPServer.ReCaptchaProtectedResource.checkSolution() expects a bool for the solution internal variable, not a t.i.defer.Deferred:

Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/web/", line 1349, in dataReceived
  File "/usr/lib/python2.7/dist-packages/twisted/web/", line 1563, in _finishRequestBody
  File "/usr/lib/python2.7/dist-packages/twisted/web/", line 1618, in allContentReceived
    req.requestReceived(command, path, version)
  File "/usr/lib/python2.7/dist-packages/twisted/web/", line 773, in requestReceived
--- <exception caught here> ---
  File "/usr/lib/python2.7/dist-packages/twisted/web/", line 132, in process
  File "/usr/lib/python2.7/dist-packages/twisted/web/", line 167, in render
    body = resrc.render(self)
  File "/usr/lib/python2.7/dist-packages/twisted/web/", line 216, in render
    return m(request)
  File "/srv/", line 470, in render_POST
    return CaptchaProtectedResource.render_POST(self, request)
  File "/srv/", line 220, in render_POST
    if self.checkSolution(request):
  File "/srv/", line 432, in checkSolution
    if solution.is_valid:
exceptions.AttributeError: Deferred instance has no attribute 'is_valid'

Should be easy, just reorder the current code to make solution.is_valid be checked inside a callback function on the deferred returned from txrecaptcha.submit(). See the test_submit_resultIsRecaptchaResponse() unittest for an example of how it was designed to work.

Child Tickets

Change History (3)

comment:1 Changed 6 years ago by isis

Resolution: fixed
Status: newclosed

Fixed in my fix/11218-deferred-solution-isvalid branch. Merged for bridgedb-0.1.6 (since it's a technically hotfix to get 0.1.5 to run).

comment:2 Changed 6 years ago by isis

Resolution: fixed
Status: closedreopened

There is a new error in that if you solve a reCaptcha CAPTCHA correctly (and the logs show that the reCaptcha API server even returns true in the response HTML), the deferred from checkSolution() causes the page to redirect to a new CAPTCHA.

To fix this, we'll need to handle writing the response asynchronously, and, if I recall correctly, return twisted.web.server.NOT_DONE_YET from all of the HTTPServer.ReCaptchaProtectedResource.render_* methods.

comment:3 Changed 6 years ago by isis

Resolution: fixed
Status: reopenedclosed

Fixed in my hotfix/11218-async-render branch, unittests added also.

Note: See TracTickets for help on using tickets.