Skip to content

Commit 82dd2cd

Browse files
committed
Switched to SystemRandom() and updated README w/ correct Twitter links. Fixes CVE-2013-4347. Closes #146. Closes #137.
1 parent 25f46b8 commit 82dd2cd

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ consumer = oauth.Consumer(key="your-twitter-consumer-key",
6060
secret="your-twitter-consumer-secret")
6161

6262
# Request token URL for Twitter.
63-
request_token_url = "http://twitter.com/oauth/request_token"
63+
request_token_url = "https://api.twitter.com/oauth/request_token"
6464

6565
# Create our client.
6666
client = oauth.Client(consumer)
@@ -84,9 +84,9 @@ import oauth2 as oauth
8484
consumer_key = 'my_key_from_twitter'
8585
consumer_secret = 'my_secret_from_twitter'
8686

87-
request_token_url = 'http://twitter.com/oauth/request_token'
88-
access_token_url = 'http://twitter.com/oauth/access_token'
89-
authorize_url = 'http://twitter.com/oauth/authorize'
87+
request_token_url = 'https://api.twitter.com/oauth/request_token'
88+
access_token_url = 'https://api.twitter.com/oauth/access_token'
89+
authorize_url = 'https://api.twitter.com/oauth/authorize'
9090

9191
consumer = oauth.Consumer(consumer_key, consumer_secret)
9292
client = oauth.Client(consumer)
@@ -145,7 +145,7 @@ print
145145

146146
# Logging into Django w/ Twitter
147147

148-
Twitter also has the ability to authenticate a user [via an OAuth flow](http://apiwiki.twitter.com/Sign-in-with-Twitter). This
148+
Twitter also has the ability to authenticate a user [via an OAuth flow](https://dev.twitter.com/docs/auth/sign-twitter). This
149149
flow is exactly like the three-legged OAuth flow, except you send them to a
150150
slightly different URL to authorize them.
151151

@@ -221,11 +221,11 @@ from mytwitterapp.models import Profile
221221
consumer = oauth.Consumer(settings.TWITTER_TOKEN, settings.TWITTER_SECRET)
222222
client = oauth.Client(consumer)
223223

224-
request_token_url = 'http://twitter.com/oauth/request_token'
225-
access_token_url = 'http://twitter.com/oauth/access_token'
224+
request_token_url = 'https://api.twitter.com/oauth/request_token'
225+
access_token_url = 'https://api.twitter.com/oauth/access_token'
226226

227227
# This is the slightly different URL used to authenticate/authorize.
228-
authenticate_url = 'http://twitter.com/oauth/authenticate'
228+
authenticate_url = 'https://api.twitter.com/oauth/authenticate'
229229

230230
def twitter_login(request):
231231
# Step 1. Get a request token from Twitter.
@@ -254,6 +254,7 @@ def twitter_authenticated(request):
254254
# Step 1. Use the request token in the session to build a new client.
255255
token = oauth.Token(request.session['request_token']['oauth_token'],
256256
request.session['request_token']['oauth_token_secret'])
257+
token.set_verifier(request.GET['oauth_verifier'])
257258
client = oauth.Client(consumer, token)
258259

259260
# Step 2. Request the authorized access token from Twitter.

oauth2/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ def generate_timestamp():
164164

165165
def generate_nonce(length=8):
166166
"""Generate pseudorandom number."""
167-
return ''.join([str(random.randint(0, 9)) for i in range(length)])
167+
return ''.join([str(random.SystemRandom().randint(0, 9)) for i in range(length)])
168168

169169

170170
def generate_verifier(length=8):
171171
"""Generate pseudorandom number."""
172-
return ''.join([str(random.randint(0, 9)) for i in range(length)])
172+
return ''.join([str(random.SystemRandom().randint(0, 9)) for i in range(length)])
173173

174174

175175
class Consumer(object):
@@ -509,7 +509,7 @@ def make_timestamp(cls):
509509
@classmethod
510510
def make_nonce(cls):
511511
"""Generate pseudorandom number."""
512-
return str(random.randint(0, 100000000))
512+
return str(random.SystemRandom().randint(0, 100000000))
513513

514514
@classmethod
515515
def from_request(cls, http_method, http_url, headers=None, parameters=None,

0 commit comments

Comments
 (0)