Skip to content

Fixed csrf failures #374

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ You can install Geeknote as a python script.
$ [sudo] apt-get update; [sudo] apt-get -y install python-setuptools

# Download the repository.
$ git clone git://github.com/VitaliyRodnenko/geeknote.git
$ git clone git://github.com/pipakin/geeknote.git

$ cd geeknote

Expand Down
43 changes: 39 additions & 4 deletions geeknote/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
from urllib import urlencode, unquote
from urlparse import urlparse
from lxml import html

import out
import tools
Expand Down Expand Up @@ -42,6 +43,7 @@ class GeekNoteAuth(object):
'oauth_token': None,
'oauth_callback': None,
'embed': 'false',
'expireMillis': '31536000000',
},
'tfa': {
'code': '',
Expand Down Expand Up @@ -72,7 +74,7 @@ def getTokenRequestData(self, **kwargs):

return params

def loadPage(self, url, uri=None, method="GET", params=""):
def loadPage(self, url, uri=None, method="GET", params="", additionalParams=""):
if not url:
logging.error("Request URL undefined")
tools.exitErr()
Expand All @@ -84,7 +86,7 @@ def loadPage(self, url, uri=None, method="GET", params=""):

# prepare params, append to uri
if params:
params = urlencode(params)
params = urlencode(params) + additionalParams
if method == "GET":
uri += ('?' if uri.find('?') == -1 else '&') + params
params = ""
Expand Down Expand Up @@ -239,16 +241,49 @@ def login(self):
#self.allowAccess(response.location)

def allowAccess(self):
response = self.loadPage(self.url['base'],
self.url['access'],
"GET",
{'oauth_token': self.tmpOAuthToken})

logging.debug(response.data)
tree = html.fromstring(response.data);
token = "&" + urlencode({ 'csrfBusterToken': tree.xpath("//input[@name='csrfBusterToken']/@value")[0]}) + "&" + urlencode({ 'csrfBusterToken': tree.xpath("//input[@name='csrfBusterToken']/@value")[1]})
sourcePage = tree.xpath("//input[@name='_sourcePage']/@value")[0]
fp = tree.xpath("//input[@name='__fp']/@value")[0]
targetUrl = tree.xpath("//input[@name='targetUrl']/@value")[0]
logging.debug(token);

if response.status != 200:
logging.error("Unexpected response status "
"on login 200 != %s", response.status)
tools.exitErr()

if 'JSESSIONID' not in self.cookies:
logging.error("Not found value JSESSIONID in the response cookies")
tools.exitErr()

access = self.postData['access']
access['oauth_token'] = self.tmpOAuthToken
access['oauth_callback'] = "https://" + self.url['base']
access['oauth_callback'] = ""
access['embed'] = 'false'
access['suggestedNotebookName'] = 'Geeknote'
access['supportLinkedSandbox'] = ''
access['analyticsLoginOrigin'] = 'Other'
access['clipperFlow'] = 'false'
access['showSwitchService'] = 'true'
access['_sourcePage'] = sourcePage
access['__fp'] = fp
access['targetUrl'] = targetUrl

response = self.loadPage(self.url['base'],
self.url['access'],
"POST", access)
"POST", access, token)

if response.status != 302:
logging.error("Unexpected response status on allowing "
"access 302 != %s", response.status)
logging.error(response.data)
tools.exitErr()

responseData = self.parseResponse(response.location)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def install_autocomplite(self):
'sqlalchemy',
'markdown2',
'beautifulsoup4',
'thrift'
'thrift',
'lxml'
],

entry_points={
Expand Down