Avoid leaking our credentials via a nefarious API request
This commit is contained in:
1 parent
d5f97abe8d
commit
33f2e6d5df
1 file changed
+8
-1
+8
-1
@@ -134,14 +134,21 @@ def getBranch(request, errors, name):
|
|||||||
target = repo.replace('github.com', 'api.github.com/repos')
|
target = repo.replace('github.com', 'api.github.com/repos')
|
||||||
target = pathjoin(target, url, branch).rstrip('/')
|
target = pathjoin(target, url, branch).rstrip('/')
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
|
# 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'):
|
if os.path.exists('credentials'):
|
||||||
with open('credentials') as fin:
|
with open('credentials') as fin:
|
||||||
user, token = fin.readlines()[0].rstrip().split()
|
user, token = fin.readlines()[0].rstrip().split()
|
||||||
auth = requests.auth.HTTPBasicAuth(user, token)
|
auth = requests.auth.HTTPBasicAuth(user, token)
|
||||||
else: auth = None
|
else: auth = None
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
data = requests.get(target, auth=auth).json()
|
data = requests.get(target, auth=auth).json()
|
||||||
data = data if bysha else data['commit']
|
data = data if bysha else data['commit']
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user