Browse Source

gist: send csrf token

raylu 12 years ago
parent
commit
1dabca00cc
1 changed files with 7 additions and 0 deletions
  1. 7 0
      gist

+ 7 - 0
gist

@@ -2,6 +2,7 @@
 
 import argparse
 import os.path
+import re
 import requests
 import sys
 
@@ -30,17 +31,23 @@ else:
         else:
           args.language = r.json()['language'] # new requests behavior
 
+r = rs.get('https://gist.github.com/') # also gets _gist_session cookie
+match = re.search('<meta content="([A-Za-z0-9+/]+=*)" name="csrf-token" />', r.content)
+csrf_token = match.group(1)
 content = f.read()
 data = {
     'gist[description]': '',
     'gist[files][][content]': content,
     'gist[files][][language]': args.language,
     'gist[files][][name]': args.filename,
+    'gist[files][][oid]': '',
     'gist[public]': 0,
     'indent': 'Tabs',
+    'authenticity_token': csrf_token,
 }
 r = rs.post('https://gist.github.com/gists', data=data, allow_redirects=False)
 if 'location' in r.headers:
     print r.headers['location']
 else:
     print r.headers['status']
+    print '\n' + r.content