Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions mig/server/grid_openid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -116,7 +116,7 @@
from mig.shared.tlsserver import hardened_ssl_context
from mig.shared.url import urlparse, urlencode, check_local_site_url, \
parse_qsl
from mig.shared.useradm import get_openid_user_dn, check_password_scramble, \

Check warning on line 119 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
check_hash
from mig.shared.userdb import default_db_path
from mig.shared.validstring import possible_user_id
Expand All @@ -130,12 +130,12 @@
cert_field_map.update({'role': 'ROLE', 'timezone': 'TZ', 'nickname': 'NICK',
'fullname': 'CN', 'o': 'O', 'ou': 'OU'})
cert_field_names = list(cert_field_map)
cert_field_values = list(cert_field_map.values())

Check failure on line 133 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'cert_field_values' (60% confidence)
cert_field_aliases = {}

# NOTE: response may contain password on the form
# (<Symbol Bare namespace>, 'password'): 'S3cr3tP4ssw0rd'
pw_pattern = "\(<Symbol Bare namespace>, 'password'\): '(.+)'"

Check warning on line 138 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

invalid escape sequence '\)'

Check warning on line 138 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

invalid escape sequence '\('
pw_regexp = re.compile(pw_pattern)


Expand All @@ -158,7 +158,7 @@
def valid_cert_fields(arg):
"""Make sure only valid cert field names are allowed"""
valid_job_id(arg, extra_chars=',')
if [i for i in arg.split(',') if not i in cert_field_names]:

Check warning on line 161 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
invalid_argument(arg)


Expand Down Expand Up @@ -303,7 +303,7 @@

# Add our own SReg fields to list of valid fields from sreg 1.1 spec
for (key, val) in cert_field_map.items():
if not key in sreg.data_fields:

Check warning on line 306 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
sreg.data_fields[key] = key.replace('_', ' ').title()
# print "DEBUG: sreg fields: %s" % sreg.data_fields
for name in cert_field_names:
Expand Down Expand Up @@ -397,11 +397,19 @@
cookies = self.headers.get('Cookie')
cookie = http.cookies.SimpleCookie(cookies)
cookie_dict = dict((k, v.value) for k, v in cookie.items())
retry_url = cookie_dict.get('retry_url', '')
retry_url_enc = cookie_dict.get('retry_url_enc', '')
logger.debug("found retry_url_enc: %s" % retry_url_enc)
if retry_url_enc:
# NOTE: b64decode takes str and returns bytes
retry_url = force_native_str(base64.b64decode(retry_url_enc))
else:
retry_url = ''
logger.debug("decoded retry_url: %s" % retry_url)
if retry_url and retry_url.startswith("http"):
raise InputException("invalid retry_url: %s" % retry_url)
elif retry_url:
valid_url(retry_url)
# NOTE: we get here with /openid/id/EMAIL as retry_url
valid_url(retry_url, extra_chars='@')
except http.cookies.CookieError as err:
retry_url = None
logger.error("found invalid cookie: %s" % err)
Expand All @@ -411,15 +419,40 @@

return retry_url

def __format_retry_url_for_cookie(self):
"""Format retry_url to fit in cookie"""
if self.retry_url is None:
retry_url = ''
else:
retry_url = self.retry_url
# NOTE: prevent header injection from cookie or header splitting
retry_url = retry_url.replace('\r', '').replace('\n', '')
logger.debug("encoding retry_url: %s" % retry_url)
try:
# NOTE: we get here with /openid/id/EMAIL as retry_url
valid_url(retry_url, extra_chars='@')
except InputException as exc:
retry_url = ''
logger.error("found invalid retry_url: %s" % exc)

# NOTE: b64encode takes bytes and returns bytes
enc = force_native_str(base64.b64encode(force_utf8(retry_url)))
logger.debug("encoded retry_url: %s" % enc)
cookie = http.cookies.SimpleCookie()
cookie['retry_url_enc'] = enc
cookie['retry_url_enc']['secure'] = True
cookie['retry_url_enc']['httponly'] = True
return cookie.output(header='').strip()

def clearUser(self):
"""Reset all saved user variables"""
self.user = None
self.user_dn = None

