Amend refererer

XCC can struggle with link local addresses. Simplify by just using a
static fake name so that XCC treats
it like maybe some unknown
/etc/hosts entry on the client.

Change-Id: I1c6dc9d3eb86ae876c24441a924bcff4720b53ac
This commit is contained in:
Jarrod Johnson
2020-08-05 08:27:09 -04:00
parent 51608edee9
commit 01b75d78c4
3 changed files with 8 additions and 8 deletions

View File

@@ -965,22 +965,20 @@ class XCCClient(IMMClient):
return None return None
if not login: if not login:
return wc return wc
srv = self.imm
if ':' in srv:
srv = '[{0}]'.format(self.imm)
referer = 'https://{0}/'.format(srv)
adata = json.dumps({'username': self.username, adata = json.dumps({'username': self.username,
'password': self.password 'password': self.password
}) })
headers = {'Connection': 'keep-alive', headers = {'Connection': 'keep-alive',
'Referer': referer, 'Referer': 'https://xcc/',
'Host': 'xcc',
'Content-Type': 'application/json'} 'Content-Type': 'application/json'}
wc.request('POST', '/api/login', adata, headers) wc.request('POST', '/api/login', adata, headers)
rsp = wc.getresponse() rsp = wc.getresponse()
if rsp.status == 200: if rsp.status == 200:
rspdata = json.loads(rsp.read()) rspdata = json.loads(rsp.read())
wc.set_header('Content-Type', 'application/json') wc.set_header('Content-Type', 'application/json')
wc.set_header('Referer', referer) wc.set_header('Referer', 'https://xcc/')
wc.set_header('Host', 'xcc')
wc.set_header('Authorization', 'Bearer ' + rspdata['access_token']) wc.set_header('Authorization', 'Bearer ' + rspdata['access_token'])
if '_csrf_token' in wc.cookies: if '_csrf_token' in wc.cookies:
wc.set_header('X-XSRF-TOKEN', wc.cookies['_csrf_token']) wc.set_header('X-XSRF-TOKEN', wc.cookies['_csrf_token'])

View File

@@ -463,12 +463,13 @@ class OEMHandler(generic.OEMHandler):
return None return None
if not login: if not login:
return wc return wc
referer = 'https://{0}/'.format(wc.thehost) referer = 'https://xcc/'
adata = json.dumps({'username': self.username, adata = json.dumps({'username': self.username,
'password': self.password 'password': self.password
}) })
headers = {'Connection': 'keep-alive', headers = {'Connection': 'keep-alive',
'Referer': referer, 'Referer': referer,
'Host': 'xcc',
'Content-Type': 'application/json'} 'Content-Type': 'application/json'}
wc.request('POST', '/api/login', adata, headers) wc.request('POST', '/api/login', adata, headers)
rsp = wc.getresponse() rsp = wc.getresponse()
@@ -477,6 +478,7 @@ class OEMHandler(generic.OEMHandler):
wc.set_header('Content-Type', 'application/json') wc.set_header('Content-Type', 'application/json')
wc.set_header('Authorization', 'Bearer ' + rspdata['access_token']) wc.set_header('Authorization', 'Bearer ' + rspdata['access_token'])
wc.set_header('Referer', referer) wc.set_header('Referer', referer)
wc.set_header('Host', 'xcc')
if '_csrf_token' in wc.cookies: if '_csrf_token' in wc.cookies:
wc.set_header('X-XSRF-TOKEN', wc.cookies['_csrf_token']) wc.set_header('X-XSRF-TOKEN', wc.cookies['_csrf_token'])
return wc return wc

View File

@@ -141,7 +141,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
self.cert_reqs = ssl.CERT_NONE # use custom validation self.cert_reqs = ssl.CERT_NONE # use custom validation
else: else:
self.cert_reqs = ssl.CERT_REQUIRED # use standard validation self.cert_reqs = ssl.CERT_REQUIRED # use standard validation
if '[' not in host and '%' in host: if '[' not in host and '%' in host and 'Host'not in self.stdheaders:
self.stdheaders['Host'] = '[' + host[:host.find('%')] + ']' self.stdheaders['Host'] = '[' + host[:host.find('%')] + ']'
def dupe(self): def dupe(self):