-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Django strategy should respect X-Forwarded-Port #841
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't
80
be the default? Orself.request.META['SERVER_PORT']
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only hit this code path if the port is 80 or 443, in which case it will be stripped anyway: https://github.com/onelogin/python-saml/blob/efb2515e0a12fb43271d5d6b8bddcbaa4a61f451/src/onelogin/saml2/utils.py#L268-L271
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So shouldn't the
except AttributeError:
path just returnself.request.META['SERVER_PORT']
then instead of splitting the host?Or does looking at the port from get_host() emulate using
USE_X_FORWARDED_PORT
? In that case, it seems like theexcept IndexError:
should still fall back toself.request.META['SERVER_PORT']
so we get at least80
or443
rather thanNone
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USE_X_FORWARDED_PORT
was introduced in django 1.9, and if we're on theexcept AttributeError:
path it means we're using an older version so we can't use that setting. In this case,get_host()
will respect theUSE_X_FORWARDED_HOST
setting, and the reverse proxy can be configured to pass the port along with theX-Forwarded-Host
header.If you prefer we can fallback to using
self.request.META['SERVER_PORT']
fromexcept IndexError:
. The behaviour would be the same, as the port would just be stripped in the python-saml code later on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should note - I have not authority over this repo whatsoever, I'm just a fellow user of PSA, trying to help out if I can :)
I'm worried about the behavior staying the same because things other than
python-saml
might be relying onget_port()
. Seems like the behavior in PSA shouldn't change dramatically (possibly returningNone
now) because of starting to useUSE_X_FORWARDED_HOST
. So yeah it seems like falling back to old behavior when nothing else works might be more likely to result in the PR getting merged, but that's just my guess.