forked from SAML-Toolkits/python3-saml
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate server_port from request data dictionary
`server_port` is unnecessary, since the HTTP Host header sent by the client already includes any non-standard port. In addition, when the Python application server is sitting behind a reverse proxy/TLS terminator, SERVER_PORT is likely to be wrong anyway (since it would be the server port of the non-reverse-proxied server). See SAML-Toolkits#273 (comment)
- Loading branch information
Showing
8 changed files
with
24 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
""" | ||
|
||
import base64 | ||
import warnings | ||
from copy import deepcopy | ||
import calendar | ||
from datetime import datetime | ||
|
@@ -254,27 +255,25 @@ def get_self_url_host(request_data): | |
:rtype: string | ||
""" | ||
current_host = OneLogin_Saml2_Utils.get_self_host(request_data) | ||
port = '' | ||
if OneLogin_Saml2_Utils.is_https(request_data): | ||
protocol = 'https' | ||
else: | ||
protocol = 'http' | ||
|
||
if 'server_port' in request_data and request_data['server_port'] is not None: | ||
port_number = str(request_data['server_port']) | ||
port = ':' + port_number | ||
protocol = 'https' if OneLogin_Saml2_Utils.is_https(request_data) else 'http' | ||
|
||
if protocol == 'http' and port_number == '80': | ||
port = '' | ||
elif protocol == 'https' and port_number == '443': | ||
port = '' | ||
if request_data.get('server_port') is not None: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
akx
Author
Owner
|
||
warnings.warn( | ||
'The server_port key in request data is deprecated. ' | ||
'The http_host key should include a port, if required.', | ||
category=DeprecationWarning, | ||
) | ||
port_suffix = ':%s' % request_data['server_port'] | ||
if not current_host.endswith(port_suffix): | ||
if not ((protocol == 'https' and port_suffix == ':443') or (protocol == 'http' and port_suffix == ':80')): | ||
current_host += port_suffix | ||
|
||
return '%s://%s%s' % (protocol, current_host, port) | ||
return '%s://%s' % (protocol, current_host) | ||
|
||
@staticmethod | ||
def get_self_host(request_data): | ||
""" | ||
Returns the current host. | ||
Returns the current host (which may include a port number part). | ||
:param request_data: The request as a dict | ||
:type: dict | ||
|
@@ -283,22 +282,11 @@ def get_self_host(request_data): | |
:rtype: string | ||
""" | ||
if 'http_host' in request_data: | ||
current_host = request_data['http_host'] | ||
return request_data['http_host'] | ||
elif 'server_name' in request_data: | ||
current_host = request_data['server_name'] | ||
else: | ||
raise Exception('No hostname defined') | ||
|
||
if ':' in current_host: | ||
current_host_data = current_host.split(':') | ||
possible_port = current_host_data[-1] | ||
try: | ||
int(possible_port) | ||
current_host = current_host_data[0] | ||
except ValueError: | ||
current_host = ':'.join(current_host_data) | ||
|
||
return current_host | ||
warnings.warn("The server_name key in request data is undocumented & deprecated.", category=DeprecationWarning) | ||
return request_data['server_name'] | ||
raise Exception('No hostname defined') | ||
|
||
@staticmethod | ||
def is_https(request_data): | ||
|
@@ -312,6 +300,7 @@ def is_https(request_data): | |
:rtype: boolean | ||
""" | ||
is_https = 'https' in request_data and request_data['https'] != 'off' | ||
# TODO: this use of server_port should be removed too | ||
This comment has been minimized.
Sorry, something went wrong.
pitbulk
|
||
is_https = is_https or ('server_port' in request_data and str(request_data['server_port']) == '443') | ||
return is_https | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1534,8 +1534,7 @@ def testIsInValidEncIssues(self): | |
settings_2 = OneLogin_Saml2_Settings(settings_info_2) | ||
|
||
request_data = { | ||
'http_host': 'pytoolkit.com', | ||
'server_port': 8000, | ||
'http_host': 'pytoolkit.com:8000', | ||
This comment has been minimized.
Sorry, something went wrong.
pitbulk
|
||
'script_name': '', | ||
'request_uri': '?acs', | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In the Readme you are using
but in the demo-flask/index.py it still uses:
May it be updated as well?