Avoid leaking our credentials via a nefarious API request
This commit is contained in:
1 parent
d5f97abe8d
commit
33f2e6d5df
1 file changed
+14
-7
+14
-7
@@ -134,14 +134,21 @@ def getBranch(request, errors, name):
|
||||
target = repo.replace('github.com', 'api.github.com/repos')
|
||||
target = pathjoin(target, url, branch).rstrip('/')
|
||||
|
||||
|
||||
# Avoid leaking our credentials to other sites
|
||||
if not target.startswith('https://api.github.com/'):
|
||||
errors.append('OpenBench may only reach Github\'s API')
|
||||
return (None, None, None, None)
|
||||
|
||||
# Check for a (User, Token) credentials file
|
||||
if os.path.exists('credentials'):
|
||||
with open('credentials') as fin:
|
||||
user, token = fin.readlines()[0].rstrip().split()
|
||||
auth = requests.auth.HTTPBasicAuth(user, token)
|
||||
else: auth = None
|
||||
|
||||
|
||||
try:
|
||||
|
||||
if os.path.exists('credentials'):
|
||||
with open('credentials') as fin:
|
||||
user, token = fin.readlines()[0].rstrip().split()
|
||||
auth = requests.auth.HTTPBasicAuth(user, token)
|
||||
else: auth = None
|
||||
|
||||
data = requests.get(target, auth=auth).json()
|
||||
data = data if bysha else data['commit']
|
||||
|
||||
|
||||
Reference in new issue
Block a user