Opened 4 years ago

Closed 4 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: Obfuscation/BridgeDB Version:
Severity: Keywords: bridgedb-https, bridgedb-0.1.6, easy
Cc: isis, sysrqb Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

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/http.py", line 1349, in dataReceived
    finishCallback(data[contentLength:])
  File "/usr/lib/python2.7/dist-packages/twisted/web/http.py", line 1563, in _finishRequestBody
    self.allContentReceived()
  File "/usr/lib/python2.7/dist-packages/twisted/web/http.py", line 1618, in allContentReceived
    req.requestReceived(command, path, version)
  File "/usr/lib/python2.7/dist-packages/twisted/web/http.py", line 773, in requestReceived
    self.process()
--- <exception caught here> ---
  File "/usr/lib/python2.7/dist-packages/twisted/web/server.py", line 132, in process
    self.render(resrc)
  File "/usr/lib/python2.7/dist-packages/twisted/web/server.py", line 167, in render
    body = resrc.render(self)
  File "/usr/lib/python2.7/dist-packages/twisted/web/resource.py", line 216, in render
    return m(request)
  File "/srv/bridges.torproject.org/local/lib/python2.7/site-packages/bridgedb-0.1.5_dirty-py2.7.egg/bridgedb/HTTPServer.py", line 470, in render_POST
    return CaptchaProtectedResource.render_POST(self, request)
  File "/srv/bridges.torproject.org/local/lib/python2.7/site-packages/bridgedb-0.1.5_dirty-py2.7.egg/bridgedb/HTTPServer.py", line 220, in render_POST
    if self.checkSolution(request):
  File "/srv/bridges.torproject.org/local/lib/python2.7/site-packages/bridgedb-0.1.5_dirty-py2.7.egg/bridgedb/HTTPServer.py", 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 4 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 4 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 4 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.