Check failure on line 450 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused attribute 'user_dn' (60% confidence)
self.user_dn_dir = None

Check failure on line 451 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused attribute 'user_dn_dir' (60% confidence)
self.password = None
self.login_expire = None

def do_GET(self):

Check failure on line 455 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused method 'do_GET' (60% confidence)
"""Handle all HTTP GET requests"""
# Make sure key is always available for exception handler
key = 'UNSET'
Expand All @@ -442,7 +475,7 @@
# Resolve retry url, strip password and err

retry_query = {key: val for (key, val) in self.query.items()
if not key in ['password', 'err']}

Check warning on line 478 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
self.retry_url = "%s?%s" \
% (self.parsed_uri[2], urlencode(retry_query))

Expand Down Expand Up @@ -507,7 +540,7 @@
</p>""" % (configuration.support_email, error_ref)
self.showErrorPage(err_msg, error_code=500)

def do_POST(self):

Check failure on line 543 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused method 'do_POST' (60% confidence)
"""Handle all HTTP POST requests"""
try:
# NOTE: force native string even if socketserver provides bytes
Expand Down Expand Up @@ -634,7 +667,7 @@
# Old IE 8 does not send contents of submit buttons thus only the
# fields login_as and password are set with the allow requests. We
# manually add a yes here if so to avoid the else case.
if not 'yes' in query and not 'no' in query:

Check warning on line 670 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
query['yes'] = 'yes'

if 'yes' in query:
Expand Down Expand Up @@ -721,7 +754,7 @@
logger.warning("handleAllow rejected login %s" % identity)
# logger.debug("full query: %s" % self.query)
# logger.debug("full headers: %s" % self.headers)
fail_user, fail_pw = self.user, self.password

Check failure on line 757 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'fail_user' (60% confidence)

Check failure on line 757 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'fail_pw' (60% confidence)
self.clearUser()
# Login failed - return to refering page to let user try again
retry_url = self.__retry_url_from_cookie()
Expand Down Expand Up @@ -852,7 +885,7 @@
self.addSRegResponse(request, response)
return response

def rejected(self, request, identifier=None):

Check failure on line 888 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused method 'rejected' (60% confidence)
"""Reject helper"""
response = request.answer(False, identity=identifier)
return response
Expand Down Expand Up @@ -941,7 +974,7 @@
allow_legacy):
logger.info("Accepted password hash login for %s from %s" %
(username, addr))
self.user_dn = distinguished_name

Check failure on line 977 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused attribute 'user_dn' (60% confidence)
self.user_dn_dir = client_id_dir(distinguished_name)
self.login_expire = int(time.time() + self.session_ttl)
return True
Expand Down Expand Up @@ -1268,7 +1301,7 @@
</fieldset>
</form>
<p>
<a href="%(sid_url)s/cgi-sid/reqpwreset.py?show=migoid">Forgot your password?

Check warning on line 1304 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (89 > 80 characters)
</a>
</p>
</div>
Expand Down Expand Up @@ -1304,7 +1337,7 @@
<input type="checkbox" id="remember" name="remember" value="yes"
/><label for="remember">Remember this
decision</label><br />
Password: <input type="password" name="password" autofocus /><br />

Check warning on line 1340 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
<input type="submit" name="yes" value="yes" />
<input type="submit" name="no" value="no" />
</form>
Expand Down Expand Up @@ -1473,7 +1506,7 @@

<p>The URL for this server is
<a href=%s><span class="verbatim">%s</span></a>.</p>
''' % (user_message, quoteattr(self.server.base_url), self.server.base_url))

Check warning on line 1509 in mig/server/grid_openid.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (84 > 80 characters)

def showLoginPage(self, success_to, fail_to, query):
"""Login page provider"""
Expand Down Expand Up @@ -1578,8 +1611,7 @@

self.send_response(response_code)
self.writeUserHeader()
self.send_header('Set-Cookie', 'retry_url=%s;secure;httponly'
% self.retry_url)
self.send_header('Set-Cookie', self.__format_retry_url_for_cookie())
self.send_header('Content-type', 'text/html')
self.end_headers()
page_template = openid_page_template(configuration, head_extras)
Expand Down
Loading